[Feature] Filter extension list automatically by preferred media language.

This commit is contained in:
Jace 2022-11-27 12:57:40 +08:00 committed by Cloudburst
parent 789f3db554
commit 9be50eb28b
3 changed files with 23 additions and 0 deletions

View file

@ -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

View file

@ -58,6 +58,7 @@
<string name="pref_filter_search_quality_key" translatable="false">pref_filter_search_quality_key</string>
<string name="enable_nsfw_on_providers_key" translatable="false">enable_nsfw_on_providers_key</string>
<string name="enable_skip_op_from_database" translatable="false">enable_skip_op_from_database</string>
<string name="pref_filter_ext_by_lang_key" translatable="false">pref_filter_ext_by_lang_key</string>
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
<string name="extra_info_format" formatted="true" translatable="false">%d %s | %s</string>
@ -448,6 +449,7 @@
<string name="app_layout">App Layout</string>
<string name="preferred_media_settings">Preferred media</string>
<string name="enable_nsfw_on_providers">Enable NSFW on supported providers</string>
<string name="filter_ext_by_preferred_lang">Filter Extension list by Preferred Language</string>
<string name="subtitles_encoding">Subtitle encoding</string>
<string name="category_providers">Providers</string>
<string name="category_ui">Layout</string>

View file

@ -21,4 +21,9 @@
android:icon="@drawable/ic_baseline_extension_24"
android:summary="@string/apply_on_restart"
app:defaultValue="false"/>
<SwitchPreference
android:key="@string/pref_filter_ext_by_lang_key"
android:title="@string/filter_ext_by_preferred_lang"
android:icon="@drawable/ic_baseline_extension_24"
app:defaultValue="false"/>
</PreferenceScreen>