diff --git a/app/src/main/java/com/tangem/tap/common/extensions/Navigation.kt b/app/src/main/java/com/tangem/tap/common/extensions/Navigation.kt index 1890cabce0..9c7b3cf106 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/Navigation.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/Navigation.kt @@ -4,6 +4,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentManager import com.tangem.tap.common.redux.navigation.AppScreen +import com.tangem.tap.features.details.ui.DetailsFragment import com.tangem.tap.features.home.HomeFragment import com.tangem.tap.features.send.ui.SendFragment import com.tangem.tap.features.wallet.ui.WalletFragment @@ -36,5 +37,6 @@ private fun fragmentFactory(screen: AppScreen): Fragment { AppScreen.Home -> HomeFragment() AppScreen.Wallet -> WalletFragment() AppScreen.Send -> SendFragment() + AppScreen.Details -> DetailsFragment() } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt b/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt index 0ce1e1e244..0a8ce24105 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt @@ -2,6 +2,7 @@ package com.tangem.tap.common.redux import com.tangem.tap.common.redux.global.globalReducer import com.tangem.tap.common.redux.navigation.NavigationReducer +import com.tangem.tap.features.details.redux.DetailsReducer import com.tangem.tap.features.send.redux.SendReducer import com.tangem.tap.features.wallet.redux.WalletReducer import org.rekotlin.Action @@ -11,10 +12,11 @@ fun appReducer(action: Action, state: AppState?): AppState { if (action is AppAction.RestoreState) return action.state return AppState( - navigationState = NavigationReducer.reduce(action, state), - globalState = globalReducer(action, state), - walletState = WalletReducer.reduce(action, state), - sendState = SendReducer.reduce(action, state.sendState) + navigationState = NavigationReducer.reduce(action, state), + globalState = globalReducer(action, state), + walletState = WalletReducer.reduce(action, state), + sendState = SendReducer.reduce(action, state.sendState), + detailsState = DetailsReducer.reduce(action, state) ) } diff --git a/app/src/main/java/com/tangem/tap/common/redux/AppState.kt b/app/src/main/java/com/tangem/tap/common/redux/AppState.kt index 045c802a04..4c153c1a85 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/AppState.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/AppState.kt @@ -3,6 +3,7 @@ package com.tangem.tap.common.redux import com.tangem.tap.common.redux.global.GlobalState import com.tangem.tap.common.redux.navigation.NavigationState import com.tangem.tap.common.redux.navigation.navigationMiddleware +import com.tangem.tap.features.details.redux.DetailsState import com.tangem.tap.features.home.redux.homeMiddleware import com.tangem.tap.features.send.redux.SendState import com.tangem.tap.features.send.redux.sendMiddleware @@ -16,6 +17,7 @@ data class AppState( val globalState: GlobalState = GlobalState(), val walletState: WalletState = WalletState(), val sendState: SendState = SendState(), + val detailsState: DetailsState = DetailsState() ) : StateType { companion object { diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt index 7fcff63909..c1b700abec 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt @@ -9,4 +9,4 @@ data class NavigationState( val activity: WeakReference? = null ) : StateType -enum class AppScreen { Home, Wallet, Send } \ No newline at end of file +enum class AppScreen { Home, Wallet, Send, Details } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsAction.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsAction.kt new file mode 100644 index 0000000000..01128b15c7 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsAction.kt @@ -0,0 +1,10 @@ +package com.tangem.tap.features.details.redux + +import com.tangem.commands.Card +import org.rekotlin.Action + +sealed class DetailsAction : Action { + + data class SetCard(val card: Card): DetailsAction() + +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsMiddleware.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsMiddleware.kt new file mode 100644 index 0000000000..78d6334eea --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsMiddleware.kt @@ -0,0 +1 @@ +package com.tangem.tap.features.details.redux diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt new file mode 100644 index 0000000000..711b3e67a9 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt @@ -0,0 +1,31 @@ +package com.tangem.tap.features.details.redux + +import com.tangem.commands.Card +import com.tangem.tap.common.redux.AppState +import org.rekotlin.Action + +class DetailsReducer { + companion object { + fun reduce(action: Action, state: AppState): DetailsState = internalReduce(action, state) + } +} + +private fun internalReduce(action: Action, state: AppState): DetailsState { + + if (action !is DetailsAction) return state.detailsState + + var detailsState = state.detailsState + when (action) { + is DetailsAction.SetCard -> { + detailsState = DetailsState(card = action.card, cardInfo = action.card.toCardInfo()) + } + } + return detailsState +} + +private fun Card.toCardInfo(): CardInfo? { + val cardId = this.cardId.chunked(4).joinToString(separator = " ") + val issuer = this.cardData?.issuerName ?: return null + val signedHashes = this.walletSignedHashes ?: return null + return CardInfo(cardId, issuer, signedHashes) +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsState.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsState.kt new file mode 100644 index 0000000000..0ef9e23e9a --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsState.kt @@ -0,0 +1,15 @@ +package com.tangem.tap.features.details.redux + +import com.tangem.commands.Card +import org.rekotlin.StateType + +data class DetailsState( + val card: Card? = null, + val cardInfo: CardInfo? = null +) : StateType + +data class CardInfo( + val cardId: String, + val issuer: String, + val signedHashes: Int +) diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt new file mode 100644 index 0000000000..8ba573d72a --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt @@ -0,0 +1,67 @@ +package com.tangem.tap.features.details.ui + +import android.os.Bundle +import android.view.View +import androidx.activity.OnBackPressedCallback +import androidx.fragment.app.Fragment +import androidx.transition.TransitionInflater +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 kotlinx.android.synthetic.main.fragment_details.* +import kotlinx.android.synthetic.main.fragment_wallet.toolbar +import org.rekotlin.StoreSubscriber + +class DetailsFragment : Fragment(R.layout.fragment_details), StoreSubscriber { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + activity?.onBackPressedDispatcher?.addCallback(this, object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + store.dispatch(NavigationAction.PopBackTo()) + } + }) + val inflater = TransitionInflater.from(requireContext()) + enterTransition = inflater.inflateTransition(R.transition.slide_right) + exitTransition = inflater.inflateTransition(R.transition.fade) + } + + override fun onStart() { + super.onStart() + store.subscribe(this) { state -> + state.skipRepeats { oldState, newState -> + oldState.detailsState == newState.detailsState + }.select { it.detailsState } + } + } + + override fun onStop() { + super.onStop() + store.unsubscribe(this) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + toolbar.setNavigationOnClickListener { + store.dispatch(NavigationAction.PopBackTo()) + } + } + + + + + + override fun newState(state: DetailsState) { + if (activity == null) return + + + if (state.cardInfo != null) { + tv_card_id.text = state.cardInfo.cardId + tv_issuer.text = state.cardInfo.issuer + tv_signed_hashes.text = state.cardInfo.signedHashes.toString() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt index d461023e6d..7a5016f045 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt @@ -3,8 +3,12 @@ package com.tangem.tap.features.wallet.ui import android.app.Dialog import android.graphics.Bitmap import android.os.Bundle +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.View import androidx.activity.OnBackPressedCallback +import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.transition.TransitionInflater @@ -12,7 +16,9 @@ import com.google.android.material.snackbar.Snackbar import com.tangem.tap.common.extensions.getDrawable import com.tangem.tap.common.extensions.hide import com.tangem.tap.common.extensions.show +import com.tangem.tap.common.redux.navigation.AppScreen import com.tangem.tap.common.redux.navigation.NavigationAction +import com.tangem.tap.features.details.redux.DetailsAction import com.tangem.tap.features.wallet.redux.* import com.tangem.tap.features.wallet.ui.dialogs.AmountToSendDialog import com.tangem.tap.features.wallet.ui.dialogs.PayIdDialog @@ -35,6 +41,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber { + store.state.globalState.scanNoteResponse?.card?.let { card -> + store.dispatch(DetailsAction.SetCard(card)) + store.dispatch(NavigationAction.NavigateTo(AppScreen.Details)) + true + } + false + } + else -> super.onOptionsItemSelected(item) + } + } + + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.wallet, menu) + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_details.xml b/app/src/main/res/layout/fragment_details.xml new file mode 100644 index 0000000000..792fa1942c --- /dev/null +++ b/app/src/main/res/layout/fragment_details.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_wallet.xml b/app/src/main/res/layout/fragment_wallet.xml index ccaf8611ff..1864b49550 100644 --- a/app/src/main/res/layout/fragment_wallet.xml +++ b/app/src/main/res/layout/fragment_wallet.xml @@ -21,6 +21,7 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:navigationIcon="@drawable/ic_baseline_arrow_back_24" + app:menu="@menu/wallet" app:title="@string/wallet_toolbar_title" /> diff --git a/app/src/main/res/menu/wallet.xml b/app/src/main/res/menu/wallet.xml new file mode 100644 index 0000000000..0f6a7ccd07 --- /dev/null +++ b/app/src/main/res/menu/wallet.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c8fa6038ac..d6ccd1164c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,4 +64,7 @@ Balance: %1s %2s Maximum amount + Details + + \ No newline at end of file