| 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 typeface = 0; |
| 19 | public static int nameOrder = 1; |
| 20 | public static int mapPreviewProvider = 0; |
| 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 | |
| 26 | public static boolean showAddToSavedMessages = true; |
| 27 | public static boolean showReport = false; |
| 28 | public static boolean showPrPr = true; |
| 29 | public static boolean showAdminActions = true; |
| 30 | public static boolean showChangePermissions = true; |
| 31 | |
| 32 | public static boolean xmas = false; |
| 33 | public static boolean newYear = false; |
| 34 | public static boolean newYearEve = false; |
| 35 | public static boolean fireworks = false; |
| 36 | |
| 37 | private static boolean configLoaded; |
| 38 | |
| 39 | static { |
| 40 | loadConfig(); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | public static void saveConfig() { |
| 45 | synchronized (sync) { |
| 46 | try { |
| 47 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfing", Context.MODE_PRIVATE); |
| 48 | SharedPreferences.Editor editor = preferences.edit(); |
| 49 | editor.putBoolean("useIPv6", useIPv6); |
| 50 | editor.putBoolean("hidePhone", hidePhone); |
| 51 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 52 | editor.putBoolean("forceTablet", forceTablet); |
| 53 | editor.putInt("typeface", typeface); |
| 54 | editor.putInt("nameOrder", nameOrder); |
| 55 | editor.putInt("mapPreviewProvider", mapPreviewProvider); |
| 56 | editor.putBoolean("transparentStatusBar", transparentStatusBar); |
| 57 | editor.putBoolean("navigationBarTint", navigationBarTint); |
| 58 | editor.putInt("navigationBarColor", navigationBarColor); |
| 59 | editor.putBoolean("residentNotification", residentNotification); |
| 60 | editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages); |
| 61 | editor.putBoolean("showReport", showReport); |
| 62 | editor.putBoolean("showPrPr", showPrPr); |
| 63 | editor.putBoolean("showAdminActions", showAdminActions); |
| 64 | editor.putBoolean("showChangePermissions", showChangePermissions); |
| 65 | editor.putBoolean("xmas", xmas); |
| 66 | editor.putBoolean("newYear", newYear); |
| 67 | editor.putBoolean("newYearEve", newYearEve); |
| 68 | editor.putBoolean("fireworks", fireworks); |
| 69 | |
| 70 | editor.commit(); |
| 71 | } catch (Exception e) { |
| 72 | FileLog.e(e); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | public static void loadConfig() { |
| 78 | synchronized (sync) { |
| 79 | if (configLoaded) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 84 | useIPv6 = preferences.getBoolean("useIPv6", false); |
| 85 | hidePhone = preferences.getBoolean("hidePhone", true); |
| 86 | ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); |
| 87 | forceTablet = preferences.getBoolean("forceTablet", false); |
| 88 | typeface = preferences.getInt("typeface", 0); |
| 89 | nameOrder = preferences.getInt("nameOrder", 1); |
| 90 | mapPreviewProvider = preferences.getInt("mapPreviewProvider", 0); |
| 91 | transparentStatusBar = preferences.getBoolean("transparentStatusBar", true); |
| 92 | navigationBarTint = preferences.getBoolean("navigationBarTint", true); |
| 93 | navigationBarColor = preferences.getInt("navigationBarColor", 2); |
| 94 | residentNotification = preferences.getBoolean("residentNotification", false); |
| 95 | showAddToSavedMessages = preferences.getBoolean("showAddToSavedMessages", true); |
| 96 | showReport = preferences.getBoolean("showReport", false); |
| 97 | showPrPr = preferences.getBoolean("showPrPr", true); |
| 98 | showAdminActions = preferences.getBoolean("showAdminActions", true); |
| 99 | showChangePermissions = preferences.getBoolean("showChangePermissions", true); |
| 100 | xmas = preferences.getBoolean("xmas", false); |
| 101 | newYear = preferences.getBoolean("newYear", false); |
| 102 | newYearEve = preferences.getBoolean("newYearEve", false); |
| 103 | fireworks = preferences.getBoolean("fireworks", false); |
| 104 | configLoaded = true; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | public static void toggleShowAddToSavedMessages() { |
| 109 | showAddToSavedMessages = !showAddToSavedMessages; |
| 110 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 111 | SharedPreferences.Editor editor = preferences.edit(); |
| 112 | editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages); |
| 113 | editor.commit(); |
| 114 | } |
| 115 | |
| 116 | public static void toggleShowReport() { |
| 117 | showReport = !showReport; |
| 118 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 119 | SharedPreferences.Editor editor = preferences.edit(); |
| 120 | editor.putBoolean("showReport", showReport); |
| 121 | editor.commit(); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | public static void toggleShowPrPr() { |
| 126 | showPrPr = !showPrPr; |
| 127 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 128 | SharedPreferences.Editor editor = preferences.edit(); |
| 129 | editor.putBoolean("showPrPr", showPrPr); |
| 130 | editor.commit(); |
| 131 | } |
| 132 | |
| 133 | public static void toggleShowAdminActions() { |
| 134 | showAdminActions = !showAdminActions; |
| 135 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 136 | SharedPreferences.Editor editor = preferences.edit(); |
| 137 | editor.putBoolean("showAdminActions", showAdminActions); |
| 138 | editor.commit(); |
| 139 | } |
| 140 | |
| 141 | public static void toggleShowChangePermissions() { |
| 142 | showChangePermissions = !showChangePermissions; |
| 143 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 144 | SharedPreferences.Editor editor = preferences.edit(); |
| 145 | editor.putBoolean("showChangePermissions", showChangePermissions); |
| 146 | editor.commit(); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | public static void toggleIPv6() { |
| 151 | useIPv6 = !useIPv6; |
| 152 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 153 | SharedPreferences.Editor editor = preferences.edit(); |
| 154 | editor.putBoolean("useIPv6", useIPv6); |
| 155 | editor.commit(); |
| 156 | } |
| 157 | |
| 158 | public static void toggleHidePhone() { |
| 159 | hidePhone = !hidePhone; |
| 160 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 161 | SharedPreferences.Editor editor = preferences.edit(); |
| 162 | editor.putBoolean("hidePhone", hidePhone); |
| 163 | editor.commit(); |
| 164 | } |
| 165 | |
| 166 | public static void toggleIgnoreBlocked() { |
| 167 | ignoreBlocked = !ignoreBlocked; |
| 168 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 169 | SharedPreferences.Editor editor = preferences.edit(); |
| 170 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 171 | editor.commit(); |
| 172 | } |
| 173 | |
| 174 | public static void toggleForceTablet() { |
| 175 | forceTablet = !forceTablet; |
| 176 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 177 | SharedPreferences.Editor editor = preferences.edit(); |
| 178 | editor.putBoolean("forceTablet", forceTablet); |
| 179 | editor.commit(); |
| 180 | } |
| 181 | |
| 182 | public static void toggleTypeface() { |
| 183 | typeface = typeface == 0 ? 1 : 0; |
| 184 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 185 | SharedPreferences.Editor editor = preferences.edit(); |
| 186 | editor.putInt("typeface", typeface); |
| 187 | editor.commit(); |
| 188 | } |
| 189 | |
| 190 | public static void setNameOrder(int order) { |
| 191 | nameOrder = order; |
| 192 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 193 | SharedPreferences.Editor editor = preferences.edit(); |
| 194 | editor.putInt("nameOrder", nameOrder); |
| 195 | editor.commit(); |
| 196 | } |
| 197 | |
| 198 | public static void setMapPreviewProvider(int provider) { |
| 199 | mapPreviewProvider = provider; |
| 200 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 201 | SharedPreferences.Editor editor = preferences.edit(); |
| 202 | editor.putInt("mapPreviewProvider", mapPreviewProvider); |
| 203 | editor.commit(); |
| 204 | } |
| 205 | |
| 206 | public static void toggleTransparentStatusBar() { |
| 207 | transparentStatusBar = !transparentStatusBar; |
| 208 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 209 | SharedPreferences.Editor editor = preferences.edit(); |
| 210 | editor.putBoolean("transparentStatusBar", transparentStatusBar); |
| 211 | editor.commit(); |
| 212 | } |
| 213 | |
| 214 | public static void toggleNavigationBarTint() { |
| 215 | navigationBarTint = !navigationBarTint; |
| 216 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 217 | SharedPreferences.Editor editor = preferences.edit(); |
| 218 | editor.putBoolean("navigationBarTint", navigationBarTint); |
| 219 | editor.commit(); |
| 220 | } |
| 221 | |
| 222 | public static void setNavigationBarColor(int color) { |
| 223 | navigationBarColor = color; |
| 224 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 225 | SharedPreferences.Editor editor = preferences.edit(); |
| 226 | editor.putInt("navigationBarColor", navigationBarColor); |
| 227 | editor.commit(); |
| 228 | } |
| 229 | |
| 230 | public static void toggleResidentNotification() { |
| 231 | residentNotification = !residentNotification; |
| 232 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 233 | SharedPreferences.Editor editor = preferences.edit(); |
| 234 | editor.putBoolean("residentNotification", residentNotification); |
| 235 | editor.commit(); |
| 236 | Intent duangIntent = new Intent(ApplicationLoader.applicationContext, DuangService.class); |
| 237 | if (residentNotification) { |
| 238 | ApplicationLoader.applicationContext.startService(duangIntent); |
| 239 | } else { |
| 240 | ApplicationLoader.applicationContext.stopService(duangIntent); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | public static void toggleXmas() { |
| 245 | xmas = !xmas; |
| 246 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 247 | SharedPreferences.Editor editor = preferences.edit(); |
| 248 | editor.putBoolean("xmas", xmas); |
| 249 | editor.commit(); |
| 250 | } |
| 251 | |
| 252 | public static void toggleNewYear() { |
| 253 | newYear = !newYear; |
| 254 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 255 | SharedPreferences.Editor editor = preferences.edit(); |
| 256 | editor.putBoolean("newYear", newYear); |
| 257 | editor.commit(); |
| 258 | } |
| 259 | |
| 260 | public static void toggleNewYearEve() { |
| 261 | newYearEve = !newYearEve; |
| 262 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 263 | SharedPreferences.Editor editor = preferences.edit(); |
| 264 | editor.putBoolean("newYearEve", newYearEve); |
| 265 | editor.commit(); |
| 266 | } |
| 267 | |
| 268 | public static void toggleFireworks() { |
| 269 | fireworks = !fireworks; |
| 270 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 271 | SharedPreferences.Editor editor = preferences.edit(); |
| 272 | editor.putBoolean("fireworks", fireworks); |
| 273 | editor.commit(); |
| 274 | } |
| 275 | |
| 276 | } |
| 277 | |