| 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 transparentStatusBar = true; |
| 20 | public static boolean navigationBarTint = true; |
| 21 | public static int navigationBarColor = 2; |
| 22 | public static boolean residentNotification = false; |
| 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("transparentStatusBar", transparentStatusBar); |
| 41 | editor.putBoolean("navigationBarTint", navigationBarTint); |
| 42 | editor.putInt("navigationBarColor", navigationBarColor); |
| 43 | editor.putBoolean("residentNotification", residentNotification); |
| 44 | |
| 45 | editor.commit(); |
| 46 | } catch (Exception e) { |
| 47 | FileLog.e(e); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public static void loadConfig() { |
| 53 | synchronized (sync) { |
| 54 | if (configLoaded) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 59 | useIPv6 = preferences.getBoolean("useIPv6", false); |
| 60 | hidePhone = preferences.getBoolean("hidePhone", true); |
| 61 | ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); |
| 62 | forceTablet = preferences.getBoolean("forceTablet", false); |
| 63 | nameOrder = preferences.getInt("nameOrder", 1); |
| 64 | transparentStatusBar = preferences.getBoolean("transparentStatusBar", true); |
| 65 | navigationBarTint = preferences.getBoolean("navigationBarTint", true); |
| 66 | navigationBarColor = preferences.getInt("navigationBarColor", 2); |
| 67 | residentNotification = preferences.getBoolean("residentNotification", false); |
| 68 | configLoaded = true; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | public static void toggleIPv6() { |
| 73 | useIPv6 = !useIPv6; |
| 74 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 75 | SharedPreferences.Editor editor = preferences.edit(); |
| 76 | editor.putBoolean("useIPv6", useIPv6); |
| 77 | editor.commit(); |
| 78 | } |
| 79 | |
| 80 | public static void toggleHidePhone() { |
| 81 | hidePhone = !hidePhone; |
| 82 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 83 | SharedPreferences.Editor editor = preferences.edit(); |
| 84 | editor.putBoolean("hidePhone", hidePhone); |
| 85 | editor.commit(); |
| 86 | } |
| 87 | |
| 88 | public static void toggleIgnoreBlocked() { |
| 89 | ignoreBlocked = !ignoreBlocked; |
| 90 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 91 | SharedPreferences.Editor editor = preferences.edit(); |
| 92 | editor.putBoolean("ignoreBlocked", ignoreBlocked); |
| 93 | editor.commit(); |
| 94 | } |
| 95 | |
| 96 | public static void toggleForceTablet() { |
| 97 | forceTablet = !forceTablet; |
| 98 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 99 | SharedPreferences.Editor editor = preferences.edit(); |
| 100 | editor.putBoolean("forceTablet", forceTablet); |
| 101 | editor.commit(); |
| 102 | } |
| 103 | |
| 104 | public static void setNameOrder(int order) { |
| 105 | nameOrder = order; |
| 106 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 107 | SharedPreferences.Editor editor = preferences.edit(); |
| 108 | editor.putInt("nameOrder", nameOrder); |
| 109 | editor.commit(); |
| 110 | } |
| 111 | |
| 112 | public static void toggleTransparentStatusBar() { |
| 113 | transparentStatusBar = !transparentStatusBar; |
| 114 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 115 | SharedPreferences.Editor editor = preferences.edit(); |
| 116 | editor.putBoolean("transparentStatusBar", transparentStatusBar); |
| 117 | editor.commit(); |
| 118 | } |
| 119 | |
| 120 | public static void toggleNavigationBarTint() { |
| 121 | navigationBarTint = !navigationBarTint; |
| 122 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 123 | SharedPreferences.Editor editor = preferences.edit(); |
| 124 | editor.putBoolean("navigationBarTint", navigationBarTint); |
| 125 | editor.commit(); |
| 126 | } |
| 127 | |
| 128 | public static void setNavigationBarColor(int color) { |
| 129 | navigationBarColor = color; |
| 130 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 131 | SharedPreferences.Editor editor = preferences.edit(); |
| 132 | editor.putInt("navigationBarColor", navigationBarColor); |
| 133 | editor.commit(); |
| 134 | } |
| 135 | |
| 136 | public static void toggleResidentNotification() { |
| 137 | residentNotification = !residentNotification; |
| 138 | SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); |
| 139 | SharedPreferences.Editor editor = preferences.edit(); |
| 140 | editor.putBoolean("residentNotification", residentNotification); |
| 141 | editor.commit(); |
| 142 | Intent duangIntent = new Intent(ApplicationLoader.applicationContext, DuangService.class); |
| 143 | if (residentNotification) { |
| 144 | ApplicationLoader.applicationContext.startService(duangIntent); |
| 145 | } else { |
| 146 | ApplicationLoader.applicationContext.stopService(duangIntent); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | |