mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
removed potential killswitch
This commit is contained in:
parent
0f5971a870
commit
62266cedb2
3 changed files with 71 additions and 43 deletions
|
@ -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<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)
|
||||
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<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)
|
||||
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<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)
|
||||
}
|
||||
}
|
||||
}
|
||||
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<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) {
|
||||
logError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
apis = allProviders
|
||||
e.printStackTrace()
|
||||
logError(e)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
} else {
|
||||
apis = allProviders
|
||||
e.printStackTrace()
|
||||
logError(e)
|
||||
}
|
||||
|
||||
loadThemes(this)
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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" />
|
||||
|
|
Loading…
Reference in a new issue