Skip to content

Commit

Permalink
Minor UI cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaskioko committed Dec 16, 2023
1 parent 9b40a74 commit 7d39c6b
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.toMutableStateList
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand All @@ -46,8 +45,8 @@ import com.thomaskioko.tvmaniac.presentation.seasondetails.SeasonDetailsAction
import com.thomaskioko.tvmaniac.presentation.seasondetails.SeasonDetailsLoaded
import com.thomaskioko.tvmaniac.presentation.seasondetails.SeasonDetailsPresenter
import com.thomaskioko.tvmaniac.presentation.seasondetails.SeasonDetailsState
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.Episode
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.SeasonDetails
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.EpisodeDetailsModel
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.SeasonDetailsModel
import com.thomaskioko.tvmaniac.resources.R
import com.thomaskioko.tvmaniac.seasondetails.components.CollapsableContent
import com.thomaskioko.tvmaniac.seasondetails.components.EpisodeItem
Expand Down Expand Up @@ -103,8 +102,7 @@ internal fun SeasonDetailsScreen(

is SeasonDetailsLoaded -> {
SeasonContent(
seasonsEpList = state.seasonDetailsList,
initialSeasonName = state.selectedSeason,
seasonDetailsModel = state.seasonDetailsModel,
onEpisodeClicked = { onAction(EpisodeClicked(it)) },
listState = listState,
contentPadding = contentPadding,
Expand Down Expand Up @@ -132,77 +130,64 @@ private fun TopBar(

@Composable
private fun SeasonContent(
seasonsEpList: ImmutableList<SeasonDetails>?,
initialSeasonName: String?,
seasonDetailsModel: SeasonDetailsModel,
listState: LazyListState,
contentPadding: PaddingValues,
onEpisodeClicked: (Long) -> Unit = {},
onAction: (SeasonDetailsAction) -> Unit,
) {
seasonsEpList?.let {
LaunchedEffect(initialSeasonName) {
val initialIndex = seasonsEpList.indexOfFirst { it.seasonName == initialSeasonName }

if (initialIndex in 0 until seasonsEpList.count()) {
listState.animateScrollToItem(index = initialIndex)
}
}
val collapsedState = remember { mutableStateOf(true) }

LazyColumn(
state = listState,
contentPadding = contentPadding.copy(copyTop = false),
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxSize(),
) {
item { Spacer(modifier = Modifier.height(64.dp)) }

val collapsedState = remember(seasonsEpList) {
seasonsEpList.map {
it.seasonName != initialSeasonName
}.toMutableStateList()
item {
WatchNextContent(
episodeDetailsModelList = seasonDetailsModel.episodeDetailModels,
onAction = onAction,
)
}

LazyColumn(
state = listState,
contentPadding = contentPadding.copy(copyTop = false),
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxSize(),
) {
item { Spacer(modifier = Modifier.height(64.dp)) }

item {
WatchNextContent(
episodeList = seasonsEpList.firstOrNull()?.episodes,
onAction = onAction,
)
}

item { Spacer(modifier = Modifier.height(16.dp)) }
item { Spacer(modifier = Modifier.height(16.dp)) }

item {
LabelTitle(
label = stringResource(id = R.string.title_all_episodes),
)
}
item {
LabelTitle(
label = stringResource(id = R.string.title_all_episodes),
)
}

itemsIndexed(seasonsEpList) { index, season ->
CollapsableContent(
episodesCount = season.episodeCount,
headerTitle = season.seasonName,
watchProgress = season.watchProgress,
episodeList = season.episodes,
collapsed = collapsedState[index],
onEpisodeClicked = { onEpisodeClicked(it) },
onSeasonHeaderClicked = { collapsedState[index] = !collapsedState[index] },
onAction = onAction,
)
}
item {
CollapsableContent(
episodesCount = seasonDetailsModel.episodeCount,
headerTitle = seasonDetailsModel.seasonName,
watchProgress = seasonDetailsModel.watchProgress,
episodeDetailsModelList = seasonDetailsModel.episodeDetailModels,
collapsed = collapsedState.value,
onEpisodeClicked = { onEpisodeClicked(it) },
onSeasonHeaderClicked = {
collapsedState.value = !collapsedState.value
},
onAction = onAction,
)
}
}
}

@OptIn(ExperimentalSnapperApi::class)
@Composable
fun WatchNextContent(
episodeList: ImmutableList<Episode>?,
episodeDetailsModelList: ImmutableList<EpisodeDetailsModel>?,
onAction: (SeasonDetailsAction) -> Unit,
modifier: Modifier = Modifier,
onEpisodeClicked: () -> Unit = {},
) {
episodeList?.let {
episodeDetailsModelList?.let {
LabelTitle(
modifier = modifier
.padding(top = 16.dp, bottom = 8.dp),
Expand All @@ -215,7 +200,7 @@ fun WatchNextContent(
state = lazyListState,
flingBehavior = rememberSnapperFlingBehavior(lazyListState),
) {
itemsIndexed(episodeList) { index, episode ->
itemsIndexed(episodeDetailsModelList) { index, episode ->
val value = if (index == 0) 0 else 8
Spacer(modifier = Modifier.width(value.dp))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.thomaskioko.tvmaniac.presentation.seasondetails.LoadingError
import com.thomaskioko.tvmaniac.presentation.seasondetails.SeasonDetailsLoaded
import com.thomaskioko.tvmaniac.presentation.seasondetails.SeasonDetailsState
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.Episode
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.SeasonDetails
import kotlinx.collections.immutable.persistentListOf
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.EpisodeDetailsModel
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.SeasonDetailsModel
import kotlinx.collections.immutable.toPersistentList

val episode = Episode(
val episodeDetailsModel = EpisodeDetailsModel(
id = 2534997,
episodeNumberTitle = "E01 • Glorious Purpose",
overview = "After stealing the Tesseract in Avengers: Endgame, Loki lands before the Time Variance Authority.",
Expand All @@ -22,13 +21,13 @@ val episode = Episode(
seasonEpisodeNumber = "S01 | E01",
)

val seasonDetails = SeasonDetails(
val seasonDetailsModel = SeasonDetailsModel(
seasonId = 1,
seasonName = "Specials",
episodeCount = 8,
watchProgress = 0.4f,
episodes = List(8) {
episode
episodeDetailModels = List(8) {
episodeDetailsModel
}.toPersistentList(),
)

Expand All @@ -38,7 +37,7 @@ class SeasonPreviewParameterProvider : PreviewParameterProvider<SeasonDetailsSta
return sequenceOf(
SeasonDetailsLoaded(
showTitle = "Loki",
seasonDetailsList = persistentListOf(seasonDetails),
seasonDetailsModel = seasonDetailsModel,
),
LoadingError(message = "Something went Wrong "),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ import com.thomaskioko.tvmaniac.compose.components.ThemePreviews
import com.thomaskioko.tvmaniac.compose.theme.TvManiacTheme
import com.thomaskioko.tvmaniac.compose.theme.green
import com.thomaskioko.tvmaniac.presentation.seasondetails.SeasonDetailsAction
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.Episode
import com.thomaskioko.tvmaniac.seasondetails.seasonDetails
import com.thomaskioko.tvmaniac.presentation.seasondetails.model.EpisodeDetailsModel
import com.thomaskioko.tvmaniac.seasondetails.seasonDetailsModel
import kotlinx.collections.immutable.ImmutableList

@Composable
fun CollapsableContent(
headerTitle: String,
episodesCount: Long,
watchProgress: Float,
episodeList: ImmutableList<Episode>,
episodeDetailsModelList: ImmutableList<EpisodeDetailsModel>,
collapsed: Boolean,
onAction: (SeasonDetailsAction) -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -71,7 +71,7 @@ fun CollapsableContent(
Spacer(modifier = Modifier.height(8.dp))

if (!collapsed) {
episodeList.forEach { episode ->
episodeDetailsModelList.forEach { episode ->
Spacer(modifier = Modifier.height(8.dp))

EpisodeItem(
Expand Down Expand Up @@ -163,7 +163,6 @@ private fun SeasonTitleHeader(
Text(
text = "$episodesCount",
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier
.constrainAs(count) {
Expand Down Expand Up @@ -232,10 +231,10 @@ fun CollapsableContentPreview() {
TvManiacTheme {
Surface {
CollapsableContent(
episodesCount = seasonDetails.episodeCount,
watchProgress = seasonDetails.watchProgress,
episodeList = seasonDetails.episodes,
headerTitle = seasonDetails.seasonName,
episodesCount = seasonDetailsModel.episodeCount,
watchProgress = seasonDetailsModel.watchProgress,
episodeDetailsModelList = seasonDetailsModel.episodeDetailModels,
headerTitle = seasonDetailsModel.seasonName,
collapsed = false,
onAction = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.thomaskioko.tvmaniac.compose.components.ThemePreviews
import com.thomaskioko.tvmaniac.compose.theme.TvManiacTheme
import com.thomaskioko.tvmaniac.presentation.seasondetails.UpdateEpisodeStatus
import com.thomaskioko.tvmaniac.resources.R
import com.thomaskioko.tvmaniac.seasondetails.episode
import com.thomaskioko.tvmaniac.seasondetails.episodeDetailsModel

@Composable
fun EpisodeItem(
Expand Down Expand Up @@ -101,7 +101,7 @@ fun EpisodeItem(
)

IconButton(
onClick = { onAction(UpdateEpisodeStatus(episode.id)) },
onClick = { onAction(UpdateEpisodeStatus(episodeDetailsModel.id)) },
modifier = Modifier
.constrainAs(watchedStatusIcon) {
centerVerticallyTo(parent)
Expand All @@ -126,9 +126,9 @@ fun WatchlistRowItemPreview() {
TvManiacTheme {
Surface {
EpisodeItem(
title = episode.episodeNumberTitle,
episodeOverview = episode.overview,
imageUrl = episode.imageUrl,
title = episodeDetailsModel.episodeNumberTitle,
episodeOverview = episodeDetailsModel.overview,
imageUrl = episodeDetailsModel.imageUrl,
onAction = {},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private val showDetailsLoaded = ShowDetailsState(
seasonId = 114355,
tvShowId = 84958,
name = "Season 1",
seasonNumber = 1,
),
),
errorMessage = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import com.thomaskioko.tvmaniac.presentation.showdetails.WatchTrailerClicked
import com.thomaskioko.tvmaniac.presentation.showdetails.WebViewError
import com.thomaskioko.tvmaniac.presentation.showdetails.model.Season
import com.thomaskioko.tvmaniac.presentation.showdetails.model.ShowDetails
import com.thomaskioko.tvmaniac.presentation.showdetails.model.ShowSeasonDetailsParam
import com.thomaskioko.tvmaniac.presentation.showdetails.model.SimilarShow
import com.thomaskioko.tvmaniac.presentation.showdetails.model.Trailer
import com.thomaskioko.tvmaniac.resources.R
Expand Down Expand Up @@ -189,8 +190,16 @@ private fun ShowDetailsContent(
SeasonsContent(
isLoading = seasonsContent.isLoading,
seasonsList = seasonsContent.seasonsList,
onSeasonClicked = { id, name ->
onAction(SeasonClicked(id, name))
onSeasonClicked = { tvShowId, seasonId, seasonNumber ->
onAction(
SeasonClicked(
ShowSeasonDetailsParam(
tvShowId,
seasonId,
seasonNumber,
),
),
)
},
)
}
Expand Down Expand Up @@ -537,47 +546,47 @@ fun ShowDetailButtons(
private fun SeasonsContent(
isLoading: Boolean,
seasonsList: ImmutableList<Season>,
onSeasonClicked: (Long, String) -> Unit,
onSeasonClicked: (Long, Long, Long) -> Unit,
) {
if (seasonsList.isNotEmpty()) {
TextLoadingItem(
isLoading = isLoading,
text = stringResource(id = R.string.title_seasons),
)
val selectedIndex by remember { mutableIntStateOf(0) }

ScrollableTabRow(
selectedTabIndex = selectedIndex,
divider = {}, /* Disable the built-in divider */
indicator = {},
edgePadding = 0.dp,
containerColor = Color.Transparent,
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
) {
seasonsList.forEach { season ->
Tab(
modifier = Modifier
.padding(end = 4.dp),
selected = true,
TextLoadingItem(
isLoading = isLoading,
text = stringResource(id = R.string.title_seasons),
)
val selectedIndex by remember { mutableIntStateOf(0) }

ScrollableTabRow(
selectedTabIndex = selectedIndex,
divider = {}, /* Disable the built-in divider */
indicator = {},
edgePadding = 0.dp,
containerColor = Color.Transparent,
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
) {
seasonsList.forEach { season ->
Tab(
modifier = Modifier
.padding(end = 4.dp),
selected = true,
onClick = {
onSeasonClicked(
season.tvShowId,
season.seasonId,
season.seasonNumber,
)
},
) {
TvManiacChip(
text = season.name,
onClick = {
onSeasonClicked(
season.tvShowId,
season.name,
season.seasonId,
season.seasonNumber,
)
},
) {
TvManiacChip(
text = season.name,
onClick = {
onSeasonClicked(
season.tvShowId,
season.name,
)
},
)
}
)
}
}
}
Expand Down

0 comments on commit 7d39c6b

Please sign in to comment.