| 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.BuildVars; |
| 14 | import org.telegram.messenger.FileLog; |
| 15 | import org.telegram.messenger.LocaleController; |
| 16 | import org.telegram.messenger.NotificationCenter; |
| 17 | import org.telegram.messenger.NotificationsService; |
| 18 | import org.telegram.messenger.R; |
| 19 | import org.telegram.ui.ActionBar.Theme; |
| 20 | |
| 21 | import java.io.BufferedReader; |
| 22 | import java.io.FileReader; |
| 23 | import java.util.Locale; |
| 24 | import java.util.regex.Matcher; |
| 25 | import java.util.regex.Pattern; |
| 26 | |
| 27 | import cn.hutool.core.util.StrUtil; |
| 28 | |
| 29 | public class NekoConfig { |
| 30 | |
| 31 | public static final int TITLE_TYPE_TEXT = 0; |
| 32 | public static final int TITLE_TYPE_ICON = 1; |
| 33 | public static final int TITLE_TYPE_MIX = 2; |
| 34 | |
| 35 | public static SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 36 | |
| 37 | public static boolean useIPv6; |
| 38 | |
| 39 | public static boolean useSystemEmoji; |
| 40 | public static boolean ignoreBlocked; |
| 41 | public static boolean hideProxySponsorChannel; |
| 42 | public static boolean disablePhotoSideAction; |
| 43 | public static boolean hideKeyboardOnChatScroll; |
| 44 | public static boolean rearVideoMessages; |
| 45 | public static boolean hideAllTab; |
| 46 | public static boolean pressTitleToOpenAllChats; |
| 47 | public static boolean confirmAVMessage; |
| 48 | public static boolean askBeforeCall; |
| 49 | public static boolean disableNumberRounding; |
| 50 | public static int mapPreviewProvider; |
| 51 | public static float stickerSize; |
| 52 | public static int translationProvider; |
| 53 | public static int tabsTitleType; |
| 54 | |
| 55 | public static boolean showAddToSavedMessages; |
| 56 | public static boolean showReport; |
| 57 | public static boolean showViewHistory; |
| 58 | public static boolean showAdminActions; |
| 59 | public static boolean showChangePermissions; |
| 60 | public static boolean showDeleteDownloadedFile; |
| 61 | public static boolean showMessageDetails; |
| 62 | public static boolean showTranslate; |
| 63 | public static boolean showRepeat; |
| 64 | public static boolean showMessageHide; |
| 65 | |
| 66 | public static boolean hidePhone; |
| 67 | public static int typeface; |
| 68 | public static boolean transparentStatusBar; |
| 69 | public static int tabletMode; |
| 70 | public static boolean openArchiveOnPull; |
| 71 | public static boolean avatarAsDrawerBackground; |
| 72 | public static boolean showTabsOnForward; |
| 73 | public static int nameOrder; |
| 74 | public static int eventType; |
| 75 | public static boolean newYear; |
| 76 | public static int actionBarDecoration; |
| 77 | public static boolean unlimitedFavedStickers; |
| 78 | public static boolean unlimitedPinnedDialogs; |
| 79 | public static boolean residentNotification; |
| 80 | |
| 81 | public static boolean disableChatAction; |
| 82 | public static boolean sortByUnread; |
| 83 | public static boolean sortByUnmuted; |
| 84 | public static boolean sortByUser; |
| 85 | public static boolean sortByContacts; |
| 86 | |
| 87 | public static boolean disableUndo; |
| 88 | |
| 89 | public static boolean filterUsers; |
| 90 | public static boolean filterContacts; |
| 91 | public static boolean filterGroups; |
| 92 | public static boolean filterChannels; |
| 93 | public static boolean filterBots; |
| 94 | public static boolean filterAdmins; |
| 95 | public static boolean filterUnmuted; |
| 96 | public static boolean filterUnread; |
| 97 | public static boolean filterUnmutedAndUnread; |
| 98 | |
| 99 | public static boolean ignoreMutedCount; |
| 100 | |
| 101 | public static boolean disableSystemAccount; |
| 102 | public static boolean disableProxyWhenVpnEnabled; |
| 103 | public static boolean skipOpenLinkConfirm; |
| 104 | |
| 105 | public static boolean useDefaultTheme; |
| 106 | public static boolean showIdAndDc; |
| 107 | |
| 108 | public static String googleCloudTranslateKey; |
| 109 | |
| 110 | public static String cachePath; |
| 111 | private static Typeface systemEmojiTypeface; |
| 112 | public static boolean loadSystemEmojiFailed = false; |
| 113 | |
| 114 | public static String translateToLang; |
| 115 | public static String translateInputLang; |
| 116 | |
| 117 | public static String ccToLang; |
| 118 | public static String ccInputLang; |
| 119 | public static boolean increaseVoiceMessageQuality; |
| 120 | |
| 121 | public static boolean useSystemDNS; |
| 122 | public static String customDoH; |
| 123 | public static boolean hideProxyByDefault; |
| 124 | public static boolean useProxyItem; |
| 125 | |
| 126 | public static boolean disableAppBarShadow; |
| 127 | public static boolean mediaPreview; |
| 128 | |
| 129 | public static boolean proxyAutoSwitch; |
| 130 | |
| 131 | public static int usePersianCalendar; |
| 132 | public static boolean displayPersianCalendarByLatin; |
| 133 | |
| 134 | public static String openPGPApp; |
| 135 | public static long openPGPKeyId; |
| 136 | |
| 137 | public static boolean disableVibration; |
| 138 | public static boolean autoPauseVideo; |
| 139 | public static boolean disableProximityEvents; |
| 140 | |
| 141 | public static boolean ignoreContentRestrictions; |
| 142 | public static boolean useChatAttachMediaMenu; |
| 143 | public static boolean disableLinkPreviewByDefault; |
| 144 | public static boolean sendCommentAfterForward; |
| 145 | public static boolean acceptSecretChat; |
| 146 | |
| 147 | public static boolean avatarBackgroundBlur; |
| 148 | public static boolean avatarBackgroundDarken; |
| 149 | public static boolean disableTrending; |
| 150 | public static boolean dontSendGreetingSticker; |
| 151 | public static boolean hideTimeForSticker; |
| 152 | public static boolean takeGIFasVideo; |
| 153 | public static int maxRecentStickerCount; |
| 154 | public static boolean disableSwipeToNext; |
| 155 | public static boolean disableRemoteEmojiInteractions; |
| 156 | public static boolean disableChoosingSticker; |
| 157 | |
| 158 | public static boolean disableAutoDownloadingWin32Executable; |
| 159 | public static boolean disableAutoDownloadingArchive; |
| 160 | |
| 161 | public static boolean enableStickerPin; |
| 162 | public static boolean useMediaStreamInVoip; |
| 163 | public static short customAudioBitrate = 320; |
| 164 | public static boolean disableGroupVoipAudioProcessing = false; |
| 165 | |
| 166 | public static String getOpenPGPAppName() { |
| 167 | |
| 168 | if (StrUtil.isNotBlank(openPGPApp)) { |
| 169 | |
| 170 | try { |
| 171 | PackageManager manager = ApplicationLoader.applicationContext.getPackageManager(); |
| 172 | ApplicationInfo info = manager.getApplicationInfo(openPGPApp, PackageManager.GET_META_DATA); |
| 173 | return (String) manager.getApplicationLabel(info); |
| 174 | } catch (PackageManager.NameNotFoundException e) { |
| 175 | openPGPApp = ""; |
| 176 | } |
| 177 | |
| 178 | } |
| 179 | |
| 180 | return LocaleController.getString("None", R.string.None); |
| 181 | |
| 182 | } |
| 183 | |
| 184 | public static String formatLang(String name) { |
| 185 | |
| 186 | if (name == null) { |
| 187 | |
| 188 | return LocaleController.getString("Default", R.string.Default); |
| 189 | |
| 190 | } else { |
| 191 | |
| 192 | if (name.contains("-")) { |
| 193 | |
| 194 | return new Locale(StrUtil.subBefore(name, "-", false), StrUtil.subAfter(name, "-", false)).getDisplayName(LocaleController.getInstance().currentLocale); |
| 195 | |
| 196 | } else { |
| 197 | |
| 198 | return new Locale(name).getDisplayName(LocaleController.getInstance().currentLocale); |
| 199 | |
| 200 | } |
| 201 | |
| 202 | } |
| 203 | |
| 204 | } |
| 205 | |
| 206 | static { |
| 207 | useIPv6 = preferences.getBoolean("useIPv6", false); |
| 208 | hidePhone = preferences.getBoolean("hidePhone", true); |
| 209 | ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); |
| 210 | |
| 211 | boolean forceTablet = preferences.getBoolean("forceTablet", false); |
| 212 | if (forceTablet) { |
| 213 | tabletMode = 1; |
| 214 | preferences.edit() |
| 215 | .remove("forceTablet") |
| 216 | .putInt("tabletMode", 1) |
| 217 | .apply(); |
| 218 | } else { |
| 219 | tabletMode = preferences.getInt("tabletMode", 0); |
| 220 | } |
| 221 | |
| 222 | typeface = preferences.getInt("typeface", 0); |
| 223 | nameOrder = preferences.getInt("nameOrder", 1); |
| 224 | mapPreviewProvider = preferences.getInt("mapPreviewProvider", 0); |
| 225 | transparentStatusBar = preferences.getBoolean("transparentStatusBar", false); |
| 226 | residentNotification = preferences.getBoolean("residentNotification", false); |
| 227 | hideProxySponsorChannel = preferences.getBoolean("hideProxySponsorChannel", false); |
| 228 | showAddToSavedMessages = preferences.getBoolean("showAddToSavedMessages", true); |
| 229 | showReport = preferences.getBoolean("showReport", true); |
| 230 | showViewHistory = preferences.getBoolean("showViewHistory", true); |
| 231 | showAdminActions = preferences.getBoolean("showAdminActions", true); |
| 232 | showChangePermissions = preferences.getBoolean("showChangePermissions", true); |
| 233 | showDeleteDownloadedFile = preferences.getBoolean("showDeleteDownloadedFile", true); |
| 234 | showMessageDetails = preferences.getBoolean("showMessageDetails", false); |
| 235 | showTranslate = preferences.getBoolean("showTranslate", true); |
| 236 | showRepeat = preferences.getBoolean("showRepeat", false); |
| 237 | showMessageHide = preferences.getBoolean("showMessageHide", false); |
| 238 | |
| 239 | eventType = preferences.getInt("eventType", 0); |
| 240 | actionBarDecoration = preferences.getInt("actionBarDecoration", 0); |
| 241 | newYear = preferences.getBoolean("newYear", false); |
| 242 | stickerSize = preferences.getFloat("stickerSize", 14.0f); |
| 243 | unlimitedFavedStickers = preferences.getBoolean("unlimitedFavedStickers", false); |
| 244 | unlimitedPinnedDialogs = preferences.getBoolean("unlimitedPinnedDialogs", false); |
| 245 | translationProvider = preferences.getInt("translationProvider", 1); |
| 246 | disablePhotoSideAction = preferences.getBoolean("disablePhotoSideAction", true); |
| 247 | openArchiveOnPull = preferences.getBoolean("openArchiveOnPull", false); |
| 248 | //showHiddenFeature = preferences.getBoolean("showHiddenFeature", false); |
| 249 | hideKeyboardOnChatScroll = preferences.getBoolean("hideKeyboardOnChatScroll", false); |
| 250 | avatarAsDrawerBackground = preferences.getBoolean("avatarAsDrawerBackground", true); |
| 251 | avatarBackgroundBlur = preferences.getBoolean("avatarBackgroundBlur", false); |
| 252 | avatarBackgroundDarken = preferences.getBoolean("avatarBackgroundDarken", false); |
| 253 | useSystemEmoji = preferences.getBoolean("useSystemEmoji", false); |
| 254 | showTabsOnForward = preferences.getBoolean("showTabsOnForward", false); |
| 255 | rearVideoMessages = preferences.getBoolean("rearVideoMessages", false); |
| 256 | hideAllTab = preferences.getBoolean("hideAllTab", false); |
| 257 | pressTitleToOpenAllChats = preferences.getBoolean("pressTitleToOpenAllChats", false); |
| 258 | |
| 259 | disableChatAction = preferences.getBoolean("disable_chat_action", false); |
| 260 | sortByUnread = preferences.getBoolean("sort_by_unread", false); |
| 261 | sortByUnmuted = preferences.getBoolean("sort_by_unmuted", true); |
| 262 | sortByUser = preferences.getBoolean("sort_by_user", true); |
| 263 | sortByContacts = preferences.getBoolean("sort_by_contacts", true); |
| 264 | |
| 265 | disableUndo = preferences.getBoolean("disable_undo", false); |
| 266 | |
| 267 | filterUsers = preferences.getBoolean("filter_users", true); |
| 268 | filterContacts = preferences.getBoolean("filter_contacts", true); |
| 269 | filterGroups = preferences.getBoolean("filter_groups", true); |
| 270 | filterChannels = preferences.getBoolean("filter_channels", true); |
| 271 | filterBots = preferences.getBoolean("filter_bots", true); |
| 272 | filterAdmins = preferences.getBoolean("filter_admins", true); |
| 273 | filterUnmuted = preferences.getBoolean("filter_unmuted", true); |
| 274 | filterUnread = preferences.getBoolean("filter_unread", true); |
| 275 | filterUnmutedAndUnread = preferences.getBoolean("filter_unmuted_and_unread", true); |
| 276 | |
| 277 | disableSystemAccount = preferences.getBoolean("disable_system_account", false); |
| 278 | disableProxyWhenVpnEnabled = preferences.getBoolean("disable_proxy_when_vpn_enabled", false); |
| 279 | skipOpenLinkConfirm = preferences.getBoolean("skip_open_link_confirm", false); |
| 280 | |
| 281 | ignoreMutedCount = preferences.getBoolean("ignore_muted_count", true); |
| 282 | useDefaultTheme = preferences.getBoolean("use_default_theme", false); |
| 283 | showIdAndDc = preferences.getBoolean("show_id_and_dc", false); |
| 284 | |
| 285 | googleCloudTranslateKey = preferences.getString("google_cloud_translate_key", null); |
| 286 | cachePath = preferences.getString("cache_path", null); |
| 287 | |
| 288 | translateToLang = preferences.getString("trans_to_lang", null); |
| 289 | translateInputLang = preferences.getString("trans_input_to_lang", "en"); |
| 290 | |
| 291 | ccToLang = preferences.getString("opencc_to_lang", null); |
| 292 | ccInputLang = preferences.getString("opencc_input_to_lang", null); |
| 293 | |
| 294 | tabsTitleType = preferences.getInt("tabsTitleType", TITLE_TYPE_TEXT); |
| 295 | confirmAVMessage = preferences.getBoolean("confirmAVMessage", false); |
| 296 | askBeforeCall = preferences.getBoolean("askBeforeCall", false); |
| 297 | disableNumberRounding = preferences.getBoolean("disableNumberRounding", false); |
| 298 | |
| 299 | useSystemDNS = preferences.getBoolean("useSystemDNS", false); |
| 300 | customDoH = preferences.getString("customDoH", ""); |
| 301 | hideProxyByDefault = preferences.getBoolean("hide_proxy_by_default", false); |
| 302 | useProxyItem = preferences.getBoolean("use_proxy_item", true); |
| 303 | |
| 304 | disableAppBarShadow = preferences.getBoolean("disableAppBarShadow", false); |
| 305 | mediaPreview = preferences.getBoolean("mediaPreview", true); |
| 306 | |
| 307 | proxyAutoSwitch = preferences.getBoolean("proxy_auto_switch", false); |
| 308 | |
| 309 | usePersianCalendar = preferences.getInt("persian_calendar", 0); |
| 310 | displayPersianCalendarByLatin = preferences.getBoolean("displayPersianCalendarByLatin", false); |
| 311 | openPGPApp = preferences.getString("openPGPApp", ""); |
| 312 | openPGPKeyId = preferences.getLong("openPGPKeyId", 0L); |
| 313 | |
| 314 | disableVibration = preferences.getBoolean("disableVibration", false); |
| 315 | autoPauseVideo = preferences.getBoolean("autoPauseVideo", false); |
| 316 | disableProximityEvents = preferences.getBoolean("disableProximityEvents", false); |
| 317 | |
| 318 | ignoreContentRestrictions = preferences.getBoolean("ignoreContentRestrictions", !BuildVars.isPlay); |
| 319 | useChatAttachMediaMenu = preferences.getBoolean("useChatAttachMediaMenu", true); |
| 320 | disableLinkPreviewByDefault = preferences.getBoolean("disableLinkPreviewByDefault", false); |
| 321 | sendCommentAfterForward = preferences.getBoolean("sendCommentAfterForward", true); |
| 322 | increaseVoiceMessageQuality = preferences.getBoolean("increaseVoiceMessageQuality", true); |
| 323 | acceptSecretChat = preferences.getBoolean("acceptSecretChat", true); |
| 324 | disableTrending = preferences.getBoolean("disableTrending", true); |
| 325 | dontSendGreetingSticker = preferences.getBoolean("dontSendGreetingSticker", false); |
| 326 | hideTimeForSticker = preferences.getBoolean("hideTimeForSticker", false); |
| 327 | takeGIFasVideo = preferences.getBoolean("takeGIFasVideo", false); |
| 328 | maxRecentStickerCount = preferences.getInt("maxRecentStickerCount", 20); |
| 329 | disableSwipeToNext = preferences.getBoolean("disableSwipeToNext", true); |
| 330 | disableRemoteEmojiInteractions = preferences.getBoolean("disableRemoteEmojiInteractions", true); |
| 331 | disableChoosingSticker = preferences.getBoolean("disableChoosingSticker", false); |
| 332 | |
| 333 | disableAutoDownloadingWin32Executable = preferences.getBoolean("disableAutoDownloadingWin32Executable", true); |
| 334 | disableAutoDownloadingArchive = preferences.getBoolean("disableAutoDownloadingArchive", true); |
| 335 | |
| 336 | enableStickerPin = preferences.getBoolean("enableStickerPin", false); |
| 337 | useMediaStreamInVoip = preferences.getBoolean("useMediaStreamInVoip", false); |
| 338 | customAudioBitrate = (short) preferences.getInt("customAudioBitrate", 32); |
| 339 | disableGroupVoipAudioProcessing = preferences.getBoolean("disableGroupVoipAudioProcessing", false); |
| 340 | } |
| 341 | |
| 342 | public static void setNameOrder(int order) { |
| 343 | nameOrder = order; |
| 344 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 345 | SharedPreferences.Editor editor = preferences.edit(); |
| 346 | editor.putInt("nameOrder", nameOrder); |
| 347 | editor.apply(); |
| 348 | |
| 349 | LocaleController.getInstance().recreateFormatters(); |
| 350 | } |
| 351 | |
| 352 | |
| 353 | private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf"; |
| 354 | |
| 355 | public static Typeface getSystemEmojiTypeface() { |
| 356 | if (!loadSystemEmojiFailed && systemEmojiTypeface == null) { |
| 357 | try { |
| 358 | Pattern p = Pattern.compile(">(.*emoji.*)</font>", Pattern.CASE_INSENSITIVE); |
| 359 | BufferedReader br = new BufferedReader(new FileReader("/system/etc/fonts.xml")); |
| 360 | String line; |
| 361 | while ((line = br.readLine()) != null) { |
| 362 | Matcher m = p.matcher(line); |
| 363 | if (m.find()) { |
| 364 | systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + m.group(1)); |
| 365 | FileLog.d("emoji font file fonts.xml = " + m.group(1)); |
| 366 | break; |
| 367 | } |
| 368 | } |
| 369 | br.close(); |
| 370 | } catch (Exception e) { |
| 371 | FileLog.e(e); |
| 372 | } |
| 373 | if (systemEmojiTypeface == null) { |
| 374 | try { |
| 375 | systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + EMOJI_FONT_AOSP); |
| 376 | FileLog.d("emoji font file = " + EMOJI_FONT_AOSP); |
| 377 | } catch (Exception e) { |
| 378 | FileLog.e(e); |
| 379 | loadSystemEmojiFailed = true; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | return systemEmojiTypeface; |
| 384 | } |
| 385 | |
| 386 | public static int getNotificationColor() { |
| 387 | int color = 0; |
| 388 | Configuration configuration = ApplicationLoader.applicationContext.getResources().getConfiguration(); |
| 389 | boolean isDark = (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; |
| 390 | if (isDark) { |
| 391 | color = 0xffffffff; |
| 392 | } else { |
| 393 | if (Theme.getActiveTheme().hasAccentColors()) { |
| 394 | color = Theme.getActiveTheme().getAccentColor(Theme.getActiveTheme().currentAccentId); |
| 395 | } |
| 396 | if (Theme.getActiveTheme().isDark() || color == 0) { |
| 397 | color = Theme.getColor(Theme.key_actionBarDefault); |
| 398 | } |
| 399 | // too bright |
| 400 | if (AndroidUtilities.computePerceivedBrightness(color) >= 0.721f) { |
| 401 | color = Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader) | 0xff000000; |
| 402 | } |
| 403 | } |
| 404 | return color; |
| 405 | } |
| 406 | |
| 407 | } |