From 62266cedb273fb7bda76120167fcb04cabcee5b2 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Wed, 16 Mar 2022 20:02:30 +0100 Subject: [PATCH] removed potential killswitch --- .../lagradost/cloudstream3/MainActivity.kt | 103 ++++++++++-------- app/src/main/res/values/strings.xml | 4 + app/src/main/res/xml/settings.xml | 7 ++ 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 01445dae..0df034f4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -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,56 +333,66 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { } // this pulls the latest data so ppl don't have to update to simply change provider url - try { - runBlocking { - withContext(Dispatchers.IO) { - val cacheStr: String? = getKey(PROVIDER_STATUS_KEY) - val cache : HashMap? = 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>(txt) - 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) + if(downloadFromGithub) { + try { + runBlocking { + withContext(Dispatchers.IO) { + try { + val cacheStr: String? = getKey(PROVIDER_STATUS_KEY) + val cache: HashMap? = + 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>(txt) + 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) { - logError(e) + cache + } 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>(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) + } } - } - cache - } 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>(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) { + logError(e) } } } + } catch (e: Exception) { + apis = allProviders + e.printStackTrace() + logError(e) } - } catch (e: Exception) { + } else { apis = allProviders - e.printStackTrace() - logError(e) } loadThemes(this) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c8546a9a..c6f60da3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,6 +32,7 @@ app_layout_key primary_color_key restore_key + killswitch_key backup_key prefer_media_type_key app_theme_key @@ -198,6 +199,9 @@ Restore data from backup + Download latest metadata from github + If you want access to all providers (even broken ones) turn this off + Backup data Loaded backup file Failed to restore data from file %s diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 29e53091..c1fec4aa 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -179,6 +179,13 @@ android:key="@string/restore_key" android:title="@string/restore_settings" /> + +