Skip to content

Commit

Permalink
Split :feature:home module to api and impl
Browse files Browse the repository at this point in the history
  • Loading branch information
fornewid committed Nov 9, 2024
1 parent 8944772 commit 676aecb
Show file tree
Hide file tree
Showing 39 changed files with 330 additions and 91 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ dependencies {
implementation projects.core.logger
implementation projects.data.repository.api
implementation projects.data.model
implementation projects.feature.home
implementation projects.feature.home.api
runtimeOnly projects.feature.home.impl
implementation projects.feature.detail
implementation projects.feature.search
implementation projects.feature.settings.api
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/soup/movie/ui/main/MainNavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import androidx.navigation.navArgument
import soup.movie.core.designsystem.windowsizeclass.WindowWidthSizeClass
import soup.movie.feature.detail.DetailNavGraph
import soup.movie.feature.detail.DetailViewModel
import soup.movie.feature.home.HomeViewModel
import soup.movie.feature.home.MainScreen
import soup.movie.feature.home.rememberHomeComposableFactory
import soup.movie.feature.search.SearchScreen
import soup.movie.feature.search.SearchViewModel

Expand All @@ -50,10 +49,9 @@ fun MainNavGraph(
startDestination = Screen.Main.route,
) {
composable(Screen.Main.route) {
val viewModel = hiltViewModel<HomeViewModel>()
MainScreen(
val factory = rememberHomeComposableFactory()
factory.HomeNavGraph(
widthSizeClass = widthSizeClass,
viewModel = viewModel,
onSearchClick = {
navController.navigate(Screen.Search.route)
},
Expand Down
2 changes: 1 addition & 1 deletion feature/detail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
implementation projects.data.repository.api
implementation projects.data.model
implementation projects.domain
implementation projects.feature.home
implementation projects.feature.home.api

implementation libs.kotlin.stdlib

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ import soup.movie.core.designsystem.theme.MovieTheme
import soup.movie.core.imageloading.AsyncImage
import soup.movie.domain.movie.getDDayLabel
import soup.movie.domain.movie.isDDay
import soup.movie.feature.home.favorite.MovieAgeTag
import soup.movie.feature.home.favorite.MovieDDayTag
import soup.movie.feature.home.rememberHomeComposableFactory
import soup.movie.model.MovieModel
import soup.movie.resources.R

Expand All @@ -62,6 +61,7 @@ internal fun DetailHeader(
modifier: Modifier = Modifier,
actions: @Composable () -> Unit = {},
) {
val factory = rememberHomeComposableFactory()
val movie: MovieModel = uiModel.movie
Column(modifier = modifier) {
Row(modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp)) {
Expand Down Expand Up @@ -100,12 +100,12 @@ internal fun DetailHeader(
)
}
Column {
MovieAgeTag(
factory.MovieAgeTag(
age = movie.age,
modifier = Modifier.padding(top = 12.dp),
)
if (movie.isDDay()) {
MovieDDayTag(
factory.MovieDDayTag(
text = movie.getDDayLabel().orEmpty(),
modifier = Modifier.padding(top = 4.dp),
)
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions feature/home/api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id "moop.android.library"
id "moop.android.compose"
id "moop.android.hilt"
}

android {
namespace "soup.movie.feature.home"
}

dependencies {
implementation projects.core.kotlin
implementation projects.core.designsystem
implementation projects.data.model

implementation libs.kotlin.stdlib

implementation libs.androidx.hilt.navigation.compose
implementation libs.compose.foundation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2024 SOUP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package soup.movie.feature.home

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent
import soup.movie.core.designsystem.windowsizeclass.WindowWidthSizeClass
import soup.movie.model.MovieModel

interface HomeComposableFactory {

@Composable
fun HomeNavGraph(
widthSizeClass: WindowWidthSizeClass,
onSearchClick: () -> Unit,
onMovieItemClick: (MovieModel) -> Unit,
)

@Composable
fun MovieList(
movies: List<MovieModel>,
onItemClick: (MovieModel) -> Unit,
onLongItemClick: (MovieModel) -> Unit,
modifier: Modifier = Modifier,
)

@Composable
fun NoMovieItems(
modifier: Modifier = Modifier,
)

@Composable
fun MovieAgeTag(
age: Int,
modifier: Modifier = Modifier,
)

@Composable
fun MovieDDayTag(
text: String,
modifier: Modifier = Modifier,
)
}

@Composable
fun rememberHomeComposableFactory(): HomeComposableFactory {
val context = LocalContext.current
return remember(context) {
EntryPointAccessors
.fromApplication(context, HomeComposableFactoryEntryPoint::class.java)
.homeComposableFactory()
}
}

@EntryPoint
@InstallIn(SingletonComponent::class)
interface HomeComposableFactoryEntryPoint {
fun homeComposableFactory(): HomeComposableFactory
}
1 change: 1 addition & 0 deletions feature/home/impl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

android {
namespace "soup.movie.feature.home"
namespace "soup.movie.feature.home.impl"
}

dependencies {
Expand All @@ -18,6 +18,7 @@ dependencies {
implementation projects.data.repository.api
implementation projects.data.model
implementation projects.domain
implementation projects.feature.home.api
implementation projects.feature.settings.api

implementation libs.kotlin.stdlib
Expand Down
1 change: 1 addition & 0 deletions feature/home/impl/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2024 SOUP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package soup.movie.feature.home.impl

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import soup.movie.core.designsystem.windowsizeclass.WindowWidthSizeClass
import soup.movie.feature.home.HomeComposableFactory
import soup.movie.model.MovieModel
import javax.inject.Inject

class HomeComposableFactoryImpl @Inject constructor() : HomeComposableFactory {

@Composable
override fun HomeNavGraph(
widthSizeClass: WindowWidthSizeClass,
onSearchClick: () -> Unit,
onMovieItemClick: (MovieModel) -> Unit,
) {
HomeNavGraph(
widthSizeClass = widthSizeClass,
viewModel = hiltViewModel(),
onSearchClick = onSearchClick,
onMovieItemClick = onMovieItemClick,
)
}

@Composable
override fun MovieList(
movies: List<MovieModel>,
onItemClick: (MovieModel) -> Unit,
onLongItemClick: (MovieModel) -> Unit,
modifier: Modifier,
) {
MovieList(
movies = movies,
onItemClick = onItemClick,
onLongItemClick = onLongItemClick,
modifier = modifier,
)
}

@Composable
override fun NoMovieItems(
modifier: Modifier,
) {
soup.movie.feature.home.impl.tab.NoMovieItems(
modifier = modifier,
)
}

@Composable
override fun MovieAgeTag(
age: Int,
modifier: Modifier,
) {
soup.movie.feature.home.impl.favorite.MovieAgeTag(
age = age,
modifier = modifier,
)
}

@Composable
override fun MovieDDayTag(
text: String,
modifier: Modifier,
) {
soup.movie.feature.home.impl.favorite.MovieDDayTag(
text = text,
modifier = modifier,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package soup.movie.feature.home
package soup.movie.feature.home.impl

import androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi
import androidx.compose.animation.graphics.res.animatedVectorResource
Expand Down Expand Up @@ -49,13 +49,13 @@ import soup.movie.core.designsystem.icon.MovieIcons
import soup.movie.core.designsystem.showToast
import soup.movie.core.designsystem.theme.MovieTheme
import soup.movie.core.designsystem.windowsizeclass.WindowWidthSizeClass
import soup.movie.feature.home.favorite.HomeFavoriteList
import soup.movie.feature.home.impl.favorite.HomeFavoriteList
import soup.movie.feature.settings.rememberSettingsComposableFactory
import soup.movie.model.MovieModel
import soup.movie.resources.R

@Composable
fun MainScreen(
fun HomeNavGraph(
widthSizeClass: WindowWidthSizeClass,
viewModel: HomeViewModel,
onSearchClick: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package soup.movie.feature.home
package soup.movie.feature.home.impl

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.clickable
Expand All @@ -29,7 +29,6 @@ import androidx.compose.material.BottomSheetScaffold
import androidx.compose.material.BottomSheetValue
import androidx.compose.material.ContentAlpha
import androidx.compose.material.Divider
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
Expand All @@ -53,15 +52,14 @@ import kotlinx.coroutines.launch
import soup.movie.core.designsystem.icon.MovieIcons
import soup.movie.core.designsystem.showToast
import soup.movie.core.designsystem.theme.MovieTheme
import soup.movie.feature.home.filter.HomeFilterScreen
import soup.movie.feature.home.now.HomeNowList
import soup.movie.feature.home.plan.HomePlanList
import soup.movie.feature.home.impl.filter.HomeFilterScreen
import soup.movie.feature.home.impl.now.HomeNowList
import soup.movie.feature.home.impl.plan.HomePlanList
import soup.movie.model.MovieModel
import soup.movie.resources.R

@OptIn(ExperimentalMaterialApi::class)
@Composable
internal fun HomeScreen(
fun HomeScreen(
viewModel: HomeViewModel,
onSearchClick: () -> Unit,
onMovieItemClick: (MovieModel) -> Unit,
Expand All @@ -70,7 +68,7 @@ internal fun HomeScreen(
val coroutineScope = rememberCoroutineScope()
val selectedTab by viewModel.selectedHomeTab.collectAsState()

val homeTabs = HomeTabUiModel.values()
val homeTabs = remember { HomeTabUiModel.entries.toTypedArray() }
val gridStates = homeTabs.map { rememberLazyGridState() }
val isTopAtCurrentTab by remember {
derivedStateOf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package soup.movie.feature.home
package soup.movie.feature.home.impl

enum class MainTabUiModel {
Home, Favorite, Settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package soup.movie.feature.home
package soup.movie.feature.home.impl

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package soup.movie.feature.home
package soup.movie.feature.home.impl

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalDensity
Expand Down
Loading

0 comments on commit 676aecb

Please sign in to comment.