diff --git a/core/ui/film/src/main/kotlin/com/flixclusive/core/ui/film/BaseFilmScreenViewModel.kt b/core/ui/film/src/main/kotlin/com/flixclusive/core/ui/film/BaseFilmScreenViewModel.kt index 8ecbe046..5fd95992 100644 --- a/core/ui/film/src/main/kotlin/com/flixclusive/core/ui/film/BaseFilmScreenViewModel.kt +++ b/core/ui/film/src/main/kotlin/com/flixclusive/core/ui/film/BaseFilmScreenViewModel.kt @@ -140,8 +140,9 @@ abstract class BaseFilmScreenViewModel( return onSeasonChangeJob = viewModelScope.launch { + selectedSeasonNumber = seasonNumber + if (_film.value?.isFromTmdb != true) { - selectedSeasonNumber = seasonNumber val tvShow = _film.value as TvShow val season = tvShow.seasons .find { it.number == seasonNumber } diff --git a/core/util/src/main/res/values/strings.xml b/core/util/src/main/res/values/strings.xml index c1cb8174..7ec7e9e0 100644 --- a/core/util/src/main/res/values/strings.xml +++ b/core/util/src/main/res/values/strings.xml @@ -61,6 +61,7 @@ Player has not been initialized An error occurred while initializing the app. Sorry for the inconvenience. We\'re performing a quick update. Be back soon! + Unknown season Are you sure you want to uninstall Pre-release versions may be unstable and may contain bugs or other issues. Please use at your own risk. @@ -283,6 +284,7 @@ Copy to clipboard button Configure this if your ISP blocks you from watching. Drag indicator for provider card + A down arrow for dropdown menu An image of episode %1$s: %2$s An image of episode %1$s: %2$s An icon for episodes button diff --git a/feature/mobile/film/src/main/kotlin/com/flixclusive/feature/mobile/film/FilmScreen.kt b/feature/mobile/film/src/main/kotlin/com/flixclusive/feature/mobile/film/FilmScreen.kt index 3be0cc1e..f50d7fbe 100644 --- a/feature/mobile/film/src/main/kotlin/com/flixclusive/feature/mobile/film/FilmScreen.kt +++ b/feature/mobile/film/src/main/kotlin/com/flixclusive/feature/mobile/film/FilmScreen.kt @@ -215,7 +215,8 @@ fun FilmScreen( } } - val isTvShowAndIsTabSelected = film.filmType == FilmType.TV_SHOW && currentTabSelected == FilmTab.Episodes + val isTvShowAndIsTabSelected = film.filmType == FilmType.TV_SHOW + && currentTabSelected == FilmTab.Episodes if (isTvShowAndIsTabSelected) { val tvShow = film as TvShow item(span = { GridItemSpan(maxLineSpan) }) { @@ -223,7 +224,7 @@ fun FilmScreen( modifier = Modifier .padding(vertical = 5.dp), seasons = tvShow.seasons, - selectedSeasonProvider = { viewModel.selectedSeasonNumber }, + selectedSeason = viewModel.selectedSeasonNumber, onSeasonChange = { viewModel.onSeasonChange(it) } diff --git a/feature/mobile/film/src/main/kotlin/com/flixclusive/feature/mobile/film/component/TvShowSeasonDropdown.kt b/feature/mobile/film/src/main/kotlin/com/flixclusive/feature/mobile/film/component/TvShowSeasonDropdown.kt index d2dd97bd..8faced64 100644 --- a/feature/mobile/film/src/main/kotlin/com/flixclusive/feature/mobile/film/component/TvShowSeasonDropdown.kt +++ b/feature/mobile/film/src/main/kotlin/com/flixclusive/feature/mobile/film/component/TvShowSeasonDropdown.kt @@ -16,6 +16,7 @@ import androidx.compose.material3.MenuDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf @@ -26,24 +27,26 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.scale import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp +import com.flixclusive.core.util.common.ui.UiText import com.flixclusive.feature.mobile.film.R import com.flixclusive.model.tmdb.common.tv.Season +import com.flixclusive.core.util.R as UtilR @Composable internal fun TvShowSeasonDropdown( modifier: Modifier = Modifier, seasons: List, - selectedSeasonProvider: () -> Int, + selectedSeason: Int, onSeasonChange: (Int) -> Unit, ) { var dropdownIcon by remember { mutableIntStateOf(R.drawable.down_arrow) } - var isDropdownExpanded by remember { mutableStateOf(false) } - val selectedSeason = remember(selectedSeasonProvider()) { selectedSeasonProvider() } + val isDropdownExpanded = remember { mutableStateOf(false) } - LaunchedEffect(key1 = isDropdownExpanded) { - dropdownIcon = when(isDropdownExpanded) { + LaunchedEffect(key1 = isDropdownExpanded.value) { + dropdownIcon = when(isDropdownExpanded.value) { true -> R.drawable.up_arrow false -> R.drawable.down_arrow } @@ -52,30 +55,30 @@ internal fun TvShowSeasonDropdown( SeasonDropdownMenu( modifier = modifier, seasons = seasons, - dropdownIconProvider = { dropdownIcon }, - isDropdownExpandedProvider = { isDropdownExpanded }, - selectedSeasonProvider = { selectedSeason }, + dropdownIcon = dropdownIcon, + isDropdownExpanded = isDropdownExpanded, + selectedSeason = selectedSeason, onSeasonChange = { if(it != selectedSeason) { onSeasonChange(it) } }, - onDropdownStateChange = { isDropdownExpanded = it } ) } @Composable -fun SeasonDropdownMenu( +private fun SeasonDropdownMenu( modifier: Modifier = Modifier, seasons: List, - dropdownIconProvider: () -> Int, - isDropdownExpandedProvider: () -> Boolean, - selectedSeasonProvider: () -> Int, + dropdownIcon: Int, + isDropdownExpanded: MutableState, + selectedSeason: Int, onSeasonChange: (Int) -> Unit, - onDropdownStateChange: (Boolean) -> Unit, ) { - val selectedSeason = remember(selectedSeasonProvider()) { - selectedSeasonProvider() - 1 + val currentSeasonName = remember(selectedSeason) { + seasons.getOrNull(selectedSeason - 1)?.name?.run { + UiText.StringValue(this) + } ?: UiText.StringResource(UtilR.string.unknown_season) } Box( @@ -91,12 +94,12 @@ fun SeasonDropdownMenu( Row( modifier = Modifier .height(40.dp) - .clickable(onClick = { onDropdownStateChange(true) }), + .clickable(onClick = { isDropdownExpanded.value = true }), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween ) { Text( - text = seasons[selectedSeason].name, + text = currentSeasonName.asString(), style = MaterialTheme.typography.labelLarge, modifier = Modifier .padding(start = 15.dp) @@ -104,42 +107,51 @@ fun SeasonDropdownMenu( Spacer( modifier = Modifier - .padding(horizontal = 2.dp) + .padding( + horizontal = when { + seasons.isNotEmpty() -> 2.dp + else -> 7.dp + } + ) ) - Icon( - painter = painterResource(dropdownIconProvider()), - contentDescription = "A down arrow for dropdown menu", - modifier = Modifier - .scale(0.6F) - .padding(end = 15.dp) - ) + if (seasons.isNotEmpty()) { + Icon( + painter = painterResource(dropdownIcon), + contentDescription = stringResource(UtilR.string.down_arrow_season_dropdown_content_desc), + modifier = Modifier + .scale(0.6F) + .padding(end = 15.dp) + ) + } } - DropdownMenu( - expanded = isDropdownExpandedProvider(), - onDismissRequest = { onDropdownStateChange(false) }, - ) { - seasons.forEach { season -> - DropdownMenuItem( - onClick = { - onSeasonChange(season.number) - onDropdownStateChange(false) - }, - enabled = season.number != selectedSeason, - colors = MenuDefaults.itemColors( - textColor = Color.White, - disabledTextColor = Color.White - ), - text = { - Text( - text = season.name, - fontWeight = if(selectedSeason == season.number) { - FontWeight.Medium - } else FontWeight.Light - ) - } - ) + if (seasons.isNotEmpty()) { + DropdownMenu( + expanded = isDropdownExpanded.value, + onDismissRequest = { isDropdownExpanded.value = false }, + ) { + seasons.forEach { season -> + DropdownMenuItem( + onClick = { + onSeasonChange(season.number) + isDropdownExpanded.value = false + }, + enabled = season.number != selectedSeason, + colors = MenuDefaults.itemColors( + textColor = Color.White, + disabledTextColor = Color.White + ), + text = { + Text( + text = season.name, + fontWeight = if(selectedSeason == season.number) { + FontWeight.Medium + } else FontWeight.Light + ) + } + ) + } } } }