From 1df5aa475be37a293670f01a8a8b196ebac8f2eb Mon Sep 17 00:00:00 2001 From: Rodrigo Varela Date: Sat, 14 Dec 2024 15:25:21 +1100 Subject: [PATCH] - show create profile if no user is saved --- .../android/node/di/AndroidNodeModule.kt | 1 + .../node/presentation/NodeSplashPresenter.kt | 4 ++- .../presentation/di/PresentationModule.kt | 1 + .../ui/uicases/startup/SplashPresenter.kt | 36 ++++++++++++------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/di/AndroidNodeModule.kt b/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/di/AndroidNodeModule.kt index c4a5e669..3694bd95 100644 --- a/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/di/AndroidNodeModule.kt +++ b/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/di/AndroidNodeModule.kt @@ -54,6 +54,7 @@ val androidNodeModule = module { get(), get(), get(), + get(), ) } diff --git a/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/presentation/NodeSplashPresenter.kt b/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/presentation/NodeSplashPresenter.kt index 16f6c3d8..895e35a3 100644 --- a/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/presentation/NodeSplashPresenter.kt +++ b/androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/presentation/NodeSplashPresenter.kt @@ -2,6 +2,7 @@ package network.bisq.mobile.android.node.presentation import network.bisq.mobile.domain.data.model.Settings import network.bisq.mobile.domain.data.repository.SettingsRepository +import network.bisq.mobile.domain.data.repository.UserRepository import network.bisq.mobile.domain.service.bootstrap.ApplicationBootstrapFacade import network.bisq.mobile.domain.service.user_profile.UserProfileServiceFacade import network.bisq.mobile.presentation.MainPresenter @@ -11,8 +12,9 @@ class NodeSplashPresenter( mainPresenter: MainPresenter, applicationBootstrapFacade: ApplicationBootstrapFacade, private val userProfileService: UserProfileServiceFacade, + private val userRepository: UserRepository, private val settingsRepository: SettingsRepository -) : SplashPresenter(mainPresenter, applicationBootstrapFacade, userProfileService, settingsRepository) { +) : SplashPresenter(mainPresenter, applicationBootstrapFacade, userProfileService, userRepository, settingsRepository) { /** * diff --git a/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/di/PresentationModule.kt b/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/di/PresentationModule.kt index 276f659f..a398336c 100644 --- a/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/di/PresentationModule.kt +++ b/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/di/PresentationModule.kt @@ -50,6 +50,7 @@ val presentationModule = module { get(), get(), get(), + get() ) } diff --git a/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/ui/uicases/startup/SplashPresenter.kt b/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/ui/uicases/startup/SplashPresenter.kt index 6339660b..2e70f5af 100644 --- a/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/ui/uicases/startup/SplashPresenter.kt +++ b/shared/presentation/src/commonMain/kotlin/network/bisq/mobile/presentation/ui/uicases/startup/SplashPresenter.kt @@ -6,7 +6,9 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import network.bisq.mobile.domain.data.model.Settings +import network.bisq.mobile.domain.data.model.User import network.bisq.mobile.domain.data.repository.SettingsRepository +import network.bisq.mobile.domain.data.repository.UserRepository import network.bisq.mobile.domain.service.bootstrap.ApplicationBootstrapFacade import network.bisq.mobile.domain.service.user_profile.UserProfileServiceFacade import network.bisq.mobile.presentation.BasePresenter @@ -17,7 +19,8 @@ open class SplashPresenter( mainPresenter: MainPresenter, applicationBootstrapFacade: ApplicationBootstrapFacade, private val userProfileService: UserProfileServiceFacade, - private val settingsRepository: SettingsRepository + private val userRepository: UserRepository, + private val settingsRepository: SettingsRepository, ) : BasePresenter(mainPresenter) { val state: StateFlow = applicationBootstrapFacade.state @@ -41,14 +44,11 @@ open class SplashPresenter( private fun navigateToNextScreen() { CoroutineScope(Dispatchers.Main).launch { + val settings: Settings = settingsRepository.fetch() ?: Settings() + val user: User? = userRepository.fetch() - settingsRepository.fetch() - val settings: Settings? = settingsRepository.data.value - - if (settings == null) { - if (!doCustomNavigationLogic(Settings())) { - navigateToHome() - } + if (user == null) { + navigateToCreateProfile() } else { if (userProfileService.hasUserProfile()) { if (!doCustomNavigationLogic(settings)) { @@ -58,6 +58,7 @@ open class SplashPresenter( // If firstTimeApp launch, goto Onboarding[clientMode] (androidNode / xClient) // If not, goto CreateProfile if (settings.firstLaunch) { + // TODO after onboarding need to make sure the rest is configured? rootNavigator.navigate(Routes.Onboarding.name) { popUpTo(Routes.Splash.name) { inclusive = true } } @@ -71,22 +72,31 @@ open class SplashPresenter( } } + private fun navigateToCreateProfile() { + rootNavigator.navigate(Routes.CreateProfile.name) { + popUpTo(Routes.Splash.name) { inclusive = true } + } + } + private fun navigateToHome() { rootNavigator.navigate(Routes.TabContainer.name) { popUpTo(Routes.Splash.name) { inclusive = true } } } + /** * Default implementation in shared is for xClients. Override on node to avoid this. * @return true if handled, false otherwise */ open fun doCustomNavigationLogic(settings: Settings): Boolean { - if (settings.bisqApiUrl.isNotEmpty()) { - navigateToHome() - } else { - rootNavigator.navigate(Routes.TrustedNodeSetup.name) { - popUpTo(Routes.Splash.name) { inclusive = true } + when { + settings.bisqApiUrl.isEmpty() -> { + rootNavigator.navigate(Routes.TrustedNodeSetup.name) { + popUpTo(Routes.Splash.name) { inclusive = true } + } } +// settings.firstLaunch -> navigateToCreateProfile() + else -> navigateToHome() } return true }