From 7881a1ae89a27979b7878564b76b74ab396e6253 Mon Sep 17 00:00:00 2001 From: stslex Date: Tue, 17 Oct 2023 20:56:10 +0300 Subject: [PATCH 1/8] refactor nav abstraction --- .../slex/csplashscreen/di/main/MainModule.kt | 2 +- .../core/ui/base/BaseViewModel.kt | 10 ++++++-- .../core/ui/base/ViewModelFactory.kt | 2 +- .../slex/csplashscreen/core/ui/mvi/Router.kt | 5 ++++ .../slex/csplashscreen/core/ui/mvi/Store.kt | 6 ++++- .../collection/di/SingleCollectionModule.kt | 2 +- .../navigation/SingleCollectionGraph.kt | 2 +- .../navigation/SingleCollectionRouter.kt | 8 +++---- .../navigation/SingleCollectionRouterImpl.kt | 16 +++++++++---- .../ui/SingleCollectionViewModel.kt | 12 ++-------- .../ui/store/SingleCollectionStore.kt | 2 +- .../feature/favourite/di/FavouriteModule.kt | 2 +- .../favourite/navigation/FavouriteGraph.kt | 2 +- .../favourite/navigation/FavouriteRouter.kt | 11 +++------ .../navigation/FavouriteRouterImpl.kt | 19 +++++++++++---- .../favourite/ui/FavouriteViewModel.kt | 14 +++-------- .../favourite/ui/store/FavouriteStore.kt | 2 +- .../feature/home/di/HomeModule.kt | 2 +- .../feature/home/navigation/HomeGraph.kt | 2 +- .../feature/home/navigation/HomeRouter.kt | 11 +++------ .../feature/home/navigation/HomeRouterImpl.kt | 21 +++++++++++----- .../feature/home/ui/HomeViewModel.kt | 14 +++-------- .../feature/home/ui/store/HomeStore.kt | 2 +- .../di/ImageDetailModule.kt | 2 +- .../navigation/ImageDetailGraph.kt | 2 +- .../navigation/ImageDetailRouter.kt | 9 +++---- .../navigation/ImageDetailRouterImpl.kt | 16 +++++++++---- .../ui/ImageDetailViewModel.kt | 13 +++------- .../ui/store/ImageDetailStore.kt | 2 +- .../feature/search/di/SearchPhotosModule.kt | 2 +- .../search/navigation/SearchPhotosGraph.kt | 2 +- .../search/navigation/SearchPhotosRouter.kt | 9 +++---- .../navigation/SearchPhotosRouterImpl.kt | 16 +++++++++---- .../feature/search/ui/SearchViewModel.kt | 13 +++------- .../feature/search/ui/store/SearchStore.kt | 2 +- .../feature/user/di/UserModule.kt | 2 +- .../feature/user/navigation/UserGraph.kt | 2 +- .../feature/user/navigation/UserRouter.kt | 13 +++------- .../feature/user/navigation/UserRouterImpl.kt | 24 +++++++++++++------ .../feature/user/ui/UserViewModel.kt | 14 ++--------- .../feature/user/ui/store/UserStore.kt | 2 +- 41 files changed, 154 insertions(+), 160 deletions(-) create mode 100644 core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Router.kt diff --git a/app/src/main/java/st/slex/csplashscreen/di/main/MainModule.kt b/app/src/main/java/st/slex/csplashscreen/di/main/MainModule.kt index a8caed4f..8e121886 100644 --- a/app/src/main/java/st/slex/csplashscreen/di/main/MainModule.kt +++ b/app/src/main/java/st/slex/csplashscreen/di/main/MainModule.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.di.main import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import com.stslex93.notes.core.ui.base.ViewModelFactory +import st.slex.csplashscreen.core.ui.base.ViewModelFactory import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/BaseViewModel.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/BaseViewModel.kt index 17c295cc..1a788c77 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/BaseViewModel.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/BaseViewModel.kt @@ -4,13 +4,15 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow +import st.slex.csplashscreen.core.ui.mvi.Router import st.slex.csplashscreen.core.ui.mvi.Store import st.slex.csplashscreen.core.ui.mvi.Store.Action import st.slex.csplashscreen.core.ui.mvi.Store.Event import st.slex.csplashscreen.core.ui.mvi.Store.State -open class BaseViewModel( - private val store: Store +open class BaseViewModel( + private val store: Store, + private val router: Router ) : ViewModel() { val state: StateFlow = store.state @@ -24,6 +26,10 @@ open class BaseViewModel( store.processAction(action) } + fun navigate(event: N) { + router(event) + } + override fun onCleared() { super.onCleared() store.destroy() diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/ViewModelFactory.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/ViewModelFactory.kt index 5f5bb442..f7bf08a7 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/ViewModelFactory.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/ViewModelFactory.kt @@ -1,4 +1,4 @@ -package com.stslex93.notes.core.ui.base +package st.slex.csplashscreen.core.ui.base import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Router.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Router.kt new file mode 100644 index 00000000..98c7abfd --- /dev/null +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Router.kt @@ -0,0 +1,5 @@ +package st.slex.csplashscreen.core.ui.mvi + +fun interface Router { + operator fun invoke(event: E) +} \ No newline at end of file diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Store.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Store.kt index 7f7612ae..4a8eb7c5 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Store.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Store.kt @@ -19,6 +19,10 @@ interface Store { fun destroy() interface State - interface Event + + interface Event { + interface Navigation : Event + } + interface Action } diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionModule.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionModule.kt index e55688d2..a80246d6 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionModule.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionModule.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.collection.di import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import com.stslex93.notes.core.ui.base.ViewModelFactory +import st.slex.csplashscreen.core.ui.base.ViewModelFactory import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt index 311431db..33d06260 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt @@ -44,7 +44,7 @@ fun NavGraphBuilder.singleCollectionGraph( viewModel.event.CollectAsEvent { event -> when (event) { - is Event.Navigation -> viewModel.processNavigation(event) + is Event.Navigation -> viewModel.navigate(event) } } diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouter.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouter.kt index b41b5294..225028f1 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouter.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouter.kt @@ -1,8 +1,6 @@ package st.slex.csplashscreen.feature.collection.navigation -interface SingleCollectionRouter { +import st.slex.csplashscreen.core.ui.mvi.Router +import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event.Navigation - fun navToImage(uuid: String) - - fun navToProfile(username: String) -} \ No newline at end of file +interface SingleCollectionRouter : Router \ No newline at end of file diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouterImpl.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouterImpl.kt index d97dd836..b39385b5 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouterImpl.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouterImpl.kt @@ -2,17 +2,25 @@ package st.slex.csplashscreen.feature.collection.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator +import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event.Navigation import javax.inject.Inject class SingleCollectionRouterImpl @Inject constructor( private val navigator: Navigator ) : SingleCollectionRouter { - override fun navToImage(uuid: String) { - navigator(NavigationScreen.ImageDetailScreen(uuid)) + override fun invoke(event: Navigation) { + when (event) { + is Navigation.ImageDetail -> navToImage(event) + is Navigation.Profile -> navToProfile(event) + } } - override fun navToProfile(username: String) { - navigator(NavigationScreen.UserScreen(username)) + private fun navToImage(event: Navigation.ImageDetail) { + navigator(NavigationScreen.ImageDetailScreen(event.uuid)) + } + + private fun navToProfile(event: Navigation.Profile) { + navigator(NavigationScreen.UserScreen(event.username)) } } \ No newline at end of file diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/SingleCollectionViewModel.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/SingleCollectionViewModel.kt index 94f61d72..ecfac045 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/SingleCollectionViewModel.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/SingleCollectionViewModel.kt @@ -11,13 +11,5 @@ import javax.inject.Inject class SingleCollectionViewModel @Inject constructor( store: SingleCollectionStore, - private val router: SingleCollectionRouter -) : BaseViewModel(store) { - - fun processNavigation(event: Navigation) { - when (event) { - is Navigation.ImageDetail -> router.navToImage(event.uuid) - is Navigation.Profile -> router.navToProfile(event.username) - } - } -} \ No newline at end of file + router: SingleCollectionRouter +) : BaseViewModel(store, router) \ No newline at end of file diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStore.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStore.kt index 7dd424bf..56997efb 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStore.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStore.kt @@ -21,7 +21,7 @@ interface SingleCollectionStore : Store { sealed interface Event : Store.Event { @Stable - sealed interface Navigation : Event { + sealed interface Navigation : Event, Store.Event.Navigation { @Stable data class Profile( diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteModule.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteModule.kt index 7d56551d..a5167ab3 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteModule.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteModule.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.favourite.di import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import com.stslex93.notes.core.ui.base.ViewModelFactory +import st.slex.csplashscreen.core.ui.base.ViewModelFactory import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt index c58a59a3..5519adb4 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt @@ -35,7 +35,7 @@ fun NavGraphBuilder.favouriteGraph( viewModel.event.CollectAsEvent { event -> when (event) { - is Event.Navigation -> viewModel.processNavigation(event) + is Event.Navigation -> viewModel.navigate(event) } } diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouter.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouter.kt index d32aed05..0366f000 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouter.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouter.kt @@ -1,11 +1,6 @@ package st.slex.csplashscreen.feature.favourite.navigation -interface FavouriteRouter { - - fun navToUser(username: String) - - fun navToImage(uuid: String) - - fun navHome() -} +import st.slex.csplashscreen.core.ui.mvi.Router +import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore +interface FavouriteRouter : Router diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouterImpl.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouterImpl.kt index d462634a..c04eb662 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouterImpl.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouterImpl.kt @@ -2,21 +2,30 @@ package st.slex.csplashscreen.feature.favourite.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator +import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore import javax.inject.Inject class FavouriteRouterImpl @Inject constructor( private val navigator: Navigator ) : FavouriteRouter { - override fun navToUser(username: String) { - navigator(NavigationScreen.UserScreen(username)) + override fun invoke(event: FavouriteStore.Event.Navigation) { + when (event) { + FavouriteStore.Event.Navigation.Home -> navHome() + is FavouriteStore.Event.Navigation.Image -> navToImage(event) + is FavouriteStore.Event.Navigation.User -> navToUser(event) + } } - override fun navToImage(uuid: String) { - navigator(NavigationScreen.ImageDetailScreen(uuid)) + private fun navToUser(event: FavouriteStore.Event.Navigation.User) { + navigator(NavigationScreen.UserScreen(event.username)) } - override fun navHome() { + private fun navToImage(event: FavouriteStore.Event.Navigation.Image) { + navigator(NavigationScreen.ImageDetailScreen(event.uuid)) + } + + private fun navHome() { navigator(NavigationScreen.Home) } } \ No newline at end of file diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/FavouriteViewModel.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/FavouriteViewModel.kt index 79f754c9..1848ef19 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/FavouriteViewModel.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/FavouriteViewModel.kt @@ -5,19 +5,11 @@ import st.slex.csplashscreen.feature.favourite.navigation.FavouriteRouter import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Action import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Event +import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Event.Navigation import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.State import javax.inject.Inject class FavouriteViewModel @Inject constructor( - private val router: FavouriteRouter, + router: FavouriteRouter, store: FavouriteStore -) : BaseViewModel(store) { - - fun processNavigation(event: Event.Navigation) { - when (event) { - Event.Navigation.Home -> router.navHome() - is Event.Navigation.Image -> router.navToImage(event.uuid) - is Event.Navigation.User -> router.navToUser(event.username) - } - } -} \ No newline at end of file +) : BaseViewModel(store, router) \ No newline at end of file diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt index 52e62289..b76d4cda 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt @@ -20,7 +20,7 @@ interface FavouriteStore : Store { sealed interface Event : Store.Event { @Stable - sealed interface Navigation : Event { + sealed interface Navigation : Event, Store.Event.Navigation { @Stable data class User( diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeModule.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeModule.kt index 738890e0..e86518cd 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeModule.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeModule.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.home.di import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import com.stslex93.notes.core.ui.base.ViewModelFactory +import st.slex.csplashscreen.core.ui.base.ViewModelFactory import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt index 327de9d4..44bac1cd 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt @@ -35,7 +35,7 @@ fun NavGraphBuilder.homeGraph( viewModel.event.CollectAsEvent { event -> when (event) { - is HomeStore.Event.Navigation -> viewModel.processNavigation(event) + is HomeStore.Event.Navigation -> viewModel.navigate(event) } } diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouter.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouter.kt index 887cffce..90028d85 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouter.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouter.kt @@ -1,11 +1,6 @@ package st.slex.csplashscreen.feature.home.navigation -interface HomeRouter { - - fun navToProfile(username: String) - - fun navToImage(uuid: String) - - fun navToCollection(uuid: String) -} +import st.slex.csplashscreen.core.ui.mvi.Router +import st.slex.csplashscreen.feature.home.ui.store.HomeStore +interface HomeRouter : Router diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouterImpl.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouterImpl.kt index 754f0e44..318e6959 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouterImpl.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouterImpl.kt @@ -2,21 +2,30 @@ package st.slex.csplashscreen.feature.home.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator +import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Event.Navigation import javax.inject.Inject class HomeRouterImpl @Inject constructor( private val navigator: Navigator ) : HomeRouter { - override fun navToProfile(username: String) { - navigator(NavigationScreen.UserScreen(username)) + override fun invoke(event: Navigation) { + when (event) { + is Navigation.Collection -> navToCollection(event) + is Navigation.Image -> navToImage(event) + is Navigation.User -> navToProfile(event) + } } - override fun navToImage(uuid: String) { - navigator(NavigationScreen.ImageDetailScreen(uuid)) + private fun navToProfile(event: Navigation.User) { + navigator(NavigationScreen.UserScreen(event.username)) } - override fun navToCollection(uuid: String) { - navigator(NavigationScreen.CollectionScreen(uuid)) + private fun navToImage(event: Navigation.Image) { + navigator(NavigationScreen.ImageDetailScreen(event.uuid)) + } + + private fun navToCollection(event: Navigation.Collection) { + navigator(NavigationScreen.CollectionScreen(event.uuid)) } } \ No newline at end of file diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/HomeViewModel.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/HomeViewModel.kt index cf67e86d..64a14e6d 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/HomeViewModel.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/HomeViewModel.kt @@ -5,19 +5,11 @@ import st.slex.csplashscreen.feature.home.navigation.HomeRouter import st.slex.csplashscreen.feature.home.ui.store.HomeStore import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Action import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Event +import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Event.Navigation import st.slex.csplashscreen.feature.home.ui.store.HomeStore.State import javax.inject.Inject class HomeViewModel @Inject constructor( - private val router: HomeRouter, + router: HomeRouter, store: HomeStore -) : BaseViewModel(store) { - - fun processNavigation(event: Event.Navigation) { - when (event) { - is Event.Navigation.Collection -> router.navToCollection(event.uuid) - is Event.Navigation.Image -> router.navToImage(event.uuid) - is Event.Navigation.User -> router.navToProfile(event.username) - } - } -} \ No newline at end of file +) : BaseViewModel(store, router) \ No newline at end of file diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStore.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStore.kt index c6aca570..b56f63fb 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStore.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStore.kt @@ -22,7 +22,7 @@ interface HomeStore : Store { sealed interface Event : Store.Event { @Stable - sealed interface Navigation : Event { + sealed interface Navigation : Event, Store.Event.Navigation { @Stable data class User( diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailModule.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailModule.kt index 592ff63b..2f86e8f2 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailModule.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailModule.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.feature_photo_detail.di import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import com.stslex93.notes.core.ui.base.ViewModelFactory +import st.slex.csplashscreen.core.ui.base.ViewModelFactory import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt index b7acf517..dda4bdbb 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt @@ -41,7 +41,7 @@ fun NavGraphBuilder.imageDetailGraph( viewModel.event.CollectAsEvent { event -> when (event) { - is ImageDetailStore.Event.Navigation -> viewModel.processNavigation(event) + is ImageDetailStore.Event.Navigation -> viewModel.navigate(event) } } diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouter.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouter.kt index f10431e8..1035efd9 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouter.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouter.kt @@ -1,9 +1,6 @@ package st.slex.csplashscreen.feature.feature_photo_detail.navigation -interface ImageDetailRouter { - - fun navToSearch(tag: String) - - fun navToProfile(username: String) -} +import st.slex.csplashscreen.core.ui.mvi.Router +import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event.Navigation +interface ImageDetailRouter : Router diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouterImpl.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouterImpl.kt index 4e74d00f..dc094608 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouterImpl.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouterImpl.kt @@ -2,17 +2,25 @@ package st.slex.csplashscreen.feature.feature_photo_detail.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator +import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event.Navigation import javax.inject.Inject class ImageDetailRouterImpl @Inject constructor( private val navigator: Navigator ) : ImageDetailRouter { - override fun navToSearch(tag: String) { - navigator(NavigationScreen.SearchPhotosScreen(tag)) + override fun invoke(event: Navigation) { + when (event) { + is Navigation.Profile -> navToProfile(event) + is Navigation.Search -> navToSearch(event) + } } - override fun navToProfile(username: String) { - navigator(NavigationScreen.UserScreen(username)) + private fun navToSearch(event: Navigation.Search) { + navigator(NavigationScreen.SearchPhotosScreen(event.tag)) + } + + private fun navToProfile(event: Navigation.Profile) { + navigator(NavigationScreen.UserScreen(event.username)) } } \ No newline at end of file diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/ImageDetailViewModel.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/ImageDetailViewModel.kt index dc8ceab6..4dcd92e3 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/ImageDetailViewModel.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/ImageDetailViewModel.kt @@ -5,18 +5,11 @@ import st.slex.csplashscreen.feature.feature_photo_detail.navigation.ImageDetail import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Action import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event +import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event.Navigation import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.State import javax.inject.Inject class ImageDetailViewModel @Inject constructor( - private val router: ImageDetailRouter, + router: ImageDetailRouter, store: ImageDetailStore -) : BaseViewModel(store) { - - fun processNavigation(event: Event.Navigation) { - when (event) { - is Event.Navigation.Profile -> router.navToProfile(event.username) - is Event.Navigation.Search -> router.navToSearch(event.tag) - } - } -} \ No newline at end of file +) : BaseViewModel(store, router) \ No newline at end of file diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStore.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStore.kt index ef3b422c..1bc145bb 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStore.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStore.kt @@ -40,7 +40,7 @@ interface ImageDetailStore : Store { sealed interface Event : Store.Event { @Stable - sealed interface Navigation : Event { + sealed interface Navigation : Event, Store.Event.Navigation { @Stable data class Profile( diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosModule.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosModule.kt index 5c97c5bf..81f87239 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosModule.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosModule.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.search.di import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import com.stslex93.notes.core.ui.base.ViewModelFactory +import st.slex.csplashscreen.core.ui.base.ViewModelFactory import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt index b35b4231..c7802507 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt @@ -37,7 +37,7 @@ fun NavGraphBuilder.searchPhotosGraph( viewModel.event.CollectAsEvent { event -> when (event) { - is SearchStore.Event.Navigation -> viewModel.processNavigation(event) + is SearchStore.Event.Navigation -> viewModel.navigate(event) } } diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouter.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouter.kt index 0e8b7abf..ac1869f8 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouter.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouter.kt @@ -1,9 +1,6 @@ package st.slex.csplashscreen.feature.search.navigation -interface SearchPhotosRouter { - - fun navToImage(uuid: String) - - fun navToProfile(username: String) -} +import st.slex.csplashscreen.core.ui.mvi.Router +import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event.Navigation +interface SearchPhotosRouter : Router diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouterImpl.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouterImpl.kt index 903ae0e8..6ae6f353 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouterImpl.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouterImpl.kt @@ -2,17 +2,25 @@ package st.slex.csplashscreen.feature.search.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator +import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event.Navigation import javax.inject.Inject class SearchPhotosRouterImpl @Inject constructor( private val navigator: Navigator ) : SearchPhotosRouter { - override fun navToImage(uuid: String) { - navigator(NavigationScreen.ImageDetailScreen(uuid)) + override fun invoke(event: Navigation) { + when (event) { + is Navigation.ImageDetail -> navToImage(event) + is Navigation.Profile -> navToProfile(event) + } } - override fun navToProfile(username: String) { - navigator(NavigationScreen.UserScreen(username)) + private fun navToImage(event: Navigation.ImageDetail) { + navigator(NavigationScreen.ImageDetailScreen(event.uuid)) + } + + private fun navToProfile(event: Navigation.Profile) { + navigator(NavigationScreen.UserScreen(event.username)) } } \ No newline at end of file diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/SearchViewModel.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/SearchViewModel.kt index 7651dd69..3b45a091 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/SearchViewModel.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/SearchViewModel.kt @@ -5,18 +5,11 @@ import st.slex.csplashscreen.feature.search.navigation.SearchPhotosRouter import st.slex.csplashscreen.feature.search.ui.store.SearchStore import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Action import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event +import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event.Navigation import st.slex.csplashscreen.feature.search.ui.store.SearchStore.State import javax.inject.Inject class SearchViewModel @Inject constructor( store: SearchStore, - private val router: SearchPhotosRouter -) : BaseViewModel(store) { - - fun processNavigation(event: Event.Navigation) { - when (event) { - is Event.Navigation.ImageDetail -> router.navToImage(event.uuid) - is Event.Navigation.Profile -> router.navToProfile(event.username) - } - } -} \ No newline at end of file + router: SearchPhotosRouter +) : BaseViewModel(store, router) \ No newline at end of file diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStore.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStore.kt index 983cd02a..b9a5c306 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStore.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStore.kt @@ -24,7 +24,7 @@ interface SearchStore : Store { sealed interface Event : Store.Event { @Stable - sealed interface Navigation : Event { + sealed interface Navigation : Event, Store.Event.Navigation { @Stable data class Profile( diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserModule.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserModule.kt index d4ae4b04..7289b4cf 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserModule.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserModule.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.user.di import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import com.stslex93.notes.core.ui.base.ViewModelFactory +import st.slex.csplashscreen.core.ui.base.ViewModelFactory import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt index afc940e1..42e9dd6e 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt @@ -44,7 +44,7 @@ fun NavGraphBuilder.userGraph( viewModel.event.CollectAsEvent { event -> when (event) { - is UserStore.Event.Navigation -> viewModel.processNavigation(event) + is UserStore.Event.Navigation -> viewModel.navigate(event) } } diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouter.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouter.kt index 13f4185a..76065b36 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouter.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouter.kt @@ -1,13 +1,6 @@ package st.slex.csplashscreen.feature.user.navigation -interface UserRouter { - - fun popBack() - - fun navToUser(username: String) - - fun navToImage(uuid: String) - - fun navToCollection(uuid: String) -} +import st.slex.csplashscreen.core.ui.mvi.Router +import st.slex.csplashscreen.feature.user.ui.store.UserStore +interface UserRouter : Router \ No newline at end of file diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouterImpl.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouterImpl.kt index d7bbc3ff..1c1ac92f 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouterImpl.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouterImpl.kt @@ -2,25 +2,35 @@ package st.slex.csplashscreen.feature.user.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator +import st.slex.csplashscreen.feature.user.ui.store.UserStore import javax.inject.Inject class UserRouterImpl @Inject constructor( private val navigator: Navigator ) : UserRouter { - override fun popBack() { + override fun invoke(event: UserStore.Event.Navigation) { + when (event) { + is UserStore.Event.Navigation.Collection -> navToCollection(event) + is UserStore.Event.Navigation.Image -> navToImage(event) + is UserStore.Event.Navigation.PopBack -> popBack() + is UserStore.Event.Navigation.User -> navToUser(event) + } + } + + private fun popBack() { navigator(NavigationScreen.PopBackStack) } - override fun navToUser(username: String) { - navigator(NavigationScreen.UserScreen(username)) + private fun navToUser(event: UserStore.Event.Navigation.User) { + navigator(NavigationScreen.UserScreen(event.username)) } - override fun navToImage(uuid: String) { - navigator(NavigationScreen.ImageDetailScreen(uuid)) + private fun navToImage(event: UserStore.Event.Navigation.Image) { + navigator(NavigationScreen.ImageDetailScreen(event.uuid)) } - override fun navToCollection(uuid: String) { - navigator(NavigationScreen.CollectionScreen(uuid)) + private fun navToCollection(event: UserStore.Event.Navigation.Collection) { + navigator(NavigationScreen.CollectionScreen(event.uuid)) } } \ No newline at end of file diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/UserViewModel.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/UserViewModel.kt index af10a296..935923c0 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/UserViewModel.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/UserViewModel.kt @@ -10,16 +10,6 @@ import st.slex.csplashscreen.feature.user.ui.store.UserStore.State import javax.inject.Inject class UserViewModel @Inject constructor( - private val router: UserRouter, + router: UserRouter, store: UserStore -) : BaseViewModel(store) { - - fun processNavigation(event: Navigation) { - when (event) { - is Navigation.Collection -> router.navToCollection(event.uuid) - is Navigation.Image -> router.navToImage(event.uuid) - is Navigation.PopBack -> router.popBack() - is Navigation.User -> router.navToUser(event.username) - } - } -} \ No newline at end of file +) : BaseViewModel(store, router) \ No newline at end of file diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStore.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStore.kt index c7ce079c..7980a1bc 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStore.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStore.kt @@ -25,7 +25,7 @@ interface UserStore : Store { @Stable sealed interface Event : Store.Event { - sealed interface Navigation : Event { + sealed interface Navigation : Event, Store.Event.Navigation { data object PopBack : Navigation From b9cf57ed6c8cbed9b023f081c12927039741aa7d Mon Sep 17 00:00:00 2001 From: stslex Date: Sun, 29 Oct 2023 13:56:49 +0300 Subject: [PATCH 2/8] add feature builder --- .../core/ui/base/DaggerViewModel.kt | 17 ++++++++- .../core/ui/di/builder/Feature.kt | 8 +++++ .../core/ui/di/builder/FeatureBuilder.kt | 17 +++++++++ .../collection/di/SingleCollectionBuilder.kt | 27 ++++---------- .../di/SingleCollectionComponent.kt | 6 ++-- .../navigation/SingleCollectionGraph.kt | 9 +++-- .../favourite/di/FavouriteComponent.kt | 6 ++-- .../favourite/di/FavouriteComponentBuilder.kt | 35 +++++-------------- .../favourite/navigation/FavouriteGraph.kt | 6 ++-- .../feature/home/di/HomeComponent.kt | 6 ++-- .../feature/home/di/HomeComponentBuilder.kt | 28 ++++----------- .../feature/home/navigation/HomeGraph.kt | 6 ++-- .../di/ImageDetailComponent.kt | 6 ++-- .../di/ImageDetailComponentBuilder.kt | 32 +++++------------ .../navigation/ImageDetailGraph.kt | 8 +++-- .../search/di/SearchPhotosComponent.kt | 6 ++-- .../search/di/SearchPhotosComponentBuilder.kt | 32 +++++------------ .../search/navigation/SearchPhotosGraph.kt | 9 +++-- .../feature/user/di/UserComponent.kt | 6 ++-- .../feature/user/di/UserComponentBuilder.kt | 28 +++++---------- .../feature/user/navigation/UserGraph.kt | 9 +++-- 21 files changed, 134 insertions(+), 173 deletions(-) create mode 100644 core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/Feature.kt create mode 100644 core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/FeatureBuilder.kt diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/DaggerViewModel.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/DaggerViewModel.kt index 2a77b389..614470f1 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/DaggerViewModel.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/DaggerViewModel.kt @@ -1,9 +1,11 @@ package st.slex.csplashscreen.core.ui.base import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewmodel.compose.viewModel +import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder @Composable inline fun daggerViewModel( @@ -13,4 +15,17 @@ inline fun daggerViewModel( modelClass = T::class.java, key = key, factory = factory() -) \ No newline at end of file +) + +@Composable +inline fun setupComponent( + builder: FeatureBuilder, + key: String? = null, +): VM { + val context = LocalContext.current + return daggerViewModel(key) { + builder + .build(context) + .viewModelFactory + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/Feature.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/Feature.kt new file mode 100644 index 00000000..1cd48a3d --- /dev/null +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/Feature.kt @@ -0,0 +1,8 @@ +package st.slex.csplashscreen.core.ui.di.builder + +import androidx.lifecycle.ViewModelProvider + +interface Feature { + + val viewModelFactory: ViewModelProvider.Factory +} diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/FeatureBuilder.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/FeatureBuilder.kt new file mode 100644 index 00000000..51b4dfe9 --- /dev/null +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/FeatureBuilder.kt @@ -0,0 +1,17 @@ +package st.slex.csplashscreen.core.ui.di.builder + +import android.content.Context + +interface FeatureBuilder { + + fun create(context: Context): Feature + + fun build(context: Context): Feature = _feature ?: create(context) + .also { createdFeature -> + _feature = createdFeature + } + + companion object { + private var _feature: Feature? = null + } +} \ No newline at end of file diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionBuilder.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionBuilder.kt index 5a65d079..a2ea90ed 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionBuilder.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionBuilder.kt @@ -1,36 +1,21 @@ package st.slex.csplashscreen.feature.collection.di -import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext +import android.content.Context import st.slex.csplashscreen.core.network.di.NetworkApiBuilder -import st.slex.csplashscreen.core.ui.base.daggerViewModel -import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature +import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -import st.slex.csplashscreen.feature.collection.ui.SingleCollectionViewModel -object SingleCollectionBuilder { +object SingleCollectionBuilder : FeatureBuilder { - fun build( - navigationApi: NavigationApi - ): SingleCollectionComponent = DaggerSingleCollectionComponent + override fun create(context: Context): Feature = DaggerSingleCollectionComponent .factory() .create( dependencies = DaggerSingleCollectionComponent_SingleCollectionDependenciesComponent .factory() .create( networkClientApi = NetworkApiBuilder.build(), - navigationApi = navigationApi + navigationApi = context.navigationApi ) - ) } - -@Composable -fun setupComponent(key: String): SingleCollectionViewModel { - val context = LocalContext.current - return daggerViewModel(key) { - SingleCollectionBuilder - .build(context.navigationApi) - .viewModelFactory - } -} diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionComponent.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionComponent.kt index b6c372e6..b2f380db 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionComponent.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionComponent.kt @@ -1,16 +1,16 @@ package st.slex.csplashscreen.feature.collection.di -import androidx.lifecycle.ViewModelProvider import dagger.Component import st.slex.csplashscreen.core.network.di.NetworkClientApi import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature @Component( dependencies = [SingleCollectionDependencies::class], modules = [SingleCollectionModule::class] ) @SingleCollectionScope -interface SingleCollectionComponent { +interface SingleCollectionComponent : Feature { @Component.Factory interface Factory { @@ -32,6 +32,4 @@ interface SingleCollectionComponent { ): SingleCollectionDependencies } } - - val viewModelFactory: ViewModelProvider.Factory } \ No newline at end of file diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt index 33d06260..c20cb0cb 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt @@ -12,9 +12,11 @@ import st.slex.csplashscreen.core.navigation.AppArguments import st.slex.csplashscreen.core.navigation.AppDestination import st.slex.csplashscreen.core.navigation.NavExt.composableArguments import st.slex.csplashscreen.core.navigation.NavExt.parseArguments +import st.slex.csplashscreen.core.ui.base.setupComponent import st.slex.csplashscreen.core.ui.utils.CollectAsEvent -import st.slex.csplashscreen.feature.collection.di.setupComponent +import st.slex.csplashscreen.feature.collection.di.SingleCollectionBuilder import st.slex.csplashscreen.feature.collection.ui.CollectionScreen +import st.slex.csplashscreen.feature.collection.ui.SingleCollectionViewModel import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Action import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event @@ -28,7 +30,10 @@ fun NavGraphBuilder.singleCollectionGraph( val arguments = AppDestination.COLLECTION.parseArguments(navBackStackEntry).let { args -> AppArguments.CollectionScreen(args[0]) } - val viewModel = setupComponent(key = arguments.collectionId) + val viewModel: SingleCollectionViewModel = setupComponent( + key = arguments.collectionId, + builder = SingleCollectionBuilder + ) val state by remember { viewModel.state diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponent.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponent.kt index 484e2e7d..0dffea26 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponent.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponent.kt @@ -1,16 +1,16 @@ package st.slex.csplashscreen.feature.favourite.di -import androidx.lifecycle.ViewModelProvider import dagger.Component import st.slex.csplashscreen.core.favourite.di.FavouriteApi import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature @Component( dependencies = [FavouriteDependencies::class], modules = [FavouriteModule::class] ) @FavouriteScope -interface FavouriteComponent { +interface FavouriteComponent : Feature { @Component.Factory interface Factory { @@ -31,6 +31,4 @@ interface FavouriteComponent { ): FavouriteDependencies } } - - val viewModelFactory: ViewModelProvider.Factory } \ No newline at end of file diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponentBuilder.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponentBuilder.kt index f9916a49..9f3d8723 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponentBuilder.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponentBuilder.kt @@ -1,40 +1,23 @@ package st.slex.csplashscreen.feature.favourite.di -import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext -import st.slex.csplashscreen.core.core.AppApi +import android.content.Context import st.slex.csplashscreen.core.core.appApi import st.slex.csplashscreen.core.favourite.di.FavouriteApiBuilder -import st.slex.csplashscreen.core.ui.base.daggerViewModel -import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature +import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -import st.slex.csplashscreen.feature.favourite.ui.FavouriteViewModel -object FavouriteComponentBuilder { +object FavouriteComponentBuilder : FeatureBuilder { - fun build( - appApi: AppApi, - navigationApi: NavigationApi - ): FavouriteComponent = DaggerFavouriteComponent.factory() + override fun create( + context: Context + ): Feature = DaggerFavouriteComponent.factory() .create( dependencies = DaggerFavouriteComponent_FavouriteDependenciesComponent .factory() .create( - navigationApi = navigationApi, - favouriteApi = FavouriteApiBuilder.build(appApi) + navigationApi = context.navigationApi, + favouriteApi = FavouriteApiBuilder.build(context.appApi) ) ) } - -@Composable -fun setupComponent(): FavouriteViewModel { - val context = LocalContext.current - return daggerViewModel { - FavouriteComponentBuilder - .build( - appApi = context.appApi, - navigationApi = context.navigationApi - ) - .viewModelFactory - } -} \ No newline at end of file diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt index 5519adb4..6f21396a 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt @@ -9,9 +9,11 @@ import androidx.navigation.compose.composable import androidx.paging.compose.collectAsLazyPagingItems import st.slex.csplashscreen.core.navigation.AppDestination import st.slex.csplashscreen.core.navigation.NavExt.composableArguments +import st.slex.csplashscreen.core.ui.base.setupComponent import st.slex.csplashscreen.core.ui.utils.CollectAsEvent -import st.slex.csplashscreen.feature.favourite.di.setupComponent +import st.slex.csplashscreen.feature.favourite.di.FavouriteComponentBuilder import st.slex.csplashscreen.feature.favourite.ui.FavouriteScreen +import st.slex.csplashscreen.feature.favourite.ui.FavouriteViewModel import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Action import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Event @@ -23,7 +25,7 @@ fun NavGraphBuilder.favouriteGraph( arguments = AppDestination.FAVOURITE.composableArguments ) { - val viewModel = setupComponent() + val viewModel: FavouriteViewModel = setupComponent(FavouriteComponentBuilder) val state by remember { viewModel.state diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponent.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponent.kt index 87b8c4b7..54ec92d1 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponent.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponent.kt @@ -1,17 +1,17 @@ package st.slex.csplashscreen.feature.home.di -import androidx.lifecycle.ViewModelProvider import dagger.Component import st.slex.csplashscreen.core.collection.di.CollectionApi import st.slex.csplashscreen.core.photos.di.PhotosApi import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature @Component( dependencies = [HomeDependencies::class], modules = [HomeModule::class] ) @HomeScope -interface HomeComponent { +interface HomeComponent : Feature { @Component.Factory interface Factory { @@ -38,6 +38,4 @@ interface HomeComponent { ): HomeDependencies } } - - val viewModelFactory: ViewModelProvider.Factory } \ No newline at end of file diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponentBuilder.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponentBuilder.kt index ddd71c5d..c068a474 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponentBuilder.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponentBuilder.kt @@ -1,39 +1,23 @@ package st.slex.csplashscreen.feature.home.di -import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext +import android.content.Context import st.slex.csplashscreen.core.collection.di.CollectionApiBuilder import st.slex.csplashscreen.core.photos.di.PhotosApiBuilder -import st.slex.csplashscreen.core.ui.base.daggerViewModel -import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature +import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -import st.slex.csplashscreen.feature.home.ui.HomeViewModel -object HomeComponentBuilder { +object HomeComponentBuilder : FeatureBuilder { - fun build( - navigationApi: NavigationApi - ): HomeComponent = DaggerHomeComponent + override fun create(context: Context): Feature = DaggerHomeComponent .factory() .create( dependencies = DaggerHomeComponent_HomeDependenciesComponent .factory() .create( - navigationApi = navigationApi, + navigationApi = context.navigationApi, collectionApi = CollectionApiBuilder.build(), photosApi = PhotosApiBuilder.build() ) ) } - -@Composable -fun setupComponent(): HomeViewModel { - val context = LocalContext.current - return daggerViewModel { - HomeComponentBuilder - .build( - navigationApi = context.navigationApi - ) - .viewModelFactory - } -} \ No newline at end of file diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt index 44bac1cd..c483b2a1 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt @@ -8,8 +8,10 @@ import androidx.navigation.NavGraphBuilder import androidx.navigation.compose.composable import androidx.paging.compose.collectAsLazyPagingItems import st.slex.csplashscreen.core.navigation.AppDestination +import st.slex.csplashscreen.core.ui.base.setupComponent import st.slex.csplashscreen.core.ui.utils.CollectAsEvent -import st.slex.csplashscreen.feature.home.di.setupComponent +import st.slex.csplashscreen.feature.home.di.HomeComponentBuilder +import st.slex.csplashscreen.feature.home.ui.HomeViewModel import st.slex.csplashscreen.feature.home.ui.MainScreen import st.slex.csplashscreen.feature.home.ui.store.HomeStore @@ -19,7 +21,7 @@ fun NavGraphBuilder.homeGraph( composable( route = AppDestination.HOME.navigationRoute ) { - val viewModel = setupComponent() + val viewModel: HomeViewModel = setupComponent(HomeComponentBuilder) val state by remember { viewModel.state diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponent.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponent.kt index 905a4eeb..edf2bfce 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponent.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponent.kt @@ -1,18 +1,18 @@ package st.slex.csplashscreen.feature.feature_photo_detail.di -import androidx.lifecycle.ViewModelProvider import dagger.Component import st.slex.csplashscreen.core.core.AppApi import st.slex.csplashscreen.core.favourite.di.FavouriteApi import st.slex.csplashscreen.core.photos.di.PhotosApi import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature @Component( dependencies = [ImageDetailDependencies::class], modules = [ImageDetailModule::class] ) @ImageDetailScope -interface ImageDetailComponent { +interface ImageDetailComponent : Feature { @Component.Factory interface Factory { @@ -40,6 +40,4 @@ interface ImageDetailComponent { ): ImageDetailDependencies } } - - val viewModelFactory: ViewModelProvider.Factory } \ No newline at end of file diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponentBuilder.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponentBuilder.kt index 26583bba..2eb079e9 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponentBuilder.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponentBuilder.kt @@ -1,41 +1,25 @@ package st.slex.csplashscreen.feature.feature_photo_detail.di -import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext -import st.slex.csplashscreen.core.core.AppApi +import android.content.Context import st.slex.csplashscreen.core.core.appApi import st.slex.csplashscreen.core.favourite.di.FavouriteApiBuilder import st.slex.csplashscreen.core.photos.di.PhotosApiBuilder -import st.slex.csplashscreen.core.ui.base.daggerViewModel -import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature +import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -import st.slex.csplashscreen.feature.feature_photo_detail.ui.ImageDetailViewModel -object ImageDetailComponentBuilder { +object ImageDetailComponentBuilder : FeatureBuilder { - fun build( - appApi: AppApi, - navigationApi: NavigationApi - ): ImageDetailComponent = DaggerImageDetailComponent + override fun create(context: Context): Feature = DaggerImageDetailComponent .factory() .create( dependencies = DaggerImageDetailComponent_ImageDetailDependenciesComponent .factory() .create( - appApi = appApi, + appApi = context.appApi, photosApi = PhotosApiBuilder.build(), - favouriteApi = FavouriteApiBuilder.build(appApi), - navigationApi = navigationApi + favouriteApi = FavouriteApiBuilder.build(context.appApi), + navigationApi = context.navigationApi ) ) } - -@Composable -fun setupImageDetailComponent(key: String): ImageDetailViewModel { - val context = LocalContext.current - return daggerViewModel(key) { - ImageDetailComponentBuilder - .build(context.appApi, context.navigationApi) - .viewModelFactory - } -} \ No newline at end of file diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt index dda4bdbb..b281cb5a 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt @@ -11,8 +11,9 @@ import st.slex.csplashscreen.core.navigation.AppArguments import st.slex.csplashscreen.core.navigation.AppDestination import st.slex.csplashscreen.core.navigation.NavExt.composableArguments import st.slex.csplashscreen.core.navigation.NavExt.parseArguments +import st.slex.csplashscreen.core.ui.base.setupComponent import st.slex.csplashscreen.core.ui.utils.CollectAsEvent -import st.slex.csplashscreen.feature.feature_photo_detail.di.setupImageDetailComponent +import st.slex.csplashscreen.feature.feature_photo_detail.di.ImageDetailComponentBuilder import st.slex.csplashscreen.feature.feature_photo_detail.ui.ImageDetailScreen import st.slex.csplashscreen.feature.feature_photo_detail.ui.ImageDetailViewModel import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore @@ -29,7 +30,10 @@ fun NavGraphBuilder.imageDetailGraph( AppArguments.ImageDetailScreen(args[0]) } - val viewModel: ImageDetailViewModel = setupImageDetailComponent(arguments.imageId) + val viewModel: ImageDetailViewModel = setupComponent( + key = arguments.imageId, + builder = ImageDetailComponentBuilder + ) LaunchedEffect(arguments) { viewModel.sendAction(Action.Init(arguments)) diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt index 40e301ad..33cce365 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt @@ -1,20 +1,18 @@ package st.slex.csplashscreen.feature.search.di -import androidx.lifecycle.ViewModelProvider import dagger.Component +import st.slex.csplashscreen.core.ui.di.builder.Feature @Component( dependencies = [SearchPhotosDependencies::class], modules = [SearchPhotosModule::class] ) @SearchPhotosScope -interface SearchPhotosComponent { +interface SearchPhotosComponent : Feature { @Component.Factory interface Factory { fun create(dependencies: SearchPhotosDependencies): SearchPhotosComponent } - - val viewModelFactory: ViewModelProvider.Factory } diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt index 53af73b3..cdccba10 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt @@ -1,40 +1,26 @@ package st.slex.csplashscreen.feature.search.di -import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext -import st.slex.csplashscreen.core.core.AppApi +import android.content.Context import st.slex.csplashscreen.core.core.appApi import st.slex.csplashscreen.core.database.di.DatabaseApiBuilder import st.slex.csplashscreen.core.network.di.NetworkApiBuilder -import st.slex.csplashscreen.core.ui.base.daggerViewModel -import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature +import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -import st.slex.csplashscreen.feature.search.ui.SearchViewModel -object SearchPhotosComponentBuilder { +object SearchPhotosComponentBuilder : FeatureBuilder { - fun build( - appApi: AppApi, - navigationApi: NavigationApi - ): SearchPhotosComponent = DaggerSearchPhotosComponent + override fun create( + context: Context + ): Feature = DaggerSearchPhotosComponent .factory() .create( dependencies = DaggerSearchPhotosDependenciesComponent .factory() .create( - databaseApi = DatabaseApiBuilder.build(appApi), - navigationApi = navigationApi, + databaseApi = DatabaseApiBuilder.build(context.appApi), + navigationApi = context.navigationApi, networkClientApi = NetworkApiBuilder.build() ) ) } - -@Composable -fun setupSearchPhotosComponent(key: String): SearchViewModel { - val context = LocalContext.current - return daggerViewModel(key) { - SearchPhotosComponentBuilder - .build(context.appApi, context.navigationApi) - .viewModelFactory - } -} \ No newline at end of file diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt index c7802507..e91e4e72 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt @@ -12,9 +12,11 @@ import st.slex.csplashscreen.core.navigation.AppArguments import st.slex.csplashscreen.core.navigation.AppDestination import st.slex.csplashscreen.core.navigation.NavExt.composableArguments import st.slex.csplashscreen.core.navigation.NavExt.parseArguments +import st.slex.csplashscreen.core.ui.base.setupComponent import st.slex.csplashscreen.core.ui.utils.CollectAsEvent -import st.slex.csplashscreen.feature.search.di.setupSearchPhotosComponent +import st.slex.csplashscreen.feature.search.di.SearchPhotosComponentBuilder import st.slex.csplashscreen.feature.search.ui.SearchPhotosScreen +import st.slex.csplashscreen.feature.search.ui.SearchViewModel import st.slex.csplashscreen.feature.search.ui.store.SearchStore import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Action @@ -29,7 +31,10 @@ fun NavGraphBuilder.searchPhotosGraph( AppArguments.SearchPhotosScreen(args[0]) } - val viewModel = setupSearchPhotosComponent(arguments.hashCode().toString()) + val viewModel: SearchViewModel = setupComponent( + key = arguments.hashCode().toString(), + builder = SearchPhotosComponentBuilder + ) LaunchedEffect(arguments) { viewModel.sendAction(Action.Init(arguments)) diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponent.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponent.kt index 618c5461..5e50c0a8 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponent.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponent.kt @@ -1,18 +1,18 @@ package st.slex.csplashscreen.feature.user.di -import androidx.lifecycle.ViewModelProvider import dagger.Component import st.slex.csplashscreen.core.collection.di.CollectionApi import st.slex.csplashscreen.core.network.di.NetworkClientApi import st.slex.csplashscreen.core.photos.di.PhotosApi import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature @Component( dependencies = [UserDependencies::class], modules = [UserModule::class] ) @UserScope -interface UserComponent { +interface UserComponent : Feature { @Component.Factory interface Factory { @@ -39,6 +39,4 @@ interface UserComponent { ): UserDependencies } } - - val viewModelFactory: ViewModelProvider.Factory } \ No newline at end of file diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponentBuilder.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponentBuilder.kt index 20cd85b5..7090518d 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponentBuilder.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponentBuilder.kt @@ -1,39 +1,27 @@ package st.slex.csplashscreen.feature.user.di -import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext +import android.content.Context import st.slex.csplashscreen.core.collection.di.CollectionApiBuilder import st.slex.csplashscreen.core.network.di.NetworkApiBuilder import st.slex.csplashscreen.core.photos.di.PhotosApiBuilder -import st.slex.csplashscreen.core.ui.base.daggerViewModel -import st.slex.csplashscreen.core.ui.di.NavigationApi +import st.slex.csplashscreen.core.ui.di.builder.Feature +import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -import st.slex.csplashscreen.feature.user.ui.UserViewModel -object UserComponentBuilder { +object UserComponentBuilder : FeatureBuilder { - fun build( - navigationApi: NavigationApi - ): UserComponent = DaggerUserComponent + override fun create( + context: Context + ): Feature = DaggerUserComponent .factory() .create( dependencies = DaggerUserComponent_UserDependenciesComponent .factory() .create( - navigationApi = navigationApi, + navigationApi = context.navigationApi, networkClientApi = NetworkApiBuilder.build(), photosApi = PhotosApiBuilder.build(), collectionApi = CollectionApiBuilder.build() ) ) } - -@Composable -fun setupUserComponent(key: String): UserViewModel { - val context = LocalContext.current - return daggerViewModel(key) { - UserComponentBuilder - .build(context.navigationApi) - .viewModelFactory - } -} \ No newline at end of file diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt index 42e9dd6e..04ca88dc 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt @@ -12,9 +12,11 @@ import st.slex.csplashscreen.core.navigation.AppArguments import st.slex.csplashscreen.core.navigation.AppDestination import st.slex.csplashscreen.core.navigation.NavExt.composableArguments import st.slex.csplashscreen.core.navigation.NavExt.parseArguments +import st.slex.csplashscreen.core.ui.base.setupComponent import st.slex.csplashscreen.core.ui.utils.CollectAsEvent -import st.slex.csplashscreen.feature.user.di.setupUserComponent +import st.slex.csplashscreen.feature.user.di.UserComponentBuilder import st.slex.csplashscreen.feature.user.ui.UserScreen +import st.slex.csplashscreen.feature.user.ui.UserViewModel import st.slex.csplashscreen.feature.user.ui.state.rememberUserPagerState import st.slex.csplashscreen.feature.user.ui.state.rememberUserSwipeState import st.slex.csplashscreen.feature.user.ui.store.UserStore @@ -36,7 +38,10 @@ fun NavGraphBuilder.userGraph( AppArguments.UserScreen(args.first()) } - val viewModel = setupUserComponent(arguments.username) + val viewModel: UserViewModel = setupComponent( + key = arguments.username, + builder = UserComponentBuilder + ) LaunchedEffect(arguments) { viewModel.sendAction(Init(arguments)) From 874cc2899191b501dc00ddab48cc1bbcaa2d4494 Mon Sep 17 00:00:00 2001 From: stslex Date: Sun, 29 Oct 2023 14:12:49 +0300 Subject: [PATCH 3/8] refactor favourite store --- .../core/ui/base/BaseViewModel.kt | 8 +----- .../csplashscreen/core/ui/mvi/BaseStore.kt | 24 +++++++++++------ .../slex/csplashscreen/core/ui/mvi/Router.kt | 2 +- .../slex/csplashscreen/core/ui/mvi/Store.kt | 6 ++--- .../csplashscreen/core/ui/mvi/StoreImpl.kt | 14 ---------- .../ui/store/SingleCollectionStoreImpl.kt | 7 ++--- .../favourite/navigation/FavouriteRouter.kt | 4 +-- .../navigation/FavouriteRouterImpl.kt | 14 +++++----- .../favourite/ui/FavouriteViewModel.kt | 5 +--- .../favourite/ui/store/FavouriteStore.kt | 27 +++++++++---------- .../favourite/ui/store/FavouriteStoreImpl.kt | 18 ++++++------- .../feature/home/ui/store/HomeStoreImpl.kt | 7 ++--- .../ui/store/ImageDetailStoreImpl.kt | 7 ++--- .../search/ui/store/SearchStoreImpl.kt | 7 ++--- .../feature/user/ui/store/UserStoreImpl.kt | 7 ++--- 15 files changed, 63 insertions(+), 94 deletions(-) delete mode 100644 core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/StoreImpl.kt diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/BaseViewModel.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/BaseViewModel.kt index 1a788c77..743a7153 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/BaseViewModel.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/BaseViewModel.kt @@ -4,15 +4,13 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow -import st.slex.csplashscreen.core.ui.mvi.Router import st.slex.csplashscreen.core.ui.mvi.Store import st.slex.csplashscreen.core.ui.mvi.Store.Action import st.slex.csplashscreen.core.ui.mvi.Store.Event import st.slex.csplashscreen.core.ui.mvi.Store.State -open class BaseViewModel( +open class BaseViewModel( private val store: Store, - private val router: Router ) : ViewModel() { val state: StateFlow = store.state @@ -26,10 +24,6 @@ open class BaseViewModel : - Store, - StoreImpl { +abstract class BaseStore( + private val router: Router +) : Store { + + abstract val initialState: S private var _scope: CoroutineScope? = null val scope: CoroutineScope get() = requireNotNull(_scope) - @Suppress("LeakingThis") - override val state: MutableStateFlow = MutableStateFlow(initialState) + override val state: MutableStateFlow + get() = MutableStateFlow(initialState) + override val event: MutableSharedFlow = MutableSharedFlow() - override fun updateState(update: (S) -> S) { + fun updateState(update: (S) -> S) { state.update(update) } - override fun sendEvent(event: E) { + fun sendEvent(event: E) { scope.launch { - this@BaseStoreImpl.event.emit(event) + this@BaseStore.event.emit(event) } } + fun navigate(event: N) { + router(event) + } + override fun init(scope: CoroutineScope) { _scope = scope } diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Router.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Router.kt index 98c7abfd..4763faa2 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Router.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Router.kt @@ -1,5 +1,5 @@ package st.slex.csplashscreen.core.ui.mvi -fun interface Router { +fun interface Router { operator fun invoke(event: E) } \ No newline at end of file diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Store.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Store.kt index 4a8eb7c5..38454895 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Store.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/Store.kt @@ -20,9 +20,9 @@ interface Store { interface State - interface Event { - interface Navigation : Event - } + interface Event + + interface Navigation interface Action } diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/StoreImpl.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/StoreImpl.kt deleted file mode 100644 index d90eb9d5..00000000 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/mvi/StoreImpl.kt +++ /dev/null @@ -1,14 +0,0 @@ -package st.slex.csplashscreen.core.ui.mvi - -import st.slex.csplashscreen.core.ui.mvi.Store.Action -import st.slex.csplashscreen.core.ui.mvi.Store.Event -import st.slex.csplashscreen.core.ui.mvi.Store.State - -internal interface StoreImpl { - - val initialState: S - - fun sendEvent(event: E) - - fun updateState(update: (S) -> S) -} \ No newline at end of file diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt index eb74db26..a801d6c6 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt @@ -5,7 +5,6 @@ import androidx.paging.PagingConfig import androidx.paging.PagingData import androidx.paging.map import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flatMapLatest @@ -13,7 +12,7 @@ import kotlinx.coroutines.flow.map import st.slex.csplashscreen.core.core.CoroutineExt.mapState import st.slex.csplashscreen.core.photos.ui.model.PhotoModel import st.slex.csplashscreen.core.photos.ui.model.toPresentation -import st.slex.csplashscreen.core.ui.mvi.BaseStoreImpl +import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.collection.domain.SingleCollectionInteractor import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Action @@ -23,7 +22,7 @@ import javax.inject.Inject class SingleCollectionStoreImpl @Inject constructor( private val interactor: SingleCollectionInteractor -) : SingleCollectionStore, BaseStoreImpl() { +) : SingleCollectionStore, BaseStore() { override val initialState: State get() = State( @@ -31,8 +30,6 @@ class SingleCollectionStoreImpl @Inject constructor( collectionId = "" ) - override val state: MutableStateFlow = MutableStateFlow(initialState) - override fun processAction(action: Action) { when (action) { is Action.Init -> actionInit(action) diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouter.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouter.kt index 0366f000..14087839 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouter.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouter.kt @@ -1,6 +1,6 @@ package st.slex.csplashscreen.feature.favourite.navigation import st.slex.csplashscreen.core.ui.mvi.Router -import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore +import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Navigation -interface FavouriteRouter : Router +interface FavouriteRouter : Router diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouterImpl.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouterImpl.kt index c04eb662..c95b1fd6 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouterImpl.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteRouterImpl.kt @@ -2,26 +2,26 @@ package st.slex.csplashscreen.feature.favourite.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator -import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore +import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Navigation import javax.inject.Inject class FavouriteRouterImpl @Inject constructor( private val navigator: Navigator ) : FavouriteRouter { - override fun invoke(event: FavouriteStore.Event.Navigation) { + override fun invoke(event: Navigation) { when (event) { - FavouriteStore.Event.Navigation.Home -> navHome() - is FavouriteStore.Event.Navigation.Image -> navToImage(event) - is FavouriteStore.Event.Navigation.User -> navToUser(event) + Navigation.Home -> navHome() + is Navigation.Image -> navToImage(event) + is Navigation.User -> navToUser(event) } } - private fun navToUser(event: FavouriteStore.Event.Navigation.User) { + private fun navToUser(event: Navigation.User) { navigator(NavigationScreen.UserScreen(event.username)) } - private fun navToImage(event: FavouriteStore.Event.Navigation.Image) { + private fun navToImage(event: Navigation.Image) { navigator(NavigationScreen.ImageDetailScreen(event.uuid)) } diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/FavouriteViewModel.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/FavouriteViewModel.kt index 1848ef19..ed4dd866 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/FavouriteViewModel.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/FavouriteViewModel.kt @@ -1,15 +1,12 @@ package st.slex.csplashscreen.feature.favourite.ui import st.slex.csplashscreen.core.ui.base.BaseViewModel -import st.slex.csplashscreen.feature.favourite.navigation.FavouriteRouter import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Action import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Event -import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Event.Navigation import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.State import javax.inject.Inject class FavouriteViewModel @Inject constructor( - router: FavouriteRouter, store: FavouriteStore -) : BaseViewModel(store, router) \ No newline at end of file +) : BaseViewModel(store) \ No newline at end of file diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt index b76d4cda..3fd2ff9d 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt @@ -17,24 +17,23 @@ interface FavouriteStore : Store { ) : Store.State @Stable - sealed interface Event : Store.Event { + sealed interface Event : Store.Event - @Stable - sealed interface Navigation : Event, Store.Event.Navigation { + @Stable + sealed interface Navigation : Event, Store.Navigation { - @Stable - data class User( - val username: String - ) : Navigation + @Stable + data class User( + val username: String + ) : Navigation - @Stable - data class Image( - val uuid: String - ) : Navigation + @Stable + data class Image( + val uuid: String + ) : Navigation - @Stable - data object Home : Navigation - } + @Stable + data object Home : Navigation } @Stable diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStoreImpl.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStoreImpl.kt index 728d1f9e..4e8ca257 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStoreImpl.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStoreImpl.kt @@ -1,27 +1,27 @@ package st.slex.csplashscreen.feature.favourite.ui.store import androidx.paging.PagingData -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import st.slex.csplashscreen.core.photos.ui.model.PhotoModel -import st.slex.csplashscreen.core.ui.mvi.BaseStoreImpl +import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.feature.favourite.domain.FavouriteInteractor +import st.slex.csplashscreen.feature.favourite.navigation.FavouriteRouter import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Action import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Event +import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Navigation import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.State import javax.inject.Inject class FavouriteStoreImpl @Inject constructor( - private val interactor: FavouriteInteractor -) : FavouriteStore, BaseStoreImpl() { + private val interactor: FavouriteInteractor, + router: FavouriteRouter +) : FavouriteStore, BaseStore(router) { override val initialState: State = State( photos = ::photos ) - override val state: MutableStateFlow = MutableStateFlow(initialState) - private val photos: StateFlow> get() = interactor.photos .map { pagingData -> @@ -38,14 +38,14 @@ class FavouriteStoreImpl @Inject constructor( } private fun actionGoHome() { - sendEvent(Event.Navigation.Home) + navigate(Navigation.Home) } private fun actionImageClick(action: Action.OnImageClick) { - sendEvent(Event.Navigation.Image(action.uuid)) + navigate(Navigation.Image(action.uuid)) } private fun actionUserClick(action: Action.OnUserClick) { - sendEvent(Event.Navigation.User(action.username)) + navigate(Navigation.User(action.username)) } } \ No newline at end of file diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt index 10aab328..958264aa 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt @@ -6,7 +6,6 @@ import androidx.paging.PagingData import androidx.paging.cachedIn import androidx.paging.map import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.flowOn @@ -16,7 +15,7 @@ import st.slex.csplashscreen.core.collection.ui.model.CollectionModel import st.slex.csplashscreen.core.collection.ui.model.toPresentation import st.slex.csplashscreen.core.photos.ui.model.PhotoModel import st.slex.csplashscreen.core.photos.ui.model.toPresentation -import st.slex.csplashscreen.core.ui.mvi.BaseStoreImpl +import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.home.domain.HomeInteractor import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Action @@ -26,15 +25,13 @@ import javax.inject.Inject class HomeStoreImpl @Inject constructor( private val interactor: HomeInteractor -) : HomeStore, BaseStoreImpl() { +) : HomeStore, BaseStore() { override val initialState: State = State( collections = ::collections, photos = ::photos ) - override val state = MutableStateFlow(initialState) - private val collections: StateFlow> get() = Pager(config = config) { PagingSource(interactor::getAllCollections) diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt index efcd313b..e4c22bbb 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt @@ -1,14 +1,13 @@ package st.slex.csplashscreen.feature.feature_photo_detail.ui.store import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import st.slex.csplashscreen.core.core.Logger -import st.slex.csplashscreen.core.ui.mvi.BaseStoreImpl +import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.feature.feature_photo_detail.domain.interactor.ImageDetailInteractor import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Action import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event @@ -22,15 +21,13 @@ class ImageDetailStoreImpl @Inject constructor( private val interactor: ImageDetailInteractor, private val downloadImageUseCase: DownloadImageUseCase, private val wallpaperSetUseCase: WallpaperSetUseCase, -) : ImageDetailStore, BaseStoreImpl() { +) : ImageDetailStore, BaseStore() { override val initialState: State = State( imageId = "", screenState = ScreenState.Loading ) - override val state: MutableStateFlow = MutableStateFlow(initialState) - override fun processAction(action: Action) { when (action) { is Action.Init -> actionInit(action) diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt index 94eaa670..2989165b 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt @@ -6,7 +6,6 @@ import androidx.paging.PagingData import androidx.paging.map import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest @@ -16,7 +15,7 @@ import st.slex.csplashscreen.core.core.Logger import st.slex.csplashscreen.core.network.model.ui.ImageModel import st.slex.csplashscreen.core.photos.ui.model.PhotoModel import st.slex.csplashscreen.core.photos.ui.model.toPresentation -import st.slex.csplashscreen.core.ui.mvi.BaseStoreImpl +import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.search.domain.interactor.SearchPhotosInteractor import st.slex.csplashscreen.feature.search.ui.model.SearchItem @@ -27,7 +26,7 @@ import javax.inject.Inject class SearchStoreImpl @Inject constructor( val interactor: SearchPhotosInteractor -) : SearchStore, BaseStoreImpl() { +) : SearchStore, BaseStore() { override val initialState = State( query = "", @@ -35,8 +34,6 @@ class SearchStoreImpl @Inject constructor( historyItems = ::searchHistory ) - override val state = MutableStateFlow(initialState) - private val searchHistory: StateFlow> get() = interactor.searchHistory.state() diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt index ab58580c..8b87943f 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt @@ -4,7 +4,6 @@ import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOn @@ -15,7 +14,7 @@ import st.slex.csplashscreen.core.collection.ui.model.toPresentation import st.slex.csplashscreen.core.core.Logger import st.slex.csplashscreen.core.photos.ui.model.PhotoModel import st.slex.csplashscreen.core.photos.ui.model.toPresentation -import st.slex.csplashscreen.core.ui.mvi.BaseStoreImpl +import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.user.domain.UserInteractor import st.slex.csplashscreen.feature.user.ui.store.UserStore.Action @@ -25,7 +24,7 @@ import javax.inject.Inject class UserStoreImpl @Inject constructor( private val interactor: UserInteractor -) : UserStore, BaseStoreImpl() { +) : UserStore, BaseStore() { override val initialState: State = State( user = null, @@ -34,8 +33,6 @@ class UserStoreImpl @Inject constructor( collections = ::getCollections ) - override val state = MutableStateFlow(initialState) - override fun processAction(action: Action) { when (action) { is Action.Init -> actionInit(action) From 7df7350b6e37250b9dd2aeefea973ca0b3f47731 Mon Sep 17 00:00:00 2001 From: stslex Date: Sun, 29 Oct 2023 14:15:31 +0300 Subject: [PATCH 4/8] refactor store navigation single collection --- .../navigation/SingleCollectionRouter.kt | 2 +- .../navigation/SingleCollectionRouterImpl.kt | 2 +- .../ui/SingleCollectionViewModel.kt | 5 +--- .../ui/store/SingleCollectionStore.kt | 25 +++++++++---------- .../ui/store/SingleCollectionStoreImpl.kt | 11 +++++--- .../favourite/ui/store/FavouriteStore.kt | 2 +- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouter.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouter.kt index 225028f1..1e9fb85c 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouter.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouter.kt @@ -1,6 +1,6 @@ package st.slex.csplashscreen.feature.collection.navigation import st.slex.csplashscreen.core.ui.mvi.Router -import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event.Navigation +import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Navigation interface SingleCollectionRouter : Router \ No newline at end of file diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouterImpl.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouterImpl.kt index b39385b5..d6364064 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouterImpl.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionRouterImpl.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.collection.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator -import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event.Navigation +import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Navigation import javax.inject.Inject class SingleCollectionRouterImpl @Inject constructor( diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/SingleCollectionViewModel.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/SingleCollectionViewModel.kt index ecfac045..39702bd8 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/SingleCollectionViewModel.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/SingleCollectionViewModel.kt @@ -1,15 +1,12 @@ package st.slex.csplashscreen.feature.collection.ui import st.slex.csplashscreen.core.ui.base.BaseViewModel -import st.slex.csplashscreen.feature.collection.navigation.SingleCollectionRouter import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Action import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event -import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event.Navigation import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.State import javax.inject.Inject class SingleCollectionViewModel @Inject constructor( store: SingleCollectionStore, - router: SingleCollectionRouter -) : BaseViewModel(store, router) \ No newline at end of file +) : BaseViewModel(store) \ No newline at end of file diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStore.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStore.kt index 56997efb..213bac19 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStore.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStore.kt @@ -18,21 +18,20 @@ interface SingleCollectionStore : Store { ) : Store.State @Stable - sealed interface Event : Store.Event { + sealed interface Event : Store.Event + + @Stable + sealed interface Navigation : Store.Navigation { + + @Stable + data class Profile( + val username: String + ) : Navigation @Stable - sealed interface Navigation : Event, Store.Event.Navigation { - - @Stable - data class Profile( - val username: String - ) : Navigation - - @Stable - data class ImageDetail( - val uuid: String - ) : Navigation - } + data class ImageDetail( + val uuid: String + ) : Navigation } @Stable diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt index a801d6c6..32f876ee 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt @@ -13,16 +13,19 @@ import st.slex.csplashscreen.core.core.CoroutineExt.mapState import st.slex.csplashscreen.core.photos.ui.model.PhotoModel import st.slex.csplashscreen.core.photos.ui.model.toPresentation import st.slex.csplashscreen.core.ui.mvi.BaseStore +import st.slex.csplashscreen.core.ui.mvi.Router import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.collection.domain.SingleCollectionInteractor import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Action import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event +import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Navigation import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.State import javax.inject.Inject class SingleCollectionStoreImpl @Inject constructor( - private val interactor: SingleCollectionInteractor -) : SingleCollectionStore, BaseStore() { + private val interactor: SingleCollectionInteractor, + router: Router +) : SingleCollectionStore, BaseStore(router) { override val initialState: State get() = State( @@ -68,11 +71,11 @@ class SingleCollectionStoreImpl @Inject constructor( .state() private fun actionProfileClick(action: Action.OnProfileClick) { - sendEvent(Event.Navigation.Profile(action.username)) + navigate(Navigation.Profile(action.username)) } private fun actionImageClick(action: Action.OnImageClick) { - sendEvent(Event.Navigation.ImageDetail(action.uuid)) + navigate(Navigation.ImageDetail(action.uuid)) } companion object { diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt index 3fd2ff9d..7854badf 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStore.kt @@ -20,7 +20,7 @@ interface FavouriteStore : Store { sealed interface Event : Store.Event @Stable - sealed interface Navigation : Event, Store.Navigation { + sealed interface Navigation : Store.Navigation { @Stable data class User( From 1c6b3f5c46e675adcae98c91dc69e732c2c89d69 Mon Sep 17 00:00:00 2001 From: stslex Date: Sun, 29 Oct 2023 14:20:41 +0300 Subject: [PATCH 5/8] refactor store navigation image detail --- .../navigation/SingleCollectionGraph.kt | 5 +-- .../favourite/navigation/FavouriteGraph.kt | 5 +-- .../feature/home/navigation/HomeGraph.kt | 4 +-- .../feature/home/navigation/HomeRouter.kt | 2 +- .../feature/home/navigation/HomeRouterImpl.kt | 2 +- .../feature/home/ui/HomeViewModel.kt | 5 +-- .../feature/home/ui/store/HomeStore.kt | 35 +++++++++---------- .../feature/home/ui/store/HomeStoreImpl.kt | 13 ++++--- .../navigation/ImageDetailGraph.kt | 5 +-- .../navigation/ImageDetailRouter.kt | 2 +- .../navigation/ImageDetailRouterImpl.kt | 2 +- .../ui/ImageDetailViewModel.kt | 5 +-- .../ui/store/ImageDetailStore.kt | 25 +++++++------ .../ui/store/ImageDetailStoreImpl.kt | 9 +++-- 14 files changed, 53 insertions(+), 66 deletions(-) diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt index c20cb0cb..ac278bcf 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/navigation/SingleCollectionGraph.kt @@ -18,7 +18,6 @@ import st.slex.csplashscreen.feature.collection.di.SingleCollectionBuilder import st.slex.csplashscreen.feature.collection.ui.CollectionScreen import st.slex.csplashscreen.feature.collection.ui.SingleCollectionViewModel import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Action -import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event fun NavGraphBuilder.singleCollectionGraph( modifier: Modifier = Modifier, @@ -48,9 +47,7 @@ fun NavGraphBuilder.singleCollectionGraph( } viewModel.event.CollectAsEvent { event -> - when (event) { - is Event.Navigation -> viewModel.navigate(event) - } + // TODO NOT IMPLEMENTED YET } CollectionScreen( diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt index 6f21396a..f19d27d2 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/navigation/FavouriteGraph.kt @@ -15,7 +15,6 @@ import st.slex.csplashscreen.feature.favourite.di.FavouriteComponentBuilder import st.slex.csplashscreen.feature.favourite.ui.FavouriteScreen import st.slex.csplashscreen.feature.favourite.ui.FavouriteViewModel import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Action -import st.slex.csplashscreen.feature.favourite.ui.store.FavouriteStore.Event fun NavGraphBuilder.favouriteGraph( modifier: Modifier = Modifier, @@ -36,9 +35,7 @@ fun NavGraphBuilder.favouriteGraph( }.collectAsLazyPagingItems() viewModel.event.CollectAsEvent { event -> - when (event) { - is Event.Navigation -> viewModel.navigate(event) - } + // TODO NOT IMPLEMENTED YET } FavouriteScreen( diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt index c483b2a1..390117e4 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeGraph.kt @@ -36,9 +36,7 @@ fun NavGraphBuilder.homeGraph( }.collectAsLazyPagingItems() viewModel.event.CollectAsEvent { event -> - when (event) { - is HomeStore.Event.Navigation -> viewModel.navigate(event) - } + // TODO NOT IMPLEMENTED YET } MainScreen( diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouter.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouter.kt index 90028d85..df235791 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouter.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouter.kt @@ -3,4 +3,4 @@ package st.slex.csplashscreen.feature.home.navigation import st.slex.csplashscreen.core.ui.mvi.Router import st.slex.csplashscreen.feature.home.ui.store.HomeStore -interface HomeRouter : Router +interface HomeRouter : Router diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouterImpl.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouterImpl.kt index 318e6959..3082a0c2 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouterImpl.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/navigation/HomeRouterImpl.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.home.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator -import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Event.Navigation +import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Navigation import javax.inject.Inject class HomeRouterImpl @Inject constructor( diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/HomeViewModel.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/HomeViewModel.kt index 64a14e6d..717492f9 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/HomeViewModel.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/HomeViewModel.kt @@ -1,15 +1,12 @@ package st.slex.csplashscreen.feature.home.ui import st.slex.csplashscreen.core.ui.base.BaseViewModel -import st.slex.csplashscreen.feature.home.navigation.HomeRouter import st.slex.csplashscreen.feature.home.ui.store.HomeStore import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Action import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Event -import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Event.Navigation import st.slex.csplashscreen.feature.home.ui.store.HomeStore.State import javax.inject.Inject class HomeViewModel @Inject constructor( - router: HomeRouter, store: HomeStore -) : BaseViewModel(store, router) \ No newline at end of file +) : BaseViewModel(store) \ No newline at end of file diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStore.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStore.kt index b56f63fb..a3eb17ca 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStore.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStore.kt @@ -19,26 +19,25 @@ interface HomeStore : Store { ) : Store.State @Stable - sealed interface Event : Store.Event { + sealed interface Event : Store.Event + + @Stable + sealed interface Navigation : Store.Navigation { + + @Stable + data class User( + val username: String + ) : Navigation @Stable - sealed interface Navigation : Event, Store.Event.Navigation { - - @Stable - data class User( - val username: String - ) : Navigation - - @Stable - data class Collection( - val uuid: String - ) : Navigation - - @Stable - data class Image( - val uuid: String - ) : Navigation - } + data class Collection( + val uuid: String + ) : Navigation + + @Stable + data class Image( + val uuid: String + ) : Navigation } @Stable diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt index 958264aa..88d523c7 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt @@ -18,14 +18,17 @@ import st.slex.csplashscreen.core.photos.ui.model.toPresentation import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.home.domain.HomeInteractor +import st.slex.csplashscreen.feature.home.navigation.HomeRouter import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Action import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Event +import st.slex.csplashscreen.feature.home.ui.store.HomeStore.Navigation import st.slex.csplashscreen.feature.home.ui.store.HomeStore.State import javax.inject.Inject class HomeStoreImpl @Inject constructor( - private val interactor: HomeInteractor -) : HomeStore, BaseStore() { + private val interactor: HomeInteractor, + router: HomeRouter +) : HomeStore, BaseStore(router) { override val initialState: State = State( collections = ::collections, @@ -63,15 +66,15 @@ class HomeStoreImpl @Inject constructor( } private fun actionCollectionClick(action: Action.OnCollectionClick) { - sendEvent(Event.Navigation.Collection(action.uuid)) + navigate(Navigation.Collection(action.uuid)) } private fun actionImageClick(action: Action.OnImageClick) { - sendEvent(Event.Navigation.Image(action.uuid)) + navigate(Navigation.Image(action.uuid)) } private fun actionUserClick(action: Action.OnUserClick) { - sendEvent(Event.Navigation.User(action.username)) + navigate(Navigation.User(action.username)) } companion object { diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt index b281cb5a..d15b1943 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailGraph.kt @@ -16,7 +16,6 @@ import st.slex.csplashscreen.core.ui.utils.CollectAsEvent import st.slex.csplashscreen.feature.feature_photo_detail.di.ImageDetailComponentBuilder import st.slex.csplashscreen.feature.feature_photo_detail.ui.ImageDetailScreen import st.slex.csplashscreen.feature.feature_photo_detail.ui.ImageDetailViewModel -import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Action fun NavGraphBuilder.imageDetailGraph( @@ -44,9 +43,7 @@ fun NavGraphBuilder.imageDetailGraph( }.collectAsState() viewModel.event.CollectAsEvent { event -> - when (event) { - is ImageDetailStore.Event.Navigation -> viewModel.navigate(event) - } + // TODO NOT IMPLEMENTED YET } ImageDetailScreen( diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouter.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouter.kt index 1035efd9..86e9fb67 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouter.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouter.kt @@ -1,6 +1,6 @@ package st.slex.csplashscreen.feature.feature_photo_detail.navigation import st.slex.csplashscreen.core.ui.mvi.Router -import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event.Navigation +import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Navigation interface ImageDetailRouter : Router diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouterImpl.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouterImpl.kt index dc094608..0890b180 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouterImpl.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/navigation/ImageDetailRouterImpl.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.feature_photo_detail.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator -import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event.Navigation +import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Navigation import javax.inject.Inject class ImageDetailRouterImpl @Inject constructor( diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/ImageDetailViewModel.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/ImageDetailViewModel.kt index 4dcd92e3..2c5c77bd 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/ImageDetailViewModel.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/ImageDetailViewModel.kt @@ -1,15 +1,12 @@ package st.slex.csplashscreen.feature.feature_photo_detail.ui import st.slex.csplashscreen.core.ui.base.BaseViewModel -import st.slex.csplashscreen.feature.feature_photo_detail.navigation.ImageDetailRouter import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Action import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event -import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event.Navigation import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.State import javax.inject.Inject class ImageDetailViewModel @Inject constructor( - router: ImageDetailRouter, store: ImageDetailStore -) : BaseViewModel(store, router) \ No newline at end of file +) : BaseViewModel(store) \ No newline at end of file diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStore.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStore.kt index 1bc145bb..4dcf3d4f 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStore.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStore.kt @@ -37,21 +37,20 @@ interface ImageDetailStore : Store { } @Stable - sealed interface Event : Store.Event { + sealed interface Event : Store.Event + + @Stable + sealed interface Navigation : Store.Navigation { + + @Stable + data class Profile( + val username: String + ) : Navigation @Stable - sealed interface Navigation : Event, Store.Event.Navigation { - - @Stable - data class Profile( - val username: String - ) : Navigation - - @Stable - data class Search( - val tag: String - ) : Navigation - } + data class Search( + val tag: String + ) : Navigation } @Stable diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt index e4c22bbb..62389b54 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt @@ -9,8 +9,10 @@ import kotlinx.coroutines.launch import st.slex.csplashscreen.core.core.Logger import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.feature.feature_photo_detail.domain.interactor.ImageDetailInteractor +import st.slex.csplashscreen.feature.feature_photo_detail.navigation.ImageDetailRouter import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Action import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Event +import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.Navigation import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.ScreenState import st.slex.csplashscreen.feature.feature_photo_detail.ui.store.ImageDetailStore.State import st.slex.csplashscreen.feature.feature_photo_detail.ui.utils.DownloadImageUseCase @@ -21,7 +23,8 @@ class ImageDetailStoreImpl @Inject constructor( private val interactor: ImageDetailInteractor, private val downloadImageUseCase: DownloadImageUseCase, private val wallpaperSetUseCase: WallpaperSetUseCase, -) : ImageDetailStore, BaseStore() { + router: ImageDetailRouter +) : ImageDetailStore, BaseStore(router) { override val initialState: State = State( imageId = "", @@ -57,11 +60,11 @@ class ImageDetailStoreImpl @Inject constructor( } private fun actionProfileClick(action: Action.OnProfileClick) { - sendEvent(Event.Navigation.Profile(action.username)) + navigate(Navigation.Profile(action.username)) } private fun actionTagClick(action: Action.OnTagClick) { - sendEvent(Event.Navigation.Search(action.tag)) + navigate(Navigation.Search(action.tag)) } private fun setWallpaperClick(action: Action.SetWallpaperClick) { From 068982854bbacb1f06c52bb8ca90e8024c948624 Mon Sep 17 00:00:00 2001 From: stslex Date: Sun, 29 Oct 2023 14:25:17 +0300 Subject: [PATCH 6/8] refactor store navigation search, user --- .../ui/store/SingleCollectionStoreImpl.kt | 4 +-- .../search/navigation/SearchPhotosGraph.kt | 5 +--- .../search/navigation/SearchPhotosRouter.kt | 2 +- .../navigation/SearchPhotosRouterImpl.kt | 2 +- .../feature/search/ui/SearchViewModel.kt | 5 +--- .../feature/search/ui/store/SearchStore.kt | 23 ++++++++--------- .../search/ui/store/SearchStoreImpl.kt | 11 +++++--- .../feature/user/navigation/UserGraph.kt | 4 +-- .../feature/user/navigation/UserRouter.kt | 2 +- .../feature/user/navigation/UserRouterImpl.kt | 18 ++++++------- .../feature/user/ui/UserViewModel.kt | 5 +--- .../feature/user/ui/store/UserStore.kt | 25 +++++++++---------- .../feature/user/ui/store/UserStoreImpl.kt | 15 ++++++----- 13 files changed, 57 insertions(+), 64 deletions(-) diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt index 32f876ee..11b3c9e0 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt @@ -13,9 +13,9 @@ import st.slex.csplashscreen.core.core.CoroutineExt.mapState import st.slex.csplashscreen.core.photos.ui.model.PhotoModel import st.slex.csplashscreen.core.photos.ui.model.toPresentation import st.slex.csplashscreen.core.ui.mvi.BaseStore -import st.slex.csplashscreen.core.ui.mvi.Router import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.collection.domain.SingleCollectionInteractor +import st.slex.csplashscreen.feature.collection.navigation.SingleCollectionRouter import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Action import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Event import st.slex.csplashscreen.feature.collection.ui.store.SingleCollectionStore.Navigation @@ -24,7 +24,7 @@ import javax.inject.Inject class SingleCollectionStoreImpl @Inject constructor( private val interactor: SingleCollectionInteractor, - router: Router + router: SingleCollectionRouter ) : SingleCollectionStore, BaseStore(router) { override val initialState: State diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt index e91e4e72..ba195ded 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosGraph.kt @@ -17,7 +17,6 @@ import st.slex.csplashscreen.core.ui.utils.CollectAsEvent import st.slex.csplashscreen.feature.search.di.SearchPhotosComponentBuilder import st.slex.csplashscreen.feature.search.ui.SearchPhotosScreen import st.slex.csplashscreen.feature.search.ui.SearchViewModel -import st.slex.csplashscreen.feature.search.ui.store.SearchStore import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Action fun NavGraphBuilder.searchPhotosGraph( @@ -41,9 +40,7 @@ fun NavGraphBuilder.searchPhotosGraph( } viewModel.event.CollectAsEvent { event -> - when (event) { - is SearchStore.Event.Navigation -> viewModel.navigate(event) - } + // TODO NOT IMPLEMENTED YET } val state by remember { diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouter.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouter.kt index ac1869f8..03c1555f 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouter.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouter.kt @@ -1,6 +1,6 @@ package st.slex.csplashscreen.feature.search.navigation import st.slex.csplashscreen.core.ui.mvi.Router -import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event.Navigation +import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Navigation interface SearchPhotosRouter : Router diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouterImpl.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouterImpl.kt index 6ae6f353..494f6f3a 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouterImpl.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/navigation/SearchPhotosRouterImpl.kt @@ -2,7 +2,7 @@ package st.slex.csplashscreen.feature.search.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator -import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event.Navigation +import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Navigation import javax.inject.Inject class SearchPhotosRouterImpl @Inject constructor( diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/SearchViewModel.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/SearchViewModel.kt index 3b45a091..ca71e9c8 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/SearchViewModel.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/SearchViewModel.kt @@ -1,15 +1,12 @@ package st.slex.csplashscreen.feature.search.ui import st.slex.csplashscreen.core.ui.base.BaseViewModel -import st.slex.csplashscreen.feature.search.navigation.SearchPhotosRouter import st.slex.csplashscreen.feature.search.ui.store.SearchStore import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Action import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event -import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event.Navigation import st.slex.csplashscreen.feature.search.ui.store.SearchStore.State import javax.inject.Inject class SearchViewModel @Inject constructor( store: SearchStore, - router: SearchPhotosRouter -) : BaseViewModel(store, router) \ No newline at end of file +) : BaseViewModel(store) \ No newline at end of file diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStore.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStore.kt index b9a5c306..8c7b9098 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStore.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStore.kt @@ -21,21 +21,20 @@ interface SearchStore : Store { ) : Store.State @Stable - sealed interface Event : Store.Event { + sealed interface Event : Store.Event - @Stable - sealed interface Navigation : Event, Store.Event.Navigation { + @Stable + sealed interface Navigation : Store.Navigation { - @Stable - data class Profile( - val username: String - ) : Navigation + @Stable + data class Profile( + val username: String + ) : Navigation - @Stable - data class ImageDetail( - val uuid: String - ) : Navigation - } + @Stable + data class ImageDetail( + val uuid: String + ) : Navigation } @Stable diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt index 2989165b..debc937e 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt @@ -18,15 +18,18 @@ import st.slex.csplashscreen.core.photos.ui.model.toPresentation import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.search.domain.interactor.SearchPhotosInteractor +import st.slex.csplashscreen.feature.search.navigation.SearchPhotosRouter import st.slex.csplashscreen.feature.search.ui.model.SearchItem import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Action import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Event +import st.slex.csplashscreen.feature.search.ui.store.SearchStore.Navigation import st.slex.csplashscreen.feature.search.ui.store.SearchStore.State import javax.inject.Inject class SearchStoreImpl @Inject constructor( - val interactor: SearchPhotosInteractor -) : SearchStore, BaseStore() { + private val interactor: SearchPhotosInteractor, + router: SearchPhotosRouter +) : SearchStore, BaseStore(router) { override val initialState = State( query = "", @@ -76,11 +79,11 @@ class SearchStoreImpl @Inject constructor( } private fun actionOnProfileClick(action: Action.OnProfileClick) { - sendEvent(Event.Navigation.Profile(action.username)) + navigate(Navigation.Profile(action.username)) } private fun actionOnImageClick(action: Action.OnImageClick) { - sendEvent(Event.Navigation.ImageDetail(action.uuid)) + navigate(Navigation.ImageDetail(action.uuid)) } private fun actionClearHistory() { diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt index 04ca88dc..973fc762 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt @@ -48,9 +48,7 @@ fun NavGraphBuilder.userGraph( } viewModel.event.CollectAsEvent { event -> - when (event) { - is UserStore.Event.Navigation -> viewModel.navigate(event) - } + // TODO NOT IMPLEMENTED YET } val state by remember { diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouter.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouter.kt index 76065b36..a477996b 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouter.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouter.kt @@ -3,4 +3,4 @@ package st.slex.csplashscreen.feature.user.navigation import st.slex.csplashscreen.core.ui.mvi.Router import st.slex.csplashscreen.feature.user.ui.store.UserStore -interface UserRouter : Router \ No newline at end of file +interface UserRouter : Router \ No newline at end of file diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouterImpl.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouterImpl.kt index 1c1ac92f..f725f582 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouterImpl.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserRouterImpl.kt @@ -2,19 +2,19 @@ package st.slex.csplashscreen.feature.user.navigation import st.slex.csplashscreen.core.navigation.NavigationScreen import st.slex.csplashscreen.core.ui.di.Navigator -import st.slex.csplashscreen.feature.user.ui.store.UserStore +import st.slex.csplashscreen.feature.user.ui.store.UserStore.Navigation import javax.inject.Inject class UserRouterImpl @Inject constructor( private val navigator: Navigator ) : UserRouter { - override fun invoke(event: UserStore.Event.Navigation) { + override fun invoke(event: Navigation) { when (event) { - is UserStore.Event.Navigation.Collection -> navToCollection(event) - is UserStore.Event.Navigation.Image -> navToImage(event) - is UserStore.Event.Navigation.PopBack -> popBack() - is UserStore.Event.Navigation.User -> navToUser(event) + is Navigation.Collection -> navToCollection(event) + is Navigation.Image -> navToImage(event) + is Navigation.PopBack -> popBack() + is Navigation.User -> navToUser(event) } } @@ -22,15 +22,15 @@ class UserRouterImpl @Inject constructor( navigator(NavigationScreen.PopBackStack) } - private fun navToUser(event: UserStore.Event.Navigation.User) { + private fun navToUser(event: Navigation.User) { navigator(NavigationScreen.UserScreen(event.username)) } - private fun navToImage(event: UserStore.Event.Navigation.Image) { + private fun navToImage(event: Navigation.Image) { navigator(NavigationScreen.ImageDetailScreen(event.uuid)) } - private fun navToCollection(event: UserStore.Event.Navigation.Collection) { + private fun navToCollection(event: Navigation.Collection) { navigator(NavigationScreen.CollectionScreen(event.uuid)) } } \ No newline at end of file diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/UserViewModel.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/UserViewModel.kt index 935923c0..8eea3548 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/UserViewModel.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/UserViewModel.kt @@ -1,15 +1,12 @@ package st.slex.csplashscreen.feature.user.ui import st.slex.csplashscreen.core.ui.base.BaseViewModel -import st.slex.csplashscreen.feature.user.navigation.UserRouter import st.slex.csplashscreen.feature.user.ui.store.UserStore import st.slex.csplashscreen.feature.user.ui.store.UserStore.Action import st.slex.csplashscreen.feature.user.ui.store.UserStore.Event -import st.slex.csplashscreen.feature.user.ui.store.UserStore.Event.Navigation import st.slex.csplashscreen.feature.user.ui.store.UserStore.State import javax.inject.Inject class UserViewModel @Inject constructor( - router: UserRouter, store: UserStore -) : BaseViewModel(store, router) \ No newline at end of file +) : BaseViewModel(store) \ No newline at end of file diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStore.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStore.kt index 7980a1bc..38e5a4d4 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStore.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStore.kt @@ -23,24 +23,23 @@ interface UserStore : Store { ) : Store.State @Stable - sealed interface Event : Store.Event { + sealed interface Event : Store.Event - sealed interface Navigation : Event, Store.Event.Navigation { + sealed interface Navigation : Store.Navigation { - data object PopBack : Navigation + data object PopBack : Navigation - data class User( - val username: String - ) : Navigation + data class User( + val username: String + ) : Navigation - data class Image( - val uuid: String - ) : Navigation + data class Image( + val uuid: String + ) : Navigation - data class Collection( - val uuid: String - ) : Navigation - } + data class Collection( + val uuid: String + ) : Navigation } @Stable diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt index 8b87943f..c2457d9a 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt @@ -17,14 +17,17 @@ import st.slex.csplashscreen.core.photos.ui.model.toPresentation import st.slex.csplashscreen.core.ui.mvi.BaseStore import st.slex.csplashscreen.core.ui.paging.PagingSource import st.slex.csplashscreen.feature.user.domain.UserInteractor +import st.slex.csplashscreen.feature.user.navigation.UserRouter import st.slex.csplashscreen.feature.user.ui.store.UserStore.Action import st.slex.csplashscreen.feature.user.ui.store.UserStore.Event +import st.slex.csplashscreen.feature.user.ui.store.UserStore.Navigation import st.slex.csplashscreen.feature.user.ui.store.UserStore.State import javax.inject.Inject class UserStoreImpl @Inject constructor( - private val interactor: UserInteractor -) : UserStore, BaseStore() { + private val interactor: UserInteractor, + router: UserRouter +) : UserStore, BaseStore(router) { override val initialState: State = State( user = null, @@ -97,19 +100,19 @@ class UserStoreImpl @Inject constructor( }.flow.state() private fun actionBackClick() { - sendEvent(Event.Navigation.PopBack) + navigate(Navigation.PopBack) } private fun actionCollectionClick(action: Action.OnCollectionClick) { - sendEvent(Event.Navigation.Collection(action.uuid)) + navigate(Navigation.Collection(action.uuid)) } private fun actionImageClick(action: Action.OnImageClick) { - sendEvent(Event.Navigation.Image(action.uuid)) + navigate(Navigation.Image(action.uuid)) } private fun actionUserClick(action: Action.OnUserClick) { - sendEvent(Event.Navigation.User(action.username)) + navigate(Navigation.User(action.username)) } companion object { From 7829aedd4971f58e18e8eaa0a04e834e565de2eb Mon Sep 17 00:00:00 2001 From: stslex Date: Sun, 29 Oct 2023 15:31:25 +0300 Subject: [PATCH 7/8] fix store builder --- .../core/ui/base/DaggerViewModel.kt | 14 ++++++++-- .../core/ui/di/builder/FeatureBuilder.kt | 18 ++++++++----- .../collection/di/SingleCollectionBuilder.kt | 26 ++++++++++--------- .../ui/store/SingleCollectionStoreImpl.kt | 3 +++ .../favourite/di/FavouriteComponentBuilder.kt | 7 ++--- .../favourite/ui/store/FavouriteStoreImpl.kt | 3 +++ .../feature/home/di/HomeComponentBuilder.kt | 7 ++--- .../feature/home/ui/store/HomeStoreImpl.kt | 3 +++ .../di/ImageDetailComponentBuilder.kt | 7 ++--- .../ui/store/ImageDetailStoreImpl.kt | 3 +++ .../search/di/SearchPhotosComponent.kt | 1 - .../search/di/SearchPhotosComponentBuilder.kt | 7 ++--- .../search/ui/store/SearchStoreImpl.kt | 3 +++ .../feature/user/di/UserComponentBuilder.kt | 10 ++++--- .../feature/user/navigation/UserGraph.kt | 1 - .../feature/user/ui/store/UserStoreImpl.kt | 3 +++ 16 files changed, 78 insertions(+), 38 deletions(-) diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/DaggerViewModel.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/DaggerViewModel.kt index 614470f1..50b04f4c 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/DaggerViewModel.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/base/DaggerViewModel.kt @@ -1,10 +1,12 @@ package st.slex.csplashscreen.core.ui.base import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.platform.LocalContext import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewmodel.compose.viewModel +import st.slex.csplashscreen.core.ui.di.builder.Feature import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder @Composable @@ -18,11 +20,19 @@ inline fun daggerViewModel( ) @Composable -inline fun setupComponent( - builder: FeatureBuilder, +inline fun setupComponent( + builder: FeatureBuilder, key: String? = null, ): VM { val context = LocalContext.current + + DisposableEffect(Unit) { + builder.create(context) + onDispose { + builder.clear() + } + } + return daggerViewModel(key) { builder .build(context) diff --git a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/FeatureBuilder.kt b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/FeatureBuilder.kt index 51b4dfe9..711c6fa3 100644 --- a/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/FeatureBuilder.kt +++ b/core/ui/src/main/java/st/slex/csplashscreen/core/ui/di/builder/FeatureBuilder.kt @@ -2,16 +2,20 @@ package st.slex.csplashscreen.core.ui.di.builder import android.content.Context -interface FeatureBuilder { +interface FeatureBuilder { - fun create(context: Context): Feature + var feature: F? - fun build(context: Context): Feature = _feature ?: create(context) + fun create(context: Context): F + + fun build( + context: Context + ): F = feature ?: create(context) .also { createdFeature -> - _feature = createdFeature + feature = createdFeature } - companion object { - private var _feature: Feature? = null + fun clear() { + feature = null } -} \ No newline at end of file +} diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionBuilder.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionBuilder.kt index a2ea90ed..7f0bfee9 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionBuilder.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/di/SingleCollectionBuilder.kt @@ -2,20 +2,22 @@ package st.slex.csplashscreen.feature.collection.di import android.content.Context import st.slex.csplashscreen.core.network.di.NetworkApiBuilder -import st.slex.csplashscreen.core.ui.di.builder.Feature import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -object SingleCollectionBuilder : FeatureBuilder { +object SingleCollectionBuilder : FeatureBuilder { - override fun create(context: Context): Feature = DaggerSingleCollectionComponent - .factory() - .create( - dependencies = DaggerSingleCollectionComponent_SingleCollectionDependenciesComponent - .factory() - .create( - networkClientApi = NetworkApiBuilder.build(), - navigationApi = context.navigationApi - ) - ) + override var feature: SingleCollectionComponent? = null + + override fun create(context: Context): SingleCollectionComponent = + DaggerSingleCollectionComponent + .factory() + .create( + dependencies = DaggerSingleCollectionComponent_SingleCollectionDependenciesComponent + .factory() + .create( + networkClientApi = NetworkApiBuilder.build(), + navigationApi = context.navigationApi + ) + ) } diff --git a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt index 11b3c9e0..78cddf4a 100644 --- a/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt +++ b/feature/collection/src/main/java/st/slex/csplashscreen/feature/collection/ui/store/SingleCollectionStoreImpl.kt @@ -5,6 +5,7 @@ import androidx.paging.PagingConfig import androidx.paging.PagingData import androidx.paging.map import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flatMapLatest @@ -33,6 +34,8 @@ class SingleCollectionStoreImpl @Inject constructor( collectionId = "" ) + override val state: MutableStateFlow = MutableStateFlow(initialState) + override fun processAction(action: Action) { when (action) { is Action.Init -> actionInit(action) diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponentBuilder.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponentBuilder.kt index 9f3d8723..5e6e9e40 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponentBuilder.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/di/FavouriteComponentBuilder.kt @@ -3,15 +3,16 @@ package st.slex.csplashscreen.feature.favourite.di import android.content.Context import st.slex.csplashscreen.core.core.appApi import st.slex.csplashscreen.core.favourite.di.FavouriteApiBuilder -import st.slex.csplashscreen.core.ui.di.builder.Feature import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -object FavouriteComponentBuilder : FeatureBuilder { +object FavouriteComponentBuilder : FeatureBuilder { + + override var feature: FavouriteComponent? = null override fun create( context: Context - ): Feature = DaggerFavouriteComponent.factory() + ) = DaggerFavouriteComponent.factory() .create( dependencies = DaggerFavouriteComponent_FavouriteDependenciesComponent .factory() diff --git a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStoreImpl.kt b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStoreImpl.kt index 4e8ca257..af70c28c 100644 --- a/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStoreImpl.kt +++ b/feature/favourite/src/main/java/st/slex/csplashscreen/feature/favourite/ui/store/FavouriteStoreImpl.kt @@ -1,6 +1,7 @@ package st.slex.csplashscreen.feature.favourite.ui.store import androidx.paging.PagingData +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import st.slex.csplashscreen.core.photos.ui.model.PhotoModel @@ -22,6 +23,8 @@ class FavouriteStoreImpl @Inject constructor( photos = ::photos ) + override val state: MutableStateFlow = MutableStateFlow(initialState) + private val photos: StateFlow> get() = interactor.photos .map { pagingData -> diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponentBuilder.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponentBuilder.kt index c068a474..51a207df 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponentBuilder.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/di/HomeComponentBuilder.kt @@ -3,13 +3,14 @@ package st.slex.csplashscreen.feature.home.di import android.content.Context import st.slex.csplashscreen.core.collection.di.CollectionApiBuilder import st.slex.csplashscreen.core.photos.di.PhotosApiBuilder -import st.slex.csplashscreen.core.ui.di.builder.Feature import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -object HomeComponentBuilder : FeatureBuilder { +object HomeComponentBuilder : FeatureBuilder { - override fun create(context: Context): Feature = DaggerHomeComponent + override var feature: HomeComponent? = null + + override fun create(context: Context) = DaggerHomeComponent .factory() .create( dependencies = DaggerHomeComponent_HomeDependenciesComponent diff --git a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt index 88d523c7..c96cd61a 100644 --- a/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt +++ b/feature/home/src/main/java/st/slex/csplashscreen/feature/home/ui/store/HomeStoreImpl.kt @@ -6,6 +6,7 @@ import androidx.paging.PagingData import androidx.paging.cachedIn import androidx.paging.map import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.flowOn @@ -35,6 +36,8 @@ class HomeStoreImpl @Inject constructor( photos = ::photos ) + override val state: MutableStateFlow = MutableStateFlow(initialState) + private val collections: StateFlow> get() = Pager(config = config) { PagingSource(interactor::getAllCollections) diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponentBuilder.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponentBuilder.kt index 2eb079e9..0b14462f 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponentBuilder.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/di/ImageDetailComponentBuilder.kt @@ -4,13 +4,14 @@ import android.content.Context import st.slex.csplashscreen.core.core.appApi import st.slex.csplashscreen.core.favourite.di.FavouriteApiBuilder import st.slex.csplashscreen.core.photos.di.PhotosApiBuilder -import st.slex.csplashscreen.core.ui.di.builder.Feature import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -object ImageDetailComponentBuilder : FeatureBuilder { +object ImageDetailComponentBuilder : FeatureBuilder { - override fun create(context: Context): Feature = DaggerImageDetailComponent + override var feature: ImageDetailComponent? = null + + override fun create(context: Context) = DaggerImageDetailComponent .factory() .create( dependencies = DaggerImageDetailComponent_ImageDetailDependenciesComponent diff --git a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt index 62389b54..abfce83c 100644 --- a/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt +++ b/feature/photo-detail/src/main/java/st/slex/csplashscreen/feature/feature_photo_detail/ui/store/ImageDetailStoreImpl.kt @@ -1,6 +1,7 @@ package st.slex.csplashscreen.feature.feature_photo_detail.ui.store import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn @@ -31,6 +32,8 @@ class ImageDetailStoreImpl @Inject constructor( screenState = ScreenState.Loading ) + override val state: MutableStateFlow = MutableStateFlow(initialState) + override fun processAction(action: Action) { when (action) { is Action.Init -> actionInit(action) diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt index 33cce365..9258d396 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt @@ -15,4 +15,3 @@ interface SearchPhotosComponent : Feature { fun create(dependencies: SearchPhotosDependencies): SearchPhotosComponent } } - diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt index cdccba10..1fe72477 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt @@ -4,15 +4,16 @@ import android.content.Context import st.slex.csplashscreen.core.core.appApi import st.slex.csplashscreen.core.database.di.DatabaseApiBuilder import st.slex.csplashscreen.core.network.di.NetworkApiBuilder -import st.slex.csplashscreen.core.ui.di.builder.Feature import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -object SearchPhotosComponentBuilder : FeatureBuilder { +object SearchPhotosComponentBuilder : FeatureBuilder { + + override var feature: SearchPhotosComponent? = null override fun create( context: Context - ): Feature = DaggerSearchPhotosComponent + ) = DaggerSearchPhotosComponent .factory() .create( dependencies = DaggerSearchPhotosDependenciesComponent diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt index debc937e..ef8bb1e7 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/ui/store/SearchStoreImpl.kt @@ -6,6 +6,7 @@ import androidx.paging.PagingData import androidx.paging.map import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest @@ -37,6 +38,8 @@ class SearchStoreImpl @Inject constructor( historyItems = ::searchHistory ) + override val state: MutableStateFlow = MutableStateFlow(initialState) + private val searchHistory: StateFlow> get() = interactor.searchHistory.state() diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponentBuilder.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponentBuilder.kt index 7090518d..af9865ee 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponentBuilder.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/di/UserComponentBuilder.kt @@ -4,15 +4,16 @@ import android.content.Context import st.slex.csplashscreen.core.collection.di.CollectionApiBuilder import st.slex.csplashscreen.core.network.di.NetworkApiBuilder import st.slex.csplashscreen.core.photos.di.PhotosApiBuilder -import st.slex.csplashscreen.core.ui.di.builder.Feature import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder import st.slex.csplashscreen.core.ui.di.navigationApi -object UserComponentBuilder : FeatureBuilder { +object UserComponentBuilder : FeatureBuilder { + + override var feature: UserComponent? = null override fun create( context: Context - ): Feature = DaggerUserComponent + ) = feature ?: DaggerUserComponent .factory() .create( dependencies = DaggerUserComponent_UserDependenciesComponent @@ -24,4 +25,7 @@ object UserComponentBuilder : FeatureBuilder { collectionApi = CollectionApiBuilder.build() ) ) + .also { component -> + feature = component + } } diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt index 973fc762..745bb0da 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/navigation/UserGraph.kt @@ -19,7 +19,6 @@ import st.slex.csplashscreen.feature.user.ui.UserScreen import st.slex.csplashscreen.feature.user.ui.UserViewModel import st.slex.csplashscreen.feature.user.ui.state.rememberUserPagerState import st.slex.csplashscreen.feature.user.ui.state.rememberUserSwipeState -import st.slex.csplashscreen.feature.user.ui.store.UserStore import st.slex.csplashscreen.feature.user.ui.store.UserStore.Action.Init import st.slex.csplashscreen.feature.user.ui.store.UserStore.Action.OnBackButtonClick import st.slex.csplashscreen.feature.user.ui.store.UserStore.Action.OnCollectionClick diff --git a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt index c2457d9a..e9a92bbf 100644 --- a/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt +++ b/feature/user/src/main/java/st/slex/csplashscreen/feature/user/ui/store/UserStoreImpl.kt @@ -4,6 +4,7 @@ import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOn @@ -36,6 +37,8 @@ class UserStoreImpl @Inject constructor( collections = ::getCollections ) + override val state: MutableStateFlow = MutableStateFlow(initialState) + override fun processAction(action: Action) { when (action) { is Action.Init -> actionInit(action) From 2f871e12b501d3bdde56b45b09ef84a482205af1 Mon Sep 17 00:00:00 2001 From: stslex Date: Sun, 29 Oct 2023 15:40:27 +0300 Subject: [PATCH 8/8] update versions --- build-logic/dependencies/src/main/kotlin/AppVersions.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-logic/dependencies/src/main/kotlin/AppVersions.kt b/build-logic/dependencies/src/main/kotlin/AppVersions.kt index 4f1588b9..973bd849 100644 --- a/build-logic/dependencies/src/main/kotlin/AppVersions.kt +++ b/build-logic/dependencies/src/main/kotlin/AppVersions.kt @@ -1,4 +1,4 @@ object AppVersions { - const val versionName = "1.63" - const val versionCode = 9 + const val versionName = "1.64" + const val versionCode = 10 } \ No newline at end of file