Skip to content

Commit

Permalink
Cleanup after merging the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Jun 13, 2024
1 parent ed1d9df commit a03ada4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 117 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <T : TMDbItem> PagingScreen(
Expand All @@ -77,15 +54,19 @@ fun <T : TMDbItem> 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)
}
}
}
}
Expand All @@ -96,84 +77,64 @@ private fun <T : TMDbItem> LazyTMDbItemGrid(
lazyTMDbItems: LazyPagingItems<T>,
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
Expand All @@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a03ada4

Please sign in to comment.