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() 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 // must give benenes to get beta providers
val hasBenene = try { val hasBenene = try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val count = settingsManager.getInt(getString(R.string.benene_count), 0) val count = settingsManager.getInt(getString(R.string.benene_count), 0)
count > 30 count > 30
} catch (e: Exception) { } catch (e: Exception) {
@ -326,56 +333,66 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
} }
// this pulls the latest data so ppl don't have to update to simply change provider url // this pulls the latest data so ppl don't have to update to simply change provider url
try { if(downloadFromGithub) {
runBlocking { try {
withContext(Dispatchers.IO) { runBlocking {
val cacheStr: String? = getKey(PROVIDER_STATUS_KEY) withContext(Dispatchers.IO) {
val cache : HashMap<String, ProvidersInfoJson>? = cacheStr?.let { tryParseJson(cacheStr) } try {
if (cache != null) { val cacheStr: String? = getKey(PROVIDER_STATUS_KEY)
// if cache is found then spin up a new request, but dont wait val cache: HashMap<String, ProvidersInfoJson>? =
main { cacheStr?.let { tryParseJson(cacheStr) }
try { if (cache != null) {
val txt = app.get(PROVIDER_STATUS_URL).text // if cache is found then spin up a new request, but dont wait
val newCache = tryParseJson<HashMap<String, ProvidersInfoJson>>(txt) main {
setKey(PROVIDER_STATUS_KEY, txt) try {
MainAPI.overrideData = newCache // update all new providers val txt = app.get(PROVIDER_STATUS_URL).text
for (api in apis) { // update current providers val newCache =
newCache?.get(api.javaClass.simpleName)?.let { data -> tryParseJson<HashMap<String, ProvidersInfoJson>>(txt)
api.overrideWithNewData(data) setKey(PROVIDER_STATUS_KEY, txt)
MainAPI.overrideData = newCache // update all new providers
for (api in apis) { // update current providers
newCache?.get(api.javaClass.simpleName)?.let { data ->
api.overrideWithNewData(data)
}
}
} catch (e: Exception) {
logError(e)
} }
} }
} catch (e : Exception) { cache
logError(e) } else {
// if it is the first time the user has used the app then wait for a request to update all providers
val txt = app.get(PROVIDER_STATUS_URL).text
setKey(PROVIDER_STATUS_KEY, txt)
val newCache = tryParseJson<HashMap<String, ProvidersInfoJson>>(txt)
newCache
}?.let { providersJsonMap ->
MainAPI.overrideData = providersJsonMap
val acceptableProviders =
providersJsonMap.filter { it.value.status == PROVIDER_STATUS_OK || it.value.status == PROVIDER_STATUS_SLOW }
.map { it.key }.toSet()
val restrictedApis =
if (hasBenene) providersJsonMap.filter { it.value.status == PROVIDER_STATUS_BETA_ONLY }
.map { it.key }.toSet() else emptySet()
apis = allProviders.filter { api ->
val name = api.javaClass.simpleName
acceptableProviders.contains(name) || restrictedApis.contains(name)
}
} }
} } catch (e : Exception) {
cache logError(e)
} else {
// if it is the first time the user has used the app then wait for a request to update all providers
val txt = app.get(PROVIDER_STATUS_URL).text
setKey(PROVIDER_STATUS_KEY, txt)
val newCache = tryParseJson<HashMap<String, ProvidersInfoJson>>(txt)
newCache
}?.let { providersJsonMap ->
MainAPI.overrideData = providersJsonMap
val acceptableProviders =
providersJsonMap.filter { it.value.status == PROVIDER_STATUS_OK || it.value.status == PROVIDER_STATUS_SLOW }
.map { it.key }.toSet()
val restrictedApis =
if (hasBenene) providersJsonMap.filter { it.value.status == PROVIDER_STATUS_BETA_ONLY }
.map { it.key }.toSet() else emptySet()
apis = allProviders.filter { api ->
val name = api.javaClass.simpleName
acceptableProviders.contains(name) || restrictedApis.contains(name)
} }
} }
} }
} catch (e: Exception) {
apis = allProviders
e.printStackTrace()
logError(e)
} }
} catch (e: Exception) { } else {
apis = allProviders apis = allProviders
e.printStackTrace()
logError(e)
} }
loadThemes(this) loadThemes(this)

View file

@ -32,6 +32,7 @@
<string name="app_layout_key" translatable="false">app_layout_key</string> <string name="app_layout_key" translatable="false">app_layout_key</string>
<string name="primary_color_key" translatable="false">primary_color_key</string> <string name="primary_color_key" translatable="false">primary_color_key</string>
<string name="restore_key" translatable="false">restore_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="backup_key" translatable="false">backup_key</string>
<string name="prefer_media_type_key" translatable="false">prefer_media_type_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> <string name="app_theme_key" translatable="false">app_theme_key</string>
@ -198,6 +199,9 @@
</string> </string>
<string name="restore_settings">Restore data from backup</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="backup_settings">Backup data</string>
<string name="restore_success">Loaded backup file</string> <string name="restore_success">Loaded backup file</string>
<string name="restore_failed_format" formatted="true">Failed to restore data from file %s</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:key="@string/restore_key"
android:title="@string/restore_settings" /> 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 <Preference
android:key="@string/mal_key" android:key="@string/mal_key"
android:icon="@drawable/mal_logo" /> android:icon="@drawable/mal_logo" />