Updated on 2026-08-14

This commit is contained in:
Tangem 2023-07-10 21:03:00 +08:00
parent 2e07841398
commit d1bf017319
16 changed files with 84 additions and 20 deletions

View file

@ -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"))

View file

@ -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
}

View file

@ -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)
}
}

1
core/navigation/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -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)
}

View file

@ -1,4 +1,4 @@
package com.tangem.tap.common.redux.navigation
package com.tangem.core.navigation
import android.view.View
import androidx.transition.TransitionSet

View file

@ -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<AppCompatActivity>) : NavigationAction()
data class ActivityDestroyed(val activity: WeakReference<AppCompatActivity>) : NavigationAction()
}

View file

@ -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<AppCompatActivity>? = 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,

View file

@ -0,0 +1,12 @@
package com.tangem.core.navigation
/**
* Navigation state holder
*
[REDACTED_AUTHOR]
*/
interface NavigationStateHolder {
/** Navigate by [action] */
fun navigate(action: NavigationAction)
}

View file

@ -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 */

View file

@ -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)
}
}

View file

@ -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

View file

@ -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
}

View file

@ -30,4 +30,7 @@ internal interface InnerWalletRouter : WalletRouter {
/** Open organize tokens screen */
fun openOrganizeTokensScreen()
/** Open details screen */
fun openDetailsScreen()
}

View file

@ -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,

View file

@ -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