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