Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split feature modules to api and impl #304

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ dependencies {
implementation projects.core.logger
implementation projects.data.repository.api
implementation projects.data.model
implementation projects.feature.home
implementation projects.feature.detail
implementation projects.feature.search
implementation projects.feature.home.api
runtimeOnly projects.feature.home.impl
implementation projects.feature.detail.api
runtimeOnly projects.feature.detail.impl
implementation projects.feature.search.api
runtimeOnly projects.feature.search.impl
implementation projects.feature.settings.api
runtimeOnly projects.feature.settings.impl
implementation projects.feature.navigator.api
Expand Down
26 changes: 9 additions & 17 deletions app/src/main/java/soup/movie/ui/main/MainNavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@
package soup.movie.ui.main

import androidx.compose.runtime.Composable
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
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.search.SearchScreen
import soup.movie.feature.search.SearchViewModel
import soup.movie.feature.detail.rememberDetailComposableFactory
import soup.movie.feature.home.rememberHomeComposableFactory
import soup.movie.feature.search.rememberSearchComposableFactory

private enum class Screen(val route: String) {
Main("main"),
Expand All @@ -50,10 +46,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 All @@ -63,9 +58,8 @@ fun MainNavGraph(
)
}
composable(Screen.Search.route) {
val viewModel = hiltViewModel<SearchViewModel>()
SearchScreen(
viewModel = viewModel,
val factory = rememberSearchComposableFactory()
factory.SearchScreen(
upPress = { navController.navigateUp() },
onItemClick = {
navController.navigateToDetail(movieId = it.id)
Expand All @@ -76,10 +70,8 @@ fun MainNavGraph(
route = Screen.Detail.route + "/{movieId}",
arguments = listOf(navArgument("movieId") { nullable = false }),
) {
val viewModel = hiltViewModel<DetailViewModel>()
DetailNavGraph(
viewModel = viewModel,
)
val factory = rememberDetailComposableFactory()
factory.DetailNavGraph()
}
}
}
File renamed without changes.
19 changes: 19 additions & 0 deletions feature/detail/api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id "moop.android.library"
id "moop.android.compose"
id "moop.android.hilt"
}

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

dependencies {
implementation projects.core.kotlin
implementation projects.core.designsystem
implementation projects.core.resources

implementation libs.kotlin.stdlib

implementation libs.compose.foundation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.detail

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent

interface DetailComposableFactory {
@Composable
fun DetailNavGraph()
}

@Composable
fun rememberDetailComposableFactory(): DetailComposableFactory {
val context = LocalContext.current
return remember(context) {
EntryPointAccessors
.fromApplication(context, DetailComposableFactoryEntryPoint::class.java)
.detailComposableFactory()
}
}

@EntryPoint
@InstallIn(SingletonComponent::class)
interface DetailComposableFactoryEntryPoint {
fun detailComposableFactory(): DetailComposableFactory
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

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

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

implementation libs.kotlin.stdlib

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.detail.impl

import androidx.compose.runtime.Composable
import androidx.hilt.navigation.compose.hiltViewModel
import soup.movie.feature.detail.DetailComposableFactory
import javax.inject.Inject

class DetailComposableFactoryImpl @Inject constructor() : DetailComposableFactory {

@Composable
override fun DetailNavGraph() {
DetailNavGraph(
viewModel = hiltViewModel(),
)
}
}
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.detail
package soup.movie.feature.detail.impl

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
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.detail
package soup.movie.feature.detail.impl

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
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.detail
package soup.movie.feature.detail.impl

import androidx.annotation.Keep
import androidx.annotation.StringRes
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.detail
package soup.movie.feature.detail.impl

import androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi
import androidx.compose.animation.graphics.res.animatedVectorResource
Expand Down 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
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.detail
package soup.movie.feature.detail.impl

import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.tween
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.detail
package soup.movie.feature.detail.impl

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
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.detail
package soup.movie.feature.detail.impl

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
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.detail
package soup.movie.feature.detail.impl

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
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.detail
package soup.movie.feature.detail.impl

import androidx.annotation.Keep
import soup.movie.model.CompanyModel
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.detail
package soup.movie.feature.detail.impl

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.detail.impl.di

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import soup.movie.feature.detail.DetailComposableFactory
import soup.movie.feature.detail.impl.DetailComposableFactoryImpl

@Module
@InstallIn(SingletonComponent::class)
interface FeatureDetailModule {

@Binds
fun bindsDetailComposableFactoryImpl(
impl: DetailComposableFactoryImpl,
): DetailComposableFactory
}
File renamed without changes.
19 changes: 19 additions & 0 deletions feature/home/api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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.compose.foundation
}
Loading
Loading