feat(UI): Hide Platform's not related settings (#1128)

This commit is contained in:
KingLucius 2024-06-09 17:38:08 +03:00 committed by GitHub
parent 3345326cb2
commit 4c95610238
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 55 additions and 10 deletions

View file

@ -36,6 +36,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.PHONE
import com.lagradost.cloudstream3.ui.settings.Globals.TV import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.hideOn
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
@ -298,10 +299,7 @@ class SettingsAccount : PreferenceFragmentCompat(), BiometricAuthenticator.Biome
hideKeyboard() hideKeyboard()
setPreferencesFromResource(R.xml.settings_account, rootKey) setPreferencesFromResource(R.xml.settings_account, rootKey)
// hide preference on tvs and emulators getPref(R.string.biometric_key)?.hideOn(TV or EMULATOR)?.setOnPreferenceClickListener {
getPref(R.string.biometric_key)?.isEnabled = isLayout(PHONE)
getPref(R.string.biometric_key)?.setOnPreferenceClickListener {
val ctx = context ?: return@setOnPreferenceClickListener false val ctx = context ?: return@setOnPreferenceClickListener false
if (deviceHasPasswordPinLock(ctx)) { if (deviceHasPasswordPinLock(ctx)) {

View file

@ -26,6 +26,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
import com.lagradost.cloudstream3.ui.settings.Globals.PHONE import com.lagradost.cloudstream3.ui.settings.Globals.PHONE
import com.lagradost.cloudstream3.ui.settings.Globals.TV import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
import com.lagradost.cloudstream3.utils.DataStoreHelper import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.UIHelper import com.lagradost.cloudstream3.utils.UIHelper
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
@ -53,6 +54,30 @@ class SettingsFragment : Fragment() {
} }
} }
/**
* Hide many Preferences on selected layouts.
**/
fun PreferenceFragmentCompat?.hidePrefs(ids: List<Int>, layoutFlags: Int) {
if (this == null) return
try {
ids.forEach {
getPref(it)?.isVisible = !isLayout(layoutFlags)
}
} catch (e: Exception) {
logError(e)
}
}
/**
* Hide the Preference on selected layouts.
**/
fun Preference?.hideOn(layoutFlags: Int): Preference? {
if (this == null) return null
this.isVisible = !isLayout(layoutFlags)
return this
}
/** /**
* On TV you cannot properly scroll to the bottom of settings, this fixes that. * On TV you cannot properly scroll to the bottom of settings, this fixes that.
* */ * */

View file

@ -27,10 +27,13 @@ import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.network.initClient import com.lagradost.cloudstream3.network.initClient
import com.lagradost.cloudstream3.ui.EasterEggMonke import com.lagradost.cloudstream3.ui.EasterEggMonke
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
import com.lagradost.cloudstream3.ui.settings.Globals.PHONE import com.lagradost.cloudstream3.ui.settings.Globals.PHONE
import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.beneneCount import com.lagradost.cloudstream3.ui.settings.Globals.beneneCount
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.hideOn
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
@ -208,9 +211,7 @@ class SettingsGeneral : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true return@setOnPreferenceClickListener true
} }
// disable preference on tvs and emulators getPref(R.string.battery_optimisation_key)?.hideOn(TV or EMULATOR)?.setOnPreferenceClickListener {
getPref(R.string.battery_optimisation_key)?.isEnabled = isLayout(PHONE)
getPref(R.string.battery_optimisation_key)?.setOnPreferenceClickListener {
val ctx = context ?: return@setOnPreferenceClickListener false val ctx = context ?: return@setOnPreferenceClickListener false
if (isAppRestricted(ctx)) { if (isAppRestricted(ctx)) {

View file

@ -7,8 +7,14 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
import com.lagradost.cloudstream3.ui.settings.Globals.PHONE
import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getFolderSize import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getFolderSize
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.hideOn
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.hidePrefs
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
@ -31,6 +37,18 @@ class SettingsPlayer : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.settings_player, rootKey) setPreferencesFromResource(R.xml.settings_player, rootKey)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext()) val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
//Hide specific prefs on TV/EMULATOR
hidePrefs(
listOf(
R.string.pref_category_gestures_key,
R.string.rotate_video_key,
R.string.auto_rotate_video_key
),
TV or EMULATOR
)
getPref(R.string.pref_category_android_tv_key)?.hideOn(PHONE)
getPref(R.string.video_buffer_length_key)?.setOnPreferenceClickListener { getPref(R.string.video_buffer_length_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.video_buffer_length_names) val prefNames = resources.getStringArray(R.array.video_buffer_length_names)
val prefValues = resources.getIntArray(R.array.video_buffer_length_values) val prefValues = resources.getIntArray(R.array.video_buffer_length_values)
@ -227,6 +245,5 @@ class SettingsPlayer : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true return@setOnPreferenceClickListener true
} }
} }
} }
} }

View file

@ -438,7 +438,9 @@
<string name="pref_category_actions">Actions</string> <string name="pref_category_actions">Actions</string>
<string name="pref_category_cache">Cache</string> <string name="pref_category_cache">Cache</string>
<string name="pref_category_android_tv">Android TV</string> <string name="pref_category_android_tv">Android TV</string>
<string name="pref_category_android_tv_key" translatable="false" >pref_category_android_tv_key</string>
<string name="pref_category_gestures">Gestures</string> <string name="pref_category_gestures">Gestures</string>
<string name="pref_category_gestures_key" translatable="false">pref_category_gestures_key</string>
<string name="pref_category_player_features">Player features</string> <string name="pref_category_player_features">Player features</string>
<string name="pref_category_subtitles">Subtitles</string> <string name="pref_category_subtitles">Subtitles</string>
<string name="pref_category_player_layout">Layout</string> <string name="pref_category_player_layout">Layout</string>

View file

@ -101,7 +101,8 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/pref_category_gestures"> android:title="@string/pref_category_gestures"
app:key="@string/pref_category_gestures_key">
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_ondemand_video_24" android:icon="@drawable/ic_baseline_ondemand_video_24"
android:summary="@string/swipe_to_seek_settings_des" android:summary="@string/swipe_to_seek_settings_des"
@ -166,7 +167,8 @@
android:title="@string/video_buffer_clear_settings" /> android:title="@string/video_buffer_clear_settings" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/pref_category_android_tv"> android:title="@string/pref_category_android_tv"
android:key="@string/pref_category_android_tv_key" >
<SeekBarPreference <SeekBarPreference
android:defaultValue="10" android:defaultValue="10"
android:max="60" android:max="60"