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