That fuck shit the fascists are using
1package org.tm.archive.keyvalue;
2
3import android.content.Context;
4import android.net.Uri;
5
6import androidx.annotation.NonNull;
7import androidx.annotation.Nullable;
8
9import org.signal.core.util.logging.Log;
10import org.tm.archive.database.model.databaseprotos.Wallpaper;
11import org.tm.archive.wallpaper.ChatWallpaper;
12import org.tm.archive.wallpaper.ChatWallpaperFactory;
13import org.tm.archive.wallpaper.WallpaperStorage;
14
15import java.io.IOException;
16import java.util.Collections;
17import java.util.List;
18
19public final class WallpaperValues extends SignalStoreValues {
20
21 private static final String TAG = Log.tag(WallpaperValues.class);
22
23 private static final String KEY_WALLPAPER = "wallpaper.wallpaper";
24
25 WallpaperValues(@NonNull KeyValueStore store) {
26 super(store);
27 }
28
29 @Override
30 void onFirstEverAppLaunch() {
31 }
32
33 @Override
34 @NonNull List<String> getKeysToIncludeInBackup() {
35 return Collections.emptyList();
36 }
37
38 public void setWallpaper(@NonNull Context context, @Nullable ChatWallpaper wallpaper) {
39 Wallpaper currentWallpaper = getCurrentWallpaper();
40 Uri currentUri = null;
41
42 if (currentWallpaper != null && currentWallpaper.file_ != null) {
43 currentUri = Uri.parse(currentWallpaper.file_.uri);
44 }
45
46 if (wallpaper != null) {
47 putBlob(KEY_WALLPAPER, wallpaper.serialize().encode());
48 } else {
49 getStore().beginWrite().remove(KEY_WALLPAPER).apply();
50 }
51
52 if (currentUri != null) {
53 WallpaperStorage.onWallpaperDeselected(context, currentUri);
54 }
55 }
56
57 public @Nullable ChatWallpaper getWallpaper() {
58 Wallpaper currentWallpaper = getCurrentWallpaper();
59
60 if (currentWallpaper != null) {
61 return ChatWallpaperFactory.create(currentWallpaper);
62 } else {
63 return null;
64 }
65 }
66
67 public boolean hasWallpaperSet() {
68 return getStore().getBlob(KEY_WALLPAPER, null) != null;
69 }
70
71 public void setDimInDarkTheme(boolean enabled) {
72 Wallpaper currentWallpaper = getCurrentWallpaper();
73
74 if (currentWallpaper != null) {
75 putBlob(KEY_WALLPAPER,
76 currentWallpaper.newBuilder()
77 .dimLevelInDarkTheme(enabled ? 0.2f : 0)
78 .build()
79 .encode());
80 } else {
81 throw new IllegalStateException("No wallpaper currently set!");
82 }
83 }
84
85
86 /**
87 * Retrieves the URI of the current wallpaper. Note that this will only return a value if the
88 * wallpaper is both set *and* it's an image.
89 */
90 public @Nullable Uri getWallpaperUri() {
91 Wallpaper currentWallpaper = getCurrentWallpaper();
92
93 if (currentWallpaper != null && currentWallpaper.file_ != null) {
94 return Uri.parse(currentWallpaper.file_.uri);
95 } else {
96 return null;
97 }
98 }
99
100 private @Nullable Wallpaper getCurrentWallpaper() {
101 byte[] serialized = getBlob(KEY_WALLPAPER, null);
102
103 if (serialized != null) {
104 try {
105 return Wallpaper.ADAPTER.decode(serialized);
106 } catch (IOException e) {
107 Log.w(TAG, "Invalid proto stored for wallpaper!");
108 return null;
109 }
110 } else {
111 return null;
112 }
113 }
114}