aboutsummaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java/net/taler')
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainActivity.kt10
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainFragment.kt81
-rw-r--r--wallet/src/main/java/net/taler/wallet/Utils.kt11
-rw-r--r--wallet/src/main/java/net/taler/wallet/balances/BalanceAdapter.kt (renamed from wallet/src/main/java/net/taler/wallet/BalanceAdapter.kt)6
-rw-r--r--wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt86
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt6
6 files changed, 123 insertions, 77 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index fa78b16..b6e9a7a 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -75,7 +75,7 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener {
setSupportActionBar(toolbar)
val appBarConfiguration = AppBarConfiguration(
- setOf(R.id.showBalance, R.id.settings, R.id.nav_pending_operations),
+ setOf(R.id.nav_main, R.id.nav_settings, R.id.nav_pending_operations),
drawer_layout
)
toolbar.setupWithNavController(nav, appBarConfiguration)
@@ -113,8 +113,8 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener {
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
- R.id.nav_home -> nav.navigate(R.id.showBalance)
- R.id.nav_settings -> nav.navigate(R.id.settings)
+ R.id.nav_home -> nav.navigate(R.id.nav_main)
+ R.id.nav_settings -> nav.navigate(R.id.nav_settings)
R.id.nav_pending_operations -> nav.navigate(R.id.nav_pending_operations)
}
drawer_layout.closeDrawer(START)
@@ -142,12 +142,12 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener {
when {
url.toLowerCase(ROOT).startsWith("taler://pay/") -> {
Log.v(TAG, "navigating!")
- nav.navigate(R.id.action_showBalance_to_promptPayment)
+ nav.navigate(R.id.action_nav_main_to_promptPayment)
model.paymentManager.preparePay(url)
}
url.toLowerCase(ROOT).startsWith("taler://withdraw/") -> {
Log.v(TAG, "navigating!")
- nav.navigate(R.id.action_showBalance_to_promptWithdraw)
+ nav.navigate(R.id.action_nav_main_to_promptWithdraw)
model.withdrawManager.getWithdrawalInfo(url)
}
url.toLowerCase(ROOT).startsWith("taler://refund/") -> {
diff --git a/wallet/src/main/java/net/taler/wallet/MainFragment.kt b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
index e0e6f51..0bc6084 100644
--- a/wallet/src/main/java/net/taler/wallet/MainFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
@@ -17,41 +17,20 @@
package net.taler.wallet
import android.os.Bundle
-import android.transition.TransitionManager.beginDelayedTransition
import android.view.LayoutInflater
-import android.view.Menu
-import android.view.MenuInflater
-import android.view.MenuItem
import android.view.View
-import android.view.View.GONE
-import android.view.View.VISIBLE
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
-import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
-import com.google.zxing.integration.android.IntentIntegrator
-import com.google.zxing.integration.android.IntentIntegrator.QR_CODE
import kotlinx.android.synthetic.main.fragment_main.*
+import net.taler.wallet.balances.BalancesFragment
+import net.taler.wallet.transactions.TransactionsFragment
-interface BalanceClickListener {
- fun onBalanceClick(currency: String)
-}
-
-class MainFragment : Fragment(), BalanceClickListener {
+class MainFragment : Fragment() {
private val model: MainViewModel by activityViewModels()
- private val balancesAdapter = BalanceAdapter(this)
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setHasOptionsMenu(true)
- }
-
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -61,18 +40,12 @@ class MainFragment : Fragment(), BalanceClickListener {
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- mainList.apply {
- layoutManager = LinearLayoutManager(context)
- adapter = balancesAdapter
- addItemDecoration(DividerItemDecoration(context, VERTICAL))
- }
-
model.balances.observe(viewLifecycleOwner, Observer {
onBalancesChanged(it.values.toList())
})
mainFab.setOnClickListener {
- onScanButtonClicked()
+ scanQrCode(requireActivity())
}
}
@@ -81,44 +54,18 @@ class MainFragment : Fragment(), BalanceClickListener {
model.loadBalances()
}
- override fun onOptionsItemSelected(item: MenuItem): Boolean {
- return when (item.itemId) {
- else -> super.onOptionsItemSelected(item)
- }
- }
-
- override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
- inflater.inflate(R.menu.fragment_main, menu)
- super.onCreateOptionsMenu(menu, inflater)
- }
-
- private fun onScanButtonClicked() {
- IntentIntegrator(activity).apply {
- setPrompt("")
- setBeepEnabled(true)
- setOrientationLocked(false)
- }.initiateScan(listOf(QR_CODE))
- }
-
private fun onBalancesChanged(balances: List<BalanceItem>) {
- delayedTransition()
- if (balances.isEmpty()) {
- mainEmptyState.visibility = VISIBLE
- mainList.visibility = GONE
- } else {
- balancesAdapter.setItems(balances)
- mainEmptyState.visibility = GONE
- mainList.visibility = VISIBLE
+ if (childFragmentManager.fragments.isEmpty()) {
+ val f = if (balances.size == 1) {
+ model.transactionManager.selectedCurrency = balances[0].available.currency
+ TransactionsFragment()
+ } else {
+ BalancesFragment()
+ }
+ childFragmentManager.beginTransaction()
+ .add(R.id.mainFragmentContainer, f)
+ .commitNow()
}
}
- private fun delayedTransition() {
- beginDelayedTransition(view as ViewGroup)
- }
-
- override fun onBalanceClick(currency: String) {
- model.transactionManager.selectedCurrency = currency
- findNavController().navigate(R.id.nav_transactions)
- }
-
}
diff --git a/wallet/src/main/java/net/taler/wallet/Utils.kt b/wallet/src/main/java/net/taler/wallet/Utils.kt
index ae8712f..b41a202 100644
--- a/wallet/src/main/java/net/taler/wallet/Utils.kt
+++ b/wallet/src/main/java/net/taler/wallet/Utils.kt
@@ -16,6 +16,17 @@
package net.taler.wallet
+import android.app.Activity
+import com.google.zxing.integration.android.IntentIntegrator
+
+fun scanQrCode(activity: Activity) {
+ IntentIntegrator(activity).apply {
+ setPrompt("")
+ setBeepEnabled(true)
+ setOrientationLocked(false)
+ }.initiateScan(listOf(IntentIntegrator.QR_CODE))
+}
+
fun cleanExchange(exchange: String) = exchange.let {
if (it.startsWith("https://")) it.substring(8) else it
}.trimEnd('/')
diff --git a/wallet/src/main/java/net/taler/wallet/BalanceAdapter.kt b/wallet/src/main/java/net/taler/wallet/balances/BalanceAdapter.kt
index b7b2ef0..0ccfeb2 100644
--- a/wallet/src/main/java/net/taler/wallet/BalanceAdapter.kt
+++ b/wallet/src/main/java/net/taler/wallet/balances/BalanceAdapter.kt
@@ -14,7 +14,7 @@
* GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-package net.taler.wallet
+package net.taler.wallet.balances
import android.view.LayoutInflater
import android.view.View
@@ -24,7 +24,9 @@ import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.Adapter
-import net.taler.wallet.BalanceAdapter.BalanceViewHolder
+import net.taler.wallet.BalanceItem
+import net.taler.wallet.R
+import net.taler.wallet.balances.BalanceAdapter.BalanceViewHolder
class BalanceAdapter(private val listener: BalanceClickListener) : Adapter<BalanceViewHolder>() {
diff --git a/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt b/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt
new file mode 100644
index 0000000..0a2b29a
--- /dev/null
+++ b/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt
@@ -0,0 +1,86 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.wallet.balances
+
+import android.os.Bundle
+import android.transition.TransitionManager.beginDelayedTransition
+import android.view.LayoutInflater
+import android.view.View
+import android.view.View.GONE
+import android.view.View.INVISIBLE
+import android.view.View.VISIBLE
+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.*
+import net.taler.common.fadeIn
+import net.taler.wallet.BalanceItem
+import net.taler.wallet.MainViewModel
+import net.taler.wallet.R
+
+interface BalanceClickListener {
+ fun onBalanceClick(currency: String)
+}
+
+class BalancesFragment : Fragment(),
+ BalanceClickListener {
+
+ private val model: MainViewModel by activityViewModels()
+
+ private val balancesAdapter = BalanceAdapter(this)
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ return inflater.inflate(R.layout.fragment_balances, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ mainList.apply {
+ adapter = balancesAdapter
+ addItemDecoration(DividerItemDecoration(context, VERTICAL))
+ }
+
+ model.balances.observe(viewLifecycleOwner, Observer {
+ onBalancesChanged(it.values.toList())
+ })
+ }
+
+ private fun onBalancesChanged(balances: List<BalanceItem>) {
+ beginDelayedTransition(view as ViewGroup)
+ if (balances.isEmpty()) {
+ mainEmptyState.visibility = VISIBLE
+ mainList.visibility = GONE
+ } else {
+ balancesAdapter.setItems(balances)
+ mainEmptyState.visibility = INVISIBLE
+ mainList.fadeIn()
+ }
+ }
+
+ override fun onBalanceClick(currency: String) {
+ model.transactionManager.selectedCurrency = currency
+ findNavController().navigate(R.id.action_nav_main_to_nav_transactions)
+ }
+
+}
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt
index 4f62547..0d6e9ce 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt
@@ -30,7 +30,6 @@ import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DividerItemDecoration
-import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
import kotlinx.android.synthetic.main.fragment_transactions.*
import net.taler.common.fadeIn
@@ -46,6 +45,7 @@ class TransactionsFragment : Fragment(), OnEventClickListener {
private val model: MainViewModel by activityViewModels()
private val transactionManager by lazy { model.transactionManager }
+
private val transactionAdapter by lazy { TransactionAdapter(model.devMode.value == true, this) }
private val currency by lazy { transactionManager.selectedCurrency!! }
@@ -63,7 +63,6 @@ class TransactionsFragment : Fragment(), OnEventClickListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
list.apply {
- layoutManager = LinearLayoutManager(context)
adapter = transactionAdapter
addItemDecoration(DividerItemDecoration(context, VERTICAL))
}
@@ -102,7 +101,7 @@ class TransactionsFragment : Fragment(), OnEventClickListener {
override fun onEventClicked(event: Transaction) {
if (event.detailPageLayout != 0) {
transactionManager.selectedEvent = event
- findNavController().navigate(R.id.action_nav_transactions_to_nav_transaction_detail)
+ findNavController().navigate(R.id.action_nav_transaction_detail)
} else if (model.devMode.value == true) {
JsonDialogFragment.new(event.json.toString(2))
.show(parentFragmentManager, null)
@@ -118,6 +117,7 @@ class TransactionsFragment : Fragment(), OnEventClickListener {
is TransactionsResult.Success -> {
emptyState.visibility = if (result.transactions.isEmpty()) VISIBLE else INVISIBLE
transactionAdapter.update(result.transactions)
+ list.fadeIn()
}
}