From 9be50eb28b861f90fc6a350fb9aea715a28390ff Mon Sep 17 00:00:00 2001
From: Jace <54625750+Jacekun@users.noreply.github.com>
Date: Sun, 27 Nov 2022 12:57:40 +0800
Subject: [PATCH] [Feature] Filter extension list automatically by preferred
media language.
---
.../ui/settings/extensions/PluginsFragment.kt | 16 ++++++++++++++++
app/src/main/res/values/strings.xml | 2 ++
app/src/main/res/xml/settings_providers.xml | 5 +++++
3 files changed, 23 insertions(+)
diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsFragment.kt
index bacd26c8..aa49c0e9 100644
--- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsFragment.kt
+++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsFragment.kt
@@ -8,6 +8,9 @@ import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
+import androidx.preference.PreferenceManager
+import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
+import com.lagradost.cloudstream3.AllLanguagesName
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.mvvm.observe
@@ -45,6 +48,19 @@ class PluginsFragment : Fragment() {
pluginViewModel.languages = listOf()
pluginViewModel.search(null)
+ // Filter by language set on preferred media
+ activity?.let {
+ val settingsManager = PreferenceManager.getDefaultSharedPreferences(it)
+ val filter = settingsManager.getBoolean(getString(R.string.pref_filter_ext_by_lang_key), false)
+ if (filter) {
+ val providerLangs = it.getApiProviderLangSettings().toList()
+ if (!providerLangs.contains(AllLanguagesName)) {
+ pluginViewModel.languages = providerLangs
+ //Log.i("DevDebug", "providerLang => ${pluginViewModel.languages.toJson()}")
+ }
+ }
+ }
+
val name = arguments?.getString(PLUGINS_BUNDLE_NAME)
val url = arguments?.getString(PLUGINS_BUNDLE_URL)
val isLocal = arguments?.getBoolean(PLUGINS_BUNDLE_LOCAL) == true
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9381372c..b4485c26 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -58,6 +58,7 @@
pref_filter_search_quality_key
enable_nsfw_on_providers_key
enable_skip_op_from_database
+ pref_filter_ext_by_lang_key
%d %s | %s
@@ -448,6 +449,7 @@
App Layout
Preferred media
Enable NSFW on supported providers
+ Filter Extension list by Preferred Language
Subtitle encoding
Providers
Layout
diff --git a/app/src/main/res/xml/settings_providers.xml b/app/src/main/res/xml/settings_providers.xml
index a177865b..ffcd3511 100644
--- a/app/src/main/res/xml/settings_providers.xml
+++ b/app/src/main/res/xml/settings_providers.xml
@@ -21,4 +21,9 @@
android:icon="@drawable/ic_baseline_extension_24"
android:summary="@string/apply_on_restart"
app:defaultValue="false"/>
+
\ No newline at end of file