| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.app.Activity; |
| 4 | import android.content.Context; |
| 5 | import android.content.Intent; |
| 6 | import android.content.SharedPreferences; |
| 7 | |
| 8 | import org.telegram.messenger.ApplicationLoader; |
| 9 | import org.telegram.messenger.FileLog; |
| 10 | |
| 11 | public class NekoConfig { |
| 12 | |
| 13 | private static final Object sync = new Object(); |
| 14 | public static boolean useIPv6 = false; |
| 15 | public static boolean hidePhone = true; |
| 16 | public static boolean ignoreBlocked = false; |
| 17 | public static boolean forceTablet = false; |
| 18 | public static int nameOrder = 1; |
| 19 | public static boolean nya = false; |
| 20 | public static String nyaSuffix = "喵"; |
| 21 | public static boolean transparentStatusBar = true; |
| 22 | public static boolean navigationBarTint = true; |
| 23 | public static int navigationBarColor = 2; |
| 24 | public static boolean residentNotification = false; |
| 25 | private static boolean configLoaded; |
| 26 | |
| 27 | static { |
| 28 | loadConfig(); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | public static void saveConfig() { |
| 33 | synchronized (sync) { |
| 34 | try { |
| 35 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfing", Context.MODE_PRIVATE); |
| 36 | SharedPreferences.Editor editor = preferences.edit(); |
| 37 | editor.putBoolean("useIPv6", useIPv6); |
| 38 | editor.putBoolean("hidePhone", hidePhone); |
| 39 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 40 | editor.putBoolean("forceTablet", forceTablet); |
| 41 | editor.putInt("nameOrder", nameOrder); |
| 42 | editor.putBoolean("nya", nya); |
| 43 | editor.putString("nyaSuffix", nyaSuffix); |
| 44 | editor.putBoolean("transparentStatusBar", transparentStatusBar); |
| 45 | editor.putBoolean("navigationBarTint", navigationBarTint); |
| 46 | editor.putInt("navigationBarColor", navigationBarColor); |
| 47 | editor.putBoolean("residentNotification", residentNotification); |
| 48 | |
| 49 | editor.commit(); |
| 50 | } catch (Exception e) { |
| 51 | FileLog.e(e); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | public static void loadConfig() { |
| 57 | synchronized (sync) { |
| 58 | if (configLoaded) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 63 | useIPv6 = preferences.getBoolean("useIPv6", false); |
| 64 | hidePhone = preferences.getBoolean("hidePhone", true); |
| 65 | ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); |
| 66 | forceTablet = preferences.getBoolean("forceTablet", false); |
| 67 | nameOrder = preferences.getInt("nameOrder", 1); |
| 68 | nya = preferences.getBoolean("nya", false); |
| 69 | nyaSuffix = preferences.getString("nyaSuffix", "喵"); |
| 70 | transparentStatusBar = preferences.getBoolean("transparentStatusBar", true); |
| 71 | navigationBarTint = preferences.getBoolean("navigationBarTint", true); |
| 72 | navigationBarColor = preferences.getInt("navigationBarColor", 2); |
| 73 | residentNotification = preferences.getBoolean("residentNotification", false); |
| 74 | configLoaded = true; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public static void toggleIPv6() { |
| 79 | useIPv6 = !useIPv6; |
| 80 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 81 | SharedPreferences.Editor editor = preferences.edit(); |
| 82 | editor.putBoolean("useIPv6", useIPv6); |
| 83 | editor.commit(); |
| 84 | } |
| 85 | |
| 86 | public static void toggleHidePhone() { |
| 87 | hidePhone = !hidePhone; |
| 88 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 89 | SharedPreferences.Editor editor = preferences.edit(); |
| 90 | editor.putBoolean("hidePhone", hidePhone); |
| 91 | editor.commit(); |
| 92 | } |
| 93 | |
| 94 | public static void toggleIgnoreBlocked() { |
| 95 | ignoreBlocked = !ignoreBlocked; |
| 96 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 97 | SharedPreferences.Editor editor = preferences.edit(); |
| 98 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 99 | editor.commit(); |
| 100 | } |
| 101 | |
| 102 | public static void toggleForceTablet() { |
| 103 | forceTablet = !forceTablet; |
| 104 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 105 | SharedPreferences.Editor editor = preferences.edit(); |
| 106 | editor.putBoolean("forceTablet", forceTablet); |
| 107 | editor.commit(); |
| 108 | } |
| 109 | |
| 110 | public static void toggleNya() { |
| 111 | nya = !nya; |
| 112 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 113 | SharedPreferences.Editor editor = preferences.edit(); |
| 114 | editor.putBoolean("nya", nya); |
| 115 | editor.commit(); |
| 116 | } |
| 117 | |
| 118 | public static void setNyaSuffix(String suffix) { |
| 119 | nyaSuffix = suffix; |
| 120 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 121 | SharedPreferences.Editor editor = preferences.edit(); |
| 122 | editor.putString("nyaSuffix", nyaSuffix); |
| 123 | editor.commit(); |
| 124 | } |
| 125 | |
| 126 | public static void setNameOrder(int order) { |
| 127 | nameOrder = order; |
| 128 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 129 | SharedPreferences.Editor editor = preferences.edit(); |
| 130 | editor.putInt("nameOrder", nameOrder); |
| 131 | editor.commit(); |
| 132 | } |
| 133 | |
| 134 | public static void toggleTransparentStatusBar() { |
| 135 | transparentStatusBar = !transparentStatusBar; |
| 136 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 137 | SharedPreferences.Editor editor = preferences.edit(); |
| 138 | editor.putBoolean("transparentStatusBar", transparentStatusBar); |
| 139 | editor.commit(); |
| 140 | } |
| 141 | |
| 142 | public static void toggleNavigationBarTint() { |
| 143 | navigationBarTint = !navigationBarTint; |
| 144 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 145 | SharedPreferences.Editor editor = preferences.edit(); |
| 146 | editor.putBoolean("navigationBarTint", navigationBarTint); |
| 147 | editor.commit(); |
| 148 | } |
| 149 | |
| 150 | public static void setNavigationBarColor(int color) { |
| 151 | navigationBarColor = color; |
| 152 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 153 | SharedPreferences.Editor editor = preferences.edit(); |
| 154 | editor.putInt("navigationBarColor", navigationBarColor); |
| 155 | editor.commit(); |
| 156 | } |
| 157 | |
| 158 | public static void toggleResidentNotification() { |
| 159 | residentNotification = !residentNotification; |
| 160 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 161 | SharedPreferences.Editor editor = preferences.edit(); |
| 162 | editor.putBoolean("residentNotification", residentNotification); |
| 163 | editor.commit(); |
| 164 | Intent duangIntent = new Intent(ApplicationLoader.applicationContext, DuangService.class); |
| 165 | if (residentNotification) { |
| 166 | ApplicationLoader.applicationContext.startService(duangIntent); |
| 167 | } else { |
| 168 | ApplicationLoader.applicationContext.stopService(duangIntent); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | } |
| 173 | |