aboutsummaryrefslogtreecommitdiff
path: root/wallet
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-05-15 12:57:42 -0300
committerTorsten Grote <t@grobox.de>2020-05-15 14:26:44 -0300
commit49b9fb9306addd4dc5540dfd08f0ced6d56050ec (patch)
tree39060a9341986dfedd243e612ff1604b363932c3 /wallet
parent6028376333344c90ba8dbaa75aad759b2915962d (diff)
downloadtaler-android-49b9fb9306addd4dc5540dfd08f0ced6d56050ec.tar.gz
taler-android-49b9fb9306addd4dc5540dfd08f0ced6d56050ec.tar.bz2
taler-android-49b9fb9306addd4dc5540dfd08f0ced6d56050ec.zip
[wallet] show currency's transaction list after successful operations
Diffstat (limited to 'wallet')
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainActivity.kt1
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainFragment.kt25
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainViewModel.kt13
-rw-r--r--wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt4
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt3
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt3
6 files changed, 36 insertions, 13 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index a6385a9..f626e4f 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -157,6 +157,7 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener {
model.showProgressBar.value = false
val res = when (status) {
is RefundStatus.Error -> R.string.refund_error
+ // TODO once wallet-core exposes currency, navigate to its transaction list
is RefundStatus.Success -> R.string.refund_success
}
Snackbar.make(nav_view, res, LENGTH_LONG).show()
diff --git a/wallet/src/main/java/net/taler/wallet/MainFragment.kt b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
index 2905238..328d7a2 100644
--- a/wallet/src/main/java/net/taler/wallet/MainFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
@@ -23,14 +23,20 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
+import androidx.navigation.fragment.findNavController
import kotlinx.android.synthetic.main.fragment_main.*
+import net.taler.common.EventObserver
+import net.taler.wallet.CurrencyMode.MULTI
+import net.taler.wallet.CurrencyMode.SINGLE
import net.taler.wallet.balances.BalancesFragment
import net.taler.wallet.transactions.TransactionsFragment
+enum class CurrencyMode { SINGLE, MULTI }
+
class MainFragment : Fragment() {
private val model: MainViewModel by activityViewModels()
- private var currentTag: String? = null
+ private var currencyMode: CurrencyMode? = null
override fun onCreateView(
inflater: LayoutInflater,
@@ -44,6 +50,13 @@ class MainFragment : Fragment() {
model.balances.observe(viewLifecycleOwner, Observer {
onBalancesChanged(it.values.toList())
})
+ model.transactionsEvent.observe(viewLifecycleOwner, EventObserver { currency ->
+ // we only need to navigate to a dedicated list, when in multi-currency mode
+ if (currencyMode == MULTI) {
+ model.transactionManager.selectedCurrency = currency
+ findNavController().navigate(R.id.action_nav_main_to_nav_transactions)
+ }
+ })
mainFab.setOnClickListener {
scanQrCode(requireActivity())
@@ -56,17 +69,17 @@ class MainFragment : Fragment() {
}
private fun onBalancesChanged(balances: List<BalanceItem>) {
- val tag = if (balances.size == 1) "single" else "multi"
- if (currentTag != tag) {
- val f = if (tag == "single") {
+ val mode = if (balances.size == 1) SINGLE else MULTI
+ if (currencyMode != mode) {
+ val f = if (mode == SINGLE) {
model.transactionManager.selectedCurrency = balances[0].available.currency
TransactionsFragment()
} else {
BalancesFragment()
}
- currentTag = tag
+ currencyMode = mode
childFragmentManager.beginTransaction()
- .replace(R.id.mainFragmentContainer, f, tag)
+ .replace(R.id.mainFragmentContainer, f, mode.name)
.commitNow()
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
index f10666e..6a1d6aa 100644
--- a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
@@ -28,7 +28,9 @@ import com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PRO
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import net.taler.common.Amount
+import net.taler.common.Event
import net.taler.common.assertUiThread
+import net.taler.common.toEvent
import net.taler.wallet.backend.WalletBackendApi
import net.taler.wallet.history.DevHistoryManager
import net.taler.wallet.payment.PaymentManager
@@ -99,6 +101,9 @@ class MainViewModel(val app: Application) : AndroidViewModel(app) {
TransactionManager(walletBackendApi, viewModelScope, mapper)
val refundManager = RefundManager(walletBackendApi)
+ private val mTransactionsEvent = MutableLiveData<Event<String>>()
+ val transactionsEvent: LiveData<Event<String>> = mTransactionsEvent
+
override fun onCleared() {
walletBackendApi.destroy()
super.onCleared()
@@ -129,6 +134,14 @@ class MainViewModel(val app: Application) : AndroidViewModel(app) {
}
}
+ /**
+ * Navigates to the given currency's transaction list, when [MainFragment] is shown.
+ */
+ @UiThread
+ fun showTransactions(currency: String) {
+ mTransactionsEvent.value = currency.toEvent()
+ }
+
@UiThread
fun dangerouslyReset() {
walletBackendApi.sendRequest("reset", null)
diff --git a/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt b/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt
index 0a2b29a..ab4077a 100644
--- a/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt
@@ -27,7 +27,6 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
-import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
import kotlinx.android.synthetic.main.fragment_balances.*
@@ -79,8 +78,7 @@ class BalancesFragment : Fragment(),
}
override fun onBalanceClick(currency: String) {
- model.transactionManager.selectedCurrency = currency
- findNavController().navigate(R.id.action_nav_main_to_nav_transactions)
+ model.showTransactions(currency)
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt
index ab109bc..6f806b7 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt
@@ -116,9 +116,8 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener {
is PayStatus.Success -> {
showLoading(false)
paymentManager.resetPayStatus()
- // TODO bring the user to the currency's transaction page, if there's more than one currency
- model.transactionManager.selectedCurrency = payStatus.currency
findNavController().navigate(R.id.action_promptPayment_to_nav_main)
+ model.showTransactions(payStatus.currency)
Snackbar.make(requireView(), R.string.payment_initiated, LENGTH_LONG).show()
}
is PayStatus.AlreadyPaid -> {
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
index e700f67..331554b 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
@@ -77,9 +77,8 @@ class PromptWithdrawFragment : Fragment() {
is WithdrawStatus.Success -> {
model.showProgressBar.value = false
withdrawManager.withdrawStatus.value = null
- // TODO bring the user to the currency's transaction page, if there's more than one currency
- model.transactionManager.selectedCurrency = status.currency
findNavController().navigate(R.id.action_promptWithdraw_to_nav_main)
+ model.showTransactions(status.currency)
Snackbar.make(requireView(), R.string.withdraw_initiated, LENGTH_LONG).show()
}
is Loading -> {