| 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 | public static boolean nya = false; |
| 19 | public static String nyaSuffix = "喵"; |
| 20 | private static boolean configLoaded; |
| 21 | |
| 22 | static { |
| 23 | loadConfig(); |
| 24 | } |
| 25 | |
| 26 | |
| 27 | public static void saveConfig() { |
| 28 | synchronized (sync) { |
| 29 | try { |
| 30 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfing", Context.MODE_PRIVATE); |
| 31 | SharedPreferences.Editor editor = preferences.edit(); |
| 32 | editor.putBoolean("useIPv6", useIPv6); |
| 33 | editor.putBoolean("hidePhone", hidePhone); |
| 34 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 35 | editor.putBoolean("forceTablet", forceTablet); |
| 36 | editor.putInt("nameOrder", nameOrder); |
| 37 | editor.putBoolean("nya", nya); |
| 38 | editor.putString("nyaSuffix", nyaSuffix); |
| 39 | |
| 40 | editor.commit(); |
| 41 | } catch (Exception e) { |
| 42 | FileLog.e(e); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public static void loadConfig() { |
| 48 | synchronized (sync) { |
| 49 | if (configLoaded) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 54 | useIPv6 = preferences.getBoolean("useIPv6", false); |
| 55 | hidePhone = preferences.getBoolean("hidePhone", true); |
| 56 | ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); |
| 57 | forceTablet = preferences.getBoolean("forceTablet", false); |
| 58 | nameOrder = preferences.getInt("nameOrder", 1); |
| 59 | nya = preferences.getBoolean("nya", false); |
| 60 | nyaSuffix = preferences.getString("nyaSuffix", "喵"); |
| 61 | configLoaded = true; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | public static void toggleIPv6() { |
| 66 | useIPv6 = !useIPv6; |
| 67 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 68 | SharedPreferences.Editor editor = preferences.edit(); |
| 69 | editor.putBoolean("useIPv6", useIPv6); |
| 70 | editor.commit(); |
| 71 | } |
| 72 | |
| 73 | public static void toggleHidePhone() { |
| 74 | hidePhone = !hidePhone; |
| 75 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 76 | SharedPreferences.Editor editor = preferences.edit(); |
| 77 | editor.putBoolean("hidePhone", hidePhone); |
| 78 | editor.commit(); |
| 79 | } |
| 80 | |
| 81 | public static void toggleIgnoreBlocked() { |
| 82 | ignoreBlocked = !ignoreBlocked; |
| 83 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 84 | SharedPreferences.Editor editor = preferences.edit(); |
| 85 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 86 | editor.commit(); |
| 87 | } |
| 88 | |
| 89 | public static void toggleForceTablet() { |
| 90 | forceTablet = !forceTablet; |
| 91 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 92 | SharedPreferences.Editor editor = preferences.edit(); |
| 93 | editor.putBoolean("forceTablet", forceTablet); |
| 94 | editor.commit(); |
| 95 | } |
| 96 | |
| 97 | public static void toggleNya() { |
| 98 | nya = !nya; |
| 99 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 100 | SharedPreferences.Editor editor = preferences.edit(); |
| 101 | editor.putBoolean("nya", nya); |
| 102 | editor.commit(); |
| 103 | } |
| 104 | |
| 105 | public static void setNyaSuffix(String suffix) { |
| 106 | nyaSuffix = suffix; |
| 107 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 108 | SharedPreferences.Editor editor = preferences.edit(); |
| 109 | editor.putString("nyaSuffix", nyaSuffix); |
| 110 | editor.commit(); |
| 111 | } |
| 112 | |
| 113 | public static void setNameOrder(int order) { |
| 114 | nameOrder = order; |
| 115 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 116 | SharedPreferences.Editor editor = preferences.edit(); |
| 117 | editor.putInt("nameOrder", nameOrder); |
| 118 | editor.commit(); |
| 119 | } |
| 120 | |
| 121 | } |
| 122 | |