Rearrange settings based on player backend

This commit is contained in:
Damontecres 2025-11-07 17:46:59 -05:00
parent adbbd1c648
commit 24e4acec11
No known key found for this signature in database
4 changed files with 35 additions and 11 deletions

View file

@ -8,6 +8,7 @@ import androidx.preference.PreferenceManager
import com.github.damontecres.wholphin.R
import com.github.damontecres.wholphin.WholphinApplication
import com.github.damontecres.wholphin.ui.nav.Destination
import com.github.damontecres.wholphin.ui.preferences.ConditionalPreferences
import com.github.damontecres.wholphin.ui.preferences.PreferenceGroup
import com.github.damontecres.wholphin.ui.preferences.PreferenceScreenOption
import com.github.damontecres.wholphin.ui.preferences.PreferenceValidation
@ -769,6 +770,7 @@ val advancedPreferences =
preferences =
listOf(
AppPreference.OneClickPause,
AppPreference.GlobalContentScale,
AppPreference.SkipIntros,
AppPreference.SkipOutros,
AppPreference.SkipCommercials,
@ -776,20 +778,27 @@ val advancedPreferences =
AppPreference.SkipRecaps,
AppPreference.MaxBitrate,
AppPreference.PlaybackDebugInfo,
AppPreference.PlayerBackendPref,
AppPreference.MpvHardwareDecoding,
),
),
PreferenceGroup(
title = R.string.playback_overrides,
preferences =
title = R.string.player_backend,
preferences = listOf(AppPreference.PlayerBackendPref),
conditionalPreferences =
listOf(
AppPreference.GlobalContentScale,
ConditionalPreferences(
{ it.playbackPreferences.playerBackend == PlayerBackend.EXO_PLAYER },
listOf(
AppPreference.FfmpegPreference,
AppPreference.DownMixStereo,
AppPreference.Ac3Supported,
AppPreference.DirectPlayAss,
AppPreference.DirectPlayPgs,
AppPreference.FfmpegPreference,
),
),
ConditionalPreferences(
{ it.playbackPreferences.playerBackend == PlayerBackend.MPV },
listOf(AppPreference.MpvHardwareDecoding),
),
),
),
PreferenceGroup(

View file

@ -2,6 +2,7 @@ package com.github.damontecres.wholphin.ui.preferences
import androidx.annotation.StringRes
import com.github.damontecres.wholphin.preferences.AppPreference
import com.github.damontecres.wholphin.preferences.AppPreferences
import kotlinx.serialization.Serializable
/**
@ -10,6 +11,12 @@ import kotlinx.serialization.Serializable
data class PreferenceGroup(
@param:StringRes val title: Int,
val preferences: List<AppPreference<out Any?>>,
val conditionalPreferences: List<ConditionalPreferences> = listOf(),
)
data class ConditionalPreferences(
val condition: (AppPreferences) -> Boolean,
val preferences: List<AppPreference<out Any?>>,
)
/**

View file

@ -175,7 +175,13 @@ fun PreferencesContent(
.padding(top = 8.dp, bottom = 4.dp),
)
}
group.preferences.forEachIndexed { prefIndex, pref ->
val groupPreferences =
group.preferences +
group.conditionalPreferences
.filter { it.condition.invoke(preferences) }
.map { it.preferences }
.flatten()
groupPreferences.forEachIndexed { prefIndex, pref ->
pref as AppPreference<Any>
item {
val interactionSource = remember { MutableInteractionSource() }

View file

@ -147,6 +147,8 @@
<string name="player_backend">Playback Backend</string>
<string name="mpv_hardware_decoding">MPV: Use hardware decoding</string>
<string name="disable_if_crash">Disable if you experience crashes</string>
<string name="mpv_options">MPV Options</string>
<string name="exoplayer_options">ExoPlayer Options</string>
<plurals name="downloads">
<item quantity="zero">%d downloads</item>