Fix crash

This commit is contained in:
世界 2021-04-01 10:06:54 +08:00
parent ede59575b4
commit c6ce1a5988
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
4 changed files with 33 additions and 21 deletions

View File

@ -3,8 +3,8 @@ import cn.hutool.core.util.RuntimeUtil
apply plugin: "com.android.application" apply plugin: "com.android.application"
apply plugin: "kotlin-android" apply plugin: "kotlin-android"
def verName = "7.6.0-rc07" def verName = "7.6.0-rc08"
def verCode = 200 + 3 * 22 def verCode = 200 + 3 * 23
if (System.getenv("DEBUG_BUILD") == "true") { if (System.getenv("DEBUG_BUILD") == "true") {
verName += "-" + RuntimeUtil.execForStr("git log --pretty=format:'%h' -n 1)") verName += "-" + RuntimeUtil.execForStr("git log --pretty=format:'%h' -n 1)")

View File

@ -99,6 +99,8 @@ public class LocaleController {
private HashMap<String, String> translitChars; private HashMap<String, String> translitChars;
private HashMap<String, String> ruTranslitChars; private HashMap<String, String> ruTranslitChars;
public static boolean usePersianCalendar;
private class TimeZoneChangedReceiver extends BroadcastReceiver { private class TimeZoneChangedReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -911,6 +913,7 @@ public class LocaleController {
if (localeInfo == null) { if (localeInfo == null) {
return; return;
} }
boolean hasBase = localeInfo.hasBaseLang(); boolean hasBase = localeInfo.hasBaseLang();
File pathToFile = localeInfo.getPathToFile(); File pathToFile = localeInfo.getPathToFile();
File pathToBaseFile = localeInfo.getPathToBaseFile(); File pathToBaseFile = localeInfo.getPathToBaseFile();
@ -977,6 +980,8 @@ public class LocaleController {
currentLocale = newLocale; currentLocale = newLocale;
currentLocaleInfo = localeInfo; currentLocaleInfo = localeInfo;
reloadPersianCalendarConfig();
if (!TextUtils.isEmpty(currentLocaleInfo.pluralLangCode)) { if (!TextUtils.isEmpty(currentLocaleInfo.pluralLangCode)) {
currentPluralRules = allRules.get(currentLocaleInfo.pluralLangCode); currentPluralRules = allRules.get(currentLocaleInfo.pluralLangCode);
} }
@ -1010,6 +1015,10 @@ public class LocaleController {
recreateFormatters(); recreateFormatters();
} }
public static void reloadPersianCalendarConfig() {
usePersianCalendar = NekoConfig.usePersianCalendar == 2 || NekoConfig.usePersianCalendar == 0 && "fa".equals(getInstance().currentLocaleInfo.pluralLangCode);
}
public LocaleInfo getCurrentLocaleInfo() { public LocaleInfo getCurrentLocaleInfo() {
return currentLocaleInfo; return currentLocaleInfo;
} }
@ -1432,17 +1441,17 @@ public class LocaleController {
calendar.setTimeInMillis(date); calendar.setTimeInMillis(date);
PersianCalendar persianCalendar = null; PersianCalendar persianCalendar = null;
if (NekoConfig.usePersianCalender) { if (usePersianCalendar) {
persianCalendar = new PersianCalendar(date); persianCalendar = new PersianCalendar(date);
} }
if (checkYear && currentYear == calendar.get(Calendar.YEAR) || !checkYear && Math.abs(System.currentTimeMillis() - date) < 31536000000L) { if (checkYear && currentYear == calendar.get(Calendar.YEAR) || !checkYear && Math.abs(System.currentTimeMillis() - date) < 31536000000L) {
if (NekoConfig.usePersianCalender) { if (usePersianCalendar) {
return persianCalendar.getPersianMonthDay(); return persianCalendar.getPersianMonthDay();
} else { } else {
return getInstance().chatDate.format(date); return getInstance().chatDate.format(date);
} }
} else { } else {
if (NekoConfig.usePersianCalender) { if (usePersianCalendar) {
return persianCalendar.getPersianYear() + "" + persianCalendar.getPersianMonthDay(); return persianCalendar.getPersianYear() + "" + persianCalendar.getPersianMonthDay();
} else { } else {
return getInstance().chatFullDate.format(date); return getInstance().chatFullDate.format(date);
@ -1518,7 +1527,7 @@ public class LocaleController {
int dateDay = rightNow.get(Calendar.DAY_OF_YEAR); int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
int dateYear = rightNow.get(Calendar.YEAR); int dateYear = rightNow.get(Calendar.YEAR);
PersianCalendar persianCalendar = null; PersianCalendar persianCalendar = null;
if (NekoConfig.usePersianCalender) { if (usePersianCalendar) {
persianCalendar = new PersianCalendar(date); persianCalendar = new PersianCalendar(date);
} }
@ -1527,13 +1536,13 @@ public class LocaleController {
} else if (dateDay + 1 == day && year == dateYear) { } else if (dateDay + 1 == day && year == dateYear) {
return LocaleController.formatString("YesterdayAtFormatted", R.string.YesterdayAtFormatted, getInstance().formatterDay.format(new Date(date))); return LocaleController.formatString("YesterdayAtFormatted", R.string.YesterdayAtFormatted, getInstance().formatterDay.format(new Date(date)));
} else if (Math.abs(System.currentTimeMillis() - date) < 31536000000L) { } 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))); return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianMonthDay(), getInstance().formatterDay.format(new Date(date)));
} else { } else {
return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().chatDate.format(new Date(date)), getInstance().formatterDay.format(new Date(date))); return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().chatDate.format(new Date(date)), getInstance().formatterDay.format(new Date(date)));
} }
} else { } else {
if (NekoConfig.usePersianCalender) { if (usePersianCalendar) {
return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianNormalDate(), getInstance().formatterDay.format(new Date(date))); return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianNormalDate(), getInstance().formatterDay.format(new Date(date)));
} else { } else {
return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().chatFullDate.format(new Date(date)), getInstance().formatterDay.format(new Date(date))); 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 dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
int dateYear = rightNow.get(Calendar.YEAR); int dateYear = rightNow.get(Calendar.YEAR);
PersianCalendar persianCalendar = null; PersianCalendar persianCalendar = null;
if (NekoConfig.usePersianCalender) { if (usePersianCalendar) {
persianCalendar = new PersianCalendar(date); persianCalendar = new PersianCalendar(date);
} }
@ -1621,7 +1630,7 @@ public class LocaleController {
} else if (dateDay + 1 == day && year == dateYear) { } 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)))); 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) { } 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))); String format = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianMonthDay(), getInstance().formatterDay.format(new Date(date)));
return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format); return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format);
} else { } else {
@ -1629,7 +1638,7 @@ public class LocaleController {
return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format); return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format);
} }
} else { } else {
if (NekoConfig.usePersianCalender) { if (usePersianCalendar) {
String format = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianNormalDate(), getInstance().formatterDay.format(new Date(date))); String format = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, persianCalendar.getPersianNormalDate(), getInstance().formatterDay.format(new Date(date)));
return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format); return LocaleController.formatString("LastSeenDateFormatted", R.string.LastSeenDateFormatted, format);
} else { } else {
@ -1766,7 +1775,7 @@ public class LocaleController {
return getInstance().formatterDay.format(new Date(date)); return getInstance().formatterDay.format(new Date(date));
} else if (dayDiff > -7 && dayDiff <= -1) { } else if (dayDiff > -7 && dayDiff <= -1) {
return getInstance().formatterWeek.format(new Date(date)); return getInstance().formatterWeek.format(new Date(date));
} else if (NekoConfig.usePersianCalender) { } else if (usePersianCalendar) {
return new PersianCalendar(date).getPersianMonthDay(); return new PersianCalendar(date).getPersianMonthDay();
} else { } else {
return getInstance().formatterDayMonth.format(new Date(date)); return getInstance().formatterDayMonth.format(new Date(date));

View File

@ -119,7 +119,8 @@ public class NekoConfig {
public static boolean mediaPreview; public static boolean mediaPreview;
public static boolean proxyAutoSwitch; public static boolean proxyAutoSwitch;
public static boolean usePersianCalender;
public static int usePersianCalendar;
public static String openPGPApp; public static String openPGPApp;
public static long openPGPKeyId; public static long openPGPKeyId;
@ -279,7 +280,8 @@ public class NekoConfig {
mediaPreview = preferences.getBoolean("mediaPreview", true); mediaPreview = preferences.getBoolean("mediaPreview", true);
proxyAutoSwitch = preferences.getBoolean("proxy_auto_switch", false); 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", ""); openPGPApp = preferences.getString("openPGPApp", "");
openPGPKeyId = preferences.getLong("openPGPKeyId", 0L); openPGPKeyId = preferences.getLong("openPGPKeyId", 0L);
@ -691,7 +693,7 @@ public class NekoConfig {
} }
public static void toggleUsePersianCalender() { 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) { public static void setOpenPGPApp(String packageName) {

View File

@ -132,7 +132,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
private int disableNumberRoundingRow; private int disableNumberRoundingRow;
private int openArchiveOnPullRow; private int openArchiveOnPullRow;
private int nameOrderRow; private int nameOrderRow;
private int usePersianCalenderRow; private int usePersianCalendarRow;
private int general2Row; private int general2Row;
private UndoView restartTooltip; 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(); ActionBarLayout.headerShadowDrawable = NekoConfig.disableAppBarShadow ? null : parentLayout.getResources().getDrawable(R.drawable.header_shadow).mutate();
parentLayout.rebuildAllFragmentViews(true, true); parentLayout.rebuildAllFragmentViews(true, true);
} else if (position == usePersianCalenderRow) { } else if (position == usePersianCalendarRow) {
NekoConfig.toggleUsePersianCalender(); NekoConfig.toggleUsePersianCalender();
LocaleController.reloadPersianCalendarConfig();
if (view instanceof TextCheckCell) { if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.usePersianCalender); ((TextCheckCell) view).setChecked(LocaleController.usePersianCalendar);
} }
} else if (position == pgpAppRow) { } else if (position == pgpAppRow) {
@ -774,7 +775,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
disableNumberRoundingRow = rowCount++; disableNumberRoundingRow = rowCount++;
openArchiveOnPullRow = rowCount++; openArchiveOnPullRow = rowCount++;
nameOrderRow = rowCount++; nameOrderRow = rowCount++;
usePersianCalenderRow = rowCount ++; usePersianCalendarRow = rowCount ++;
general2Row = rowCount++; general2Row = rowCount++;
if (notify && listAdapter != null) { 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); textCell.setTextAndValueAndCheck(LocaleController.getString("DisableNumberRounding", R.string.DisableNumberRounding), "4.8K -> 4777", NekoConfig.disableNumberRounding, true, true);
} else if (position == appBarShadowRow) { } else if (position == appBarShadowRow) {
textCell.setTextAndCheck(LocaleController.getString("DisableAppBarShadow", R.string.DisableAppBarShadow), NekoConfig.disableAppBarShadow, true); textCell.setTextAndCheck(LocaleController.getString("DisableAppBarShadow", R.string.DisableAppBarShadow), NekoConfig.disableAppBarShadow, true);
} else if (position == usePersianCalenderRow) { } else if (position == usePersianCalendarRow) {
textCell.setTextAndValueAndCheck(LocaleController.getString("UsePersianCalender", R.string.UsePersianCalender), LocaleController.getString("UsePersianCalenderInfo", R.string.UsePersianCalenderInfo), NekoConfig.usePersianCalender, true, true); textCell.setTextAndValueAndCheck(LocaleController.getString("UsePersianCalender", R.string.UsePersianCalender), LocaleController.getString("UsePersianCalenderInfo", R.string.UsePersianCalenderInfo), LocaleController.usePersianCalendar, true, true);
} else if (position == autoPauseVideoRow) { } else if (position == autoPauseVideoRow) {
textCell.setTextAndValueAndCheck(LocaleController.getString("AutoPauseVideo", R.string.AutoPauseVideo), LocaleController.getString("AutoPauseVideoAbout", R.string.AutoPauseVideoAbout), NekoConfig.autoPauseVideo, true, true); textCell.setTextAndValueAndCheck(LocaleController.getString("AutoPauseVideo", R.string.AutoPauseVideo), LocaleController.getString("AutoPauseVideoAbout", R.string.AutoPauseVideoAbout), NekoConfig.autoPauseVideo, true, true);
} else if (position == acceptSecretChatRow) { } else if (position == acceptSecretChatRow) {