-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from hoangchungk53qx1/feature/home
add top rated movie api
- Loading branch information
Showing
15 changed files
with
8,572 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
core/core-domain/src/main/java/com/chungha/core_domain/model/HomeCategory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
core/core-domain/src/main/java/com/chungha/core_domain/usecase/TopRatedMovieUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
core/core-ui/src/main/java/com/example/core_ui/widget/widget/HomeCategoryTabIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
core/core-ui/src/main/java/com/example/core_ui/widget/widget/MovieCategoryTabs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
} | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.