commit 7d7c273cc6b56c566b03156c17c3a159b66352aa
parent fd2df3498764a256342e8eecf5d39868e20df5b9
Author: Iván Ávalos <avalos@disroot.org>
Date: Fri, 15 Nov 2024 16:46:43 +0100
[android] QC: return to tx details from transfer details when tx is done
Diffstat:
5 files changed, 73 insertions(+), 40 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -84,6 +84,13 @@ class MainActivity : AppCompatActivity(), OnPreferenceStartFragmentCallback {
setSupportActionBar(ui.toolbar)
ui.toolbar.setupWithNavController(nav)
+ ui.toolbar.setNavigationOnClickListener {
+ if (onBackPressedDispatcher.hasEnabledCallbacks()) {
+ onBackPressedDispatcher.onBackPressed()
+ } else {
+ nav.navigateUp()
+ }
+ }
// TODO: refactor and unify progress bar handling
// model.showProgressBar.observe(this) { show ->
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
@@ -197,17 +197,7 @@ class PromptWithdrawFragment: Fragment() {
}
when (status.status) {
- ManualTransferRequired -> {
- if (!navigating) {
- navigating = true
- } else return@collect
-
- findNavController().navigate(
- R.id.action_promptWithdraw_to_nav_exchange_manual_withdrawal_success,
- )
- }
-
- Success -> lifecycleScope.launch {
+ Success, ManualTransferRequired -> lifecycleScope.launch {
Snackbar.make(requireView(), R.string.withdraw_initiated, LENGTH_LONG).show()
status.transactionId?.let {
if (!navigating) {
@@ -215,7 +205,11 @@ class PromptWithdrawFragment: Fragment() {
} else return@let
if (transactionManager.selectTransaction(it)) {
- findNavController().navigate(R.id.action_promptWithdraw_to_nav_transactions_detail_withdrawal)
+ if (status.status == Success) {
+ findNavController().navigate(R.id.action_promptWithdraw_to_nav_transactions_detail_withdrawal)
+ } else {
+ findNavController().navigate(R.id.action_promptWithdraw_to_nav_exchange_manual_withdrawal_success)
+ }
} else {
findNavController().navigate(R.id.action_promptWithdraw_to_nav_main)
}
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
@@ -501,6 +501,7 @@ class WithdrawManager(
) = status.copy(
status = ManualTransferRequired,
manualTransferResponse = response,
+ transactionId = response.transactionId,
withdrawalTransfers = response.withdrawalAccountsList.mapNotNull {
val details = status.amountInfo ?: error("no amountInfo")
val uri = Uri.parse(it.paytoUri.replace("receiver-name=", "receiver_name="))
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawSuccessFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawSuccessFragment.kt
@@ -20,55 +20,49 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import androidx.activity.compose.BackHandler
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.lifecycleScope
+import androidx.lifecycle.repeatOnLifecycle
+import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
+import kotlinx.coroutines.launch
import net.taler.common.openUri
import net.taler.common.shareText
import net.taler.wallet.MainViewModel
import net.taler.wallet.R
import net.taler.wallet.compose.TalerSurface
+import net.taler.wallet.compose.collectAsStateLifecycleAware
+import net.taler.wallet.transactions.Transaction
+import net.taler.wallet.transactions.TransactionMajorState.Done
import net.taler.wallet.withdraw.TransferData
-import net.taler.wallet.withdraw.WithdrawStatus
class ManualWithdrawSuccessFragment : Fragment() {
private val model: MainViewModel by activityViewModels()
private val withdrawManager by lazy { model.withdrawManager }
+ private val transactionManager by lazy { model.transactionManager }
private val balanceManager by lazy { model.balanceManager }
- private lateinit var status: WithdrawStatus
-
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View = ComposeView(requireContext()).apply {
- status = withdrawManager.withdrawStatus.value
-
- // Set action bar subtitle and unset on exit
- if (status.withdrawalTransfers.size > 1) {
- val activity = requireActivity() as AppCompatActivity
-
- activity.apply {
- supportActionBar?.subtitle = getString(R.string.withdraw_subtitle)
- }
-
- findNavController().addOnDestinationChangedListener { _, destination, _ ->
- if (destination.id != R.id.nav_exchange_manual_withdrawal_success) {
- activity.apply {
- supportActionBar?.subtitle = null
- }
- }
- }
- }
-
setContent {
TalerSurface {
+ val status by withdrawManager.withdrawStatus.collectAsStateLifecycleAware()
+ val selectedTx by transactionManager.selectedTransaction.collectAsStateLifecycleAware()
val qrCodes by withdrawManager.qrCodes.observeAsState()
+ BackHandler {
+ selectedTx?.let { navigateToDetails(it) }
+ }
+
ScreenTransfer(
status = status,
qrCodes = qrCodes ?: emptyList(),
@@ -81,6 +75,48 @@ class ManualWithdrawSuccessFragment : Fragment() {
}
}
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ lifecycleScope.launch {
+ repeatOnLifecycle(Lifecycle.State.STARTED) {
+ model.withdrawManager.withdrawStatus.collect { status ->
+ // Set action bar subtitle and unset on exit
+ if (status.withdrawalTransfers.size > 1) {
+ (requireActivity() as? AppCompatActivity)?.apply {
+ supportActionBar?.subtitle = getString(R.string.withdraw_subtitle)
+ }
+ }
+ }
+ }
+ }
+
+ lifecycleScope.launch {
+ repeatOnLifecycle(Lifecycle.State.STARTED) {
+ model.transactionManager.selectedTransaction.collect { tx ->
+ if (tx?.txState?.major == Done) {
+ navigateToDetails(tx)
+ }
+ }
+ }
+ }
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ (requireActivity() as? AppCompatActivity)?.apply {
+ supportActionBar?.subtitle = null
+ }
+ }
+
+ private fun navigateToDetails(tx: Transaction) {
+ val options = NavOptions.Builder()
+ .setPopUpTo(R.id.nav_main, false)
+ .build()
+ findNavController()
+ .navigate(tx.detailPageNav, null, options)
+ }
+
private fun onBankAppClick(transfer: TransferData) {
requireContext().openUri(
uri = transfer.withdrawalAccount.paytoUri,
@@ -93,9 +129,4 @@ class ManualWithdrawSuccessFragment : Fragment() {
text = transfer.withdrawalAccount.paytoUri,
)
}
-
- override fun onStart() {
- super.onStart()
- activity?.setTitle(R.string.withdraw_title)
- }
}
diff --git a/wallet/src/main/res/navigation/nav_graph.xml b/wallet/src/main/res/navigation/nav_graph.xml
@@ -103,7 +103,7 @@
<fragment
android:id="@+id/nav_exchange_manual_withdrawal_success"
android:name="net.taler.wallet.withdraw.manual.ManualWithdrawSuccessFragment"
- android:label="@string/withdraw_title">
+ android:label="@string/withdraw_manual_ready_details_intro">
<action
android:id="@+id/action_nav_exchange_manual_withdrawal_success_to_nav_main"
app:destination="@id/nav_main"