| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.content.Context; |
| 4 | import android.content.SharedPreferences; |
| 5 | import android.content.pm.ApplicationInfo; |
| 6 | import android.content.pm.PackageManager; |
| 7 | import android.content.res.Configuration; |
| 8 | import android.graphics.Typeface; |
| 9 | |
| 10 | import org.telegram.messenger.AndroidUtilities; |
| 11 | import org.telegram.messenger.ApplicationLoader; |
| 12 | import org.telegram.messenger.BuildConfig; |
| 13 | import org.telegram.messenger.BuildVars; |
| 14 | import org.telegram.messenger.FileLog; |
| 15 | import org.telegram.messenger.LocaleController; |
| 16 | import org.telegram.messenger.NotificationCenter; |
| 17 | import org.telegram.messenger.R; |
| 18 | import org.telegram.messenger.SharedConfig; |
| 19 | import org.telegram.messenger.UserConfig; |
| 20 | import org.telegram.ui.ActionBar.Theme; |
| 21 | |
| 22 | import java.io.BufferedReader; |
| 23 | import java.io.FileReader; |
| 24 | import java.util.Locale; |
| 25 | import java.util.regex.Matcher; |
| 26 | import java.util.regex.Pattern; |
| 27 | |
| 28 | import cn.hutool.core.util.ArrayUtil; |
| 29 | import cn.hutool.core.util.StrUtil; |
| 30 | import xyz.nextalone.nagram.NaConfig; |
| 31 | |
| 32 | public class NekoXConfig { |
| 33 | |
| 34 | // public static String FAQ_URL = "https://telegra.ph/NekoX-FAQ-03-31"; |
| 35 | public static String FAQ_URL = "https://github.com/NextAlone/Nagram#faq"; |
| 36 | public static long[] officialChats = { |
| 37 | // 1305127566, // NekoX Updates |
| 38 | // 1151172683, // NekoX Chat |
| 39 | // 1299578049, // NekoX Chat Channel |
| 40 | // 1137038259, // NekoX APKs |
| 41 | 1500637449, // Nagram |
| 42 | 1645699549, // Nagram Updates |
| 43 | 2001739482, // Nagram Tips |
| 44 | 1633997447, // PagerGram Chat |
| 45 | 1780943907, // PagerGram APKs |
| 46 | }; |
| 47 | |
| 48 | public static long[] developers = { |
| 49 | 896711046, // nekohasekai |
| 50 | 380570774, // Haruhi |
| 51 | 784901712, // NextAlone |
| 52 | 457896977, // Queally |
| 53 | 782954985, // MaiTungTM |
| 54 | 5412523572L, //blxueya |
| 55 | 676660002, // mrwangzhe |
| 56 | 583325201, // sam |
| 57 | 842474872, // null |
| 58 | 1068402676, // Kitsune |
| 59 | 6244360706L, // Sevtinge |
| 60 | }; |
| 61 | |
| 62 | public static final int TITLE_TYPE_TEXT = 0; |
| 63 | public static final int TITLE_TYPE_ICON = 1; |
| 64 | public static final int TITLE_TYPE_MIX = 2; |
| 65 | |
| 66 | private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf"; |
| 67 | |
| 68 | public static boolean loadSystemEmojiFailed = false; |
| 69 | private static Typeface systemEmojiTypeface; |
| 70 | |
| 71 | |
| 72 | public static SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekox_config", Context.MODE_PRIVATE); |
| 73 | |
| 74 | public static boolean disableFlagSecure = NaConfig.INSTANCE.getDisableFlagSecure().Bool(); |
| 75 | |
| 76 | public static int autoUpdateReleaseChannel = preferences.getInt("autoUpdateReleaseChannel", 2); |
| 77 | // public static String ignoredUpdateTag = preferences.getString("ignoredUpdateTag", ""); |
| 78 | // public static long nextUpdateCheck = preferences.getLong("nextUpdateCheckTimestamp", 0); |
| 79 | |
| 80 | public static int customApi = preferences.getInt("custom_api", 0); |
| 81 | public static int customAppId = preferences.getInt("custom_app_id", 0); |
| 82 | public static String customAppHash = preferences.getString("custom_app_hash", ""); |
| 83 | |
| 84 | private static Boolean hasDeveloper = null; |
| 85 | |
| 86 | public static int currentAppId() { |
| 87 | switch (customApi) { |
| 88 | case -1: |
| 89 | case 0: |
| 90 | return BuildConfig.APP_ID; |
| 91 | case 1: |
| 92 | return BuildVars.OFFICAL_APP_ID; |
| 93 | case 2: |
| 94 | return BuildVars.TGX_APP_ID; |
| 95 | default: |
| 96 | return customAppId; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | public static String currentAppHash() { |
| 101 | switch (customApi) { |
| 102 | case -1: |
| 103 | case 0: |
| 104 | return BuildConfig.APP_HASH; |
| 105 | case 1: |
| 106 | return BuildVars.OFFICAL_APP_HASH; |
| 107 | case 2: |
| 108 | return BuildVars.TGX_APP_HASH; |
| 109 | default: |
| 110 | return customAppHash; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | public static void saveCustomApi() { |
| 115 | preferences.edit() |
| 116 | .putInt("custom_api", customApi) |
| 117 | .putInt("custom_app_id", customAppId) |
| 118 | .putString("custom_app_hash", customAppHash) |
| 119 | .apply(); |
| 120 | } |
| 121 | |
| 122 | public static void setAutoUpdateReleaseChannel(int channel) { |
| 123 | preferences.edit().putInt("autoUpdateReleaseChannel", autoUpdateReleaseChannel = channel).apply(); |
| 124 | } |
| 125 | |
| 126 | public static boolean isDeveloper() { |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | public static String getOpenPGPAppName() { |
| 131 | if (StrUtil.isNotBlank(NekoConfig.openPGPApp.String())) { |
| 132 | try { |
| 133 | PackageManager manager = ApplicationLoader.applicationContext.getPackageManager(); |
| 134 | ApplicationInfo info = manager.getApplicationInfo(NekoConfig.openPGPApp.String(), PackageManager.GET_META_DATA); |
| 135 | return (String) manager.getApplicationLabel(info); |
| 136 | } catch (PackageManager.NameNotFoundException e) { |
| 137 | NekoConfig.openPGPApp.setConfigString(""); |
| 138 | } |
| 139 | } |
| 140 | return LocaleController.getString("None", R.string.None); |
| 141 | } |
| 142 | |
| 143 | public static String formatLang(String name) { |
| 144 | if (name == null || name.isEmpty()) { |
| 145 | return LocaleController.getString("Default", R.string.Default); |
| 146 | } else { |
| 147 | if (name.contains("-")) { |
| 148 | return new Locale(StrUtil.subBefore(name, "-", false), StrUtil.subAfter(name, "-", false)).getDisplayName(LocaleController.getInstance().currentLocale); |
| 149 | } else { |
| 150 | return new Locale(name).getDisplayName(LocaleController.getInstance().currentLocale); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | public static Typeface getSystemEmojiTypeface() { |
| 156 | if (!loadSystemEmojiFailed && systemEmojiTypeface == null) { |
| 157 | try { |
| 158 | Pattern p = Pattern.compile(">(.*emoji.*)</font>", Pattern.CASE_INSENSITIVE); |
| 159 | BufferedReader br = new BufferedReader(new FileReader("/system/etc/fonts.xml")); |
| 160 | String line; |
| 161 | while ((line = br.readLine()) != null) { |
| 162 | Matcher m = p.matcher(line); |
| 163 | if (m.find()) { |
| 164 | systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + m.group(1)); |
| 165 | FileLog.d("emoji font file fonts.xml = " + m.group(1)); |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | br.close(); |
| 170 | } catch (Exception e) { |
| 171 | FileLog.e(e); |
| 172 | } |
| 173 | if (systemEmojiTypeface == null) { |
| 174 | try { |
| 175 | systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + EMOJI_FONT_AOSP); |
| 176 | FileLog.d("emoji font file = " + EMOJI_FONT_AOSP); |
| 177 | } catch (Exception e) { |
| 178 | FileLog.e(e); |
| 179 | loadSystemEmojiFailed = true; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | return systemEmojiTypeface; |
| 184 | } |
| 185 | |
| 186 | public static int getNotificationColor() { |
| 187 | int color = 0; |
| 188 | Configuration configuration = ApplicationLoader.applicationContext.getResources().getConfiguration(); |
| 189 | boolean isDark = (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; |
| 190 | if (isDark) { |
| 191 | color = 0xffffffff; |
| 192 | } else { |
| 193 | if (Theme.getActiveTheme().hasAccentColors()) { |
| 194 | color = Theme.getActiveTheme().getAccentColor(Theme.getActiveTheme().currentAccentId); |
| 195 | } |
| 196 | if (Theme.getActiveTheme().isDark() || color == 0) { |
| 197 | color = Theme.getColor(Theme.key_actionBarDefault); |
| 198 | } |
| 199 | // too bright |
| 200 | if (AndroidUtilities.computePerceivedBrightness(color) >= 0.721f) { |
| 201 | color = Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader) | 0xff000000; |
| 202 | } |
| 203 | } |
| 204 | return color; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | public static void setChannelAlias(long channelID, String name) { |
| 209 | preferences.edit().putString(NekoConfig.channelAliasPrefix + channelID, name).apply(); |
| 210 | } |
| 211 | |
| 212 | public static void emptyChannelAlias(long channelID) { |
| 213 | preferences.edit().remove(NekoConfig.channelAliasPrefix + channelID).apply(); |
| 214 | } |
| 215 | |
| 216 | public static String getChannelAlias(long channelID) { |
| 217 | return preferences.getString(NekoConfig.channelAliasPrefix + channelID, null); |
| 218 | } |
| 219 | } |
| 220 | |