diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 253310d..b08223d 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -109,7 +109,7 @@ object Deps { const val roomKtx = "androidx.room:room-ktx:${Versions.room_version}" const val roomCompiler = "androidx.room:room-compiler:${Versions.room_version}" - + // Lottie const val lottieCompose = "com.airbnb.android:lottie-compose:${Versions.lottie_compose}" } \ No newline at end of file diff --git a/features/feature-bookmark/src/main/java/com/sample/tmdb/bookmark/BookmarkScreen.kt b/features/feature-bookmark/src/main/java/com/sample/tmdb/bookmark/BookmarkScreen.kt index d91788b..cdc0851 100644 --- a/features/feature-bookmark/src/main/java/com/sample/tmdb/bookmark/BookmarkScreen.kt +++ b/features/feature-bookmark/src/main/java/com/sample/tmdb/bookmark/BookmarkScreen.kt @@ -117,9 +117,11 @@ private fun TVShowsTabContent( navController: NavController, viewModel: BookmarkTVShowViewModel = hiltViewModel() ) { - TabContent(viewModel = viewModel, + TabContent( + viewModel = viewModel, onClick = { navController.navigate("${MainDestinations.TMDB_TV_SHOW_DETAIL_ROUTE}/${it.id}") }, - textResourceId = R1.string.tv_series) + textResourceId = R1.string.tv_series + ) } @Composable @@ -199,13 +201,8 @@ private fun EmptyView(@StringRes textResourceId: Int) { private fun isEmptyImageVisible(): Boolean { val configuration = LocalConfiguration.current val isPortrait = when (configuration.orientation) { - Configuration.ORIENTATION_PORTRAIT -> { - true - } - - else -> { - false - } + Configuration.ORIENTATION_PORTRAIT -> true + else -> false } if (isPortrait) { return true diff --git a/features/feature-paging/src/main/java/com/sample/tmdb/paging/PagingScreen.kt b/features/feature-paging/src/main/java/com/sample/tmdb/paging/PagingScreen.kt index 070335c..cc44343 100644 --- a/features/feature-paging/src/main/java/com/sample/tmdb/paging/PagingScreen.kt +++ b/features/feature-paging/src/main/java/com/sample/tmdb/paging/PagingScreen.kt @@ -16,16 +16,12 @@ import androidx.compose.foundation.layout.windowInsetsTopHeight import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyVerticalGrid -import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel -import androidx.navigation.NavController import androidx.paging.LoadState import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems @@ -34,32 +30,13 @@ import com.airbnb.lottie.compose.LottieCompositionSpec import com.airbnb.lottie.compose.LottieConstants import com.airbnb.lottie.compose.animateLottieCompositionAsState import com.airbnb.lottie.compose.rememberLottieComposition -import com.sample.tmdb.common.MainDestinations import com.sample.tmdb.common.model.TMDbItem import com.sample.tmdb.common.ui.Dimens -import com.sample.tmdb.common.ui.component.DestinationBar import com.sample.tmdb.common.ui.component.ErrorScreen import com.sample.tmdb.common.ui.component.LoadingRow import com.sample.tmdb.common.ui.component.TMDbItemContent import com.sample.tmdb.common.ui.component.TMDbProgressBar import com.sample.tmdb.common.utils.toDp -import com.sample.tmdb.domain.model.Movie -import com.sample.tmdb.domain.model.TVShow -import com.sample.tmdb.paging.main.movie.DiscoverMoviesViewModel -import com.sample.tmdb.paging.main.movie.NowPlayingMoviesViewModel -import com.sample.tmdb.paging.main.movie.PopularMoviesViewModel -import com.sample.tmdb.paging.main.movie.SimilarMoviesViewModel -import com.sample.tmdb.paging.main.movie.TopRatedMoviesViewModel -import com.sample.tmdb.paging.main.movie.TrendingMoviesViewModel -import com.sample.tmdb.paging.main.movie.UpcomingMoviesViewModel -import com.sample.tmdb.paging.main.tvshow.AiringTodayTvSeriesViewModel -import com.sample.tmdb.paging.main.tvshow.DiscoverTvSeriesViewModel -import com.sample.tmdb.paging.main.tvshow.OnTheAirTvSeriesViewModel -import com.sample.tmdb.paging.main.tvshow.PopularTvSeriesViewModel -import com.sample.tmdb.paging.main.tvshow.SimilarTvSeriesViewModel -import com.sample.tmdb.paging.main.tvshow.TopRatedTvSeriesViewModel -import com.sample.tmdb.paging.main.tvshow.TrendingTvSeriesViewModel -import com.sample.tmdb.common.R as R1 @Composable fun PagingScreen( @@ -77,15 +54,19 @@ fun PagingScreen( val message = (lazyTMDbItems.loadState.refresh as? LoadState.Error)?.error?.message ?: return - ErrorScreen( - message = message, + ErrorScreen(message = message, modifier = Modifier.fillMaxSize(), - refresh = { lazyTMDbItems.retry() } - ) + refresh = { lazyTMDbItems.retry() }) } else -> { - LazyTMDbItemGrid(lazyTMDbItems, onClick) + if (lazyTMDbItems.itemCount == 0) { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + NoDataFoundAnimation(modifier = Modifier.size(200.dp)) + } + } else { + LazyTMDbItemGrid(lazyTMDbItems, onClick) + } } } } @@ -96,84 +77,64 @@ private fun LazyTMDbItemGrid( lazyTMDbItems: LazyPagingItems, onClick: (TMDbItem) -> Unit, ) { - if (lazyTMDbItems.itemCount == 0) { - Box( - modifier = Modifier.fillMaxSize(), - contentAlignment = Alignment.Center - ) { - NoDataFoundAnimation( - modifier = Modifier - .size(200.dp) + LazyVerticalGrid(columns = GridCells.Adaptive(minSize = 140.dp), contentPadding = PaddingValues( + start = Dimens.PaddingMedium, + end = Dimens.PaddingMedium, + bottom = WindowInsets.navigationBars.getBottom(LocalDensity.current).toDp().dp.plus( + Dimens.PaddingMedium + ) + ), horizontalArrangement = Arrangement.spacedBy( + Dimens.PaddingMedium, Alignment.CenterHorizontally + ), content = { + + item(span = { + GridItemSpan(maxLineSpan) + }) { + Spacer( + Modifier.windowInsetsTopHeight( + WindowInsets.statusBars.add(WindowInsets(top = 56.dp)) + ) ) } - } else { - LazyVerticalGrid( - columns = GridCells.Adaptive(minSize = 140.dp), - contentPadding = PaddingValues( - start = Dimens.PaddingMedium, - end = Dimens.PaddingMedium, - bottom = WindowInsets.navigationBars.getBottom(LocalDensity.current) - .toDp().dp.plus( - Dimens.PaddingMedium - ) - ), - horizontalArrangement = Arrangement.spacedBy( - Dimens.PaddingMedium, - Alignment.CenterHorizontally - ), - content = { + items(lazyTMDbItems.itemCount) { index -> + val tmdbItem = lazyTMDbItems[index] + tmdbItem?.let { + TMDbItemContent( + it, + Modifier + .height(320.dp) + .padding(vertical = Dimens.PaddingMedium), + onClick + ) + } + } + + when (lazyTMDbItems.loadState.append) { + is LoadState.Loading -> { item(span = { GridItemSpan(maxLineSpan) }) { - Spacer( - Modifier.windowInsetsTopHeight( - WindowInsets.statusBars.add(WindowInsets(top = 56.dp)) - ) - ) + LoadingRow(modifier = Modifier.padding(vertical = Dimens.PaddingMedium)) } + } - items(lazyTMDbItems.itemCount) { index -> - val tmdbItem = lazyTMDbItems[index] - tmdbItem?.let { - TMDbItemContent( - it, - Modifier - .height(320.dp) - .padding(vertical = Dimens.PaddingMedium), - onClick - ) - } - } - - when (lazyTMDbItems.loadState.append) { - is LoadState.Loading -> { - item(span = { - GridItemSpan(maxLineSpan) - }) { - LoadingRow(modifier = Modifier.padding(vertical = Dimens.PaddingMedium)) - } - } - - is LoadState.Error -> { - val message = - (lazyTMDbItems.loadState.append as? LoadState.Error)?.error?.message - ?: return@LazyVerticalGrid - - item(span = { - GridItemSpan(maxLineSpan) - }) { - ErrorScreen( - message = message, - modifier = Modifier.padding(vertical = Dimens.PaddingMedium), - refresh = { lazyTMDbItems.retry() }) - } - } + is LoadState.Error -> { + val message = (lazyTMDbItems.loadState.append as? LoadState.Error)?.error?.message + ?: return@LazyVerticalGrid - else -> {} + item(span = { + GridItemSpan(maxLineSpan) + }) { + ErrorScreen(message = message, + modifier = Modifier.padding(vertical = Dimens.PaddingMedium), + refresh = { lazyTMDbItems.retry() }) } - }) - } + } + + else -> Unit + } + }) } @Composable @@ -183,17 +144,10 @@ fun NoDataFoundAnimation(modifier: Modifier = Modifier) { R.raw.no_data_found ) ) - val preloaderProgress by animateLottieCompositionAsState( - preloaderLottieComposition, - iterations = LottieConstants.IterateForever, - isPlaying = true + preloaderLottieComposition, iterations = LottieConstants.IterateForever, isPlaying = true ) - - LottieAnimation( - composition = preloaderLottieComposition, - progress = preloaderProgress, - modifier = modifier + composition = preloaderLottieComposition, progress = preloaderProgress, modifier = modifier ) } \ No newline at end of file diff --git a/features/feature-paging/src/main/java/com/sample/tmdb/paging/search/SearchScreens.kt b/features/feature-paging/src/main/java/com/sample/tmdb/paging/search/SearchScreens.kt index 391cc76..2e2fa96 100644 --- a/features/feature-paging/src/main/java/com/sample/tmdb/paging/search/SearchScreens.kt +++ b/features/feature-paging/src/main/java/com/sample/tmdb/paging/search/SearchScreens.kt @@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.layout.width @@ -44,13 +43,13 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import com.sample.tmdb.common.MainDestinations -import com.sample.tmdb.common.R as R1 import com.sample.tmdb.common.model.TMDbItem import com.sample.tmdb.common.ui.Dimens import com.sample.tmdb.common.ui.component.TMDbDivider import com.sample.tmdb.common.ui.theme.AlphaNearOpaque import com.sample.tmdb.paging.PagingScreen import com.sample.tmdb.paging.R +import com.sample.tmdb.common.R as R1 @Composable fun SearchMoviesScreen(