removed potential killswitch

This commit is contained in:
LagradOst 2022-03-16 20:02:30 +01:00
parent 0f5971a870
commit 62266cedb2
3 changed files with 71 additions and 43 deletions

View file

@ -315,9 +315,16 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
api.init()
}
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val downloadFromGithub = try {
settingsManager.getBoolean(getString(R.string.killswitch_key), true)
} catch (e: Exception) {
logError(e)
false
}
// must give benenes to get beta providers
val hasBenene = try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val count = settingsManager.getInt(getString(R.string.benene_count), 0)
count > 30
} catch (e: Exception) {
@ -326,17 +333,21 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
}
// this pulls the latest data so ppl don't have to update to simply change provider url
if(downloadFromGithub) {
try {
runBlocking {
withContext(Dispatchers.IO) {
try {
val cacheStr: String? = getKey(PROVIDER_STATUS_KEY)
val cache : HashMap<String, ProvidersInfoJson>? = cacheStr?.let { tryParseJson(cacheStr) }
val cache: HashMap<String, ProvidersInfoJson>? =
cacheStr?.let { tryParseJson(cacheStr) }
if (cache != null) {
// if cache is found then spin up a new request, but dont wait
main {
try {
val txt = app.get(PROVIDER_STATUS_URL).text
val newCache = tryParseJson<HashMap<String, ProvidersInfoJson>>(txt)
val newCache =
tryParseJson<HashMap<String, ProvidersInfoJson>>(txt)
setKey(PROVIDER_STATUS_KEY, txt)
MainAPI.overrideData = newCache // update all new providers
for (api in apis) { // update current providers
@ -370,6 +381,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
acceptableProviders.contains(name) || restrictedApis.contains(name)
}
}
} catch (e : Exception) {
logError(e)
}
}
}
} catch (e: Exception) {
@ -377,6 +391,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
e.printStackTrace()
logError(e)
}
} else {
apis = allProviders
}
loadThemes(this)
updateLocale()

View file

@ -32,6 +32,7 @@
<string name="app_layout_key" translatable="false">app_layout_key</string>
<string name="primary_color_key" translatable="false">primary_color_key</string>
<string name="restore_key" translatable="false">restore_key</string>
<string name="killswitch_key" translatable="false">killswitch_key</string>
<string name="backup_key" translatable="false">backup_key</string>
<string name="prefer_media_type_key" translatable="false">prefer_media_type_key</string>
<string name="app_theme_key" translatable="false">app_theme_key</string>
@ -198,6 +199,9 @@
</string>
<string name="restore_settings">Restore data from backup</string>
<string name="killswitch_settings">Download latest metadata from github</string>
<string name="killswitch_settings_des">If you want access to all providers (even broken ones) turn this off</string>
<string name="backup_settings">Backup data</string>
<string name="restore_success">Loaded backup file</string>
<string name="restore_failed_format" formatted="true">Failed to restore data from file %s</string>

View file

@ -179,6 +179,13 @@
android:key="@string/restore_key"
android:title="@string/restore_settings" />
<SwitchPreference
android:icon="@drawable/netflix_download"
android:key="@string/killswitch_key"
android:defaultValue="true"
android:summary="@string/killswitch_settings_des"
android:title="@string/killswitch_settings" />
<Preference
android:key="@string/mal_key"
android:icon="@drawable/mal_logo" />