From 01c81fc4215efb813961e40c87f851c6ec1ed02c Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Mon, 29 Aug 2022 02:32:17 +0800 Subject: [PATCH] [Feature] Copy settings values from Preferences to providers APIs (#48) * [Feature] Copy settings values from Preferences to providers APIs * Use companion object instead for singular object access across all providers * Fix build * Re-order code hierarchy. Prioritize loading settings from pref --- app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt | 5 +++++ .../main/java/com/lagradost/cloudstream3/MainActivity.kt | 5 +++++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/settings_media_lang.xml | 7 +++++++ 4 files changed, 20 insertions(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index f442e175..67a3051c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -315,6 +315,10 @@ data class ProvidersInfoJson( @JsonProperty("status") var status: Int, ) +data class SettingsJson( + @JsonProperty("enableAdult") var enableAdult: Boolean = false, +) + data class MainPageData( val name: String, @@ -354,6 +358,7 @@ fun newHomePageResponse(list: List, hasNext: Boolean? = null): Hom abstract class MainAPI { companion object { var overrideData: HashMap? = null + var settingsForProvider: SettingsJson = SettingsJson() } fun init() { diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 629406aa..44f78703 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -455,6 +455,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { override fun onCreate(savedInstanceState: Bundle?) { app.initClient(this) val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) + + val settingsForProvider = SettingsJson() + settingsForProvider.enableAdult = settingsManager.getBoolean(getString(R.string.enable_nsfw_on_providers_key), false) + + MainAPI.settingsForProvider = settingsForProvider loadThemes(this) updateLocale() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1b47b180..268d6246 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,6 +55,7 @@ redo_setup_key filter_sub_lang_key pref_filter_search_quality_key + enable_nsfw_on_providers_key %d %s | %s @@ -444,6 +445,7 @@ Provider languages App Layout Preferred media + Enable NSFW on supported providers Subtitle encoding Language Layout @@ -607,4 +609,5 @@ Download all plugins from this repository? %s (Disabled) + Apply on Restart diff --git a/app/src/main/res/xml/settings_media_lang.xml b/app/src/main/res/xml/settings_media_lang.xml index 575b638c..2244eff8 100644 --- a/app/src/main/res/xml/settings_media_lang.xml +++ b/app/src/main/res/xml/settings_media_lang.xml @@ -18,4 +18,11 @@ android:key="@string/display_sub_key" android:title="@string/display_subbed_dubbed_settings" android:icon="@drawable/ic_outline_voice_over_off_24" /> + + \ No newline at end of file