Skip to content

Commit

Permalink
fix(film): resolve issue where season drop down is not changing its l…
Browse files Browse the repository at this point in the history
…abel

Fixes #86
  • Loading branch information
rhenwinch committed Jun 25, 2024
1 parent 7ce7c73 commit 322bd72
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions core/util/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<string name="player_not_initialized">Player has not been initialized</string>
<string name="splash_default_error_message">An error occurred while initializing the app.</string>
<string name="splash_maintenance_message">Sorry for the inconvenience. We\'re performing a quick update. Be back soon!</string>
<string name="unknown_season">Unknown season</string>
<string name="warning_uninstall_message_first_half">Are you sure you want to uninstall</string>
<string name="warning_use_prerelease_updates">Pre-release versions may be unstable and may contain bugs or other issues. Please use at your own risk.</string>

Expand Down Expand Up @@ -283,6 +284,7 @@
<string name="copy_button">Copy to clipboard button</string>
<string name="dns_label">Configure this if your ISP blocks you from watching.</string>
<string name="drag_icon_content_desc">Drag indicator for provider card</string>
<string name="down_arrow_season_dropdown_content_desc">A down arrow for dropdown menu</string>
<string name="episode_image_content_desc">An image of episode %1$s: %2$s</string>
<string name="episode_image_content_desc_format">An image of episode %1$s: %2$s</string>
<string name="episodes_button_desc">An icon for episodes button</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,16 @@ 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) }) {
TvShowSeasonDropdown(
modifier = Modifier
.padding(vertical = 5.dp),
seasons = tvShow.seasons,
selectedSeasonProvider = { viewModel.selectedSeasonNumber },
selectedSeason = viewModel.selectedSeasonNumber,
onSeasonChange = {
viewModel.onSeasonChange(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Season>,
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
}
Expand All @@ -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<Season>,
dropdownIconProvider: () -> Int,
isDropdownExpandedProvider: () -> Boolean,
selectedSeasonProvider: () -> Int,
dropdownIcon: Int,
isDropdownExpanded: MutableState<Boolean>,
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(
Expand All @@ -91,55 +94,64 @@ 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)
)

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
)
}
)
}
}
}
}
Expand Down

0 comments on commit 322bd72

Please sign in to comment.