Updated on 2026-08-14
This commit is contained in:
parent
ced437b892
commit
facf309dc6
10 changed files with 93 additions and 78 deletions
|
|
@ -23,10 +23,10 @@ private fun internalReduce(action: Action, state: AppState): DetailsState {
|
|||
val detailsState = state.detailsState
|
||||
return when (action) {
|
||||
is DetailsAction.PrepareScreen -> {
|
||||
handlePrepareScreen(action, detailsState)
|
||||
handlePrepareScreen(action)
|
||||
}
|
||||
is DetailsAction.PrepareCardSettingsData -> {
|
||||
hanldePrepareCardSettingsScreen(action.card, detailsState)
|
||||
handlePrepareCardSettingsScreen(action.card, detailsState)
|
||||
}
|
||||
is DetailsAction.ResetCardSettingsData -> detailsState.copy(cardSettingsState = null)
|
||||
is DetailsAction.ResetToFactory -> {
|
||||
|
|
@ -47,7 +47,6 @@ private fun internalReduce(action: Action, state: AppState): DetailsState {
|
|||
|
||||
private fun handlePrepareScreen(
|
||||
action: DetailsAction.PrepareScreen,
|
||||
state: DetailsState,
|
||||
): DetailsState {
|
||||
|
||||
return DetailsState(
|
||||
|
|
@ -59,9 +58,7 @@ private fun handlePrepareScreen(
|
|||
)
|
||||
}
|
||||
|
||||
private fun hanldePrepareCardSettingsScreen(
|
||||
card: Card, state: DetailsState,
|
||||
): DetailsState {
|
||||
private fun handlePrepareCardSettingsScreen(card: Card, state: DetailsState): DetailsState {
|
||||
val cardSettingsState = CardSettingsState(
|
||||
cardInfo = card.toCardInfo(),
|
||||
manageSecurityState = prepareSecurityOptions(card),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import com.tangem.tap.common.redux.navigation.NavigationAction
|
|||
import com.tangem.tap.features.details.redux.DetailsAction
|
||||
import com.tangem.tap.features.details.redux.DetailsState
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.wallet.R
|
||||
import org.rekotlin.StoreSubscriber
|
||||
|
||||
class CardSettingsFragment : Fragment(), StoreSubscriber<DetailsState> {
|
||||
|
|
@ -22,21 +21,21 @@ class CardSettingsFragment : Fragment(), StoreSubscriber<DetailsState> {
|
|||
private val viewModel = CardSettingsViewModel(store)
|
||||
|
||||
private var screenState: MutableState<CardSettingsScreenState> =
|
||||
mutableStateOf(viewModel.updateState(store.state.detailsState.cardSettingsState, context))
|
||||
mutableStateOf(viewModel.updateState(store.state.detailsState.cardSettingsState))
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val inflater = TransitionInflater.from(requireContext())
|
||||
enterTransition = inflater.inflateTransition(R.transition.slide_right)
|
||||
exitTransition = inflater.inflateTransition(R.transition.fade)
|
||||
enterTransition = inflater.inflateTransition(android.R.transition.fade)
|
||||
exitTransition = inflater.inflateTransition(android.R.transition.fade)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
): View {
|
||||
return ComposeView(requireContext()).apply {
|
||||
setContent {
|
||||
isTransitionGroup = true
|
||||
|
|
@ -69,6 +68,6 @@ class CardSettingsFragment : Fragment(), StoreSubscriber<DetailsState> {
|
|||
|
||||
override fun newState(state: DetailsState) {
|
||||
if (activity == null || view == null) return
|
||||
screenState.value = viewModel.updateState(state.cardSettingsState, context)
|
||||
screenState.value = viewModel.updateState(state.cardSettingsState)
|
||||
}
|
||||
}
|
||||
|
|
@ -145,13 +145,13 @@ fun CardSettings(
|
|||
val titleColor = if (it.clickable) R.color.text_primary_1 else R.color.text_tertiary
|
||||
val subtitleColor = if (it.clickable) R.color.text_secondary else R.color.text_tertiary
|
||||
Text(
|
||||
text = stringResource(id = it.titleRes),
|
||||
text = it.titleRes.resolveReference(),
|
||||
color = colorResource(id = titleColor),
|
||||
style = TangemTypography.subtitle1,
|
||||
)
|
||||
Spacer(modifier = modifier.size(4.dp))
|
||||
Text(
|
||||
text = it.subtitle,
|
||||
text = it.subtitle.resolveReference(),
|
||||
color = colorResource(id = subtitleColor),
|
||||
style = TangemTypography.body2,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
package com.tangem.tap.features.details.ui.cardsettings
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.tangem.tap.features.details.redux.SecurityOption
|
||||
import com.tangem.tap.features.details.ui.securitymode.toTitleRes
|
||||
import com.tangem.wallet.R
|
||||
|
||||
data class CardSettingsScreenState(
|
||||
|
|
@ -9,28 +15,66 @@ data class CardSettingsScreenState(
|
|||
)
|
||||
|
||||
sealed class CardInfo(
|
||||
val titleRes: Int, val subtitle: String, val clickable: Boolean = false,
|
||||
val titleRes: TextReference, val subtitle: TextReference, val clickable: Boolean = false,
|
||||
) {
|
||||
class CardId(subtitle: String) : CardInfo(R.string.details_row_title_cid, subtitle)
|
||||
class CardId(subtitle: String) : CardInfo(
|
||||
titleRes = TextReference.Res(R.string.details_row_title_cid),
|
||||
subtitle = TextReference
|
||||
.Str(subtitle),
|
||||
)
|
||||
|
||||
class Issuer(subtitle: String) : CardInfo(R.string.details_row_title_issuer, subtitle)
|
||||
class Issuer(subtitle: String) : CardInfo(
|
||||
titleRes = TextReference.Res(R.string.details_row_title_issuer),
|
||||
subtitle = TextReference
|
||||
.Str(subtitle),
|
||||
)
|
||||
|
||||
class SignedHashes(subtitle: String) : CardInfo(R.string.details_row_title_signed_hashes, subtitle)
|
||||
class SignedHashes(hashes: String) : CardInfo(
|
||||
titleRes = TextReference.Res(R.string.details_row_title_signed_hashes),
|
||||
subtitle = TextReference.Res(R.string.details_row_subtitle_signed_hashes_format, hashes),
|
||||
)
|
||||
|
||||
class SecurityMode(
|
||||
subtitle: String,
|
||||
securityOption: SecurityOption,
|
||||
clickable: Boolean,
|
||||
) : CardInfo(R.string.card_settings_security_mode, subtitle, clickable)
|
||||
|
||||
class ChangeAccessCode(subtitle: String) : CardInfo(
|
||||
R.string.card_settings_change_access_code,
|
||||
subtitle,
|
||||
true,
|
||||
) : CardInfo(
|
||||
titleRes = TextReference.Res(R.string.card_settings_security_mode),
|
||||
subtitle = TextReference.Res(securityOption.toTitleRes()),
|
||||
clickable = clickable,
|
||||
)
|
||||
|
||||
class ResetToFactorySettings(subtitle: String) : CardInfo(
|
||||
R.string.details_row_title_reset_factory_settings,
|
||||
subtitle,
|
||||
true,
|
||||
object ChangeAccessCode : CardInfo(
|
||||
titleRes = TextReference.Res(R.string.card_settings_change_access_code),
|
||||
subtitle = TextReference.Res(R.string.card_settings_change_access_code_footer),
|
||||
clickable = true,
|
||||
)
|
||||
|
||||
object ResetToFactorySettings : CardInfo(
|
||||
titleRes = TextReference.Res(R.string.details_row_title_reset_factory_settings),
|
||||
subtitle = TextReference.Res(R.string.card_settings_reset_factory_footer),
|
||||
clickable = true,
|
||||
)
|
||||
}
|
||||
|
||||
sealed interface TextReference {
|
||||
class Res(@StringRes val id: Int, val formatArgs: List<Any> = emptyList()) : TextReference {
|
||||
constructor(@StringRes id: Int, vararg formatArgs: Any) : this(id, formatArgs.toList())
|
||||
}
|
||||
|
||||
class Str(val value: String) : TextReference
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun TextReference.resolveReference(): String {
|
||||
return when (this) {
|
||||
is TextReference.Res -> {
|
||||
// if (source.formatArgs) {
|
||||
// stringResource(source.id)
|
||||
// } else {
|
||||
stringResource(this.id, *this.formatArgs.toTypedArray())
|
||||
// }
|
||||
}
|
||||
is TextReference.Str -> this.value
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.tangem.tap.features.details.ui.cardsettings
|
||||
|
||||
import android.content.Context
|
||||
import com.tangem.domain.common.getTwinCardIdForUser
|
||||
import com.tangem.domain.common.isTangemTwins
|
||||
import com.tangem.tap.common.redux.AppState
|
||||
|
|
@ -8,13 +7,11 @@ import com.tangem.tap.common.redux.navigation.AppScreen
|
|||
import com.tangem.tap.common.redux.navigation.NavigationAction
|
||||
import com.tangem.tap.features.details.redux.CardSettingsState
|
||||
import com.tangem.tap.features.details.redux.DetailsAction
|
||||
import com.tangem.tap.features.details.ui.securitymode.toTitleRes
|
||||
import com.tangem.wallet.R
|
||||
import org.rekotlin.Store
|
||||
|
||||
class CardSettingsViewModel(private val store: Store<AppState>) {
|
||||
|
||||
fun updateState(state: CardSettingsState?, context: Context?): CardSettingsScreenState {
|
||||
fun updateState(state: CardSettingsState?): CardSettingsScreenState {
|
||||
|
||||
return if (state?.manageSecurityState == null) {
|
||||
CardSettingsScreenState(
|
||||
|
|
@ -30,43 +27,25 @@ class CardSettingsViewModel(private val store: Store<AppState>) {
|
|||
} else {
|
||||
state.cardInfo.cardId
|
||||
}
|
||||
val cardDetails: MutableList<CardInfo> = listOfNotNull(
|
||||
val cardDetails: MutableList<CardInfo> = mutableListOf(
|
||||
CardInfo.CardId(cardId),
|
||||
CardInfo.Issuer(state.cardInfo.issuer),
|
||||
).toMutableList()
|
||||
)
|
||||
|
||||
context?.let { context ->
|
||||
if (!state.card.isTangemTwins()) {
|
||||
cardDetails.add(
|
||||
CardInfo.SignedHashes(
|
||||
context
|
||||
.getString(
|
||||
R.string.details_row_subtitle_signed_hashes_format,
|
||||
state.cardInfo.signedHashes.toString(),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
cardDetails.add(
|
||||
CardInfo.SecurityMode(
|
||||
subtitle = context.getString(state.manageSecurityState.currentOption.toTitleRes()),
|
||||
clickable = state.manageSecurityState.allowedOptions.size > 1,
|
||||
),
|
||||
)
|
||||
if (state.card.backupStatus?.isActive == true && state.card.isAccessCodeSet) {
|
||||
cardDetails.add(
|
||||
CardInfo.ChangeAccessCode(
|
||||
subtitle = context.getString(R.string.card_settings_change_access_code_footer),
|
||||
),
|
||||
)
|
||||
}
|
||||
if (state.resetCardAllowed) {
|
||||
cardDetails.add(
|
||||
CardInfo.ResetToFactorySettings(
|
||||
subtitle = context.getString(R.string.card_settings_reset_factory_footer),
|
||||
),
|
||||
)
|
||||
}
|
||||
if (!state.card.isTangemTwins()) {
|
||||
cardDetails.add(CardInfo.SignedHashes(state.cardInfo.signedHashes.toString()))
|
||||
}
|
||||
cardDetails.add(
|
||||
CardInfo.SecurityMode(
|
||||
securityOption = state.manageSecurityState.currentOption,
|
||||
clickable = state.manageSecurityState.allowedOptions.size > 1,
|
||||
),
|
||||
)
|
||||
if (state.card.backupStatus?.isActive == true && state.card.isAccessCodeSet) {
|
||||
cardDetails.add(CardInfo.ChangeAccessCode)
|
||||
}
|
||||
if (state.resetCardAllowed) {
|
||||
cardDetails.add(CardInfo.ResetToFactorySettings)
|
||||
}
|
||||
|
||||
CardSettingsScreenState(
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@ fun EmptyTopBarWithNavigation(
|
|||
},
|
||||
backgroundColor = colorResource(id = R.color.background_primary),
|
||||
elevation = 0.dp,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import com.google.accompanist.appcompattheme.AppCompatTheme
|
|||
import com.tangem.tap.common.redux.navigation.NavigationAction
|
||||
import com.tangem.tap.features.details.redux.DetailsState
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.wallet.R
|
||||
import org.rekotlin.StoreSubscriber
|
||||
|
||||
class DetailsFragment : Fragment(), StoreSubscriber<DetailsState> {
|
||||
|
|
@ -27,8 +26,8 @@ class DetailsFragment : Fragment(), StoreSubscriber<DetailsState> {
|
|||
super.onCreate(savedInstanceState)
|
||||
|
||||
val inflater = TransitionInflater.from(requireContext())
|
||||
enterTransition = inflater.inflateTransition(R.transition.slide_right)
|
||||
exitTransition = inflater.inflateTransition(R.transition.fade)
|
||||
enterTransition = inflater.inflateTransition(android.R.transition.fade)
|
||||
exitTransition = inflater.inflateTransition(android.R.transition.fade)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class DetailsViewModel(private val store: Store<AppState>) {
|
|||
store.dispatch(NavigationAction.NavigateTo(AppScreen.CardSettings))
|
||||
}
|
||||
SettingsElement.AppSettings -> {
|
||||
// store.dispatch(NavigationAction.NavigateTo()) TODO: To be available later
|
||||
store.dispatch(NavigationAction.NavigateTo(AppScreen.AppSettings)) //TODO: To be available later
|
||||
}
|
||||
SettingsElement.LinkMoreCards -> {
|
||||
store.dispatch(DetailsAction.CreateBackup)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import com.google.accompanist.appcompattheme.AppCompatTheme
|
|||
import com.tangem.tap.common.redux.navigation.NavigationAction
|
||||
import com.tangem.tap.features.details.redux.DetailsState
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.wallet.R
|
||||
import org.rekotlin.StoreSubscriber
|
||||
|
||||
class ResetCardFragment : Fragment(), StoreSubscriber<DetailsState> {
|
||||
|
|
@ -27,8 +26,8 @@ class ResetCardFragment : Fragment(), StoreSubscriber<DetailsState> {
|
|||
super.onCreate(savedInstanceState)
|
||||
|
||||
val inflater = TransitionInflater.from(requireContext())
|
||||
enterTransition = inflater.inflateTransition(R.transition.slide_right)
|
||||
exitTransition = inflater.inflateTransition(R.transition.fade)
|
||||
enterTransition = inflater.inflateTransition(android.R.transition.fade)
|
||||
exitTransition = inflater.inflateTransition(android.R.transition.fade)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import com.google.accompanist.appcompattheme.AppCompatTheme
|
|||
import com.tangem.tap.common.redux.navigation.NavigationAction
|
||||
import com.tangem.tap.features.details.redux.DetailsState
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.wallet.R
|
||||
import org.rekotlin.StoreSubscriber
|
||||
|
||||
class SecurityModeFragment : Fragment(), StoreSubscriber<DetailsState> {
|
||||
|
|
@ -27,8 +26,8 @@ class SecurityModeFragment : Fragment(), StoreSubscriber<DetailsState> {
|
|||
super.onCreate(savedInstanceState)
|
||||
|
||||
val inflater = TransitionInflater.from(requireContext())
|
||||
enterTransition = inflater.inflateTransition(R.transition.slide_right)
|
||||
exitTransition = inflater.inflateTransition(R.transition.fade)
|
||||
enterTransition = inflater.inflateTransition(android.R.transition.fade)
|
||||
exitTransition = inflater.inflateTransition(android.R.transition.fade)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue