mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-10-11 02:01:49 +00:00
refactored code and added video/audio settings test
This commit is contained in:
committed by
Aayush Gupta
parent
b8f9c58523
commit
939ff4254f
+7
-2
@@ -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()
|
||||
|
||||
-15
@@ -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<List<String>>
|
||||
field = MutableStateFlow(VideoAudioPreferences.resolutions(showHigherResolutions.value))
|
||||
|
||||
/** Resolution values for the mobile-data limit picker; grows with [showHigherResolutions]. */
|
||||
val mobileDataResolutionValues: StateFlow<List<String>>
|
||||
field = MutableStateFlow(VideoAudioPreferences.mobileDataResolutions(showHigherResolutions.value))
|
||||
|
||||
val videoFormat: StateFlow<String>
|
||||
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) {
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* 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<Settings> { 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()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user