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