Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home and MediaPage cleanup #122

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 33 additions & 75 deletions app/src/main/java/com/imashnake/animite/features/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEach
import androidx.hilt.navigation.compose.hiltViewModel
import com.imashnake.animite.api.anilist.sanitize.media.Media
import com.imashnake.animite.api.anilist.type.MediaType
import com.imashnake.animite.core.extensions.bannerParallax
import com.imashnake.animite.core.extensions.landscapeCutoutPadding
import com.imashnake.animite.core.ui.ProgressIndicator
import com.imashnake.animite.core.ui.TranslucentStatusBarLayout
import com.imashnake.animite.core.ui.layouts.TranslucentStatusBarLayout
import com.imashnake.animite.core.data.Resource
import com.imashnake.animite.features.destinations.MediaPageDestination
import com.imashnake.animite.features.media.MediaPageArgs
Expand All @@ -76,12 +77,15 @@ fun Home(
val upcomingList by viewModel.upcomingMediaNextSeason.collectAsState()
val allTimePopularList by viewModel.allTimePopular.collectAsState()

// TODO: [Code Smells: If Statements](https://dzone.com/articles/code-smells-if-statements).
val homeRowListToHeader = listOf(
trendingList to stringResource(R.string.trending_now),
popularList to stringResource(R.string.popular_this_season),
upcomingList to stringResource(R.string.upcoming_next_season),
allTimePopularList to stringResource(R.string.all_time_popular),
)

when {
trendingList is Resource.Success &&
popularList is Resource.Success &&
upcomingList is Resource.Success &&
allTimePopularList is Resource.Success -> {
homeRowListToHeader.all { it.first is Resource.Success } -> {
val scrollState = rememberScrollState()
TranslucentStatusBarLayout(
scrollState = scrollState,
Expand Down Expand Up @@ -121,7 +125,9 @@ fun Home(
) { }

Row(
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter),
modifier = Modifier
.fillMaxWidth()
.align(Alignment.BottomCenter),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Expand Down Expand Up @@ -163,73 +169,24 @@ fun Home(
.padding(bottom = dimensionResource(R.dimen.navigation_bar_height)),
verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.large)
) {
HomeRow(
list = trendingList.data.orEmpty(),
title = stringResource(R.string.trending_now),
onItemClicked = {
navigator.navigate(
MediaPageDestination(
MediaPageArgs(
it.id,
homeMediaType.value.rawValue
)
)
) {
launchSingleTop = true
}
}
)

HomeRow(
list = popularList.data.orEmpty(),
title = stringResource(R.string.popular_this_season),
onItemClicked = {
navigator.navigate(
MediaPageDestination(
MediaPageArgs(
it.id,
homeMediaType.value.rawValue
homeRowListToHeader.fastForEach { listToHeader ->
HomeRow(
list = listToHeader.first.data.orEmpty(),
title = listToHeader.second,
onItemClicked = {
navigator.navigate(
MediaPageDestination(
MediaPageArgs(
it.id,
homeMediaType.value.rawValue
)
)
)
) {
launchSingleTop = true
) {
launchSingleTop = true
}
}
}
)

HomeRow(
list = upcomingList.data.orEmpty(),
title = stringResource(R.string.upcoming_next_season),
onItemClicked = {
navigator.navigate(
MediaPageDestination(
MediaPageArgs(
it.id,
homeMediaType.value.rawValue
)
)
) {
launchSingleTop = true
}
}
)

HomeRow(
list = allTimePopularList.data.orEmpty(),
title = stringResource(R.string.all_time_popular),
onItemClicked = {
navigator.navigate(
MediaPageDestination(
MediaPageArgs(
it.id,
homeMediaType.value.rawValue
)
)
) {
launchSingleTop = true
}
}
)
)
}
}
}
}
Expand Down Expand Up @@ -257,7 +214,10 @@ fun HomeRow(
modifier: Modifier = Modifier
) {
if (list.isNotEmpty()) {
Column(modifier) {
Column(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.medium)
) {
Text(
text = title,
style = MaterialTheme.typography.titleMedium,
Expand All @@ -266,8 +226,6 @@ fun HomeRow(
.landscapeCutoutPadding()
)

Spacer(Modifier.size(LocalPaddings.current.medium))

MediaSmallRow(
mediaList = list,
content = { media ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import com.imashnake.animite.core.extensions.bannerParallax
import com.imashnake.animite.core.extensions.landscapeCutoutPadding
import com.imashnake.animite.core.ui.LocalPaddings
import com.imashnake.animite.core.ui.NestedScrollableContent
import com.imashnake.animite.core.ui.TranslucentStatusBarLayout
import com.imashnake.animite.core.ui.layouts.TranslucentStatusBarLayout
import com.imashnake.animite.dev.internal.Constants
import com.imashnake.animite.features.ui.MediaSmall
import com.imashnake.animite.features.ui.MediaSmallRow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imashnake.animite.core.ui
package com.imashnake.animite.core.ui.layouts

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Box
Expand Down
Loading