TVT-56: All Account Tabs Say 'No Rated Content' When Empty

This commit is contained in:
Owen LeJeune
2022-11-17 15:05:39 -05:00
parent 259b61484f
commit 0e0ce33a47
3 changed files with 97 additions and 29 deletions

View File

@@ -14,6 +14,7 @@ import kotlin.reflect.KClass
sealed class AccountTabNavItem(
stringRes: Int,
route: String,
noContentStringRes: Int,
val mediaType: MediaViewType,
val screen: AccountNavComposableFun,
val listFetchFun: ListFetchFun,
@@ -23,6 +24,7 @@ sealed class AccountTabNavItem(
private val resourceUtils: ResourceUtils by inject()
override val name = resourceUtils.getString(stringRes)
val noContentText = resourceUtils.getString(noContentStringRes)
companion object {
val GuestItems
@@ -32,19 +34,75 @@ sealed class AccountTabNavItem(
get() = listOf(RatedMovies, RatedTvShows, RatedTvEpisodes, FavoriteMovies, FavoriteTvShows, MovieWatchlist, TvWatchlist).filter { it.ordinal > -1 }.sortedBy { it.ordinal }
}
object RatedMovies: AccountTabNavItem(R.string.nav_rated_movies_title, "rated_movies_route", MediaViewType.MOVIE, screenContent, { SessionManager.currentSession?.ratedMovies ?: emptyList() }, RatedMovie::class, 0)
object RatedTvShows: AccountTabNavItem(R.string.nav_rated_shows_title, "rated_shows_route", MediaViewType.TV, screenContent, { SessionManager.currentSession?.ratedTvShows ?: emptyList() }, RatedTv::class, 1)
object RatedTvEpisodes: AccountTabNavItem(R.string.nav_rated_episodes_title, "rated_episodes_route", MediaViewType.EPISODE, screenContent, { SessionManager.currentSession?.ratedTvEpisodes ?: emptyList() }, RatedEpisode::class, 2)
object FavoriteMovies: AccountTabNavItem(R.string.nav_favorite_movies_title, "favorite_movies_route", MediaViewType.MOVIE, screenContent, { SessionManager.currentSession?.favoriteMovies ?: emptyList() }, FavoriteMovie::class, 3)
object FavoriteTvShows: AccountTabNavItem(R.string.nav_favorite_tv_show_title, "favorite_shows_route", MediaViewType.TV, screenContent, { SessionManager.currentSession?.favoriteTvShows ?: emptyList() }, FavoriteTvSeries::class, 4)
object MovieWatchlist: AccountTabNavItem(R.string.nav_movie_watchlist_title, "movie_watchlist_route", MediaViewType.MOVIE, screenContent, { SessionManager.currentSession?.movieWatchlist ?: emptyList() }, WatchlistMovie::class, 5)
object TvWatchlist: AccountTabNavItem(R.string.nav_tv_watchlist_title, "tv_watchlist_route", MediaViewType.TV, screenContent, { SessionManager.currentSession?.tvWatchlist ?: emptyList() }, WatchlistTvSeries::class, 6)
object RatedMovies: AccountTabNavItem(
R.string.nav_rated_movies_title,
"rated_movies_route",
R.string.no_rated_movies,
MediaViewType.MOVIE,
screenContent, { SessionManager.currentSession?.ratedMovies ?: emptyList() },
RatedMovie::class,
0
)
object RatedTvShows: AccountTabNavItem(
R.string.nav_rated_shows_title,
"rated_shows_route",
R.string.no_rated_tv,
MediaViewType.TV,
screenContent, { SessionManager.currentSession?.ratedTvShows ?: emptyList() },
RatedTv::class,
1
)
object RatedTvEpisodes: AccountTabNavItem(
R.string.nav_rated_episodes_title,
"rated_episodes_route",
R.string.no_rated_episodes,
MediaViewType.EPISODE,
screenContent, { SessionManager.currentSession?.ratedTvEpisodes ?: emptyList() },
RatedEpisode::class,
2
)
object FavoriteMovies: AccountTabNavItem(
R.string.nav_favorite_movies_title,
"favorite_movies_route",
R.string.no_favorite_movies,
MediaViewType.MOVIE,
screenContent, { SessionManager.currentSession?.favoriteMovies ?: emptyList() },
FavoriteMovie::class,
3
)
object FavoriteTvShows: AccountTabNavItem(
R.string.nav_favorite_tv_show_title,
"favorite_shows_route",
R.string.no_favorite_tv,
MediaViewType.TV,
screenContent, { SessionManager.currentSession?.favoriteTvShows ?: emptyList() },
FavoriteTvSeries::class,
4
)
object MovieWatchlist: AccountTabNavItem(
R.string.nav_movie_watchlist_title,
"movie_watchlist_route",
R.string.no_watchlist_movies,
MediaViewType.MOVIE,
screenContent, { SessionManager.currentSession?.movieWatchlist ?: emptyList() },
WatchlistMovie::class,
5
)
object TvWatchlist: AccountTabNavItem(
R.string.nav_tv_watchlist_title,
"tv_watchlist_route",
R.string.no_watchlist_tv,
MediaViewType.TV,
screenContent, { SessionManager.currentSession?.tvWatchlist ?: emptyList() },
WatchlistTvSeries::class,
6
)
}
private val screenContent: AccountNavComposableFun = { appNavController, mediaViewType, listFetchFun, clazz ->
AccountTabContent(appNavController = appNavController, mediaViewType = mediaViewType, listFetchFun = listFetchFun, clazz = clazz)
private val screenContent: AccountNavComposableFun = { noContentText, appNavController, mediaViewType, listFetchFun, clazz ->
AccountTabContent(noContentText = noContentText, appNavController = appNavController, mediaViewType = mediaViewType, listFetchFun = listFetchFun, clazz = clazz)
}
typealias ListFetchFun = () -> List<Any>
typealias AccountNavComposableFun = @Composable (NavHostController, MediaViewType, ListFetchFun, KClass<*>) -> Unit
typealias AccountNavComposableFun = @Composable (String, NavHostController, MediaViewType, ListFetchFun, KClass<*>) -> Unit

View File

@@ -156,6 +156,7 @@ private fun getAccountName(accountDetails: AccountDetails?): String {
@Composable
fun <T: Any> AccountTabContent(
noContentText: String,
appNavController: NavHostController,
mediaViewType: MediaViewType,
listFetchFun: ListFetchFun,
@@ -163,24 +164,26 @@ fun <T: Any> AccountTabContent(
) {
val contentItems = listFetchFun()
LazyColumn(modifier = Modifier
.fillMaxSize()
.padding(12.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
if (contentItems.isEmpty()) {
item {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 15.dp),
text = stringResource(R.string.no_rated_content_message),
color = MaterialTheme.colorScheme.onBackground,
fontSize = 22.sp,
textAlign = TextAlign.Center
)
}
} else {
if (contentItems.isEmpty()) {
Column {
Spacer(modifier = Modifier.weight(1f))
Text(
modifier = Modifier
.fillMaxWidth(),
text = noContentText,
color = MaterialTheme.colorScheme.onBackground,
fontSize = 22.sp,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.weight(1f))
}
} else {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(12.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(contentItems.size) { i ->
when (clazz) {
RatedTv::class, RatedMovie::class -> {
@@ -475,6 +478,6 @@ fun AccountTabs(
appNavController: NavHostController
) {
HorizontalPager(count = tabs.size, state = pagerState) { page ->
tabs[page].screen(appNavController, tabs[page].mediaType, tabs[page].listFetchFun, tabs[page].listType)
tabs[page].screen(tabs[page].noContentText, appNavController, tabs[page].mediaType, tabs[page].listFetchFun, tabs[page].listType)
}
}

View File

@@ -173,4 +173,11 @@
<string name="last_episode_to_air_title">Last Episode to Air</string>
<string name="original_country_title">Original Country</string>
<string name="tv_type_title">Type</string>
<string name="no_rated_movies">No Rated Movies</string>
<string name="no_rated_tv">No Rated TV</string>
<string name="no_rated_episodes">No Rated TV Episodes</string>
<string name="no_favorite_movies">No Favorite Movies</string>
<string name="no_favorite_tv">No Favorite TV</string>
<string name="no_watchlist_movies">No Watchlisted Movies</string>
<string name="no_watchlist_tv">No Watchlisted TV</string>
</resources>