That fuck shit the fascists are using
at master 163 lines 5.5 kB view raw
1package org.tm.archive.keyvalue; 2 3import android.text.TextUtils; 4 5import androidx.annotation.NonNull; 6import androidx.annotation.Nullable; 7 8import org.tm.archive.components.emoji.EmojiUtil; 9import org.tm.archive.util.Util; 10 11import java.util.ArrayList; 12import java.util.Arrays; 13import java.util.Collections; 14import java.util.HashSet; 15import java.util.List; 16import java.util.Set; 17 18public class EmojiValues extends SignalStoreValues { 19 20 public static final List<String> DEFAULT_REACTIONS_LIST = Arrays.asList("\u2764\ufe0f", 21 "\ud83d\udc4d", 22 "\ud83d\udc4e", 23 "\ud83d\ude02", 24 "\ud83d\ude2e", 25 "\ud83d\ude22"); 26 27 private static final String PREFIX = "emojiPref__"; 28 private static final String NEXT_SCHEDULED_CHECK = PREFIX + "next_scheduled_check"; 29 private static final String REACTIONS_LIST = PREFIX + "reactions_list"; 30 private static final String SEARCH_VERSION = PREFIX + "search_version"; 31 private static final String SEARCH_LANGUAGE = PREFIX + "search_language"; 32 private static final String LAST_SEARCH_CHECK = PREFIX + "last_search_check"; 33 private static final String JUMBO_EMOJI_DOWNLOAD = PREFIX + "jumbo_emoji_v"; 34 35 public static final String NO_LANGUAGE = "NO_LANGUAGE"; 36 37 EmojiValues(@NonNull KeyValueStore store) { 38 super(store); 39 } 40 41 @Override 42 void onFirstEverAppLaunch() { 43 putInteger(SEARCH_VERSION, 0); 44 } 45 46 @Override 47 @NonNull List<String> getKeysToIncludeInBackup() { 48 return Collections.singletonList(REACTIONS_LIST); 49 } 50 51 public long getNextScheduledImageCheck() { 52 return getStore().getLong(NEXT_SCHEDULED_CHECK, 0); 53 } 54 55 public void setNextScheduledImageCheck(long nextScheduledCheck) { 56 putLong(NEXT_SCHEDULED_CHECK, nextScheduledCheck); 57 } 58 59 public void setPreferredVariation(@NonNull String emoji) { 60 String canonical = EmojiUtil.getCanonicalRepresentation(emoji); 61 62 if (canonical.equals(emoji)) { 63 getStore().beginWrite().remove(PREFIX + canonical).apply(); 64 } else { 65 putString(PREFIX + canonical, emoji); 66 } 67 } 68 69 public @NonNull String getPreferredVariation(@NonNull String emoji) { 70 String canonical = EmojiUtil.getCanonicalRepresentation(emoji); 71 72 return getString(PREFIX + canonical, emoji); 73 } 74 75 /** 76 * Returns a list usable emoji that the user has selected as their defaults. If any stored reactions are unreadable, it will provide a default. 77 * For raw access to the unfiltered list of reactions, see {@link #getRawReactions()}. 78 */ 79 public @NonNull List<String> getReactions() { 80 List<String> raw = getRawReactions(); 81 List<String> out = new ArrayList<>(DEFAULT_REACTIONS_LIST.size()); 82 83 for (int i = 0; i < DEFAULT_REACTIONS_LIST.size(); i++) { 84 if (raw.size() > i && EmojiUtil.isEmoji(raw.get(i))) { 85 out.add(raw.get(i)); 86 } else { 87 out.add(DEFAULT_REACTIONS_LIST.get(i)); 88 } 89 } 90 91 return out; 92 } 93 94 /** 95 * A raw list of the default reactions the user has selected. It will be empty if there hasn't been any custom ones set. It may contain unrenderable emoji. 96 * This is primarily here for syncing to storage service. You probably want {@link #getReactions()} for everything else. 97 */ 98 public @NonNull List<String> getRawReactions() { 99 String list = getString(REACTIONS_LIST, ""); 100 if (TextUtils.isEmpty(list)) { 101 return Collections.emptyList(); 102 } else { 103 return Arrays.asList(list.split(",")); 104 } 105 } 106 107 public void setReactions(@NonNull List<String> reactions) { 108 putString(REACTIONS_LIST, Util.join(reactions, ",")); 109 } 110 111 public void onSearchIndexUpdated(int version, @NonNull String language) { 112 getStore().beginWrite() 113 .putInteger(SEARCH_VERSION, version) 114 .putString(SEARCH_LANGUAGE, language) 115 .apply(); 116 } 117 118 public boolean hasSearchIndex() { 119 return getSearchVersion() > 0 && getSearchLanguage() != null; 120 } 121 122 public int getSearchVersion() { 123 return getInteger(SEARCH_VERSION, 0); 124 } 125 126 public void clearSearchIndexMetadata() { 127 getStore().beginWrite() 128 .remove(SEARCH_VERSION) 129 .remove(SEARCH_LANGUAGE) 130 .remove(LAST_SEARCH_CHECK) 131 .apply(); 132 } 133 134 public @Nullable String getSearchLanguage() { 135 return getString(SEARCH_LANGUAGE, null); 136 } 137 138 public long getLastSearchIndexCheck() { 139 return getLong(LAST_SEARCH_CHECK, 0); 140 } 141 142 public void setLastSearchIndexCheck(long time) { 143 putLong(LAST_SEARCH_CHECK, time); 144 } 145 146 public void addJumboEmojiSheet(int version, String sheet) { 147 Set<String> sheets = getJumboEmojiSheets(version); 148 sheets.add(sheet); 149 getStore().beginWrite() 150 .putString(JUMBO_EMOJI_DOWNLOAD + version, Util.join(sheets, ",")) 151 .apply(); 152 } 153 154 public HashSet<String> getJumboEmojiSheets(int version) { 155 return new HashSet<>(Arrays.asList(getStore().getString(JUMBO_EMOJI_DOWNLOAD + version, "").split(","))); 156 } 157 158 public void clearJumboEmojiSheets(int version) { 159 getStore().beginWrite() 160 .remove(JUMBO_EMOJI_DOWNLOAD + version) 161 .apply(); 162 } 163}