Preferences update, play theme song volume

This commit is contained in:
Damontecres 2025-10-06 12:34:27 -04:00
parent 3a255fcd8a
commit 628771211d
No known key found for this signature in database
8 changed files with 206 additions and 37 deletions

View file

@ -66,7 +66,7 @@ fun SeriesDetails(
viewModel: SeriesViewModel = hiltViewModel(),
) {
LaunchedEffect(Unit) {
viewModel.init(destination.itemId, destination.item, null, null)
viewModel.init(preferences, destination.itemId, destination.item, null, null)
}
val loading by viewModel.loading.observeAsState(LoadingState.Loading)

View file

@ -14,6 +14,8 @@ import com.github.damontecres.dolphin.data.model.BaseItem
import com.github.damontecres.dolphin.data.model.Person
import com.github.damontecres.dolphin.data.model.Video
import com.github.damontecres.dolphin.hilt.AuthOkHttpClient
import com.github.damontecres.dolphin.preferences.ThemeSongVolume
import com.github.damontecres.dolphin.preferences.UserPreferences
import com.github.damontecres.dolphin.ui.letNotEmpty
import com.github.damontecres.dolphin.util.ApiRequestPager
import com.github.damontecres.dolphin.util.ExceptionHandler
@ -59,6 +61,7 @@ class SeriesViewModel
val people = MutableLiveData<List<Person>>(listOf())
fun init(
prefs: UserPreferences,
itemId: UUID,
potential: BaseItem?,
season: Int?,
@ -89,7 +92,7 @@ class SeriesViewModel
people.map { Person.fromDto(it, api) }
}.orEmpty()
}
maybePlayThemeSong()
maybePlayThemeSong(prefs.appPreferences.interfacePreferences.playThemeSongs)
} else {
withContext(Dispatchers.Main) {
seasons.value = ItemListAndMapping.empty()
@ -101,8 +104,19 @@ class SeriesViewModel
}
@OptIn(UnstableApi::class)
private fun maybePlayThemeSong() {
// TODO user preference to enable/disable this
private fun maybePlayThemeSong(playThemeSongs: ThemeSongVolume) {
val volume =
when (playThemeSongs) {
ThemeSongVolume.UNRECOGNIZED,
ThemeSongVolume.DISABLED,
-> return
ThemeSongVolume.LOWEST -> .1f
ThemeSongVolume.LOW -> .25f
ThemeSongVolume.MEDIUM -> .5f
ThemeSongVolume.HIGH -> .75f
ThemeSongVolume.HIGHEST -> 1f
}
viewModelScope.launch(ExceptionHandler()) {
val themeSongs = api.libraryApi.getThemeSongs(seriesId).content
themeSongs.items.firstOrNull()?.let { theme ->
@ -123,7 +137,7 @@ class SeriesViewModel
),
).build()
.apply {
volume = .1f
this.volume = volume
playWhenReady = true
this@SeriesViewModel.player = this
}

View file

@ -57,6 +57,7 @@ fun SeriesOverview(
OneTimeLaunchedEffect {
Timber.v("SeriesDetailParent: itemId=${destination.itemId}, initialSeasonEpisode=$initialSeasonEpisode")
viewModel.init(
preferences,
destination.itemId,
destination.item,
initialSeasonEpisode?.season,

View file

@ -20,6 +20,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
@ -76,7 +77,8 @@ fun PreferencesContent(
}
val movementSounds = true
val installedVersion = remember { "v1.0.0" }
val installedVersion =
remember { context.packageManager.getPackageInfo(context.packageName, 0).versionName }
var updateVersion by remember { mutableStateOf<Release?>(null) }
val updateAvailable = false
// remember(updateVersion) { updateVersion?.version?.isGreaterThan(installedVersion) == true }
@ -188,27 +190,27 @@ fun PreferencesContent(
}
}
when (pref) {
// AppPreference.InstalledVersion -> {
// var clickCount by remember { mutableIntStateOf(0) }
// ClickPreference(
// title = stringResource(R.string.installed_version),
// onClick = {
// if (movementSounds) playOnClickSound(context)
// if (clickCount++ >= 2) {
// clickCount = 0
// // navigationManager.navigateTo(Destination.Debug)
// }
// },
// summary = installedVersion.toString(),
// interactionSource = interactionSource,
// modifier =
// Modifier
// .ifElse(
// groupIndex == focusedIndex.first && prefIndex == focusedIndex.second,
// Modifier.focusRequester(focusRequester),
// ),
// )
// }
AppPreference.InstalledVersion -> {
var clickCount by remember { mutableIntStateOf(0) }
ClickPreference(
title = stringResource(R.string.installed_version),
onClick = {
if (movementSounds) playOnClickSound(context)
if (clickCount++ >= 2) {
clickCount = 0
// navigationManager.navigateTo(Destination.Debug)
}
},
summary = installedVersion.toString(),
interactionSource = interactionSource,
modifier =
Modifier
.ifElse(
groupIndex == focusedIndex.first && prefIndex == focusedIndex.second,
Modifier.focusRequester(focusRequester),
),
)
}
// AppPreference.Update -> {
// ClickPreference(