| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.app.Activity; |
| 4 | import android.content.Context; |
| 5 | import android.content.Intent; |
| 6 | import android.content.SharedPreferences; |
| 7 | import android.os.Build; |
| 8 | |
| 9 | import org.telegram.messenger.ApplicationLoader; |
| 10 | import org.telegram.messenger.FileLog; |
| 11 | |
| 12 | public class NekoConfig { |
| 13 | |
| 14 | private static final Object sync = new Object(); |
| 15 | public static boolean useIPv6 = false; |
| 16 | public static boolean hidePhone = true; |
| 17 | public static boolean ignoreBlocked = false; |
| 18 | public static boolean forceTablet = false; |
| 19 | public static int typeface = 0; |
| 20 | public static int nameOrder = 1; |
| 21 | public static int mapPreviewProvider = 0; |
| 22 | public static boolean transparentStatusBar = false; |
| 23 | public static boolean residentNotification = false; |
| 24 | public static boolean hideProxySponsorChannel = false; |
| 25 | public static boolean saveCacheToPrivateDirectory = Build.VERSION.SDK_INT >= 24; |
| 26 | public static float stickerSize = 14.0f; |
| 27 | public static boolean unlimitedFavedStickers = false; |
| 28 | |
| 29 | public static boolean showAddToSavedMessages = true; |
| 30 | public static boolean showReport = false; |
| 31 | public static boolean showPrPr = true; |
| 32 | public static boolean showViewHistory = true; |
| 33 | public static boolean showAdminActions = true; |
| 34 | public static boolean showChangePermissions = true; |
| 35 | public static boolean showDeleteDownloadedFile = true; |
| 36 | public static boolean showMessageDetails = false; |
| 37 | public static boolean showTranslate = true; |
| 38 | |
| 39 | public static boolean xmas = false; |
| 40 | public static boolean newYear = false; |
| 41 | public static boolean newYearEve = false; |
| 42 | public static boolean fireworks = false; |
| 43 | |
| 44 | public static int translationProvider = 1; |
| 45 | |
| 46 | private static boolean configLoaded; |
| 47 | |
| 48 | static { |
| 49 | loadConfig(); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | public static void saveConfig() { |
| 54 | synchronized (sync) { |
| 55 | try { |
| 56 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfing", Context.MODE_PRIVATE); |
| 57 | SharedPreferences.Editor editor = preferences.edit(); |
| 58 | editor.putBoolean("useIPv6", useIPv6); |
| 59 | editor.putBoolean("hidePhone", hidePhone); |
| 60 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 61 | editor.putBoolean("forceTablet", forceTablet); |
| 62 | editor.putInt("typeface", typeface); |
| 63 | editor.putInt("nameOrder", nameOrder); |
| 64 | editor.putInt("mapPreviewProvider", mapPreviewProvider); |
| 65 | editor.putBoolean("transparentStatusBar", transparentStatusBar); |
| 66 | editor.putBoolean("residentNotification", residentNotification); |
| 67 | editor.putBoolean("hideProxySponsorChannel", hideProxySponsorChannel); |
| 68 | editor.putBoolean("saveCacheToPrivateDirectory", saveCacheToPrivateDirectory); |
| 69 | editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages); |
| 70 | editor.putBoolean("showReport", showReport); |
| 71 | editor.putBoolean("showPrPr", showPrPr); |
| 72 | editor.putBoolean("showViewHistory", showViewHistory); |
| 73 | editor.putBoolean("showAdminActions", showAdminActions); |
| 74 | editor.putBoolean("showChangePermissions", showChangePermissions); |
| 75 | editor.putBoolean("showDeleteDownloadedFile", showDeleteDownloadedFile); |
| 76 | editor.putBoolean("showMessageDetails", showMessageDetails); |
| 77 | editor.putBoolean("showTranslate", showTranslate); |
| 78 | editor.putBoolean("xmas", xmas); |
| 79 | editor.putBoolean("newYear", newYear); |
| 80 | editor.putBoolean("newYearEve", newYearEve); |
| 81 | editor.putBoolean("fireworks", fireworks); |
| 82 | editor.putFloat("stickerSize", stickerSize); |
| 83 | editor.putBoolean("unlimitedFavedStickers", unlimitedFavedStickers); |
| 84 | editor.putInt("translationProvider", translationProvider); |
| 85 | |
| 86 | editor.commit(); |
| 87 | } catch (Exception e) { |
| 88 | FileLog.e(e); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | public static void loadConfig() { |
| 94 | synchronized (sync) { |
| 95 | if (configLoaded) { |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 100 | useIPv6 = preferences.getBoolean("useIPv6", false); |
| 101 | hidePhone = preferences.getBoolean("hidePhone", true); |
| 102 | ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); |
| 103 | forceTablet = preferences.getBoolean("forceTablet", false); |
| 104 | typeface = preferences.getInt("typeface", 0); |
| 105 | nameOrder = preferences.getInt("nameOrder", 1); |
| 106 | mapPreviewProvider = preferences.getInt("mapPreviewProvider", 0); |
| 107 | transparentStatusBar = preferences.getBoolean("transparentStatusBar", false); |
| 108 | residentNotification = preferences.getBoolean("residentNotification", false); |
| 109 | hideProxySponsorChannel = preferences.getBoolean("hideProxySponsorChannel", false); |
| 110 | saveCacheToPrivateDirectory = preferences.getBoolean("saveCacheToPrivateDirectory", Build.VERSION.SDK_INT >= 24); |
| 111 | showAddToSavedMessages = preferences.getBoolean("showAddToSavedMessages", true); |
| 112 | showReport = preferences.getBoolean("showReport", false); |
| 113 | showPrPr = preferences.getBoolean("showPrPr", true); |
| 114 | showViewHistory = preferences.getBoolean("showViewHistory", true); |
| 115 | showAdminActions = preferences.getBoolean("showAdminActions", true); |
| 116 | showChangePermissions = preferences.getBoolean("showChangePermissions", true); |
| 117 | showDeleteDownloadedFile = preferences.getBoolean("showDeleteDownloadedFile", true); |
| 118 | showMessageDetails = preferences.getBoolean("showMessageDetails", false); |
| 119 | showTranslate = preferences.getBoolean("showTranslate", true); |
| 120 | xmas = preferences.getBoolean("xmas", false); |
| 121 | newYear = preferences.getBoolean("newYear", false); |
| 122 | newYearEve = preferences.getBoolean("newYearEve", false); |
| 123 | fireworks = preferences.getBoolean("fireworks", false); |
| 124 | stickerSize = preferences.getFloat("stickerSize", 14.0f); |
| 125 | unlimitedFavedStickers = preferences.getBoolean("unlimitedFavedStickers", false); |
| 126 | translationProvider = preferences.getInt("translationProvider", 1); |
| 127 | configLoaded = true; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | public static void toggleShowAddToSavedMessages() { |
| 132 | showAddToSavedMessages = !showAddToSavedMessages; |
| 133 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 134 | SharedPreferences.Editor editor = preferences.edit(); |
| 135 | editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages); |
| 136 | editor.commit(); |
| 137 | } |
| 138 | |
| 139 | public static void toggleShowReport() { |
| 140 | showReport = !showReport; |
| 141 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 142 | SharedPreferences.Editor editor = preferences.edit(); |
| 143 | editor.putBoolean("showReport", showReport); |
| 144 | editor.commit(); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | public static void toggleShowViewHistory() { |
| 149 | showViewHistory = !showViewHistory; |
| 150 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 151 | SharedPreferences.Editor editor = preferences.edit(); |
| 152 | editor.putBoolean("showViewHistory", showViewHistory); |
| 153 | editor.commit(); |
| 154 | } |
| 155 | |
| 156 | public static void toggleShowPrPr() { |
| 157 | showPrPr = !showPrPr; |
| 158 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 159 | SharedPreferences.Editor editor = preferences.edit(); |
| 160 | editor.putBoolean("showPrPr", showPrPr); |
| 161 | editor.commit(); |
| 162 | } |
| 163 | |
| 164 | public static void toggleShowAdminActions() { |
| 165 | showAdminActions = !showAdminActions; |
| 166 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 167 | SharedPreferences.Editor editor = preferences.edit(); |
| 168 | editor.putBoolean("showAdminActions", showAdminActions); |
| 169 | editor.commit(); |
| 170 | } |
| 171 | |
| 172 | public static void toggleShowChangePermissions() { |
| 173 | showChangePermissions = !showChangePermissions; |
| 174 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 175 | SharedPreferences.Editor editor = preferences.edit(); |
| 176 | editor.putBoolean("showChangePermissions", showChangePermissions); |
| 177 | editor.commit(); |
| 178 | } |
| 179 | |
| 180 | public static void toggleShowDeleteDownloadedFile() { |
| 181 | showDeleteDownloadedFile = !showDeleteDownloadedFile; |
| 182 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 183 | SharedPreferences.Editor editor = preferences.edit(); |
| 184 | editor.putBoolean("showDeleteDownloadedFile", showDeleteDownloadedFile); |
| 185 | editor.commit(); |
| 186 | } |
| 187 | |
| 188 | public static void toggleShowMessageDetails() { |
| 189 | showMessageDetails = !showMessageDetails; |
| 190 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 191 | SharedPreferences.Editor editor = preferences.edit(); |
| 192 | editor.putBoolean("showMessageDetails", showMessageDetails); |
| 193 | editor.commit(); |
| 194 | } |
| 195 | |
| 196 | public static void toggleIPv6() { |
| 197 | useIPv6 = !useIPv6; |
| 198 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 199 | SharedPreferences.Editor editor = preferences.edit(); |
| 200 | editor.putBoolean("useIPv6", useIPv6); |
| 201 | editor.commit(); |
| 202 | } |
| 203 | |
| 204 | public static void toggleHidePhone() { |
| 205 | hidePhone = !hidePhone; |
| 206 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 207 | SharedPreferences.Editor editor = preferences.edit(); |
| 208 | editor.putBoolean("hidePhone", hidePhone); |
| 209 | editor.commit(); |
| 210 | } |
| 211 | |
| 212 | public static void toggleIgnoreBlocked() { |
| 213 | ignoreBlocked = !ignoreBlocked; |
| 214 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 215 | SharedPreferences.Editor editor = preferences.edit(); |
| 216 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 217 | editor.commit(); |
| 218 | } |
| 219 | |
| 220 | public static void toggleForceTablet() { |
| 221 | forceTablet = !forceTablet; |
| 222 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 223 | SharedPreferences.Editor editor = preferences.edit(); |
| 224 | editor.putBoolean("forceTablet", forceTablet); |
| 225 | editor.commit(); |
| 226 | } |
| 227 | |
| 228 | public static void toggleTypeface() { |
| 229 | typeface = typeface == 0 ? 1 : 0; |
| 230 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 231 | SharedPreferences.Editor editor = preferences.edit(); |
| 232 | editor.putInt("typeface", typeface); |
| 233 | editor.commit(); |
| 234 | } |
| 235 | |
| 236 | public static void setNameOrder(int order) { |
| 237 | nameOrder = order; |
| 238 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 239 | SharedPreferences.Editor editor = preferences.edit(); |
| 240 | editor.putInt("nameOrder", nameOrder); |
| 241 | editor.commit(); |
| 242 | } |
| 243 | |
| 244 | public static void setMapPreviewProvider(int provider) { |
| 245 | mapPreviewProvider = provider; |
| 246 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 247 | SharedPreferences.Editor editor = preferences.edit(); |
| 248 | editor.putInt("mapPreviewProvider", mapPreviewProvider); |
| 249 | editor.commit(); |
| 250 | } |
| 251 | |
| 252 | public static void toggleTransparentStatusBar() { |
| 253 | transparentStatusBar = !transparentStatusBar; |
| 254 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 255 | SharedPreferences.Editor editor = preferences.edit(); |
| 256 | editor.putBoolean("transparentStatusBar", transparentStatusBar); |
| 257 | editor.commit(); |
| 258 | } |
| 259 | |
| 260 | public static void toggleResidentNotification() { |
| 261 | residentNotification = !residentNotification; |
| 262 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 263 | SharedPreferences.Editor editor = preferences.edit(); |
| 264 | editor.putBoolean("residentNotification", residentNotification); |
| 265 | editor.commit(); |
| 266 | Intent duangIntent = new Intent(ApplicationLoader.applicationContext, DuangService.class); |
| 267 | if (residentNotification) { |
| 268 | ApplicationLoader.applicationContext.startService(duangIntent); |
| 269 | } else { |
| 270 | ApplicationLoader.applicationContext.stopService(duangIntent); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | public static void toggleHideProxySponsorChannel() { |
| 275 | hideProxySponsorChannel = !hideProxySponsorChannel; |
| 276 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 277 | SharedPreferences.Editor editor = preferences.edit(); |
| 278 | editor.putBoolean("hideProxySponsorChannel", hideProxySponsorChannel); |
| 279 | editor.commit(); |
| 280 | } |
| 281 | |
| 282 | public static void toggleSaveCacheToPrivateDirectory() { |
| 283 | saveCacheToPrivateDirectory = !saveCacheToPrivateDirectory; |
| 284 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 285 | SharedPreferences.Editor editor = preferences.edit(); |
| 286 | editor.putBoolean("saveCacheToPrivateDirectory", saveCacheToPrivateDirectory); |
| 287 | editor.commit(); |
| 288 | } |
| 289 | |
| 290 | public static void toggleXmas() { |
| 291 | xmas = !xmas; |
| 292 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 293 | SharedPreferences.Editor editor = preferences.edit(); |
| 294 | editor.putBoolean("xmas", xmas); |
| 295 | editor.commit(); |
| 296 | } |
| 297 | |
| 298 | public static void toggleNewYear() { |
| 299 | newYear = !newYear; |
| 300 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 301 | SharedPreferences.Editor editor = preferences.edit(); |
| 302 | editor.putBoolean("newYear", newYear); |
| 303 | editor.commit(); |
| 304 | } |
| 305 | |
| 306 | public static void toggleNewYearEve() { |
| 307 | newYearEve = !newYearEve; |
| 308 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 309 | SharedPreferences.Editor editor = preferences.edit(); |
| 310 | editor.putBoolean("newYearEve", newYearEve); |
| 311 | editor.commit(); |
| 312 | } |
| 313 | |
| 314 | public static void toggleFireworks() { |
| 315 | fireworks = !fireworks; |
| 316 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 317 | SharedPreferences.Editor editor = preferences.edit(); |
| 318 | editor.putBoolean("fireworks", fireworks); |
| 319 | editor.commit(); |
| 320 | } |
| 321 | |
| 322 | public static void toggleUnlimitedFavedStickers() { |
| 323 | unlimitedFavedStickers = !unlimitedFavedStickers; |
| 324 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 325 | SharedPreferences.Editor editor = preferences.edit(); |
| 326 | editor.putBoolean("unlimitedFavedStickers", unlimitedFavedStickers); |
| 327 | editor.commit(); |
| 328 | } |
| 329 | |
| 330 | public static void toggleShowTranslate() { |
| 331 | showTranslate = !showTranslate; |
| 332 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 333 | SharedPreferences.Editor editor = preferences.edit(); |
| 334 | editor.putBoolean("showTranslate", showTranslate); |
| 335 | editor.commit(); |
| 336 | } |
| 337 | |
| 338 | public static void setStickerSize(float size) { |
| 339 | stickerSize = size; |
| 340 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 341 | SharedPreferences.Editor editor = preferences.edit(); |
| 342 | editor.putFloat("stickerSize", stickerSize); |
| 343 | editor.commit(); |
| 344 | } |
| 345 | |
| 346 | public static void setTranslationProvider(int provider) { |
| 347 | translationProvider = provider; |
| 348 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 349 | SharedPreferences.Editor editor = preferences.edit(); |
| 350 | editor.putInt("translationProvider", translationProvider); |
| 351 | editor.commit(); |
| 352 | } |
| 353 | |
| 354 | } |
| 355 | |