From d1bf01731941ffd7dfeeb5ec4fff9a4a94176150 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 10 Jul 2023 21:03:00 +0800 Subject: [PATCH] Updated on 2026-08-14 --- app/build.gradle.kts | 1 + .../com/tangem/tap/di/AppStateHolderModule.kt | 5 ++++ .../com/tangem/tap/proxy/AppStateHolder.kt | 8 ++++++- core/navigation/.gitignore | 1 + core/navigation/build.gradle.kts | 14 +++++++++++ .../navigation/FragmentShareTransition.kt | 2 +- .../core}/navigation/NavigationAction.kt | 9 ++++--- .../core}/navigation/NavigationState.kt | 24 ++++++++++++------- .../core/navigation/NavigationStateHolder.kt | 12 ++++++++++ features/wallet/impl/build.gradle.kts | 2 ++ .../feature/wallet/di/WalletRouterModule.kt | 5 +++- .../wallet/presentation/WalletFragment.kt | 2 +- .../router/DefaultWalletRouter.kt | 9 ++++++- .../presentation/router/InnerWalletRouter.kt | 3 +++ .../wallet/viewmodels/WalletViewModel.kt | 4 +++- settings.gradle.kts | 3 ++- 16 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 core/navigation/.gitignore create mode 100644 core/navigation/build.gradle.kts rename {app/src/main/java/com/tangem/tap/common/redux => core/navigation/src/main/java/com/tangem/core}/navigation/FragmentShareTransition.kt (94%) rename {app/src/main/java/com/tangem/tap/common/redux => core/navigation/src/main/java/com/tangem/core}/navigation/NavigationAction.kt (83%) rename {app/src/main/java/com/tangem/tap/common/redux => core/navigation/src/main/java/com/tangem/core}/navigation/NavigationState.kt (57%) create mode 100644 core/navigation/src/main/java/com/tangem/core/navigation/NavigationStateHolder.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 53f77b0fa6..df6d24b384 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -30,6 +30,7 @@ dependencies { implementation(project(":domain:wallets:models")) implementation(project(":common")) implementation(project(":core:analytics")) + implementation(project(":core:navigation")) implementation(project(":core:featuretoggles")) implementation(project(":core:res")) implementation(project(":core:ui")) diff --git a/app/src/main/java/com/tangem/tap/di/AppStateHolderModule.kt b/app/src/main/java/com/tangem/tap/di/AppStateHolderModule.kt index 6dba03c902..05cc610f95 100644 --- a/app/src/main/java/com/tangem/tap/di/AppStateHolderModule.kt +++ b/app/src/main/java/com/tangem/tap/di/AppStateHolderModule.kt @@ -1,5 +1,6 @@ package com.tangem.tap.di +import com.tangem.core.navigation.NavigationStateHolder import com.tangem.domain.wallets.legacy.WalletsStateHolder import com.tangem.tap.proxy.AppStateHolder import dagger.Binds @@ -15,4 +16,8 @@ internal interface AppStateHolderModule { @Binds @Singleton fun bindsWalletsStateHolder(appStateHolder: AppStateHolder): WalletsStateHolder + + @Binds + @Singleton + fun bindsNavigationStateHolder(appStateHolder: AppStateHolder): NavigationStateHolder } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/proxy/AppStateHolder.kt b/app/src/main/java/com/tangem/tap/proxy/AppStateHolder.kt index f3dddfc812..cf6015d446 100644 --- a/app/src/main/java/com/tangem/tap/proxy/AppStateHolder.kt +++ b/app/src/main/java/com/tangem/tap/proxy/AppStateHolder.kt @@ -1,6 +1,8 @@ package com.tangem.tap.proxy import com.tangem.TangemSdk +import com.tangem.core.navigation.NavigationAction +import com.tangem.core.navigation.NavigationStateHolder import com.tangem.domain.models.scan.CardDTO import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.wallets.legacy.UserWalletsListManager @@ -18,7 +20,7 @@ import javax.inject.Inject * Holds objects from old modules, that missing in DI graph. * Object sets manually to use in new modules and [AppStateHolder] proxies its to DI. */ -class AppStateHolder @Inject constructor() : WalletsStateHolder { +class AppStateHolder @Inject constructor() : WalletsStateHolder, NavigationStateHolder { override var userWalletsListManager: UserWalletsListManager? = null @@ -35,4 +37,8 @@ class AppStateHolder @Inject constructor() : WalletsStateHolder { fun getActualCard(): CardDTO? { return scanResponse?.card } + + override fun navigate(action: NavigationAction) { + mainStore?.dispatch(action) + } } \ No newline at end of file diff --git a/core/navigation/.gitignore b/core/navigation/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/core/navigation/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/navigation/build.gradle.kts b/core/navigation/build.gradle.kts new file mode 100644 index 0000000000..bb00481f67 --- /dev/null +++ b/core/navigation/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + id("configuration") +} + +android { + namespace = "com.tangem.core.navigation" +} + +dependencies { + implementation(deps.material) + implementation(deps.reKotlin) +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/FragmentShareTransition.kt b/core/navigation/src/main/java/com/tangem/core/navigation/FragmentShareTransition.kt similarity index 94% rename from app/src/main/java/com/tangem/tap/common/redux/navigation/FragmentShareTransition.kt rename to core/navigation/src/main/java/com/tangem/core/navigation/FragmentShareTransition.kt index ab7aa07259..2cb2132eec 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/FragmentShareTransition.kt +++ b/core/navigation/src/main/java/com/tangem/core/navigation/FragmentShareTransition.kt @@ -1,4 +1,4 @@ -package com.tangem.tap.common.redux.navigation +package com.tangem.core.navigation import android.view.View import androidx.transition.TransitionSet diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationAction.kt b/core/navigation/src/main/java/com/tangem/core/navigation/NavigationAction.kt similarity index 83% rename from app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationAction.kt rename to core/navigation/src/main/java/com/tangem/core/navigation/NavigationAction.kt index 71f3274e4c..082ada57ae 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationAction.kt +++ b/core/navigation/src/main/java/com/tangem/core/navigation/NavigationAction.kt @@ -1,4 +1,4 @@ -package com.tangem.tap.common.redux.navigation +package com.tangem.core.navigation import android.net.Uri import android.os.Bundle @@ -7,6 +7,7 @@ import org.rekotlin.Action import java.lang.ref.WeakReference sealed class NavigationAction : Action { + data class NavigateTo( val screen: AppScreen, val fragmentShareTransition: FragmentShareTransition? = null, @@ -14,10 +15,7 @@ sealed class NavigationAction : Action { val bundle: Bundle? = null, ) : NavigationAction() - data class PopBackTo( - val screen: AppScreen? = null, - val inclusive: Boolean = false, - ) : NavigationAction() + data class PopBackTo(val screen: AppScreen? = null, val inclusive: Boolean = false) : NavigationAction() data class OpenUrl(val url: String) : NavigationAction() @@ -28,5 +26,6 @@ sealed class NavigationAction : Action { data class Share(val data: String) : NavigationAction() data class ActivityCreated(val activity: WeakReference) : NavigationAction() + data class ActivityDestroyed(val activity: WeakReference) : NavigationAction() } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt b/core/navigation/src/main/java/com/tangem/core/navigation/NavigationState.kt similarity index 57% rename from app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt rename to core/navigation/src/main/java/com/tangem/core/navigation/NavigationState.kt index 861a0a0fb9..db33dd330d 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt +++ b/core/navigation/src/main/java/com/tangem/core/navigation/NavigationState.kt @@ -1,4 +1,4 @@ -package com.tangem.tap.common.redux.navigation +package com.tangem.core.navigation import androidx.appcompat.app.AppCompatActivity import org.rekotlin.StateType @@ -9,17 +9,25 @@ data class NavigationState( val activity: WeakReference? = null, ) : StateType -enum class AppScreen( - val isDialogFragment: Boolean = false, -) { +enum class AppScreen(val isDialogFragment: Boolean = false) { Home, Shop, Disclaimer, - OnboardingNote, OnboardingWallet, OnboardingTwins, OnboardingOther, - Wallet, WalletDetails, + OnboardingNote, + OnboardingWallet, + OnboardingTwins, + OnboardingOther, + Wallet, + WalletDetails, Send, - Details, DetailsSecurity, CardSettings, AppSettings, ResetToFactory, AccessCodeRecovery, - AddTokens, AddCustomToken, + Details, + DetailsSecurity, + CardSettings, + AppSettings, + ResetToFactory, + AccessCodeRecovery, + AddTokens, + AddCustomToken, WalletConnectSessions, QrScan, ReferralProgram, diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/NavigationStateHolder.kt b/core/navigation/src/main/java/com/tangem/core/navigation/NavigationStateHolder.kt new file mode 100644 index 0000000000..7504b75656 --- /dev/null +++ b/core/navigation/src/main/java/com/tangem/core/navigation/NavigationStateHolder.kt @@ -0,0 +1,12 @@ +package com.tangem.core.navigation + +/** + * Navigation state holder + * +[REDACTED_AUTHOR] + */ +interface NavigationStateHolder { + + /** Navigate by [action] */ + fun navigate(action: NavigationAction) +} \ No newline at end of file diff --git a/features/wallet/impl/build.gradle.kts b/features/wallet/impl/build.gradle.kts index cf9833ef5b..2e5651a89c 100644 --- a/features/wallet/impl/build.gradle.kts +++ b/features/wallet/impl/build.gradle.kts @@ -9,6 +9,7 @@ plugins { dependencies { /** AndroidX */ implementation(deps.androidx.activity.compose) + implementation(deps.material) /** Compose */ implementation(deps.compose.coil) @@ -34,6 +35,7 @@ dependencies { /** Core modules */ implementation(project(":core:featuretoggles")) + implementation(project(":core:navigation")) implementation(project(":core:ui")) /** Feature Apis */ diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt index d981abb47b..721bffead3 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt @@ -1,5 +1,6 @@ package com.tangem.feature.wallet.di +import com.tangem.core.navigation.NavigationStateHolder import com.tangem.feature.wallet.presentation.router.DefaultWalletRouter import com.tangem.features.wallet.navigation.WalletRouter import dagger.Module @@ -14,5 +15,7 @@ internal object WalletRouterModule { @Provides @ActivityScoped - fun provideWalletRouter(): WalletRouter = DefaultWalletRouter() + fun provideWalletRouter(navigationStateHolder: NavigationStateHolder): WalletRouter { + return DefaultWalletRouter(navigationStateHolder = navigationStateHolder) + } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/WalletFragment.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/WalletFragment.kt index 0df20799ee..f33c221c8d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/WalletFragment.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/WalletFragment.kt @@ -1,12 +1,12 @@ package com.tangem.feature.wallet.presentation import android.os.Bundle -import android.transition.TransitionInflater import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.compose.ui.platform.ComposeView import androidx.fragment.app.Fragment +import androidx.transition.TransitionInflater import com.tangem.core.ui.components.SystemBarsEffect import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt index 0f01b919af..12a164c4fa 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt @@ -11,6 +11,9 @@ import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController +import com.tangem.core.navigation.AppScreen +import com.tangem.core.navigation.NavigationAction +import com.tangem.core.navigation.NavigationStateHolder import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.presentation.WalletFragment import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensScreen @@ -20,7 +23,7 @@ import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletViewModel import kotlin.properties.Delegates /** Default implementation of wallet feature router */ -internal class DefaultWalletRouter : InnerWalletRouter { +internal class DefaultWalletRouter(private val navigationStateHolder: NavigationStateHolder) : InnerWalletRouter { private var navController: NavHostController by Delegates.notNull() private var fragmentManager: FragmentManager by Delegates.notNull() @@ -74,6 +77,10 @@ internal class DefaultWalletRouter : InnerWalletRouter { navController.navigate(WalletScreens.ORGANIZE_TOKENS.name) } + override fun openDetailsScreen() { + navigationStateHolder.navigate(NavigationAction.NavigateTo(AppScreen.Details)) + } + private companion object { const val BACKSTACK_ENTRY_COUNT_TO_CLOSE_WALLET_SCREEN = 2 } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt index 4c5d9d90ba..520d008d6d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt @@ -30,4 +30,7 @@ internal interface InnerWalletRouter : WalletRouter { /** Open organize tokens screen */ fun openOrganizeTokensScreen() + + /** Open details screen */ + fun openDetailsScreen() } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index e13dad1715..afca89a92a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.ViewModel import com.tangem.feature.wallet.presentation.common.WalletPreviewData import com.tangem.feature.wallet.presentation.router.InnerWalletRouter import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder +import com.tangem.feature.wallet.presentation.wallet.state.WalletTopBarConfig import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject import kotlin.properties.Delegates @@ -30,8 +31,9 @@ internal class WalletViewModel @Inject constructor() : ViewModel() { // TODO: [REDACTED_TASK_KEY] Use production data instead of WalletPreviewData private fun getInitialState(): WalletStateHolder = WalletPreviewData.multicurrencyWalletScreenState.copy( onBackClick = { router.popBackStack() }, - topBarConfig = WalletPreviewData.multicurrencyWalletScreenState.topBarConfig.copy( + topBarConfig = WalletTopBarConfig( onScanCardClick = { router.openOrganizeTokensScreen() }, + onMoreClick = { router.openDetailsScreen() } ), walletsListConfig = WalletPreviewData.multicurrencyWalletScreenState.walletsListConfig.copy( onWalletChange = ::selectWallet, diff --git a/settings.gradle.kts b/settings.gradle.kts index 1f7397e4f8..523476db95 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -37,9 +37,10 @@ include(":common") include(":core:analytics") include(":core:datasource") include(":core:featuretoggles") +include(":core:navigation") include(":core:res") -include(":core:utils") include(":core:ui") +include(":core:utils") // endregion Core modules // region Libs modules