diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/VideoAudioSettingsScreen.kt b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/VideoAudioSettingsScreen.kt index 0e52457cf..02a6b8506 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/VideoAudioSettingsScreen.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/screen/settings/VideoAudioSettingsScreen.kt @@ -16,6 +16,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.tooling.preview.PreviewWrapper @@ -56,8 +57,12 @@ fun VideoAudioSettingsScreen( val defaultPopupResolution by viewModel.defaultPopupResolution.collectAsStateWithLifecycle() val mobileDataResolution by viewModel.mobileDataResolution.collectAsStateWithLifecycle() val showHigherResolutions by viewModel.showHigherResolutions.collectAsStateWithLifecycle() - val resolutionValues by viewModel.resolutionValues.collectAsStateWithLifecycle() - val mobileDataResolutionValues by viewModel.mobileDataResolutionValues.collectAsStateWithLifecycle() + val resolutionValues = remember(showHigherResolutions) { + VideoAudioPreferences.resolutions(showHigherResolutions) + } + val mobileDataResolutionValues = remember(showHigherResolutions) { + VideoAudioPreferences.mobileDataResolutions(showHigherResolutions) + } val videoFormat by viewModel.videoFormat.collectAsStateWithLifecycle() val audioFormat by viewModel.audioFormat.collectAsStateWithLifecycle() val preferOriginalAudio by viewModel.preferOriginalAudio.collectAsStateWithLifecycle() diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/VideoAudioSettingsViewModel.kt b/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/VideoAudioSettingsViewModel.kt index 4aac58452..9a467688e 100644 --- a/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/VideoAudioSettingsViewModel.kt +++ b/shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/VideoAudioSettingsViewModel.kt @@ -47,14 +47,6 @@ class VideoAudioSettingsViewModel(private val settings: Settings) : ViewModel() ) ) - /** Resolution values available for the default & popup pickers; grows with [showHigherResolutions]. */ - val resolutionValues: StateFlow> - field = MutableStateFlow(VideoAudioPreferences.resolutions(showHigherResolutions.value)) - - /** Resolution values for the mobile-data limit picker; grows with [showHigherResolutions]. */ - val mobileDataResolutionValues: StateFlow> - field = MutableStateFlow(VideoAudioPreferences.mobileDataResolutions(showHigherResolutions.value)) - val videoFormat: StateFlow field = MutableStateFlow( settings.getString( @@ -102,16 +94,9 @@ class VideoAudioSettingsViewModel(private val settings: Settings) : ViewModel() mobileDataResolution.value = value } - /** - * Toggling higher resolutions rebuilds the pickers' option lists. When turning the option - * off, any currently selected high resolution is reset to the top entry, matching the legacy - * screen (which called `setValueIndex(0)`). - */ fun setShowHigherResolutions(value: Boolean) { settings.putBoolean(VideoAudioPreferences.KEY_SHOW_HIGHER_RESOLUTIONS, value) showHigherResolutions.value = value - resolutionValues.value = VideoAudioPreferences.resolutions(value) - mobileDataResolutionValues.value = VideoAudioPreferences.mobileDataResolutions(value) if (!value) { if (defaultResolution.value in VideoAudioPreferences.HIGH_RESOLUTIONS) { diff --git a/shared/src/commonTest/kotlin/net/newpipe/app/screen/settings/VideoAudioSettingsScreenTest.kt b/shared/src/commonTest/kotlin/net/newpipe/app/screen/settings/VideoAudioSettingsScreenTest.kt new file mode 100644 index 000000000..0731e89dc --- /dev/null +++ b/shared/src/commonTest/kotlin/net/newpipe/app/screen/settings/VideoAudioSettingsScreenTest.kt @@ -0,0 +1,55 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.screen.settings + +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.v2.runComposeUiTest +import com.russhwolf.settings.MapSettings +import com.russhwolf.settings.Settings +import kotlin.test.Test +import net.newpipe.app.extensions.withKoin +import net.newpipe.app.preferences.VideoAudioPreferences +import newpipe.shared.generated.resources.Res +import newpipe.shared.generated.resources.best_resolution +import newpipe.shared.generated.resources.default_resolution_title +import newpipe.shared.generated.resources.settings_category_video_audio_title +import org.jetbrains.compose.resources.getString +import org.koin.dsl.module + +@OptIn(ExperimentalTestApi::class) +class VideoAudioSettingsScreenTest { + + private val emptySettings = module { + single { MapSettings() } + } + + @Test + fun rendersTitleAndResolutionRow() = runComposeUiTest { + withKoin( + modules = listOf(emptySettings), + content = { VideoAudioSettingsScreenContent() }, + onContent = { + onNodeWithText(getString(Res.string.settings_category_video_audio_title)).assertIsDisplayed() + onNodeWithText(getString(Res.string.default_resolution_title)).assertIsDisplayed() + } + ) + } + + @Test + fun bestResolutionShowsLocalizedLabelAsSummary() = runComposeUiTest { + withKoin( + modules = listOf(emptySettings), + content = { + VideoAudioSettingsScreenContent(defaultResolution = VideoAudioPreferences.BEST_RESOLUTION) + }, + onContent = { + onNodeWithText(getString(Res.string.best_resolution)).assertIsDisplayed() + } + ) + } +} \ No newline at end of file