From 08cc4589c2c3c8ef519da4edb72411807a1ad60c Mon Sep 17 00:00:00 2001 From: Barnabas Balogh Date: Tue, 17 Mar 2026 18:18:05 +0100 Subject: [PATCH] Refine series download actions --- .../app/content/series/SeriesComponents.kt | 82 ++++++++----------- .../app/content/series/SeriesScreen.kt | 21 +++-- .../shared/content/series/SeriesViewModel.kt | 15 +--- 3 files changed, 51 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesComponents.kt b/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesComponents.kt index c316a8e..82b4695 100644 --- a/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesComponents.kt +++ b/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesComponents.kt @@ -33,7 +33,6 @@ import androidx.compose.material.icons.outlined.Cast import androidx.compose.material.icons.outlined.Close import androidx.compose.material.icons.outlined.Download import androidx.compose.material.icons.outlined.DownloadDone -import androidx.compose.material.icons.outlined.Autorenew import androidx.compose.material.icons.outlined.MoreVert import androidx.compose.material.icons.outlined.PlayCircle import androidx.compose.material3.AlertDialog @@ -121,10 +120,10 @@ internal fun SeriesMetaChips(series: Series) { @Composable internal fun SeriesActionButtons( nextUpEpisode: Episode?, - downloadState: DownloadState, - isSmartDownloadEnabled: Boolean, - onDownloadAllClick: () -> Unit, - onSmartDownloadToggle: () -> Unit, + seriesDownloadState: DownloadState, + selectedSeason: Season, + seasonDownloadState: DownloadState, + onDownloadOptionSelected: (SeriesDownloadOption) -> Unit, modifier: Modifier = Modifier, ) { val context = LocalContext.current @@ -158,12 +157,11 @@ internal fun SeriesActionButtons( ) Spacer(modifier = Modifier.width(12.dp)) MediaActionButton( - backgroundColor = if (isSmartDownloadEnabled) scheme.primary else scheme.secondary, - iconColor = if (isSmartDownloadEnabled) scheme.onPrimary else scheme.onSecondary, + backgroundColor = scheme.secondary, + iconColor = scheme.onSecondary, icon = when { - isSmartDownloadEnabled -> Icons.Outlined.Autorenew - downloadState is DownloadState.Downloading -> Icons.Outlined.Close - downloadState is DownloadState.Downloaded -> Icons.Outlined.DownloadDone + seriesDownloadState is DownloadState.Downloading -> Icons.Outlined.Close + seriesDownloadState is DownloadState.Downloaded -> Icons.Outlined.DownloadDone else -> Icons.Outlined.Download }, height = 32.dp, @@ -173,25 +171,28 @@ internal fun SeriesActionButtons( if (showDownloadDialog) { DownloadOptionsDialog( - isSmartDownloadEnabled = isSmartDownloadEnabled, - onDownloadAll = { + selectedSeasonName = selectedSeason.name, + seasonDownloadState = seasonDownloadState, + onDownloadOptionSelected = { showDownloadDialog = false - onDownloadAllClick() - }, - onSmartDownload = { - showDownloadDialog = false - onSmartDownloadToggle() + onDownloadOptionSelected(it) }, onDismiss = { showDownloadDialog = false } ) } } +internal enum class SeriesDownloadOption { + SEASON, + SERIES, + SMART +} + @Composable private fun DownloadOptionsDialog( - isSmartDownloadEnabled: Boolean, - onDownloadAll: () -> Unit, - onSmartDownload: () -> Unit, + selectedSeasonName: String, + seasonDownloadState: DownloadState, + onDownloadOptionSelected: (SeriesDownloadOption) -> Unit, onDismiss: () -> Unit, ) { AlertDialog( @@ -203,24 +204,27 @@ private fun DownloadOptionsDialog( text = "Choose how to download this series.", style = MaterialTheme.typography.bodyMedium ) - if (isSmartDownloadEnabled) { - Spacer(modifier = Modifier.height(4.dp)) - Text( - text = "Smart download is currently enabled.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.primary - ) - } } }, confirmButton = { - TextButton(onClick = onDownloadAll) { - Text("Download All") + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + TextButton(onClick = { onDownloadOptionSelected(SeriesDownloadOption.SEASON) }) { + Text( + when (seasonDownloadState) { + is DownloadState.Downloaded -> "$selectedSeasonName Downloaded" + is DownloadState.Downloading -> "Downloading $selectedSeasonName" + else -> "Download $selectedSeasonName" + } + ) + } + TextButton(onClick = { onDownloadOptionSelected(SeriesDownloadOption.SERIES) }) { + Text("Download All") + } } }, dismissButton = { - TextButton(onClick = onSmartDownload) { - Text(if (isSmartDownloadEnabled) "Disable Smart Download" else "Smart Download") + TextButton(onClick = { onDownloadOptionSelected(SeriesDownloadOption.SMART) }) { + Text("Smart Download") } } ) @@ -230,8 +234,6 @@ private fun DownloadOptionsDialog( internal fun SeasonTabs( seasons: List, selectedSeason: Season?, - seasonDownloadState: DownloadState, - onSeasonDownloadClick: () -> Unit, modifier: Modifier = Modifier, onSelect: (Season) -> Unit ) { @@ -249,18 +251,6 @@ internal fun SeasonTabs( modifier = Modifier.clickable { onSelect(season) } ) } - MediaActionButton( - backgroundColor = MaterialTheme.colorScheme.secondary, - iconColor = MaterialTheme.colorScheme.onSecondary, - icon = when (seasonDownloadState) { - is DownloadState.NotDownloaded -> Icons.Outlined.Download - is DownloadState.Downloading -> Icons.Outlined.Close - is DownloadState.Downloaded -> Icons.Outlined.DownloadDone - is DownloadState.Failed -> Icons.Outlined.Download - }, - height = 28.dp, - onClick = onSeasonDownloadClick - ) } } diff --git a/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt b/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt index 5913c70..5ea6294 100644 --- a/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt +++ b/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt @@ -89,8 +89,6 @@ private fun SeriesScreenInternal( val seriesDownloadState by viewModel.seriesDownloadState.collectAsState() val seasonDownloadState by viewModel.seasonDownloadState.collectAsState() - val isSmartDownloadEnabled by viewModel.isSmartDownloadEnabled.collectAsState() - LaunchedEffect(selectedSeason.value) { viewModel.observeSeasonDownloadState(selectedSeason.value.episodes) } @@ -134,10 +132,19 @@ private fun SeriesScreenInternal( Spacer(modifier = Modifier.height(24.dp)) SeriesActionButtons( nextUpEpisode = nextUpEpisode, - downloadState = seriesDownloadState, - isSmartDownloadEnabled = isSmartDownloadEnabled, - onDownloadAllClick = { viewModel.downloadSeries(series) }, - onSmartDownloadToggle = { viewModel.toggleSmartDownload(series.id) } + seriesDownloadState = seriesDownloadState, + selectedSeason = selectedSeason.value, + seasonDownloadState = seasonDownloadState, + onDownloadOptionSelected = { option -> + when (option) { + SeriesDownloadOption.SEASON -> + viewModel.downloadSeason(selectedSeason.value.episodes) + SeriesDownloadOption.SERIES -> + viewModel.downloadSeries(series) + SeriesDownloadOption.SMART -> + viewModel.enableSmartDownload(series.id) + } + } ) Spacer(modifier = Modifier.height(24.dp)) MediaSynopsis( @@ -151,8 +158,6 @@ private fun SeriesScreenInternal( SeasonTabs( seasons = series.seasons, selectedSeason = selectedSeason.value, - seasonDownloadState = seasonDownloadState, - onSeasonDownloadClick = { viewModel.downloadSeason(selectedSeason.value.episodes) }, onSelect = { selectedSeason.value = it } ) EpisodeCarousel( diff --git a/feature/shared/src/main/java/hu/bbara/purefin/feature/shared/content/series/SeriesViewModel.kt b/feature/shared/src/main/java/hu/bbara/purefin/feature/shared/content/series/SeriesViewModel.kt index 9f1e8f7..808d1ef 100644 --- a/feature/shared/src/main/java/hu/bbara/purefin/feature/shared/content/series/SeriesViewModel.kt +++ b/feature/shared/src/main/java/hu/bbara/purefin/feature/shared/content/series/SeriesViewModel.kt @@ -39,13 +39,6 @@ class SeriesViewModel @Inject constructor( } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null) - @OptIn(ExperimentalCoroutinesApi::class) - val isSmartDownloadEnabled: StateFlow = _seriesId - .flatMapLatest { id -> - if (id != null) mediaDownloadManager.isSmartDownloadEnabled(id) else flowOf(false) - } - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false) - private val _seriesDownloadState = MutableStateFlow(DownloadState.NotDownloaded) val seriesDownloadState: StateFlow = _seriesDownloadState @@ -83,13 +76,9 @@ class SeriesViewModel @Inject constructor( } } - fun toggleSmartDownload(seriesId: UUID) { + fun enableSmartDownload(seriesId: UUID) { viewModelScope.launch { - if (isSmartDownloadEnabled.value) { - mediaDownloadManager.disableSmartDownload(seriesId) - } else { - mediaDownloadManager.enableSmartDownload(seriesId) - } + mediaDownloadManager.enableSmartDownload(seriesId) } }