Skip to content

Commit

Permalink
Merge pull request #43 from hoangchungk53qx1/feature/home
Browse files Browse the repository at this point in the history
add top rated movie api
  • Loading branch information
hoangchungk53qx1 authored May 29, 2024
2 parents fb7a79b + b68a0f3 commit 51673f6
Show file tree
Hide file tree
Showing 15 changed files with 8,572 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,21 @@ class MoviePlayingRepositoryImpl @Inject constructor(private val moviePlayingSer
}
}

override suspend fun getUpcomingMovie(): List<MovieModel> {
return moviePlayingService.getUpComingMovie().results.map { movie ->
movie.toMovieModel()
}
}

override suspend fun getTopRatedMovie(): List<MovieModel> {
return moviePlayingService.getTopRatedMovie().results.map { movie ->
movie.toMovieModel()
}
}

override suspend fun getPopularMovie(): List<MovieModel> {
return moviePlayingService.getPopularMovie().results.map { movie ->
movie.toMovieModel()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ val Teal90 = Color(0xFFBEEAF6)
val TextFieldTextColor = Color(0xFF818284)
val Background = Color(0xFF242A32)
val Enable = Color(0xFF0296E5)
val Disable = Color(0xFF67686D)
val Disable = Color(0xFF67686D)
val INDICATOR = Color(0xFF3A3F47)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.chungha.core_domain.model

enum class HomeCategory(val value: String) {
NOW_PLAYING("Now playing"),
UPCOMING("Upcoming"),
TOP_RATED("Top rated"),
POPULAR("Popular")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package com.chungha.core_domain.repository
import com.chungha.core_domain.model.MovieModel

interface MoviePlayingRepository {
suspend fun getPlayingMovie() : List<MovieModel>
suspend fun getPlayingMovie(): List<MovieModel>
suspend fun getPopularMovie(): List<MovieModel>
suspend fun getTopRatedMovie(): List<MovieModel>
suspend fun getUpcomingMovie(): List<MovieModel>
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.chungha.core_domain.usecase

import com.chungha.core_domain.model.HomeCategory
import com.chungha.core_domain.model.MovieModel
import com.chungha.core_domain.repository.MoviePlayingRepository
import com.chungha.core_domain.repository.MovieTopRatedRepository
import com.chungha.core_network.di.DispatcherProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
Expand All @@ -11,14 +11,25 @@ import javax.inject.Inject

class HomeMovieUseCase @Inject constructor(
private val moviePlayingRepository: MoviePlayingRepository,
private val movieTopRatedRepository: MovieTopRatedRepository,
private val dispatcherProvider: DispatcherProvider,
) {
fun invokeMoviePlaying(): Flow<List<MovieModel>> = flow {
emit(moviePlayingRepository.getPlayingMovie())
}.flowOn(dispatcherProvider.io)
fun invokeMoviePlaying(homeCategory: HomeCategory): Flow<List<MovieModel>> = flow {
when (homeCategory) {
HomeCategory.NOW_PLAYING -> {
emit(moviePlayingRepository.getPlayingMovie())
}

HomeCategory.UPCOMING -> {
emit(moviePlayingRepository.getUpcomingMovie())
}

HomeCategory.TOP_RATED -> {
emit(moviePlayingRepository.getTopRatedMovie())
}

fun invokeMovieTopRated(): Flow<List<MovieModel>> = flow {
emit(movieTopRatedRepository.getTopRatedMovie())
HomeCategory.POPULAR -> {
emit(moviePlayingRepository.getPopularMovie())
}
}
}.flowOn(dispatcherProvider.io)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.chungha.core_domain.usecase

import com.chungha.core_domain.model.MovieModel
import com.chungha.core_domain.repository.MoviePlayingRepository
import com.chungha.core_network.di.DispatcherProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

class TopRatedMovieUseCase @Inject constructor(
private val moviePlayingRepository: MoviePlayingRepository,
private val dispatcherProvider: DispatcherProvider
) {
fun invokeMovieTopRated(): Flow<List<MovieModel>> = flow {
emit(moviePlayingRepository.getTopRatedMovie())
}.flowOn(dispatcherProvider.io)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.chungha.core_network.service
import com.chungha.core_network.Constants.DEFAULT_PAGE
import com.chungha.core_network.Constants.Fields.PAGE
import com.chungha.core_network.Constants.Path.NOW_PLAYING_MOVIE
import com.chungha.core_network.Constants.Path.POPULAR_MOVIE
import com.chungha.core_network.Constants.Path.TOP_RATED_MOVIE
import com.chungha.core_network.Constants.Path.UPCOMING_MOVIE
import com.chungha.core_network.common.NetworkResponse
import com.chungha.core_network.model.response.MovieResponse
import retrofit2.http.GET
Expand All @@ -19,4 +21,14 @@ interface MovieService {
suspend fun getTopRatedMovie(
@Query(PAGE) page: Int = DEFAULT_PAGE
): NetworkResponse<List<MovieResponse>>

@GET(POPULAR_MOVIE)
suspend fun getPopularMovie(
@Query(PAGE) page: Int = DEFAULT_PAGE
): NetworkResponse<List<MovieResponse>>

@GET(UPCOMING_MOVIE)
suspend fun getUpComingMovie(
@Query(PAGE) page: Int = DEFAULT_PAGE
): NetworkResponse<List<MovieResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.core_ui.widget.widget

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.example.core_designsystem.theme.INDICATOR

@Composable
fun HomeCategoryTabIndicator(
modifier: Modifier = Modifier,
color: Color = INDICATOR
) {
Spacer(
modifier
.padding(horizontal = 12.dp)
.height(4.dp)
.background(color, RoundedCornerShape(topStartPercent = 100, topEndPercent = 100))
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.core_ui.widget.widget

import androidx.compose.foundation.background
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
Expand All @@ -9,17 +10,18 @@ import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.animateLottieCompositionAsState
import com.airbnb.lottie.compose.rememberLottieComposition
import com.chungha.movie_preview.core.ui.R
import com.example.core_designsystem.theme.Background

@Composable
fun LoadingPreview(modifier: Modifier) {
fun LoadingPreview(modifier: Modifier = Modifier) {
val composite by rememberLottieComposition(spec = LottieCompositionSpec.RawRes(R.raw.amin_loading))
val processLottie by animateLottieCompositionAsState(
composition = composite,
iterations = LottieConstants.IterateForever
)
LottieAnimation(
composition = composite,
modifier = modifier,
modifier = modifier.background(color = Background),
progress = { processLottie },
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.example.core_ui.widget.widget

import androidx.compose.material.Text
import androidx.compose.material3.ScrollableTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.TabPosition
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.chungha.core_domain.model.HomeCategory
import com.example.core_designsystem.theme.MovieTypography

@Composable
fun MovieCategoryTabs(
modifier: Modifier = Modifier,
categories: List<HomeCategory>,
selectedCategory: HomeCategory,
onCategorySelected: (HomeCategory) -> Unit,
) {
if (categories.isEmpty()) {
return
}

val selectedIndex = categories.indexOf(
selectedCategory
)

val indicator = @Composable { tabPositions: List<TabPosition> ->
HomeCategoryTabIndicator(
Modifier.tabIndicatorOffset(tabPositions[selectedIndex])
)
}

ScrollableTabRow(
edgePadding = 0.dp,
modifier = modifier,
selectedTabIndex = selectedIndex,
containerColor = Color.Transparent,
divider = {}, /* Disable the built-in divider */
indicator = indicator,
) {
categories.forEachIndexed { index, category ->
Tab(
selected = index == selectedIndex,
onClick = { onCategorySelected(category) },
text = {
Text(
color = Color.White,
style = MovieTypography.titleSmall,
text = category.value,
onTextLayout = { textLayoutResult ->
textLayoutResult.size.width // width of the text!
}
)
}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.core_ui.widget.widget

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.runtime.Composable
Expand All @@ -10,7 +9,6 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
Expand All @@ -20,12 +18,11 @@ import com.example.core_designsystem.theme.RoundedShape
@Composable
fun MoviePoster(
imagePath: String,
size: Dp,
modifier: Modifier = Modifier
) {
Card(
shape = RoundedShape,
modifier = modifier.height(size),
modifier = modifier,
elevation = CardDefaults.cardElevation(
defaultElevation = 6.dp
),
Expand All @@ -44,8 +41,5 @@ fun MoviePoster(
@Composable
@Preview(name = "MoviePoster", showBackground = true)
fun MoviePosterPreview() {
MoviePoster(
"",
100.dp,
)
MoviePoster("")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.example.core_ui.widget.widget

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -20,10 +22,13 @@ fun MoviePreviewCell(
Column(modifier = modifier.padding(vertical = 15.dp, horizontal = 15.dp)) {
MoviePoster(
imagePath = movieModel.fullMovieImagePath,
size = 240.dp,
modifier = Modifier.clickable {
clickMovie(movieModel.id)
})
modifier = Modifier
.height(210.dp)
.width(145.dp)
.clickable {
clickMovie(movieModel.id)
}
)
Text(
text = movieModel.originalTitle,
textAlign = TextAlign.Center,
Expand Down
8,245 changes: 8,244 additions & 1 deletion core/core-ui/src/main/res/raw/amin_loading.json

Large diffs are not rendered by default.

Loading

0 comments on commit 51673f6

Please sign in to comment.