| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.app.Activity; |
| 4 | import android.content.Intent; |
| 5 | import android.content.SharedPreferences; |
| 6 | import android.content.pm.ApplicationInfo; |
| 7 | import android.content.pm.PackageManager; |
| 8 | import android.content.res.Configuration; |
| 9 | import android.graphics.Typeface; |
| 10 | |
| 11 | import org.telegram.messenger.AndroidUtilities; |
| 12 | import org.telegram.messenger.ApplicationLoader; |
| 13 | import org.telegram.messenger.FileLog; |
| 14 | import org.telegram.messenger.LocaleController; |
| 15 | import org.telegram.messenger.NotificationCenter; |
| 16 | import org.telegram.messenger.NotificationsService; |
| 17 | import org.telegram.messenger.R; |
| 18 | import org.telegram.ui.ActionBar.Theme; |
| 19 | |
| 20 | import java.io.BufferedReader; |
| 21 | import java.io.FileReader; |
| 22 | import java.util.Locale; |
| 23 | import java.util.regex.Matcher; |
| 24 | import java.util.regex.Pattern; |
| 25 | |
| 26 | import cn.hutool.core.util.StrUtil; |
| 27 | |
| 28 | public class NekoConfig { |
| 29 | |
| 30 | public static final int TITLE_TYPE_TEXT = 0; |
| 31 | public static final int TITLE_TYPE_ICON = 1; |
| 32 | public static final int TITLE_TYPE_MIX = 2; |
| 33 | |
| 34 | public static SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 35 | |
| 36 | public static boolean useIPv6; |
| 37 | |
| 38 | public static boolean useSystemEmoji; |
| 39 | public static boolean ignoreBlocked; |
| 40 | public static boolean hideProxySponsorChannel; |
| 41 | public static boolean disablePhotoSideAction; |
| 42 | public static boolean hideKeyboardOnChatScroll; |
| 43 | public static boolean rearVideoMessages; |
| 44 | public static boolean hideAllTab; |
| 45 | public static boolean confirmAVMessage; |
| 46 | public static boolean askBeforeCall; |
| 47 | public static boolean disableNumberRounding; |
| 48 | public static int mapPreviewProvider; |
| 49 | public static float stickerSize; |
| 50 | public static int translationProvider; |
| 51 | public static int tabsTitleType; |
| 52 | |
| 53 | public static boolean showAddToSavedMessages; |
| 54 | public static boolean showReport; |
| 55 | public static boolean showViewHistory; |
| 56 | public static boolean showAdminActions; |
| 57 | public static boolean showChangePermissions; |
| 58 | public static boolean showDeleteDownloadedFile; |
| 59 | public static boolean showMessageDetails; |
| 60 | public static boolean showTranslate; |
| 61 | public static boolean showRepeat; |
| 62 | public static boolean showMessageHide; |
| 63 | |
| 64 | public static boolean hidePhone; |
| 65 | public static int typeface; |
| 66 | public static boolean transparentStatusBar; |
| 67 | public static int tabletMode; |
| 68 | public static boolean openArchiveOnPull; |
| 69 | public static boolean avatarAsDrawerBackground; |
| 70 | public static boolean showTabsOnForward; |
| 71 | public static int nameOrder; |
| 72 | public static int eventType; |
| 73 | public static boolean newYear; |
| 74 | public static int actionBarDecoration; |
| 75 | public static boolean unlimitedFavedStickers; |
| 76 | public static boolean unlimitedPinnedDialogs; |
| 77 | public static boolean residentNotification; |
| 78 | |
| 79 | public static boolean disableChatAction; |
| 80 | public static boolean sortByUnread; |
| 81 | public static boolean sortByUnmuted; |
| 82 | public static boolean sortByUser; |
| 83 | public static boolean sortByContacts; |
| 84 | |
| 85 | public static boolean disableUndo; |
| 86 | |
| 87 | public static boolean filterUsers; |
| 88 | public static boolean filterContacts; |
| 89 | public static boolean filterGroups; |
| 90 | public static boolean filterChannels; |
| 91 | public static boolean filterBots; |
| 92 | public static boolean filterAdmins; |
| 93 | public static boolean filterUnmuted; |
| 94 | public static boolean filterUnread; |
| 95 | public static boolean filterUnmutedAndUnread; |
| 96 | |
| 97 | public static boolean ignoreMutedCount; |
| 98 | |
| 99 | public static boolean disableSystemAccount; |
| 100 | public static boolean disableProxyWhenVpnEnabled; |
| 101 | public static boolean skipOpenLinkConfirm; |
| 102 | |
| 103 | public static boolean useDefaultTheme; |
| 104 | public static boolean showIdAndDc; |
| 105 | |
| 106 | public static String googleCloudTranslateKey; |
| 107 | |
| 108 | public static String cachePath; |
| 109 | private static Typeface systemEmojiTypeface; |
| 110 | public static boolean loadSystemEmojiFailed = false; |
| 111 | |
| 112 | public static String translateToLang; |
| 113 | public static String translateInputLang; |
| 114 | |
| 115 | public static String ccToLang; |
| 116 | public static String ccInputLang; |
| 117 | public static boolean increaseVoiceMessageQuality; |
| 118 | |
| 119 | public static boolean hideProxyByDefault; |
| 120 | public static boolean useProxyItem; |
| 121 | |
| 122 | public static boolean disableAppBarShadow; |
| 123 | public static boolean mediaPreview; |
| 124 | |
| 125 | public static boolean proxyAutoSwitch; |
| 126 | |
| 127 | public static int usePersianCalendar; |
| 128 | public static boolean displayPersianCalendarByLatin; |
| 129 | |
| 130 | public static String openPGPApp; |
| 131 | public static long openPGPKeyId; |
| 132 | |
| 133 | public static boolean disableVibration; |
| 134 | public static boolean autoPauseVideo; |
| 135 | public static boolean disableProximityEvents; |
| 136 | |
| 137 | public static boolean ignoreContentRestrictions; |
| 138 | public static boolean useChatAttachMediaMenu; |
| 139 | public static boolean disableLinkPreviewByDefault; |
| 140 | public static boolean sendCommentAfterForward; |
| 141 | public static boolean acceptSecretChat; |
| 142 | |
| 143 | public static boolean avatarBackgroundBlur; |
| 144 | public static boolean avatarBackgroundDarken; |
| 145 | public static boolean disableTrending; |
| 146 | |
| 147 | public static boolean disableAutoDownloadingWin32Executable; |
| 148 | public static boolean disableAutoDownloadingArchive; |
| 149 | |
| 150 | public static String getOpenPGPAppName() { |
| 151 | |
| 152 | if (StrUtil.isNotBlank(openPGPApp)) { |
| 153 | |
| 154 | try { |
| 155 | PackageManager manager = ApplicationLoader.applicationContext.getPackageManager(); |
| 156 | ApplicationInfo info = manager.getApplicationInfo(openPGPApp, PackageManager.GET_META_DATA); |
| 157 | return (String) manager.getApplicationLabel(info); |
| 158 | } catch (PackageManager.NameNotFoundException e) { |
| 159 | openPGPApp = ""; |
| 160 | } |
| 161 | |
| 162 | } |
| 163 | |
| 164 | return LocaleController.getString("None", R.string.None); |
| 165 | |
| 166 | } |
| 167 | |
| 168 | public static String formatLang(String name) { |
| 169 | |
| 170 | if (name == null) { |
| 171 | |
| 172 | return LocaleController.getString("Default", R.string.Default); |
| 173 | |
| 174 | } else { |
| 175 | |
| 176 | if (name.contains("-")) { |
| 177 | |
| 178 | return new Locale(StrUtil.subBefore(name, "-", false), StrUtil.subAfter(name, "-", false)).getDisplayName(LocaleController.getInstance().currentLocale); |
| 179 | |
| 180 | } else { |
| 181 | |
| 182 | return new Locale(name).getDisplayName(LocaleController.getInstance().currentLocale); |
| 183 | |
| 184 | } |
| 185 | |
| 186 | } |
| 187 | |
| 188 | } |
| 189 | |
| 190 | static { |
| 191 | |
| 192 | useIPv6 = preferences.getBoolean("useIPv6", false); |
| 193 | hidePhone = preferences.getBoolean("hidePhone", true); |
| 194 | ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); |
| 195 | |
| 196 | boolean forceTablet = preferences.getBoolean("forceTablet", false); |
| 197 | if (forceTablet) { |
| 198 | tabletMode = 1; |
| 199 | preferences.edit() |
| 200 | .remove("forceTablet") |
| 201 | .putInt("tabletMode", 1) |
| 202 | .apply(); |
| 203 | } else { |
| 204 | tabletMode = preferences.getInt("tabletMode", 0); |
| 205 | } |
| 206 | |
| 207 | typeface = preferences.getInt("typeface", 0); |
| 208 | nameOrder = preferences.getInt("nameOrder", 1); |
| 209 | mapPreviewProvider = preferences.getInt("mapPreviewProvider", 0); |
| 210 | transparentStatusBar = preferences.getBoolean("transparentStatusBar", false); |
| 211 | residentNotification = preferences.getBoolean("residentNotification", false); |
| 212 | hideProxySponsorChannel = preferences.getBoolean("hideProxySponsorChannel", false); |
| 213 | showAddToSavedMessages = preferences.getBoolean("showAddToSavedMessages", true); |
| 214 | showReport = preferences.getBoolean("showReport", true); |
| 215 | showViewHistory = preferences.getBoolean("showViewHistory", true); |
| 216 | showAdminActions = preferences.getBoolean("showAdminActions", true); |
| 217 | showChangePermissions = preferences.getBoolean("showChangePermissions", true); |
| 218 | showDeleteDownloadedFile = preferences.getBoolean("showDeleteDownloadedFile", true); |
| 219 | showMessageDetails = preferences.getBoolean("showMessageDetails", false); |
| 220 | showTranslate = preferences.getBoolean("showTranslate", true); |
| 221 | showRepeat = preferences.getBoolean("showRepeat", false); |
| 222 | showMessageHide = preferences.getBoolean("showMessageHide", false); |
| 223 | |
| 224 | eventType = preferences.getInt("eventType", 0); |
| 225 | actionBarDecoration = preferences.getInt("actionBarDecoration", 0); |
| 226 | newYear = preferences.getBoolean("newYear", false); |
| 227 | stickerSize = preferences.getFloat("stickerSize", 14.0f); |
| 228 | unlimitedFavedStickers = preferences.getBoolean("unlimitedFavedStickers", false); |
| 229 | unlimitedPinnedDialogs = preferences.getBoolean("unlimitedPinnedDialogs", false); |
| 230 | translationProvider = preferences.getInt("translationProvider", 1); |
| 231 | disablePhotoSideAction = preferences.getBoolean("disablePhotoSideAction", true); |
| 232 | openArchiveOnPull = preferences.getBoolean("openArchiveOnPull", false); |
| 233 | //showHiddenFeature = preferences.getBoolean("showHiddenFeature", false); |
| 234 | hideKeyboardOnChatScroll = preferences.getBoolean("hideKeyboardOnChatScroll", false); |
| 235 | avatarAsDrawerBackground = preferences.getBoolean("avatarAsDrawerBackground", true); |
| 236 | avatarBackgroundBlur = preferences.getBoolean("avatarBackgroundBlur", false); |
| 237 | avatarBackgroundDarken = preferences.getBoolean("avatarBackgroundDarken", false); |
| 238 | useSystemEmoji = preferences.getBoolean("useSystemEmoji", false); |
| 239 | showTabsOnForward = preferences.getBoolean("showTabsOnForward", false); |
| 240 | rearVideoMessages = preferences.getBoolean("rearVideoMessages", false); |
| 241 | hideAllTab = preferences.getBoolean("hideAllTab", false); |
| 242 | |
| 243 | disableChatAction = preferences.getBoolean("disable_chat_action", false); |
| 244 | sortByUnread = preferences.getBoolean("sort_by_unread", false); |
| 245 | sortByUnmuted = preferences.getBoolean("sort_by_unmuted", true); |
| 246 | sortByUser = preferences.getBoolean("sort_by_user", true); |
| 247 | sortByContacts = preferences.getBoolean("sort_by_contacts", true); |
| 248 | |
| 249 | disableUndo = preferences.getBoolean("disable_undo", false); |
| 250 | |
| 251 | filterUsers = preferences.getBoolean("filter_users", true); |
| 252 | filterContacts = preferences.getBoolean("filter_contacts", true); |
| 253 | filterGroups = preferences.getBoolean("filter_groups", true); |
| 254 | filterChannels = preferences.getBoolean("filter_channels", true); |
| 255 | filterBots = preferences.getBoolean("filter_bots", true); |
| 256 | filterAdmins = preferences.getBoolean("filter_admins", true); |
| 257 | filterUnmuted = preferences.getBoolean("filter_unmuted", true); |
| 258 | filterUnread = preferences.getBoolean("filter_unread", true); |
| 259 | filterUnmutedAndUnread = preferences.getBoolean("filter_unmuted_and_unread", true); |
| 260 | |
| 261 | disableSystemAccount = preferences.getBoolean("disable_system_account", false); |
| 262 | disableProxyWhenVpnEnabled = preferences.getBoolean("disable_proxy_when_vpn_enabled", false); |
| 263 | skipOpenLinkConfirm = preferences.getBoolean("skip_open_link_confirm", false); |
| 264 | |
| 265 | ignoreMutedCount = preferences.getBoolean("ignore_muted_count", true); |
| 266 | useDefaultTheme = preferences.getBoolean("use_default_theme", false); |
| 267 | showIdAndDc = preferences.getBoolean("show_id_and_dc", false); |
| 268 | |
| 269 | googleCloudTranslateKey = preferences.getString("google_cloud_translate_key", null); |
| 270 | cachePath = preferences.getString("cache_path", null); |
| 271 | |
| 272 | translateToLang = preferences.getString("trans_to_lang", null); |
| 273 | translateInputLang = preferences.getString("trans_input_to_lang", "en"); |
| 274 | |
| 275 | ccToLang = preferences.getString("opencc_to_lang", null); |
| 276 | ccInputLang = preferences.getString("opencc_input_to_lang", null); |
| 277 | |
| 278 | tabsTitleType = preferences.getInt("tabsTitleType", TITLE_TYPE_TEXT); |
| 279 | confirmAVMessage = preferences.getBoolean("confirmAVMessage", false); |
| 280 | askBeforeCall = preferences.getBoolean("askBeforeCall", false); |
| 281 | disableNumberRounding = preferences.getBoolean("disableNumberRounding", false); |
| 282 | |
| 283 | hideProxyByDefault = preferences.getBoolean("hide_proxy_by_default", false); |
| 284 | useProxyItem = preferences.getBoolean("use_proxy_item", true); |
| 285 | |
| 286 | disableAppBarShadow = preferences.getBoolean("disableAppBarShadow", false); |
| 287 | mediaPreview = preferences.getBoolean("mediaPreview", true); |
| 288 | |
| 289 | proxyAutoSwitch = preferences.getBoolean("proxy_auto_switch", false); |
| 290 | |
| 291 | usePersianCalendar = preferences.getInt("persian_calendar", 0); |
| 292 | displayPersianCalendarByLatin = preferences.getBoolean("displayPersianCalendarByLatin", false); |
| 293 | openPGPApp = preferences.getString("openPGPApp", ""); |
| 294 | openPGPKeyId = preferences.getLong("openPGPKeyId", 0L); |
| 295 | |
| 296 | disableVibration = preferences.getBoolean("disableVibration", false); |
| 297 | autoPauseVideo = preferences.getBoolean("autoPauseVideo", false); |
| 298 | disableProximityEvents = preferences.getBoolean("disableProximityEvents", false); |
| 299 | |
| 300 | ignoreContentRestrictions = preferences.getBoolean("ignoreContentRestrictions", false); |
| 301 | useChatAttachMediaMenu = preferences.getBoolean("useChatAttachMediaMenu", true); |
| 302 | disableLinkPreviewByDefault = preferences.getBoolean("disableLinkPreviewByDefault", false); |
| 303 | sendCommentAfterForward = preferences.getBoolean("sendCommentAfterForward", true); |
| 304 | increaseVoiceMessageQuality = preferences.getBoolean("increaseVoiceMessageQuality", true); |
| 305 | acceptSecretChat = preferences.getBoolean("acceptSecretChat", true); |
| 306 | disableTrending = preferences.getBoolean("disableTrending", true); |
| 307 | |
| 308 | disableAutoDownloadingWin32Executable = preferences.getBoolean("disableAutoDownloadingWin32Executable", true); |
| 309 | disableAutoDownloadingArchive = preferences.getBoolean("disableAutoDownloadingArchive", true); |
| 310 | |
| 311 | } |
| 312 | |
| 313 | public static void toggleShowAddToSavedMessages() { |
| 314 | showAddToSavedMessages = !showAddToSavedMessages; |
| 315 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 316 | SharedPreferences.Editor editor = preferences.edit(); |
| 317 | editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages); |
| 318 | editor.apply(); |
| 319 | } |
| 320 | |
| 321 | public static void toggleShowReport() { |
| 322 | showReport = !showReport; |
| 323 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 324 | SharedPreferences.Editor editor = preferences.edit(); |
| 325 | editor.putBoolean("showReport", showReport); |
| 326 | editor.apply(); |
| 327 | } |
| 328 | |
| 329 | public static void toggleShowViewHistory() { |
| 330 | showViewHistory = !showViewHistory; |
| 331 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 332 | SharedPreferences.Editor editor = preferences.edit(); |
| 333 | editor.putBoolean("showViewHistory", showViewHistory); |
| 334 | editor.apply(); |
| 335 | } |
| 336 | |
| 337 | public static void toggleShowAdminActions() { |
| 338 | showAdminActions = !showAdminActions; |
| 339 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 340 | SharedPreferences.Editor editor = preferences.edit(); |
| 341 | editor.putBoolean("showAdminActions", showAdminActions); |
| 342 | editor.apply(); |
| 343 | } |
| 344 | |
| 345 | public static void toggleShowChangePermissions() { |
| 346 | showChangePermissions = !showChangePermissions; |
| 347 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 348 | SharedPreferences.Editor editor = preferences.edit(); |
| 349 | editor.putBoolean("showChangePermissions", showChangePermissions); |
| 350 | editor.apply(); |
| 351 | } |
| 352 | |
| 353 | public static void toggleShowDeleteDownloadedFile() { |
| 354 | showDeleteDownloadedFile = !showDeleteDownloadedFile; |
| 355 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 356 | SharedPreferences.Editor editor = preferences.edit(); |
| 357 | editor.putBoolean("showDeleteDownloadedFile", showDeleteDownloadedFile); |
| 358 | editor.apply(); |
| 359 | } |
| 360 | |
| 361 | public static void toggleShowMessageDetails() { |
| 362 | showMessageDetails = !showMessageDetails; |
| 363 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 364 | SharedPreferences.Editor editor = preferences.edit(); |
| 365 | editor.putBoolean("showMessageDetails", showMessageDetails); |
| 366 | editor.apply(); |
| 367 | } |
| 368 | |
| 369 | public static void toggleShowRepeat() { |
| 370 | showRepeat = !showRepeat; |
| 371 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 372 | SharedPreferences.Editor editor = preferences.edit(); |
| 373 | editor.putBoolean("showRepeat", showRepeat); |
| 374 | editor.apply(); |
| 375 | } |
| 376 | |
| 377 | public static void toggleShowHide() { |
| 378 | showMessageHide = !showMessageHide; |
| 379 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 380 | SharedPreferences.Editor editor = preferences.edit(); |
| 381 | editor.putBoolean("showMessageHide", showMessageHide); |
| 382 | editor.apply(); |
| 383 | } |
| 384 | |
| 385 | public static void toggleIPv6() { |
| 386 | useIPv6 = !useIPv6; |
| 387 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 388 | SharedPreferences.Editor editor = preferences.edit(); |
| 389 | editor.putBoolean("useIPv6", useIPv6); |
| 390 | editor.apply(); |
| 391 | } |
| 392 | |
| 393 | public static void toggleHidePhone() { |
| 394 | hidePhone = !hidePhone; |
| 395 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 396 | SharedPreferences.Editor editor = preferences.edit(); |
| 397 | editor.putBoolean("hidePhone", hidePhone); |
| 398 | editor.apply(); |
| 399 | } |
| 400 | |
| 401 | public static void toggleIgnoreBlocked() { |
| 402 | ignoreBlocked = !ignoreBlocked; |
| 403 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 404 | SharedPreferences.Editor editor = preferences.edit(); |
| 405 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 406 | editor.apply(); |
| 407 | } |
| 408 | |
| 409 | public static void toggleTypeface() { |
| 410 | typeface = typeface == 0 ? 1 : 0; |
| 411 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 412 | SharedPreferences.Editor editor = preferences.edit(); |
| 413 | editor.putInt("typeface", typeface); |
| 414 | editor.apply(); |
| 415 | } |
| 416 | |
| 417 | public static void setNameOrder(int order) { |
| 418 | nameOrder = order; |
| 419 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 420 | SharedPreferences.Editor editor = preferences.edit(); |
| 421 | editor.putInt("nameOrder", nameOrder); |
| 422 | editor.apply(); |
| 423 | |
| 424 | LocaleController.getInstance().recreateFormatters(); |
| 425 | } |
| 426 | |
| 427 | public static void setMapPreviewProvider(int provider) { |
| 428 | mapPreviewProvider = provider; |
| 429 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 430 | SharedPreferences.Editor editor = preferences.edit(); |
| 431 | editor.putInt("mapPreviewProvider", mapPreviewProvider); |
| 432 | editor.apply(); |
| 433 | } |
| 434 | |
| 435 | public static void toggleTransparentStatusBar() { |
| 436 | transparentStatusBar = !transparentStatusBar; |
| 437 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 438 | SharedPreferences.Editor editor = preferences.edit(); |
| 439 | editor.putBoolean("transparentStatusBar", transparentStatusBar); |
| 440 | editor.apply(); |
| 441 | } |
| 442 | |
| 443 | public static void toggleResidentNotification() { |
| 444 | residentNotification = !residentNotification; |
| 445 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 446 | SharedPreferences.Editor editor = preferences.edit(); |
| 447 | editor.putBoolean("residentNotification", residentNotification); |
| 448 | editor.apply(); |
| 449 | ApplicationLoader.applicationContext.stopService(new Intent(ApplicationLoader.applicationContext, NotificationsService.class)); |
| 450 | ApplicationLoader.startPushService(); |
| 451 | } |
| 452 | |
| 453 | public static void toggleHideProxySponsorChannel() { |
| 454 | hideProxySponsorChannel = !hideProxySponsorChannel; |
| 455 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 456 | SharedPreferences.Editor editor = preferences.edit(); |
| 457 | editor.putBoolean("hideProxySponsorChannel", hideProxySponsorChannel); |
| 458 | editor.apply(); |
| 459 | } |
| 460 | |
| 461 | public static void setActionBarDecoration(int decoration) { |
| 462 | actionBarDecoration = decoration; |
| 463 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 464 | SharedPreferences.Editor editor = preferences.edit(); |
| 465 | editor.putInt("actionBarDecoration", actionBarDecoration); |
| 466 | editor.apply(); |
| 467 | } |
| 468 | |
| 469 | public static void toggleNewYear() { |
| 470 | newYear = !newYear; |
| 471 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 472 | SharedPreferences.Editor editor = preferences.edit(); |
| 473 | editor.putBoolean("newYear", newYear); |
| 474 | editor.apply(); |
| 475 | } |
| 476 | |
| 477 | public static void toggleUnlimitedFavedStickers() { |
| 478 | unlimitedFavedStickers = !unlimitedFavedStickers; |
| 479 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 480 | SharedPreferences.Editor editor = preferences.edit(); |
| 481 | editor.putBoolean("unlimitedFavedStickers", unlimitedFavedStickers); |
| 482 | editor.apply(); |
| 483 | } |
| 484 | |
| 485 | public static void toggleUnlimitedPinnedDialogs() { |
| 486 | unlimitedPinnedDialogs = !unlimitedPinnedDialogs; |
| 487 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 488 | SharedPreferences.Editor editor = preferences.edit(); |
| 489 | editor.putBoolean("unlimitedPinnedDialogs", unlimitedPinnedDialogs); |
| 490 | editor.apply(); |
| 491 | } |
| 492 | |
| 493 | public static void toggleShowTranslate() { |
| 494 | showTranslate = !showTranslate; |
| 495 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 496 | SharedPreferences.Editor editor = preferences.edit(); |
| 497 | editor.putBoolean("showTranslate", showTranslate); |
| 498 | editor.apply(); |
| 499 | } |
| 500 | |
| 501 | public static void setStickerSize(float size) { |
| 502 | stickerSize = size; |
| 503 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 504 | SharedPreferences.Editor editor = preferences.edit(); |
| 505 | editor.putFloat("stickerSize", stickerSize); |
| 506 | editor.apply(); |
| 507 | } |
| 508 | |
| 509 | public static void setTranslationProvider(int provider) { |
| 510 | translationProvider = provider; |
| 511 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 512 | SharedPreferences.Editor editor = preferences.edit(); |
| 513 | editor.putInt("translationProvider", translationProvider); |
| 514 | editor.apply(); |
| 515 | } |
| 516 | |
| 517 | public static void toggleDisablePhotoSideAction() { |
| 518 | disablePhotoSideAction = !disablePhotoSideAction; |
| 519 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 520 | SharedPreferences.Editor editor = preferences.edit(); |
| 521 | editor.putBoolean("disablePhotoSideAction", disablePhotoSideAction); |
| 522 | editor.apply(); |
| 523 | } |
| 524 | |
| 525 | public static void toggleOpenArchiveOnPull() { |
| 526 | openArchiveOnPull = !openArchiveOnPull; |
| 527 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 528 | SharedPreferences.Editor editor = preferences.edit(); |
| 529 | editor.putBoolean("openArchiveOnPull", openArchiveOnPull); |
| 530 | editor.apply(); |
| 531 | } |
| 532 | |
| 533 | public static void toggleHideKeyboardOnChatScroll() { |
| 534 | preferences.edit().putBoolean("hideKeyboardOnChatScroll", hideKeyboardOnChatScroll = !hideKeyboardOnChatScroll).apply(); |
| 535 | } |
| 536 | |
| 537 | public static void toggleAvatarAsDrawerBackground() { |
| 538 | preferences.edit().putBoolean("avatarAsDrawerBackground", avatarAsDrawerBackground = !avatarAsDrawerBackground).apply(); |
| 539 | } |
| 540 | |
| 541 | public static void toggleAvatarBackgroundBlur() { |
| 542 | avatarBackgroundBlur = !avatarBackgroundBlur; |
| 543 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 544 | SharedPreferences.Editor editor = preferences.edit(); |
| 545 | editor.putBoolean("avatarBackgroundBlur", avatarBackgroundBlur); |
| 546 | editor.commit(); |
| 547 | } |
| 548 | |
| 549 | public static void toggleAvatarBackgroundDarken() { |
| 550 | avatarBackgroundDarken = !avatarBackgroundDarken; |
| 551 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 552 | SharedPreferences.Editor editor = preferences.edit(); |
| 553 | editor.putBoolean("avatarBackgroundDarken", avatarBackgroundDarken); |
| 554 | editor.commit(); |
| 555 | } |
| 556 | |
| 557 | public static void toggleUseSystemEmoji() { |
| 558 | preferences.edit().putBoolean("useSystemEmoji", useSystemEmoji = !useSystemEmoji).apply(); |
| 559 | } |
| 560 | |
| 561 | public static void toggleDisableChatAction() { |
| 562 | preferences.edit().putBoolean("disable_chat_action", disableChatAction = !disableChatAction).apply(); |
| 563 | } |
| 564 | |
| 565 | public static void toggleSortByUnread() { |
| 566 | preferences.edit().putBoolean("sort_by_unread", sortByUnread = !sortByUnread).apply(); |
| 567 | } |
| 568 | |
| 569 | public static void toggleShowTabsOnForward() { |
| 570 | preferences.edit().putBoolean("showTabsOnForward", showTabsOnForward = !showTabsOnForward).apply(); |
| 571 | } |
| 572 | |
| 573 | public static void toggleRearVideoMessages() { |
| 574 | preferences.edit().putBoolean("rearVideoMessages", rearVideoMessages = !rearVideoMessages).apply(); |
| 575 | } |
| 576 | |
| 577 | public static void toggleHideAllTab() { |
| 578 | preferences.edit().putBoolean("hideAllTab", hideAllTab = !hideAllTab).apply(); |
| 579 | } |
| 580 | |
| 581 | public static void toggleSortByUnmuted() { |
| 582 | preferences.edit().putBoolean("sort_by_unmuted", sortByUnmuted = !sortByUnmuted).apply(); |
| 583 | } |
| 584 | |
| 585 | public static void toggleSortByUser() { |
| 586 | preferences.edit().putBoolean("sort_by_user", sortByUser = !sortByUser).apply(); |
| 587 | } |
| 588 | |
| 589 | public static void toggleSortByContacts() { |
| 590 | preferences.edit().putBoolean("sort_by_contacts", sortByContacts = !sortByContacts).apply(); |
| 591 | } |
| 592 | |
| 593 | public static void toggleDisableUndo() { |
| 594 | preferences.edit().putBoolean("disable_undo", disableUndo = !disableUndo).apply(); |
| 595 | } |
| 596 | |
| 597 | public static void toggleFilterUsers() { |
| 598 | preferences.edit().putBoolean("filter_users", filterUsers = !filterUsers).apply(); |
| 599 | } |
| 600 | |
| 601 | public static void toggleFilterContacts() { |
| 602 | preferences.edit().putBoolean("filter_contacts", filterContacts = !filterContacts).apply(); |
| 603 | } |
| 604 | |
| 605 | public static void toggleFilterGroups() { |
| 606 | preferences.edit().putBoolean("filterGroups", filterGroups = !filterGroups).apply(); |
| 607 | } |
| 608 | |
| 609 | public static void toggleFilterChannels() { |
| 610 | preferences.edit().putBoolean("filter_channels", filterChannels = !filterChannels).apply(); |
| 611 | } |
| 612 | |
| 613 | public static void toggleFilterBots() { |
| 614 | preferences.edit().putBoolean("filter_bots", filterBots = !filterBots).apply(); |
| 615 | } |
| 616 | |
| 617 | public static void toggleFilterAdmins() { |
| 618 | preferences.edit().putBoolean("filter_admins", filterAdmins = !filterAdmins).apply(); |
| 619 | } |
| 620 | |
| 621 | public static void toggleFilterUnmuted() { |
| 622 | preferences.edit().putBoolean("filter_unmuted", filterUnmuted = !filterUnmuted).apply(); |
| 623 | } |
| 624 | |
| 625 | public static void toggleDisableFilterUnread() { |
| 626 | preferences.edit().putBoolean("filter_unread", filterUnread = !filterUnread).apply(); |
| 627 | } |
| 628 | |
| 629 | public static void toggleFilterUnmutedAndUnread() { |
| 630 | preferences.edit().putBoolean("filter_unmuted_and_unread", filterUnmutedAndUnread = !filterUnmutedAndUnread).apply(); |
| 631 | } |
| 632 | |
| 633 | public static void toggleDisableSystemAccount() { |
| 634 | preferences.edit().putBoolean("disable_system_account", disableSystemAccount = !disableSystemAccount).apply(); |
| 635 | } |
| 636 | |
| 637 | public static void toggleDisableProxyWhenVpnEnabled() { |
| 638 | preferences.edit().putBoolean("disable_proxy_when_vpn_enabled", disableProxyWhenVpnEnabled = !disableProxyWhenVpnEnabled).apply(); |
| 639 | } |
| 640 | |
| 641 | public static void toggleSkipOpenLinkConfirm() { |
| 642 | preferences.edit().putBoolean("skip_open_link_confirm", skipOpenLinkConfirm = !skipOpenLinkConfirm).apply(); |
| 643 | } |
| 644 | |
| 645 | public static void toggleIgnoredMutedCount() { |
| 646 | preferences.edit().putBoolean("ignore_muted_count", ignoreMutedCount = !ignoreMutedCount).apply(); |
| 647 | } |
| 648 | |
| 649 | public static void toggleUseDefaultTheme() { |
| 650 | preferences.edit().putBoolean("use_default_theme", useDefaultTheme = !useDefaultTheme).apply(); |
| 651 | } |
| 652 | |
| 653 | public static void toggleShowIdAndDc() { |
| 654 | preferences.edit().putBoolean("show_id_and_dc", showIdAndDc = !showIdAndDc).apply(); |
| 655 | } |
| 656 | |
| 657 | public static void setGoogleTranslateKey(String key) { |
| 658 | preferences.edit().putString("google_cloud_translate_key", googleCloudTranslateKey = key).apply(); |
| 659 | } |
| 660 | |
| 661 | public static void setCachePath(String cachePath) { |
| 662 | preferences.edit().putString("cache_path", NekoConfig.cachePath = cachePath).apply(); |
| 663 | } |
| 664 | |
| 665 | public static void setTranslateToLang(String toLang) { |
| 666 | preferences.edit().putString("trans_to_lang", translateToLang = toLang).apply(); |
| 667 | } |
| 668 | |
| 669 | public static void setTranslateInputToLang(String toLang) { |
| 670 | preferences.edit().putString("trans_input_to_lang", translateInputLang = toLang).apply(); |
| 671 | } |
| 672 | |
| 673 | public static void setTabsTitleType(int type) { |
| 674 | preferences.edit().putInt("tabsTitleType", tabsTitleType = type).apply(); |
| 675 | } |
| 676 | |
| 677 | public static void toggleConfirmAVMessage() { |
| 678 | preferences.edit().putBoolean("confirmAVMessage", confirmAVMessage = !confirmAVMessage).apply(); |
| 679 | } |
| 680 | |
| 681 | public static void toggleAskBeforeCall() { |
| 682 | preferences.edit().putBoolean("askBeforeCall", askBeforeCall = !askBeforeCall).apply(); |
| 683 | } |
| 684 | |
| 685 | public static void toggleHideProxyByDefault() { |
| 686 | preferences.edit().putBoolean("hide_proxy_by_default", hideProxyByDefault = !hideProxyByDefault).apply(); |
| 687 | NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.proxySettingsChanged); |
| 688 | } |
| 689 | |
| 690 | public static void toggleUseProxyItem() { |
| 691 | preferences.edit().putBoolean("use_proxy_item", useProxyItem = !useProxyItem).apply(); |
| 692 | NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.proxySettingsChanged); |
| 693 | } |
| 694 | |
| 695 | public static void toggleDisableNumberRounding() { |
| 696 | preferences.edit().putBoolean("disableNumberRounding", disableNumberRounding = !disableNumberRounding).apply(); |
| 697 | } |
| 698 | |
| 699 | public static void toggleDisableAppBarShadow() { |
| 700 | preferences.edit().putBoolean("disableAppBarShadow", disableAppBarShadow = !disableAppBarShadow).apply(); |
| 701 | } |
| 702 | |
| 703 | public static void toggleMediaPreview() { |
| 704 | preferences.edit().putBoolean("mediaPreview", mediaPreview = !mediaPreview).apply(); |
| 705 | } |
| 706 | |
| 707 | public static void toggleProxyAutoSwitch() { |
| 708 | preferences.edit().putBoolean("proxy_auto_switch", proxyAutoSwitch = !proxyAutoSwitch).apply(); |
| 709 | } |
| 710 | |
| 711 | public static void toggleUsePersiancalendar() { |
| 712 | preferences.edit().putInt("persian_calendar", usePersianCalendar = usePersianCalendar > 1 ? 1 : 2).apply(); |
| 713 | } |
| 714 | |
| 715 | public static void toggleDisplayPersianCalendarByLatin() { |
| 716 | preferences.edit().putBoolean("displayPersianCalendarByLatin", displayPersianCalendarByLatin = !displayPersianCalendarByLatin).apply(); |
| 717 | } |
| 718 | |
| 719 | public static void setOpenPGPApp(String packageName) { |
| 720 | preferences.edit().putString("openPGPApp", openPGPApp = packageName).apply(); |
| 721 | } |
| 722 | |
| 723 | public static void setOpenPGPKeyId(long keyId) { |
| 724 | preferences.edit().putLong("openPGPKeyId", openPGPKeyId = keyId).apply(); |
| 725 | } |
| 726 | |
| 727 | public static void toggleDisableVibration() { |
| 728 | preferences.edit().putBoolean("disableVibration", disableVibration = !disableVibration).apply(); |
| 729 | } |
| 730 | |
| 731 | public static void toggleAutoPauseVideo() { |
| 732 | preferences.edit().putBoolean("autoPauseVideo", autoPauseVideo = !autoPauseVideo).apply(); |
| 733 | } |
| 734 | |
| 735 | public static void toggleDisableProximityEvents() { |
| 736 | preferences.edit().putBoolean("disableProximityEvents", disableProximityEvents = !disableProximityEvents).apply(); |
| 737 | } |
| 738 | |
| 739 | public static void toggleIgnoreContentRestrictions() { |
| 740 | preferences.edit().putBoolean("ignoreContentRestrictions", ignoreContentRestrictions = !ignoreContentRestrictions).apply(); |
| 741 | } |
| 742 | |
| 743 | public static void toggleUseChatAttachMediaMenu() { |
| 744 | preferences.edit().putBoolean("useChatAttachMediaMenu", useChatAttachMediaMenu = !useChatAttachMediaMenu).apply(); |
| 745 | } |
| 746 | |
| 747 | public static void toggleDisableLinkPreviewByDefault() { |
| 748 | preferences.edit().putBoolean("disableLinkPreviewByDefault", disableLinkPreviewByDefault = !disableLinkPreviewByDefault).apply(); |
| 749 | } |
| 750 | |
| 751 | public static void toggleSendCommentAfterForward() { |
| 752 | preferences.edit().putBoolean("sendCommentAfterForward", sendCommentAfterForward = !sendCommentAfterForward).apply(); |
| 753 | } |
| 754 | |
| 755 | public static void setCCToLang(String toLang) { |
| 756 | preferences.edit().putString("opencc_to_lang", ccToLang = toLang).apply(); |
| 757 | } |
| 758 | |
| 759 | public static void setCCInputToLang(String toLang) { |
| 760 | preferences.edit().putString("opencc_input_to_lang", ccInputLang = toLang).apply(); |
| 761 | } |
| 762 | |
| 763 | public static void toggleIncreaseVoiceMessageQuality() { |
| 764 | preferences.edit().putBoolean("increaseVoiceMessageQuality", increaseVoiceMessageQuality = !increaseVoiceMessageQuality).apply(); |
| 765 | } |
| 766 | |
| 767 | public static void toggleAcceptSecretChat() { |
| 768 | preferences.edit().putBoolean("acceptSecretChat", acceptSecretChat = !acceptSecretChat).apply(); |
| 769 | } |
| 770 | |
| 771 | public static void setTabletMode(int mode) { |
| 772 | preferences.edit().putInt("tabletMode", tabletMode = mode).apply(); |
| 773 | } |
| 774 | |
| 775 | public static void toggleDisableTrending() { |
| 776 | preferences.edit().putBoolean("disableTrending", disableTrending = !disableTrending).apply(); |
| 777 | } |
| 778 | |
| 779 | public static void toggleDisableAutoDownloadingWin32Executable() { |
| 780 | preferences.edit().putBoolean("disableAutoDownloadingWin32Executable", disableAutoDownloadingWin32Executable = !disableAutoDownloadingWin32Executable).apply(); |
| 781 | } |
| 782 | |
| 783 | public static void toggleDisableAutoDownloadingArchive() { |
| 784 | preferences.edit().putBoolean("disableAutoDownloadingArchive", disableAutoDownloadingArchive = !disableAutoDownloadingArchive).apply(); |
| 785 | } |
| 786 | |
| 787 | private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf"; |
| 788 | |
| 789 | public static Typeface getSystemEmojiTypeface() { |
| 790 | if (!loadSystemEmojiFailed && systemEmojiTypeface == null) { |
| 791 | try { |
| 792 | Pattern p = Pattern.compile(">(.*emoji.*)</font>", Pattern.CASE_INSENSITIVE); |
| 793 | BufferedReader br = new BufferedReader(new FileReader("/system/etc/fonts.xml")); |
| 794 | String line; |
| 795 | while ((line = br.readLine()) != null) { |
| 796 | Matcher m = p.matcher(line); |
| 797 | if (m.find()) { |
| 798 | systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + m.group(1)); |
| 799 | FileLog.d("emoji font file fonts.xml = " + m.group(1)); |
| 800 | break; |
| 801 | } |
| 802 | } |
| 803 | br.close(); |
| 804 | } catch (Exception e) { |
| 805 | FileLog.e(e); |
| 806 | } |
| 807 | if (systemEmojiTypeface == null) { |
| 808 | try { |
| 809 | systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + EMOJI_FONT_AOSP); |
| 810 | FileLog.d("emoji font file = " + EMOJI_FONT_AOSP); |
| 811 | } catch (Exception e) { |
| 812 | FileLog.e(e); |
| 813 | loadSystemEmojiFailed = true; |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | return systemEmojiTypeface; |
| 818 | } |
| 819 | |
| 820 | public static int getNotificationColor() { |
| 821 | int color = 0; |
| 822 | Configuration configuration = ApplicationLoader.applicationContext.getResources().getConfiguration(); |
| 823 | boolean isDark = (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; |
| 824 | if (isDark) { |
| 825 | color = 0xffffffff; |
| 826 | } else { |
| 827 | if (Theme.getActiveTheme().hasAccentColors()) { |
| 828 | color = Theme.getActiveTheme().getAccentColor(Theme.getActiveTheme().currentAccentId); |
| 829 | } |
| 830 | if (Theme.getActiveTheme().isDark() || color == 0) { |
| 831 | color = Theme.getColor(Theme.key_actionBarDefault); |
| 832 | } |
| 833 | // too bright |
| 834 | if (AndroidUtilities.computePerceivedBrightness(color) >= 0.721f) { |
| 835 | color = Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader) | 0xff000000; |
| 836 | } |
| 837 | } |
| 838 | return color; |
| 839 | } |
| 840 | |
| 841 | } |