commit 1dbc22f1faba07331953d761097d5ad91ffff5ce
parent 864160280872fdb400c2e0e61aaaa1b858fba3f8
Author: Torsten Grote <t@grobox.de>
Date: Tue, 24 Mar 2020 09:22:01 -0300
Fix Wallet QR code scanning and nightly version number display
Diffstat:
8 files changed, 403 insertions(+), 399 deletions(-)
diff --git a/wallet/build.gradle b/wallet/build.gradle
@@ -72,7 +72,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// QR codes
- implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
+ implementation 'com.journeyapps:zxing-android-embedded:4.0.2@aar'
// Nicer ProgressBar
implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1'
diff --git a/wallet/src/main/java/net/taler/wallet/BalanceFragment.kt b/wallet/src/main/java/net/taler/wallet/BalanceFragment.kt
@@ -37,7 +37,7 @@ import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.google.zxing.integration.android.IntentIntegrator
-import com.google.zxing.integration.android.IntentIntegrator.QR_CODE_TYPES
+import com.google.zxing.integration.android.IntentIntegrator.QR_CODE
import kotlinx.android.synthetic.main.fragment_show_balance.*
import net.taler.wallet.BalanceAdapter.BalanceViewHolder
@@ -92,7 +92,7 @@ class BalanceFragment : Fragment() {
setPrompt("")
setBeepEnabled(true)
setOrientationLocked(false)
- }.initiateScan(QR_CODE_TYPES)
+ }.initiateScan(listOf(QR_CODE))
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/history/HistoryAdapter.kt b/wallet/src/main/java/net/taler/wallet/history/HistoryAdapter.kt
@@ -0,0 +1,236 @@
+/*
+ * 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.history
+
+import android.annotation.SuppressLint
+import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG
+import android.text.format.DateUtils.DAY_IN_MILLIS
+import android.text.format.DateUtils.FORMAT_ABBREV_MONTH
+import android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE
+import android.text.format.DateUtils.FORMAT_NO_YEAR
+import android.text.format.DateUtils.FORMAT_SHOW_DATE
+import android.text.format.DateUtils.FORMAT_SHOW_TIME
+import android.text.format.DateUtils.MINUTE_IN_MILLIS
+import android.text.format.DateUtils.formatDateTime
+import android.text.format.DateUtils.getRelativeTimeSpanString
+import android.view.LayoutInflater
+import android.view.View
+import android.view.View.GONE
+import android.view.View.VISIBLE
+import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.TextView
+import androidx.annotation.CallSuper
+import androidx.core.net.toUri
+import androidx.recyclerview.widget.RecyclerView.Adapter
+import androidx.recyclerview.widget.RecyclerView.ViewHolder
+import net.taler.common.Amount
+import net.taler.wallet.BuildConfig
+import net.taler.wallet.R
+import net.taler.wallet.history.HistoryAdapter.HistoryEventViewHolder
+
+
+internal class HistoryAdapter(
+ private val listener: OnEventClickListener,
+ private var history: History = History()
+) : Adapter<HistoryEventViewHolder>() {
+
+ init {
+ setHasStableIds(false)
+ }
+
+ override fun getItemViewType(position: Int): Int = history[position].layout
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryEventViewHolder {
+ val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
+ return when (viewType) {
+ R.layout.history_receive -> HistoryReceiveViewHolder(view)
+ R.layout.history_payment -> HistoryPaymentViewHolder(view)
+ else -> GenericHistoryEventViewHolder(view)
+ }
+ }
+
+ override fun getItemCount(): Int = history.size
+
+ override fun onBindViewHolder(holder: HistoryEventViewHolder, position: Int) {
+ val event = history[position]
+ holder.bind(event)
+ }
+
+ fun update(updatedHistory: History) {
+ this.history = updatedHistory
+ this.notifyDataSetChanged()
+ }
+
+ internal abstract inner class HistoryEventViewHolder(protected val v: View) : ViewHolder(v) {
+
+ private val icon: ImageView = v.findViewById(R.id.icon)
+ protected val title: TextView = v.findViewById(R.id.title)
+ private val time: TextView = v.findViewById(R.id.time)
+
+ @CallSuper
+ open fun bind(event: HistoryEvent) {
+ if (BuildConfig.DEBUG) { // doesn't produce recycling issues, no need to cover all cases
+ v.setOnClickListener { listener.onEventClicked(event) }
+ } else {
+ v.background = null
+ }
+ icon.setImageResource(event.icon)
+ if (event.title == 0) title.text = event::class.java.simpleName
+ else title.setText(event.title)
+ time.text = getRelativeTime(event.timestamp.ms)
+ }
+
+ private fun getRelativeTime(timestamp: Long): CharSequence {
+ val now = System.currentTimeMillis()
+ return if (now - timestamp > DAY_IN_MILLIS * 2) {
+ formatDateTime(
+ v.context,
+ timestamp,
+ FORMAT_SHOW_TIME or FORMAT_SHOW_DATE or FORMAT_ABBREV_MONTH or FORMAT_NO_YEAR
+ )
+ } else {
+ getRelativeTimeSpanString(timestamp, now, MINUTE_IN_MILLIS, FORMAT_ABBREV_RELATIVE)
+ }
+ }
+
+ }
+
+ internal inner class GenericHistoryEventViewHolder(v: View) : HistoryEventViewHolder(v) {
+
+ private val info: TextView = v.findViewById(R.id.info)
+
+ override fun bind(event: HistoryEvent) {
+ super.bind(event)
+ info.text = when (event) {
+ is ExchangeAddedEvent -> event.exchangeBaseUrl
+ is ExchangeUpdatedEvent -> event.exchangeBaseUrl
+ is ReserveBalanceUpdatedEvent -> event.amountReserveBalance.toString()
+ is HistoryPaymentSentEvent -> event.orderShortInfo.summary
+ is HistoryOrderAcceptedEvent -> event.orderShortInfo.summary
+ is HistoryOrderRefusedEvent -> event.orderShortInfo.summary
+ is HistoryOrderRedirectedEvent -> event.newOrderShortInfo.summary
+ else -> ""
+ }
+ }
+
+ }
+
+ internal inner class HistoryReceiveViewHolder(v: View) : HistoryEventViewHolder(v) {
+
+ private val summary: TextView = v.findViewById(R.id.summary)
+ private val amountWithdrawn: TextView = v.findViewById(R.id.amountWithdrawn)
+ private val feeLabel: TextView = v.findViewById(R.id.feeLabel)
+ private val fee: TextView = v.findViewById(R.id.fee)
+
+ override fun bind(event: HistoryEvent) {
+ super.bind(event)
+ when (event) {
+ is HistoryWithdrawnEvent -> bind(event)
+ is HistoryRefundedEvent -> bind(event)
+ is HistoryTipAcceptedEvent -> bind(event)
+ is HistoryTipDeclinedEvent -> bind(event)
+ }
+ }
+
+ private fun bind(event: HistoryWithdrawnEvent) {
+ title.text = getHostname(event.exchangeBaseUrl)
+ summary.setText(event.title)
+
+ showAmounts(event.amountWithdrawnEffective, event.amountWithdrawnRaw)
+ }
+
+ private fun bind(event: HistoryRefundedEvent) {
+ title.text = event.orderShortInfo.summary
+ summary.setText(event.title)
+
+ showAmounts(event.amountRefundedEffective, event.amountRefundedRaw)
+ }
+
+ private fun bind(event: HistoryTipAcceptedEvent) {
+ title.setText(event.title)
+ summary.text = null
+ showAmounts(event.tipRaw, event.tipRaw)
+ }
+
+ private fun bind(event: HistoryTipDeclinedEvent) {
+ title.setText(event.title)
+ summary.text = null
+ showAmounts(event.tipAmount, event.tipAmount)
+ amountWithdrawn.paintFlags = amountWithdrawn.paintFlags or STRIKE_THRU_TEXT_FLAG
+ }
+
+ private fun showAmounts(effective: Amount, raw: Amount) {
+ @SuppressLint("SetTextI18n")
+ amountWithdrawn.text = "+$raw"
+ val calculatedFee = raw - effective
+ if (calculatedFee.isZero()) {
+ fee.visibility = GONE
+ feeLabel.visibility = GONE
+ } else {
+ @SuppressLint("SetTextI18n")
+ fee.text = "-$calculatedFee"
+ fee.visibility = VISIBLE
+ feeLabel.visibility = VISIBLE
+ }
+ amountWithdrawn.paintFlags = fee.paintFlags
+ }
+
+ private fun getHostname(url: String): String {
+ return url.toUri().host!!
+ }
+
+ }
+
+ internal inner class HistoryPaymentViewHolder(v: View) : HistoryEventViewHolder(v) {
+
+ private val summary: TextView = v.findViewById(R.id.summary)
+ private val amountPaidWithFees: TextView = v.findViewById(R.id.amountPaidWithFees)
+
+ override fun bind(event: HistoryEvent) {
+ super.bind(event)
+ summary.setText(event.title)
+ when (event) {
+ is HistoryPaymentSentEvent -> bind(event)
+ is HistoryPaymentAbortedEvent -> bind(event)
+ is HistoryRefreshedEvent -> bind(event)
+ }
+ }
+
+ private fun bind(event: HistoryPaymentSentEvent) {
+ title.text = event.orderShortInfo.summary
+ @SuppressLint("SetTextI18n")
+ amountPaidWithFees.text = "-${event.amountPaidWithFees}"
+ }
+
+ private fun bind(event: HistoryPaymentAbortedEvent) {
+ title.text = event.orderShortInfo.summary
+ @SuppressLint("SetTextI18n")
+ amountPaidWithFees.text = "-${event.amountLost}"
+ }
+
+ private fun bind(event: HistoryRefreshedEvent) {
+ title.text = ""
+ val fee = event.amountRefreshedRaw - event.amountRefreshedEffective
+ @SuppressLint("SetTextI18n")
+ if (fee.isZero()) amountPaidWithFees.text = null
+ else amountPaidWithFees.text = "-$fee"
+ }
+
+ }
+
+}
diff --git a/wallet/src/main/java/net/taler/wallet/history/HistoryFragment.kt b/wallet/src/main/java/net/taler/wallet/history/HistoryFragment.kt
@@ -0,0 +1,114 @@
+/*
+ * 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.history
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.Menu
+import android.view.MenuInflater
+import android.view.MenuItem
+import android.view.View
+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.recyclerview.widget.DividerItemDecoration
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
+import kotlinx.android.synthetic.main.fragment_show_history.*
+import net.taler.wallet.R
+import net.taler.wallet.WalletViewModel
+
+interface OnEventClickListener {
+ fun onEventClicked(event: HistoryEvent)
+}
+
+class HistoryFragment : Fragment(), OnEventClickListener {
+
+ private val model: WalletViewModel by activityViewModels()
+ private val historyManager by lazy { model.historyManager }
+ private lateinit var showAllItem: MenuItem
+ private var reloadHistoryItem: MenuItem? = null
+ private val historyAdapter = HistoryAdapter(this)
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setHasOptionsMenu(true)
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ return inflater.inflate(R.layout.fragment_show_history, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ historyList.apply {
+ layoutManager = LinearLayoutManager(context)
+ adapter = historyAdapter
+ addItemDecoration(DividerItemDecoration(context, VERTICAL))
+ }
+
+ model.devMode.observe(viewLifecycleOwner, Observer { enabled ->
+ reloadHistoryItem?.isVisible = enabled
+ })
+ historyManager.progress.observe(viewLifecycleOwner, Observer { show ->
+ historyProgressBar.visibility = if (show) VISIBLE else INVISIBLE
+ })
+ historyManager.history.observe(viewLifecycleOwner, Observer { history ->
+ historyEmptyState.visibility = if (history.isEmpty()) VISIBLE else INVISIBLE
+ historyAdapter.update(history)
+ })
+
+ // kicks off initial load, needs to be adapted if showAll state is ever saved
+ if (savedInstanceState == null) historyManager.showAll.value = model.devMode.value
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
+ inflater.inflate(R.menu.history, menu)
+ showAllItem = menu.findItem(R.id.show_all_history)
+ showAllItem.isChecked = historyManager.showAll.value == true
+ reloadHistoryItem = menu.findItem(R.id.reload_history).apply {
+ isVisible = model.devMode.value!!
+ }
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ return when (item.itemId) {
+ R.id.show_all_history -> {
+ item.isChecked = !item.isChecked
+ historyManager.showAll.value = item.isChecked
+ true
+ }
+ R.id.reload_history -> {
+ historyManager.showAll.value = showAllItem.isChecked
+ true
+ }
+ else -> super.onOptionsItemSelected(item)
+ }
+ }
+
+ override fun onEventClicked(event: HistoryEvent) {
+ if (model.devMode.value != true) return
+ JsonDialogFragment.new(event.json.toString(4))
+ .show(parentFragmentManager, null)
+ }
+
+}
diff --git a/wallet/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt b/wallet/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt
@@ -1,235 +0,0 @@
-/*
- * 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.history
-
-import android.annotation.SuppressLint
-import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG
-import android.text.format.DateUtils.DAY_IN_MILLIS
-import android.text.format.DateUtils.FORMAT_ABBREV_MONTH
-import android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE
-import android.text.format.DateUtils.FORMAT_NO_YEAR
-import android.text.format.DateUtils.FORMAT_SHOW_DATE
-import android.text.format.DateUtils.FORMAT_SHOW_TIME
-import android.text.format.DateUtils.MINUTE_IN_MILLIS
-import android.text.format.DateUtils.formatDateTime
-import android.text.format.DateUtils.getRelativeTimeSpanString
-import android.view.LayoutInflater
-import android.view.View
-import android.view.View.GONE
-import android.view.View.VISIBLE
-import android.view.ViewGroup
-import android.widget.ImageView
-import android.widget.TextView
-import androidx.annotation.CallSuper
-import androidx.core.net.toUri
-import androidx.recyclerview.widget.RecyclerView.Adapter
-import androidx.recyclerview.widget.RecyclerView.ViewHolder
-import net.taler.common.Amount
-import net.taler.wallet.BuildConfig
-import net.taler.wallet.R
-
-
-internal class WalletHistoryAdapter(
- private val listener: OnEventClickListener,
- private var history: History = History()
-) : Adapter<WalletHistoryAdapter.HistoryEventViewHolder>() {
-
- init {
- setHasStableIds(false)
- }
-
- override fun getItemViewType(position: Int): Int = history[position].layout
-
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryEventViewHolder {
- val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
- return when (viewType) {
- R.layout.history_receive -> HistoryReceiveViewHolder(view)
- R.layout.history_payment -> HistoryPaymentViewHolder(view)
- else -> GenericHistoryEventViewHolder(view)
- }
- }
-
- override fun getItemCount(): Int = history.size
-
- override fun onBindViewHolder(holder: HistoryEventViewHolder, position: Int) {
- val event = history[position]
- holder.bind(event)
- }
-
- fun update(updatedHistory: History) {
- this.history = updatedHistory
- this.notifyDataSetChanged()
- }
-
- internal abstract inner class HistoryEventViewHolder(protected val v: View) : ViewHolder(v) {
-
- private val icon: ImageView = v.findViewById(R.id.icon)
- protected val title: TextView = v.findViewById(R.id.title)
- private val time: TextView = v.findViewById(R.id.time)
-
- @CallSuper
- open fun bind(event: HistoryEvent) {
- if (BuildConfig.DEBUG) { // doesn't produce recycling issues, no need to cover all cases
- v.setOnClickListener { listener.onEventClicked(event) }
- } else {
- v.background = null
- }
- icon.setImageResource(event.icon)
- if (event.title == 0) title.text = event::class.java.simpleName
- else title.setText(event.title)
- time.text = getRelativeTime(event.timestamp.ms)
- }
-
- private fun getRelativeTime(timestamp: Long): CharSequence {
- val now = System.currentTimeMillis()
- return if (now - timestamp > DAY_IN_MILLIS * 2) {
- formatDateTime(
- v.context,
- timestamp,
- FORMAT_SHOW_TIME or FORMAT_SHOW_DATE or FORMAT_ABBREV_MONTH or FORMAT_NO_YEAR
- )
- } else {
- getRelativeTimeSpanString(timestamp, now, MINUTE_IN_MILLIS, FORMAT_ABBREV_RELATIVE)
- }
- }
-
- }
-
- internal inner class GenericHistoryEventViewHolder(v: View) : HistoryEventViewHolder(v) {
-
- private val info: TextView = v.findViewById(R.id.info)
-
- override fun bind(event: HistoryEvent) {
- super.bind(event)
- info.text = when (event) {
- is ExchangeAddedEvent -> event.exchangeBaseUrl
- is ExchangeUpdatedEvent -> event.exchangeBaseUrl
- is ReserveBalanceUpdatedEvent -> event.amountReserveBalance.toString()
- is HistoryPaymentSentEvent -> event.orderShortInfo.summary
- is HistoryOrderAcceptedEvent -> event.orderShortInfo.summary
- is HistoryOrderRefusedEvent -> event.orderShortInfo.summary
- is HistoryOrderRedirectedEvent -> event.newOrderShortInfo.summary
- else -> ""
- }
- }
-
- }
-
- internal inner class HistoryReceiveViewHolder(v: View) : HistoryEventViewHolder(v) {
-
- private val summary: TextView = v.findViewById(R.id.summary)
- private val amountWithdrawn: TextView = v.findViewById(R.id.amountWithdrawn)
- private val feeLabel: TextView = v.findViewById(R.id.feeLabel)
- private val fee: TextView = v.findViewById(R.id.fee)
-
- override fun bind(event: HistoryEvent) {
- super.bind(event)
- when (event) {
- is HistoryWithdrawnEvent -> bind(event)
- is HistoryRefundedEvent -> bind(event)
- is HistoryTipAcceptedEvent -> bind(event)
- is HistoryTipDeclinedEvent -> bind(event)
- }
- }
-
- private fun bind(event: HistoryWithdrawnEvent) {
- title.text = getHostname(event.exchangeBaseUrl)
- summary.setText(event.title)
-
- showAmounts(event.amountWithdrawnEffective, event.amountWithdrawnRaw)
- }
-
- private fun bind(event: HistoryRefundedEvent) {
- title.text = event.orderShortInfo.summary
- summary.setText(event.title)
-
- showAmounts(event.amountRefundedEffective, event.amountRefundedRaw)
- }
-
- private fun bind(event: HistoryTipAcceptedEvent) {
- title.setText(event.title)
- summary.text = null
- showAmounts(event.tipRaw, event.tipRaw)
- }
-
- private fun bind(event: HistoryTipDeclinedEvent) {
- title.setText(event.title)
- summary.text = null
- showAmounts(event.tipAmount, event.tipAmount)
- amountWithdrawn.paintFlags = amountWithdrawn.paintFlags or STRIKE_THRU_TEXT_FLAG
- }
-
- private fun showAmounts(effective: Amount, raw: Amount) {
- @SuppressLint("SetTextI18n")
- amountWithdrawn.text = "+$raw"
- val calculatedFee = raw - effective
- if (calculatedFee.isZero()) {
- fee.visibility = GONE
- feeLabel.visibility = GONE
- } else {
- @SuppressLint("SetTextI18n")
- fee.text = "-$calculatedFee"
- fee.visibility = VISIBLE
- feeLabel.visibility = VISIBLE
- }
- amountWithdrawn.paintFlags = fee.paintFlags
- }
-
- private fun getHostname(url: String): String {
- return url.toUri().host!!
- }
-
- }
-
- internal inner class HistoryPaymentViewHolder(v: View) : HistoryEventViewHolder(v) {
-
- private val summary: TextView = v.findViewById(R.id.summary)
- private val amountPaidWithFees: TextView = v.findViewById(R.id.amountPaidWithFees)
-
- override fun bind(event: HistoryEvent) {
- super.bind(event)
- summary.setText(event.title)
- when (event) {
- is HistoryPaymentSentEvent -> bind(event)
- is HistoryPaymentAbortedEvent -> bind(event)
- is HistoryRefreshedEvent -> bind(event)
- }
- }
-
- private fun bind(event: HistoryPaymentSentEvent) {
- title.text = event.orderShortInfo.summary
- @SuppressLint("SetTextI18n")
- amountPaidWithFees.text = "-${event.amountPaidWithFees}"
- }
-
- private fun bind(event: HistoryPaymentAbortedEvent) {
- title.text = event.orderShortInfo.summary
- @SuppressLint("SetTextI18n")
- amountPaidWithFees.text = "-${event.amountLost}"
- }
-
- private fun bind(event: HistoryRefreshedEvent) {
- title.text = ""
- val fee = event.amountRefreshedRaw - event.amountRefreshedEffective
- @SuppressLint("SetTextI18n")
- if (fee.isZero()) amountPaidWithFees.text = null
- else amountPaidWithFees.text = "-$fee"
- }
-
- }
-
-}
diff --git a/wallet/src/main/java/net/taler/wallet/history/WalletHistoryFragment.kt b/wallet/src/main/java/net/taler/wallet/history/WalletHistoryFragment.kt
@@ -1,114 +0,0 @@
-/*
- * 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.history
-
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.Menu
-import android.view.MenuInflater
-import android.view.MenuItem
-import android.view.View
-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.recyclerview.widget.DividerItemDecoration
-import androidx.recyclerview.widget.LinearLayoutManager
-import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
-import kotlinx.android.synthetic.main.fragment_show_history.*
-import net.taler.wallet.R
-import net.taler.wallet.WalletViewModel
-
-interface OnEventClickListener {
- fun onEventClicked(event: HistoryEvent)
-}
-
-class WalletHistoryFragment : Fragment(), OnEventClickListener {
-
- private val model: WalletViewModel by activityViewModels()
- private val historyManager by lazy { model.historyManager }
- private lateinit var showAllItem: MenuItem
- private var reloadHistoryItem: MenuItem? = null
- private val historyAdapter = WalletHistoryAdapter(this)
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setHasOptionsMenu(true)
- }
-
- override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View? {
- return inflater.inflate(R.layout.fragment_show_history, container, false)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- historyList.apply {
- layoutManager = LinearLayoutManager(context)
- adapter = historyAdapter
- addItemDecoration(DividerItemDecoration(context, VERTICAL))
- }
-
- model.devMode.observe(viewLifecycleOwner, Observer { enabled ->
- reloadHistoryItem?.isVisible = enabled
- })
- historyManager.progress.observe(viewLifecycleOwner, Observer { show ->
- historyProgressBar.visibility = if (show) VISIBLE else INVISIBLE
- })
- historyManager.history.observe(viewLifecycleOwner, Observer { history ->
- historyEmptyState.visibility = if (history.isEmpty()) VISIBLE else INVISIBLE
- historyAdapter.update(history)
- })
-
- // kicks off initial load, needs to be adapted if showAll state is ever saved
- if (savedInstanceState == null) historyManager.showAll.value = model.devMode.value
- }
-
- override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
- inflater.inflate(R.menu.history, menu)
- showAllItem = menu.findItem(R.id.show_all_history)
- showAllItem.isChecked = historyManager.showAll.value == true
- reloadHistoryItem = menu.findItem(R.id.reload_history).apply {
- isVisible = model.devMode.value!!
- }
- }
-
- override fun onOptionsItemSelected(item: MenuItem): Boolean {
- return when (item.itemId) {
- R.id.show_all_history -> {
- item.isChecked = !item.isChecked
- historyManager.showAll.value = item.isChecked
- true
- }
- R.id.reload_history -> {
- historyManager.showAll.value = showAllItem.isChecked
- true
- }
- else -> super.onOptionsItemSelected(item)
- }
- }
-
- override fun onEventClicked(event: HistoryEvent) {
- if (model.devMode.value != true) return
- JsonDialogFragment.new(event.json.toString(4))
- .show(parentFragmentManager, null)
- }
-
-}
diff --git a/wallet/src/main/res/layout/nav_header_main.xml b/wallet/src/main/res/layout/nav_header_main.xml
@@ -15,59 +15,62 @@
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/side_nav_bar"
- android:theme="@style/ThemeOverlay.AppCompat.Dark">
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="@drawable/side_nav_bar"
+ android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
- android:id="@+id/talerLogoView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:contentDescription="@string/nav_header_desc"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:srcCompat="@mipmap/ic_launcher_round" />
+ android:id="@+id/talerLogoView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:contentDescription="@string/nav_header_desc"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
- android:id="@+id/gnuView"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginStart="16dp"
- android:layout_marginTop="8dp"
- android:layout_marginEnd="16dp"
- android:text="@string/nav_header_title"
- android:textAppearance="@style/TextAppearance.AppCompat.Body1"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/talerLogoView" />
+ android:id="@+id/gnuView"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginTop="8dp"
+ android:layout_marginEnd="16dp"
+ android:text="@string/nav_header_title"
+ android:textAppearance="@style/TextAppearance.AppCompat.Body1"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/talerLogoView" />
<TextView
- android:id="@+id/walletView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="16dp"
- android:layout_marginTop="4dp"
- android:layout_marginBottom="16dp"
- android:text="@string/nav_header_subtitle"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/gnuView" />
+ android:id="@+id/walletView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginTop="4dp"
+ android:layout_marginBottom="16dp"
+ android:text="@string/nav_header_subtitle"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/gnuView" />
<TextView
- android:id="@+id/versionView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginEnd="16dp"
- app:layout_constraintBottom_toBottomOf="@+id/walletView"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.0"
- app:layout_constraintStart_toEndOf="@+id/walletView"
- app:layout_constraintTop_toTopOf="@+id/walletView"
- tools:text="0.6.9-pre15" />
+ android:id="@+id/versionView"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:layout_marginEnd="16dp"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:singleLine="true"
+ app:layout_constraintBottom_toBottomOf="@+id/walletView"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.0"
+ app:layout_constraintStart_toEndOf="@+id/walletView"
+ app:layout_constraintTop_toTopOf="@+id/walletView"
+ tools:text="0.6.9-pre15 (eae45ae4e3) (1231242342352245345345345345)" />
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/wallet/src/main/res/navigation/nav_graph.xml b/wallet/src/main/res/navigation/nav_graph.xml
@@ -59,7 +59,7 @@
tools:layout="@layout/fragment_settings" />
<fragment
android:id="@+id/walletHistory"
- android:name="net.taler.wallet.history.WalletHistoryFragment"
+ android:name="net.taler.wallet.history.HistoryFragment"
android:label="@string/history_title"
tools:layout="@layout/fragment_show_history" />
<fragment