2019-06-11 07:13:04 +00:00
|
|
|
package tw.nekomimi.nekogram;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
2019-07-29 15:22:59 +00:00
|
|
|
import android.content.Intent;
|
2019-06-11 07:13:04 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
|
|
|
|
public class NekoConfig {
|
|
|
|
|
|
|
|
private static final Object sync = new Object();
|
|
|
|
public static boolean useIPv6 = false;
|
|
|
|
public static boolean hidePhone = true;
|
|
|
|
public static boolean ignoreBlocked = false;
|
|
|
|
public static boolean forceTablet = false;
|
2019-12-14 04:19:38 +00:00
|
|
|
public static int typeface = 0;
|
2019-06-11 07:13:04 +00:00
|
|
|
public static int nameOrder = 1;
|
2019-07-07 05:31:28 +00:00
|
|
|
public static boolean transparentStatusBar = true;
|
|
|
|
public static boolean navigationBarTint = true;
|
2019-07-09 13:01:58 +00:00
|
|
|
public static int navigationBarColor = 2;
|
2019-07-29 15:22:59 +00:00
|
|
|
public static boolean residentNotification = false;
|
2019-12-07 06:35:27 +00:00
|
|
|
|
|
|
|
public static boolean showAddToSavedMessages = true;
|
|
|
|
public static boolean showReport = false;
|
|
|
|
public static boolean showPrPr = true;
|
|
|
|
public static boolean showAdminActions = true;
|
|
|
|
public static boolean showChangePermissions = true;
|
|
|
|
|
2019-06-11 07:13:04 +00:00
|
|
|
private static boolean configLoaded;
|
|
|
|
|
|
|
|
static {
|
|
|
|
loadConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void saveConfig() {
|
|
|
|
synchronized (sync) {
|
|
|
|
try {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfing", Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("useIPv6", useIPv6);
|
|
|
|
editor.putBoolean("hidePhone", hidePhone);
|
|
|
|
editor.putBoolean("ignoreBlocked", ignoreBlocked);
|
|
|
|
editor.putBoolean("forceTablet", forceTablet);
|
2019-12-14 04:19:38 +00:00
|
|
|
editor.putInt("typeface", typeface);
|
2019-06-11 07:13:04 +00:00
|
|
|
editor.putInt("nameOrder", nameOrder);
|
2019-07-07 05:31:28 +00:00
|
|
|
editor.putBoolean("transparentStatusBar", transparentStatusBar);
|
|
|
|
editor.putBoolean("navigationBarTint", navigationBarTint);
|
2019-07-09 13:01:58 +00:00
|
|
|
editor.putInt("navigationBarColor", navigationBarColor);
|
2019-07-29 15:22:59 +00:00
|
|
|
editor.putBoolean("residentNotification", residentNotification);
|
2019-12-07 06:35:27 +00:00
|
|
|
editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages);
|
|
|
|
editor.putBoolean("showReport", showReport);
|
|
|
|
editor.putBoolean("showPrPr", showPrPr);
|
|
|
|
editor.putBoolean("showAdminActions", showAdminActions);
|
|
|
|
editor.putBoolean("showChangePermissions", showChangePermissions);
|
2019-06-11 07:13:04 +00:00
|
|
|
|
|
|
|
editor.commit();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void loadConfig() {
|
|
|
|
synchronized (sync) {
|
|
|
|
if (configLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
useIPv6 = preferences.getBoolean("useIPv6", false);
|
|
|
|
hidePhone = preferences.getBoolean("hidePhone", true);
|
|
|
|
ignoreBlocked = preferences.getBoolean("ignoreBlocked", false);
|
|
|
|
forceTablet = preferences.getBoolean("forceTablet", false);
|
2019-12-14 04:19:38 +00:00
|
|
|
typeface = preferences.getInt("typeface", 0);
|
2019-06-11 07:13:04 +00:00
|
|
|
nameOrder = preferences.getInt("nameOrder", 1);
|
2019-07-07 05:31:28 +00:00
|
|
|
transparentStatusBar = preferences.getBoolean("transparentStatusBar", true);
|
|
|
|
navigationBarTint = preferences.getBoolean("navigationBarTint", true);
|
2019-07-09 13:01:58 +00:00
|
|
|
navigationBarColor = preferences.getInt("navigationBarColor", 2);
|
2019-07-29 15:22:59 +00:00
|
|
|
residentNotification = preferences.getBoolean("residentNotification", false);
|
2019-12-07 06:35:27 +00:00
|
|
|
showAddToSavedMessages = preferences.getBoolean("showAddToSavedMessages", true);
|
|
|
|
showReport = preferences.getBoolean("showReport", false);
|
|
|
|
showPrPr = preferences.getBoolean("showPrPr", true);
|
|
|
|
showAdminActions = preferences.getBoolean("showAdminActions", true);
|
|
|
|
showChangePermissions = preferences.getBoolean("showChangePermissions", true);
|
2019-06-11 07:13:04 +00:00
|
|
|
configLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-07 06:35:27 +00:00
|
|
|
public static void toggleShowAddToSavedMessages() {
|
|
|
|
showAddToSavedMessages = !showAddToSavedMessages;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleShowReport() {
|
|
|
|
showReport = !showReport;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("showReport", showReport);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void toggleShowPrPr() {
|
|
|
|
showPrPr = !showPrPr;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("showPrPr", showPrPr);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleShowAdminActions() {
|
|
|
|
showAdminActions = !showAdminActions;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("showAdminActions", showAdminActions);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleShowChangePermissions() {
|
|
|
|
showChangePermissions = !showChangePermissions;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("showChangePermissions", showChangePermissions);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-11 07:13:04 +00:00
|
|
|
public static void toggleIPv6() {
|
|
|
|
useIPv6 = !useIPv6;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("useIPv6", useIPv6);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleHidePhone() {
|
|
|
|
hidePhone = !hidePhone;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("hidePhone", hidePhone);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleIgnoreBlocked() {
|
|
|
|
ignoreBlocked = !ignoreBlocked;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("ignoreBlocked", ignoreBlocked);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleForceTablet() {
|
|
|
|
forceTablet = !forceTablet;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("forceTablet", forceTablet);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-12-14 04:19:38 +00:00
|
|
|
public static void toogleTypeface() {
|
|
|
|
typeface = typeface == 0 ? 1 : 0;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("typeface", typeface);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-06-11 07:13:04 +00:00
|
|
|
public static void setNameOrder(int order) {
|
|
|
|
nameOrder = order;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("nameOrder", nameOrder);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-07-07 05:31:28 +00:00
|
|
|
public static void toggleTransparentStatusBar() {
|
|
|
|
transparentStatusBar = !transparentStatusBar;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("transparentStatusBar", transparentStatusBar);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleNavigationBarTint() {
|
|
|
|
navigationBarTint = !navigationBarTint;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("navigationBarTint", navigationBarTint);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-07-09 13:01:58 +00:00
|
|
|
public static void setNavigationBarColor(int color) {
|
|
|
|
navigationBarColor = color;
|
2019-07-07 05:31:28 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
2019-07-09 13:01:58 +00:00
|
|
|
editor.putInt("navigationBarColor", navigationBarColor);
|
2019-07-07 05:31:28 +00:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-07-29 15:22:59 +00:00
|
|
|
public static void toggleResidentNotification() {
|
|
|
|
residentNotification = !residentNotification;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("residentNotification", residentNotification);
|
|
|
|
editor.commit();
|
|
|
|
Intent duangIntent = new Intent(ApplicationLoader.applicationContext, DuangService.class);
|
|
|
|
if (residentNotification) {
|
|
|
|
ApplicationLoader.applicationContext.startService(duangIntent);
|
|
|
|
} else {
|
|
|
|
ApplicationLoader.applicationContext.stopService(duangIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 07:13:04 +00:00
|
|
|
}
|