diff options
author | Torsten Grote <t@grobox.de> | 2020-01-03 15:04:25 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-01-06 09:15:48 -0300 |
commit | 00596b872e5003f2a9ff8b4abc276f62759e653d (patch) | |
tree | 7d25c5ffae224d24e48b62ec5645b8d64bb3332c /app/src/main/java/net/taler/wallet | |
parent | 1e7ed72053dc5ad9a0f0264b3f154feee2cd7f35 (diff) | |
download | wallet-android-00596b872e5003f2a9ff8b4abc276f62759e653d.tar.gz wallet-android-00596b872e5003f2a9ff8b4abc276f62759e653d.tar.bz2 wallet-android-00596b872e5003f2a9ff8b4abc276f62759e653d.zip |
Implement more events and make ViewHolders more generic
Diffstat (limited to 'app/src/main/java/net/taler/wallet')
-rw-r--r-- | app/src/main/java/net/taler/wallet/history/HistoryEvent.kt | 122 | ||||
-rw-r--r-- | app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt | 92 |
2 files changed, 195 insertions, 19 deletions
diff --git a/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt b/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt index b21147a..24b7936 100644 --- a/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt +++ b/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt @@ -87,6 +87,19 @@ typealias History = ArrayList<HistoryEvent> include = PROPERTY, property = "type" ) +/** missing: +AuditorComplaintSent = "auditor-complained-sent", +AuditorComplaintProcessed = "auditor-complaint-processed", +AuditorTrustAdded = "auditor-trust-added", +AuditorTrustRemoved = "auditor-trust-removed", +ExchangeTermsAccepted = "exchange-terms-accepted", +ExchangePolicyChanged = "exchange-policy-changed", +ExchangeTrustAdded = "exchange-trust-added", +ExchangeTrustRemoved = "exchange-trust-removed", +FundsDepositedToSelf = "funds-deposited-to-self", +FundsRecouped = "funds-recouped", +ReserveCreated = "reserve-created", + */ @JsonSubTypes( Type(value = ExchangeAddedEvent::class, name = "exchange-added"), Type(value = ExchangeUpdatedEvent::class, name = "exchange-updated"), @@ -94,7 +107,12 @@ typealias History = ArrayList<HistoryEvent> Type(value = HistoryWithdrawnEvent::class, name = "withdrawn"), Type(value = HistoryOrderAcceptedEvent::class, name = "order-accepted"), Type(value = HistoryOrderRefusedEvent::class, name = "order-refused"), + Type(value = HistoryOrderRedirectedEvent::class, name = "order-redirected"), Type(value = HistoryPaymentSentEvent::class, name = "payment-sent"), + Type(value = HistoryPaymentAbortedEvent::class, name = "payment-aborted"), + Type(value = HistoryTipAcceptedEvent::class, name = "tip-accepted"), + Type(value = HistoryTipDeclinedEvent::class, name = "tip-declined"), + Type(value = HistoryRefundedEvent::class, name = "refund"), Type(value = HistoryRefreshedEvent::class, name = "refreshed") ) @JsonIgnoreProperties( @@ -176,7 +194,7 @@ class HistoryWithdrawnEvent( */ val amountWithdrawnEffective: String ) : HistoryEvent(timestamp) { - override val layout = R.layout.history_withdrawn + override val layout = R.layout.history_receive override val title = R.string.history_event_withdrawn override val icon = R.drawable.history_withdrawn override val showToUser = true @@ -231,12 +249,30 @@ class HistoryPaymentSentEvent( */ val sessionId: String? ) : HistoryEvent(timestamp) { - override val layout = R.layout.history_payment_sent + override val layout = R.layout.history_payment override val title = R.string.history_event_payment_sent override val icon = R.drawable.ic_cash_usd_outline override val showToUser = true } +@JsonTypeName("payment-aborted") +class HistoryPaymentAbortedEvent( + timestamp: Timestamp, + /** + * Condensed info about the order that we already paid for. + */ + val orderShortInfo: OrderShortInfo, + /** + * Amount that was lost due to refund and refreshing fees. + */ + val amountLost: String +) : HistoryEvent(timestamp) { + override val layout = R.layout.history_payment + override val title = R.string.history_event_payment_aborted + override val icon = R.drawable.history_payment_aborted + override val showToUser = true +} + @JsonTypeName("refreshed") class HistoryRefreshedEvent( timestamp: Timestamp, @@ -266,6 +302,88 @@ class HistoryRefreshedEvent( override val title = R.string.history_event_refreshed } +@JsonTypeName("order-redirected") +class HistoryOrderRedirectedEvent( + timestamp: Timestamp, + /** + * Condensed info about the new order that contains a + * product (identified by the fulfillment URL) that we've already paid for. + */ + val newOrderShortInfo: OrderShortInfo, + /** + * Condensed info about the order that we already paid for. + */ + val alreadyPaidOrderShortInfo: OrderShortInfo +) : HistoryEvent(timestamp) { + override val icon = R.drawable.ic_directions + override val title = R.string.history_event_order_redirected +} + +@JsonTypeName("tip-accepted") +class HistoryTipAcceptedEvent( + timestamp: Timestamp, + /** + * Unique identifier for the tip to query more information. + */ + val tipId: String, + /** + * Raw amount of the tip, without extra fees that apply. + */ + val tipRaw: String +) : HistoryEvent(timestamp) { + override val icon = R.drawable.history_tip_accepted + override val title = R.string.history_event_tip_accepted + override val layout = R.layout.history_receive + override val showToUser = true +} + +@JsonTypeName("tip-declined") +class HistoryTipDeclinedEvent( + timestamp: Timestamp, + /** + * Unique identifier for the tip to query more information. + */ + val tipId: String, + /** + * Raw amount of the tip, without extra fees that apply. + */ + val tipAmount: String +) : HistoryEvent(timestamp) { + override val icon = R.drawable.history_tip_declined + override val title = R.string.history_event_tip_declined + override val layout = R.layout.history_receive + override val showToUser = true +} + +@JsonTypeName("refund") +class HistoryRefundedEvent( + timestamp: Timestamp, + val orderShortInfo: OrderShortInfo, + /** + * Unique identifier for this refund. + * (Identifies multiple refund permissions that were obtained at once.) + */ + val refundGroupId: String, + /** + * Part of the refund that couldn't be applied because + * the refund permissions were expired. + */ + val amountRefundedInvalid: String, + /** + * Amount that has been refunded by the merchant. + */ + val amountRefundedRaw: String, + /** + * Amount will be added to the wallet's balance after fees and refreshing. + */ + val amountRefundedEffective: String +) : HistoryEvent(timestamp) { + override val icon = R.drawable.history_refund + override val title = R.string.history_event_refund + override val layout = R.layout.history_receive + override val showToUser = true +} + @JsonTypeInfo( use = NAME, include = PROPERTY, diff --git a/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt b/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt index 4cc35f7..5781f4f 100644 --- a/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt +++ b/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt @@ -16,15 +16,20 @@ package net.taler.wallet.history +import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG import android.text.format.DateUtils.* 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.wallet.ParsedAmount import net.taler.wallet.ParsedAmount.Companion.parseAmount import net.taler.wallet.R @@ -41,8 +46,8 @@ internal class WalletHistoryAdapter(private var history: History = History()) : override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryEventViewHolder { val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false) return when (viewType) { - R.layout.history_withdrawn -> HistoryWithdrawnViewHolder(view) - R.layout.history_payment_sent -> HistoryPaymentSentViewHolder(view) + R.layout.history_receive -> HistoryReceiveViewHolder(view) + R.layout.history_payment -> HistoryPaymentViewHolder(view) else -> GenericHistoryEventViewHolder(view) } } @@ -103,6 +108,7 @@ internal class GenericHistoryEventViewHolder(v: View) : HistoryEventViewHolder(v is HistoryPaymentSentEvent -> event.orderShortInfo.summary is HistoryOrderAcceptedEvent -> event.orderShortInfo.summary is HistoryOrderRefusedEvent -> event.orderShortInfo.summary + is HistoryOrderRedirectedEvent -> event.newOrderShortInfo.summary is HistoryRefreshedEvent -> { "${parseAmount(event.amountRefreshedRaw)} - ${parseAmount(event.amountRefreshedEffective)}" } @@ -112,46 +118,98 @@ internal class GenericHistoryEventViewHolder(v: View) : HistoryEventViewHolder(v } -internal class HistoryWithdrawnViewHolder(v: View) : HistoryEventViewHolder(v) { +internal class HistoryReceiveViewHolder(v: View) : HistoryEventViewHolder(v) { - private val exchangeUrl: TextView = v.findViewById(R.id.exchangeUrl) + 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) - event as HistoryWithdrawnEvent + 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) - exchangeUrl.text = event.exchangeBaseUrl val parsedEffective = parseAmount(event.amountWithdrawnEffective) val parsedRaw = parseAmount(event.amountWithdrawnRaw) - amountWithdrawn.text = "+${parsedRaw.toString()}" - val calculatedFee = parsedRaw - parsedEffective + showAmounts(parsedEffective, parsedRaw) + } + + private fun bind(event: HistoryRefundedEvent) { + title.text = event.orderShortInfo.summary + summary.setText(event.title) + + val parsedEffective = parseAmount(event.amountRefundedEffective) + val parsedRaw = parseAmount(event.amountRefundedRaw) + showAmounts(parsedEffective, parsedRaw) + } + + private fun bind(event: HistoryTipAcceptedEvent) { + title.setText(event.title) + summary.text = null + val amount = parseAmount(event.tipRaw) + showAmounts(amount, amount) + } + + private fun bind(event: HistoryTipDeclinedEvent) { + title.setText(event.title) + summary.text = null + val amount = parseAmount(event.tipAmount) + showAmounts(amount, amount) + amountWithdrawn.paintFlags = amountWithdrawn.paintFlags or STRIKE_THRU_TEXT_FLAG + } + + private fun showAmounts(effective: ParsedAmount, raw: ParsedAmount) { + amountWithdrawn.text = "+$raw" + val calculatedFee = raw - effective if (calculatedFee.isZero()) { - fee.visibility = View.GONE - feeLabel.visibility = View.GONE + fee.visibility = GONE + feeLabel.visibility = GONE } else { - fee.text = "-${calculatedFee.toString()}" - fee.visibility = View.VISIBLE - feeLabel.visibility = View.VISIBLE + fee.text = "-$calculatedFee" + fee.visibility = VISIBLE + feeLabel.visibility = VISIBLE } + amountWithdrawn.paintFlags = fee.paintFlags + } + + private fun getHostname(url: String): String { + return url.toUri().host!! } } -internal class HistoryPaymentSentViewHolder(v: View) : HistoryEventViewHolder(v) { +internal 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) - event as HistoryPaymentSentEvent + summary.setText(event.title) + when(event) { + is HistoryPaymentSentEvent -> bind(event) + is HistoryPaymentAbortedEvent -> bind(event) + } + } + private fun bind(event: HistoryPaymentSentEvent) { title.text = event.orderShortInfo.summary - summary.setText(event.title) - amountPaidWithFees.text = "-${parseAmount(event.amountPaidWithFees).toString()}" + amountPaidWithFees.text = "-${parseAmount(event.amountPaidWithFees)}" + } + + private fun bind(event: HistoryPaymentAbortedEvent) { + title.text = event.orderShortInfo.summary + amountPaidWithFees.text = "-${parseAmount(event.amountLost)}" } } |