| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.app.Activity; |
| 4 | import android.content.Context; |
| 5 | import android.content.SharedPreferences; |
| 6 | |
| 7 | import org.telegram.messenger.ApplicationLoader; |
| 8 | import org.telegram.messenger.FileLog; |
| 9 | |
| 10 | public class NekoConfig { |
| 11 | |
| 12 | private static final Object sync = new Object(); |
| 13 | public static boolean useIPv6 = false; |
| 14 | public static boolean hidePhone = true; |
| 15 | public static boolean ignoreBlocked = false; |
| 16 | public static boolean forceTablet = false; |
| 17 | public static int nameOrder = 1; |
| 18 | private static boolean configLoaded; |
| 19 | |
| 20 | static { |
| 21 | loadConfig(); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | public static void saveConfig() { |
| 26 | synchronized (sync) { |
| 27 | try { |
| 28 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfing", Context.MODE_PRIVATE); |
| 29 | SharedPreferences.Editor editor = preferences.edit(); |
| 30 | editor.putBoolean("useIPv6", useIPv6); |
| 31 | editor.putBoolean("hidePhone", hidePhone); |
| 32 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 33 | editor.putBoolean("forceTablet", forceTablet); |
| 34 | editor.putInt("nameOrder", nameOrder); |
| 35 | |
| 36 | editor.commit(); |
| 37 | } catch (Exception e) { |
| 38 | FileLog.e(e); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public static void loadConfig() { |
| 44 | synchronized (sync) { |
| 45 | if (configLoaded) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 50 | useIPv6 = preferences.getBoolean("useIPv6", false); |
| 51 | hidePhone = preferences.getBoolean("hidePhone", true); |
| 52 | ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); |
| 53 | forceTablet = preferences.getBoolean("forceTablet", false); |
| 54 | nameOrder = preferences.getInt("nameOrder", 1); |
| 55 | configLoaded = true; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | public static void toggleIPv6() { |
| 60 | useIPv6 = !useIPv6; |
| 61 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 62 | SharedPreferences.Editor editor = preferences.edit(); |
| 63 | editor.putBoolean("useIPv6", useIPv6); |
| 64 | editor.commit(); |
| 65 | } |
| 66 | |
| 67 | public static void toggleHidePhone() { |
| 68 | hidePhone = !hidePhone; |
| 69 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 70 | SharedPreferences.Editor editor = preferences.edit(); |
| 71 | editor.putBoolean("hidePhone", hidePhone); |
| 72 | editor.commit(); |
| 73 | } |
| 74 | |
| 75 | public static void toggleIgnoreBlocked() { |
| 76 | ignoreBlocked = !ignoreBlocked; |
| 77 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 78 | SharedPreferences.Editor editor = preferences.edit(); |
| 79 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 80 | editor.commit(); |
| 81 | } |
| 82 | |
| 83 | public static void toggleForceTablet() { |
| 84 | forceTablet = !forceTablet; |
| 85 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 86 | SharedPreferences.Editor editor = preferences.edit(); |
| 87 | editor.putBoolean("forceTablet", forceTablet); |
| 88 | editor.commit(); |
| 89 | } |
| 90 | |
| 91 | public static void setNameOrder(int order) { |
| 92 | nameOrder = order; |
| 93 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 94 | SharedPreferences.Editor editor = preferences.edit(); |
| 95 | editor.putInt("nameOrder", nameOrder); |
| 96 | editor.commit(); |
| 97 | } |
| 98 | |
| 99 | } |
| 100 | |