1
0
mirror of https://github.com/MGislv/NekoX.git synced 2024-07-04 11:13:36 +00:00

Allow to display persian calendar by latin characters. close #450

This commit is contained in:
herotux 2021-04-02 13:56:28 +08:00 committed by 世界
parent c6ce1a5988
commit a320bfe14b
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
7 changed files with 63 additions and 7 deletions

View File

@ -22,6 +22,9 @@ import android.text.format.DateFormat;
import android.util.Xml;
import android.view.Gravity;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.telegram.messenger.support.ArrayUtils;
import org.telegram.messenger.time.FastDateFormat;
import org.telegram.tgnet.ConnectionsManager;
@ -47,6 +50,7 @@ import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.parts.LocFiltersKt;
import tw.nekomimi.nekogram.shamsicalendar.PersianCalendar;
import tw.nekomimi.nekogram.utils.FileUtil;
import tw.nekomimi.nekogram.utils.GsonUtil;
public class LocaleController {
@ -2054,6 +2058,7 @@ public class LocaleController {
TLRPC.TL_langPackLanguage language = (TLRPC.TL_langPackLanguage) res.objects.get(a);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("loaded lang " + language.name);
FileLog.d(GsonUtil.formatObject(language));
}
LocaleInfo localeInfo = new LocaleInfo();
localeInfo.nameEnglish = language.name;

View File

@ -121,6 +121,7 @@ public class NekoConfig {
public static boolean proxyAutoSwitch;
public static int usePersianCalendar;
public static boolean displayPersianCalendarByLatin;
public static String openPGPApp;
public static long openPGPKeyId;
@ -282,6 +283,7 @@ public class NekoConfig {
proxyAutoSwitch = preferences.getBoolean("proxy_auto_switch", false);
usePersianCalendar = preferences.getInt("persian_calendar", 0);
displayPersianCalendarByLatin = preferences.getBoolean("diaplayPersianCalendarByLatin", false);
openPGPApp = preferences.getString("openPGPApp", "");
openPGPKeyId = preferences.getLong("openPGPKeyId", 0L);
@ -696,6 +698,10 @@ public class NekoConfig {
preferences.edit().putInt("persian_calendar", usePersianCalendar = usePersianCalendar > 1 ? 1 : 2).apply();
}
public static void toggleDisplayPersianCalendarByLatin() {
preferences.edit().putBoolean("displayPersianCalendarByLatin", displayPersianCalendarByLatin = !displayPersianCalendarByLatin).apply();
}
public static void setOpenPGPApp(String packageName) {
preferences.edit().putString("openPGPApp", openPGPApp = packageName).apply();
}

View File

@ -133,6 +133,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
private int openArchiveOnPullRow;
private int nameOrderRow;
private int usePersianCalendarRow;
private int displayPersianCalendarByLatinRow;
private int general2Row;
private UndoView restartTooltip;
@ -486,6 +487,11 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(LocaleController.usePersianCalendar);
}
} else if (position == displayPersianCalendarByLatinRow) {
NekoConfig.toggleDisplayPersianCalendarByLatin();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.displayPersianCalendarByLatin);
}
} else if (position == pgpAppRow) {
PopupBuilder builder = new PopupBuilder(view);
@ -775,7 +781,8 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
disableNumberRoundingRow = rowCount++;
openArchiveOnPullRow = rowCount++;
nameOrderRow = rowCount++;
usePersianCalendarRow = rowCount ++;
usePersianCalendarRow = rowCount++;
displayPersianCalendarByLatinRow = rowCount++;
general2Row = rowCount++;
if (notify && listAdapter != null) {
@ -980,6 +987,8 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
textCell.setTextAndCheck(LocaleController.getString("DisableAppBarShadow", R.string.DisableAppBarShadow), NekoConfig.disableAppBarShadow, 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 == displayPersianCalendarByLatinRow) {
textCell.setTextAndCheck(LocaleController.getString("DisplayPersianCalendarByLatin", R.string.DisplayPersianCalendarByLatin), NekoConfig.displayPersianCalendarByLatin, false);
} 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) {

View File

@ -3,6 +3,8 @@ package tw.nekomimi.nekogram.shamsicalendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import tw.nekomimi.nekogram.NekoConfig;
public class PersianCalendar extends GregorianCalendar {
private static final long serialVersionUID = 5541422440580682494L;
private String delimiter = "/";
@ -56,15 +58,23 @@ public class PersianCalendar extends GregorianCalendar {
}
public String getPersianMonthName() {
return PersianCalendarConstants.persianMonthNames[this.persianMonth];
if (NekoConfig.displayPersianCalendarByLatin) {
return PersianCalendarConstants.persianMonthNamesLatin[this.persianMonth];
} else {
return PersianCalendarConstants.persianMonthNames[this.persianMonth];
}
}
public int getPersianDay() {
return this.persianDay;
}
public String getPersianDayfanum() {
return LanguageUtils.getPersianNumbers(String.valueOf(this.persianDay));
public String getPersianDayName() {
if (NekoConfig.displayPersianCalendarByLatin) {
return getPersianDay() + "";
} else {
return LanguageUtils.getPersianNumbers(String.valueOf(this.persianDay));
}
}
public String getPersianWeekDayName() {
@ -87,17 +97,17 @@ public class PersianCalendar extends GregorianCalendar {
}
public String getPersianLongDate() {
return getPersianWeekDayName() + " " + getPersianDayfanum() + " " + getPersianMonthName() + " " + this.persianYear;
return getPersianWeekDayName() + " " + getPersianDayName() + " " + getPersianMonthName() + " " + this.persianYear;
}
public String getPersianNormalDate() {
return getPersianDayfanum() + " " + getPersianMonthName() + " " + getPersianDayfanum();
return getPersianDayName() + " " + getPersianMonthName() + " " + getPersianDayName();
}
//like 9 شهریور
public String getPersianMonthDay() {
return getPersianDayfanum() + " " + getPersianMonthName();
return getPersianDayName() + " " + getPersianMonthName();
}
public String getPersianLongDateAndTime() {

View File

@ -5,5 +5,6 @@ public class PersianCalendarConstants {
public static final long MILLIS_OF_A_DAY = 86400000;
public static final long PERSIAN_EPOCH = 1948321;
public static final String[] persianMonthNames = new String[]{"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"};
public static final String[] persianMonthNamesLatin = new String[]{"Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Day", "Bahman", "Esfand"};
public static final String[] persianWeekDays = new String[]{"شنبه", "یک‌شنبه", "دوشنبه", "سه‌شنبه", "چهارشنبه", "پنج‌شنبه", "جمعه"};
}

View File

@ -0,0 +1,24 @@
package tw.nekomimi.nekogram.utils
import com.google.gson.Gson
import com.google.gson.internal.Streams
import com.google.gson.stream.JsonWriter
import java.io.StringWriter
object GsonUtil {
private val gson = Gson()
@JvmStatic
fun formatObject(obj: Any?): String {
if (obj == null) return "null"
val json = gson.toJsonTree(obj)
val stringWriter = StringWriter()
val jsonWriter = JsonWriter(stringWriter)
jsonWriter.setIndent(" ")
jsonWriter.isLenient = true
Streams.write(json, jsonWriter)
return stringWriter.toString()
}
}

View File

@ -227,4 +227,5 @@
<string name="AppLinkFDroid">F-Droid</string>
<string name="UsePersianCalender">Use persian calender</string>
<string name="UsePersianCalenderInfo">Display date with Solar Hijri calendar</string>
<string name="DisplayPersianCalendarByLatin">Display persian calendar by latin characters</string>
</resources>