From c6ce1a5988da507571ba00d04939e2b0d8b83bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 1 Apr 2021 10:06:54 +0800 Subject: [PATCH] Fix crash --- TMessagesProj/build.gradle | 4 +-- .../telegram/messenger/LocaleController.java | 29 ++++++++++++------- .../java/tw/nekomimi/nekogram/NekoConfig.java | 8 +++-- .../settings/NekoGeneralSettingsActivity.java | 13 +++++---- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index c1de114a5..c8f5410ed 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -3,8 +3,8 @@ import cn.hutool.core.util.RuntimeUtil apply plugin: "com.android.application" apply plugin: "kotlin-android" -def verName = "7.6.0-rc07" -def verCode = 200 + 3 * 22 +def verName = "7.6.0-rc08" +def verCode = 200 + 3 * 23 if (System.getenv("DEBUG_BUILD") == "true") { verName += "-" + RuntimeUtil.execForStr("git log --pretty=format:'%h' -n 1)") diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java b/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java index 94d718afb..dadd3362b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java @@ -99,6 +99,8 @@ public class LocaleController { private HashMap translitChars; private HashMap ruTranslitChars; + public static boolean usePersianCalendar; + private class TimeZoneChangedReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { @@ -911,6 +913,7 @@ public class LocaleController { if (localeInfo == null) { return; } + boolean hasBase = localeInfo.hasBaseLang(); File pathToFile = localeInfo.getPathToFile(); File pathToBaseFile = localeInfo.getPathToBaseFile(); @@ -977,6 +980,8 @@ public class LocaleController { currentLocale = newLocale; currentLocaleInfo = localeInfo; + reloadPersianCalendarConfig(); + if (!TextUtils.isEmpty(currentLocaleInfo.pluralLangCode)) { currentPluralRules = allRules.get(currentLocaleInfo.pluralLangCode); } @@ -1010,6 +1015,10 @@ public class LocaleController { recreateFormatters(); } + public static void reloadPersianCalendarConfig() { + usePersianCalendar = NekoConfig.usePersianCalendar == 2 || NekoConfig.usePersianCalendar == 0 && "fa".equals(getInstance().currentLocaleInfo.pluralLangCode); + } + public LocaleInfo getCurrentLocaleInfo() { return currentLocaleInfo; } @@ -1432,17 +1441,17 @@ public class LocaleController { calendar.setTimeInMillis(date); PersianCalendar persianCalendar = null; - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { persianCalendar = new PersianCalendar(date); } if (checkYear && currentYear == calendar.get(Calendar.YEAR) || !checkYear && Math.abs(System.currentTimeMillis() - date) < 31536000000L) { - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { return persianCalendar.getPersianMonthDay(); } else { return getInstance().chatDate.format(date); } } else { - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { return persianCalendar.getPersianYear() + "" + persianCalendar.getPersianMonthDay(); } else { return getInstance().chatFullDate.format(date); @@ -1518,7 +1527,7 @@ public class LocaleController { int dateDay = rightNow.get(Calendar.DAY_OF_YEAR); int dateYear = rightNow.get(Calendar.YEAR); PersianCalendar persianCalendar = null; - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { persianCalendar = new PersianCalendar(date); } @@ -1527,13 +1536,13 @@ public class LocaleController { } else if (dateDay + 1 == day && year == dateYear) { return LocaleController.formatString("YesterdayAtFormatted", R.string.YesterdayAtFormatted, getInstance().formatterDay.format(new Date(date))); } else if (Math.abs(System.currentTimeMillis() - date) < 31536000000L) { - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianMonthDay(), getInstance().formatterDay.format(new Date(date))); } else { return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().chatDate.format(new Date(date)), getInstance().formatterDay.format(new Date(date))); } } else { - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianNormalDate(), getInstance().formatterDay.format(new Date(date))); } else { return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().chatFullDate.format(new Date(date)), getInstance().formatterDay.format(new Date(date))); @@ -1604,7 +1613,7 @@ public class LocaleController { int dateDay = rightNow.get(Calendar.DAY_OF_YEAR); int dateYear = rightNow.get(Calendar.YEAR); PersianCalendar persianCalendar = null; - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { persianCalendar = new PersianCalendar(date); } @@ -1621,7 +1630,7 @@ public class LocaleController { } else if (dateDay + 1 == day && year == dateYear) { return LocaleController.formatString("LastSeenFormatted", R.string.LastSeenFormatted, LocaleController.formatString("YesterdayAtFormatted", R.string.YesterdayAtFormatted, getInstance().formatterDay.format(new Date(date)))); } else if (Math.abs(System.currentTimeMillis() - date) < 31536000000L) { - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { String format = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianMonthDay(), getInstance().formatterDay.format(new Date(date))); return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format); } else { @@ -1629,7 +1638,7 @@ public class LocaleController { return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format); } } else { - if (NekoConfig.usePersianCalender) { + if (usePersianCalendar) { String format = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianNormalDate(), getInstance().formatterDay.format(new Date(date))); return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format); } else { @@ -1766,7 +1775,7 @@ public class LocaleController { return getInstance().formatterDay.format(new Date(date)); } else if (dayDiff > -7 && dayDiff <= -1) { return getInstance().formatterWeek.format(new Date(date)); - } else if (NekoConfig.usePersianCalender) { + } else if (usePersianCalendar) { return new PersianCalendar(date).getPersianMonthDay(); } else { return getInstance().formatterDayMonth.format(new Date(date)); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index e01656784..44e282541 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -119,7 +119,8 @@ public class NekoConfig { public static boolean mediaPreview; public static boolean proxyAutoSwitch; - public static boolean usePersianCalender; + + public static int usePersianCalendar; public static String openPGPApp; public static long openPGPKeyId; @@ -279,7 +280,8 @@ public class NekoConfig { mediaPreview = preferences.getBoolean("mediaPreview", true); proxyAutoSwitch = preferences.getBoolean("proxy_auto_switch", false); - usePersianCalender = preferences.getBoolean("usePersianCalender", LocaleController.getInstance().getCurrentLocaleInfo().pluralLangCode.contentEquals("fa")); + + usePersianCalendar = preferences.getInt("persian_calendar", 0); openPGPApp = preferences.getString("openPGPApp", ""); openPGPKeyId = preferences.getLong("openPGPKeyId", 0L); @@ -691,7 +693,7 @@ public class NekoConfig { } public static void toggleUsePersianCalender() { - preferences.edit().putBoolean("usePersianCalender", usePersianCalender = !usePersianCalender).apply(); + preferences.edit().putInt("persian_calendar", usePersianCalendar = usePersianCalendar > 1 ? 1 : 2).apply(); } public static void setOpenPGPApp(String packageName) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java index 8d26a298a..818d00e64 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -132,7 +132,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment { private int disableNumberRoundingRow; private int openArchiveOnPullRow; private int nameOrderRow; - private int usePersianCalenderRow; + private int usePersianCalendarRow; private int general2Row; private UndoView restartTooltip; @@ -480,10 +480,11 @@ public class NekoGeneralSettingsActivity extends BaseFragment { } ActionBarLayout.headerShadowDrawable = NekoConfig.disableAppBarShadow ? null : parentLayout.getResources().getDrawable(R.drawable.header_shadow).mutate(); parentLayout.rebuildAllFragmentViews(true, true); - } else if (position == usePersianCalenderRow) { + } else if (position == usePersianCalendarRow) { NekoConfig.toggleUsePersianCalender(); + LocaleController.reloadPersianCalendarConfig(); if (view instanceof TextCheckCell) { - ((TextCheckCell) view).setChecked(NekoConfig.usePersianCalender); + ((TextCheckCell) view).setChecked(LocaleController.usePersianCalendar); } } else if (position == pgpAppRow) { @@ -774,7 +775,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment { disableNumberRoundingRow = rowCount++; openArchiveOnPullRow = rowCount++; nameOrderRow = rowCount++; - usePersianCalenderRow = rowCount ++; + usePersianCalendarRow = rowCount ++; general2Row = rowCount++; if (notify && listAdapter != null) { @@ -977,8 +978,8 @@ public class NekoGeneralSettingsActivity extends BaseFragment { textCell.setTextAndValueAndCheck(LocaleController.getString("DisableNumberRounding", R.string.DisableNumberRounding), "4.8K -> 4777", NekoConfig.disableNumberRounding, true, true); } else if (position == appBarShadowRow) { textCell.setTextAndCheck(LocaleController.getString("DisableAppBarShadow", R.string.DisableAppBarShadow), NekoConfig.disableAppBarShadow, true); - } else if (position == usePersianCalenderRow) { - textCell.setTextAndValueAndCheck(LocaleController.getString("UsePersianCalender", R.string.UsePersianCalender), LocaleController.getString("UsePersianCalenderInfo", R.string.UsePersianCalenderInfo), NekoConfig.usePersianCalender, true, true); + } else if (position == usePersianCalendarRow) { + textCell.setTextAndValueAndCheck(LocaleController.getString("UsePersianCalender", R.string.UsePersianCalender), LocaleController.getString("UsePersianCalenderInfo", R.string.UsePersianCalenderInfo), LocaleController.usePersianCalendar, true, true); } else if (position == autoPauseVideoRow) { textCell.setTextAndValueAndCheck(LocaleController.getString("AutoPauseVideo", R.string.AutoPauseVideo), LocaleController.getString("AutoPauseVideoAbout", R.string.AutoPauseVideoAbout), NekoConfig.autoPauseVideo, true, true); } else if (position == acceptSecretChatRow) {