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