make the setting work

This commit is contained in:
Cloudburst 2023-02-21 12:55:37 +01:00
parent e9343bafc2
commit 228626c27c
5 changed files with 18 additions and 12 deletions

View file

@ -721,16 +721,16 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
changeStatusBarState(isEmulatorSettings()) changeStatusBarState(isEmulatorSettings())
// Automatically enable jsdelivr if cant connect to raw.githubusercontent.com // Automatically enable jsdelivr if cant connect to raw.githubusercontent.com
if (!settingsManager.contains("jsdelivr_proxy_key") && isNetworkAvailable()) { if (this.getKey<Boolean>(getString(R.string.jsdelivr_proxy_key)) == null && isNetworkAvailable()) {
main { main {
if (checkGithubConnectivity()) { if (checkGithubConnectivity()) {
this.setKey("jsdelivr_proxy_key", false) this.setKey(getString(R.string.jsdelivr_proxy_key), false)
} else { } else {
this.setKey("jsdelivr_proxy_key", true) this.setKey(getString(R.string.jsdelivr_proxy_key), true)
val parentView: View = findViewById(android.R.id.content) val parentView: View = findViewById(android.R.id.content)
Snackbar.make(parentView, R.string.jsdelivr_enabled, Snackbar.LENGTH_LONG).let { snackbar -> Snackbar.make(parentView, R.string.jsdelivr_enabled, Snackbar.LENGTH_LONG).let { snackbar ->
snackbar.setAction(R.string.revert) { v -> snackbar.setAction(R.string.revert) {
setKey("jsdelivr_proxy_key", false) setKey(getString(R.string.jsdelivr_proxy_key), false)
} }
snackbar.setBackgroundTint(colorFromAttribute(R.attr.primaryGrayBackground)) snackbar.setBackgroundTint(colorFromAttribute(R.attr.primaryGrayBackground))
snackbar.setTextColor(colorFromAttribute(R.attr.textColor)) snackbar.setTextColor(colorFromAttribute(R.attr.textColor))

View file

@ -2,8 +2,10 @@ package com.lagradost.cloudstream3.plugins
import android.content.Context import android.content.Context
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.AcraApplication.Companion.context
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.amap import com.lagradost.cloudstream3.amap
import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
@ -75,7 +77,7 @@ object RepositoryManager {
/* Convert raw.githubusercontent.com urls to cdn.jsdelivr.net if enabled in settings */ /* Convert raw.githubusercontent.com urls to cdn.jsdelivr.net if enabled in settings */
fun convertRawGitUrl(url: String): String { fun convertRawGitUrl(url: String): String {
if (!(getKey<Boolean>("jsdelivr_proxy_key") ?: false)) return url if (getKey<Boolean>(context!!.getString(R.string.jsdelivr_proxy_key)) != true) return url
val match = GH_REGEX.find(url) ?: return url val match = GH_REGEX.find(url) ?: return url
val (user, repo, rest) = match.destructured val (user, repo, rest) = match.destructured
return "https://cdn.jsdelivr.net/gh/$user/$repo@$rest" return "https://cdn.jsdelivr.net/gh/$user/$repo@$rest"

View file

@ -82,7 +82,7 @@ val appLanguages = arrayListOf(
Triple("", "norsk bokmål", "no"), Triple("", "norsk bokmål", "no"),
Triple("", "polski", "pl"), Triple("", "polski", "pl"),
Triple("\uD83C\uDDF5\uD83C\uDDF9", "português", "pt"), Triple("\uD83C\uDDF5\uD83C\uDDF9", "português", "pt"),
Triple("🦍", "mmmm... monke", "qt"), Triple("\uD83E\uDD8D", "mmmm... monke", "qt"),
Triple("", "română", "ro"), Triple("", "română", "ro"),
Triple("", "русский", "ru"), Triple("", "русский", "ru"),
Triple("", "slovenčina", "sk"), Triple("", "slovenčina", "sk"),
@ -97,7 +97,7 @@ val appLanguages = arrayListOf(
Triple("", "中文", "zh"), Triple("", "中文", "zh"),
Triple("\uD83C\uDDF9\uD83C\uDDFC", "文言", "zh-rTW"), Triple("\uD83C\uDDF9\uD83C\uDDFC", "文言", "zh-rTW"),
/* end language list */ /* end language list */
).sortedBy { it.second?.toLowerCase() } //ye, we go alphabetical, so ppl don't put their lang on top ).sortedBy { it.second.lowercase() } //ye, we go alphabetical, so ppl don't put their lang on top
class SettingsGeneral : PreferenceFragmentCompat() { class SettingsGeneral : PreferenceFragmentCompat() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -157,9 +157,6 @@ class SettingsGeneral : PreferenceFragmentCompat() {
getPref(R.string.locale_key)?.setOnPreferenceClickListener { pref -> getPref(R.string.locale_key)?.setOnPreferenceClickListener { pref ->
val tempLangs = appLanguages.toMutableList() val tempLangs = appLanguages.toMutableList()
//if (beneneCount > 100) {
// tempLangs.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo"))
//}
val current = getCurrentLocale(pref.context) val current = getCurrentLocale(pref.context)
val languageCodes = tempLangs.map { (_, _, iso) -> iso } val languageCodes = tempLangs.map { (_, _, iso) -> iso }
val languageNames = tempLangs.map { (emoji, name, iso) -> val languageNames = tempLangs.map { (emoji, name, iso) ->
@ -316,6 +313,12 @@ class SettingsGeneral : PreferenceFragmentCompat() {
} ?: emptyList() } ?: emptyList()
} }
settingsManager.edit().putBoolean(getString(R.string.jsdelivr_proxy_key), getKey(getString(R.string.jsdelivr_proxy_key), false) ?: false).apply()
getPref(R.string.jsdelivr_proxy_key)?.setOnPreferenceChangeListener { _, newValue ->
setKey(getString(R.string.jsdelivr_proxy_key), newValue)
return@setOnPreferenceChangeListener true
}
getPref(R.string.download_path_key)?.setOnPreferenceClickListener { getPref(R.string.download_path_key)?.setOnPreferenceClickListener {
val dirs = getDownloadDirs() val dirs = getDownloadDirs()

View file

@ -42,6 +42,7 @@
<string name="random_button_key" translatable="false">random_button_key</string> <string name="random_button_key" translatable="false">random_button_key</string>
<string name="provider_lang_key" translatable="false">provider_lang_key</string> <string name="provider_lang_key" translatable="false">provider_lang_key</string>
<string name="dns_key" translatable="false">dns_key</string> <string name="dns_key" translatable="false">dns_key</string>
<string name="jsdelivr_proxy_key" translatable="false">jsdelivr_proxy_key</string>
<string name="download_path_key" translatable="false">download_path_key</string> <string name="download_path_key" translatable="false">download_path_key</string>
<string name="app_name_download_path" translatable="false">Cloudstream</string> <string name="app_name_download_path" translatable="false">Cloudstream</string>
<string name="app_layout_key" translatable="false">app_layout_key</string> <string name="app_layout_key" translatable="false">app_layout_key</string>

View file

@ -40,7 +40,7 @@
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:icon="@drawable/ic_github_logo" android:icon="@drawable/ic_github_logo"
android:key="jsdelivr_proxy_key" android:key="@string/jsdelivr_proxy_key"
android:title="@string/jsdelivr_proxy" android:title="@string/jsdelivr_proxy"
android:summary="@string/jsdelivr_proxy_summary" /> android:summary="@string/jsdelivr_proxy_summary" />