summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/history
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/history')
-rw-r--r--wallet/src/main/java/net/taler/wallet/history/DevHistoryAdapter.kt110
-rw-r--r--wallet/src/main/java/net/taler/wallet/history/DevHistoryFragment.kt87
-rw-r--r--wallet/src/main/java/net/taler/wallet/history/DevHistoryManager.kt75
-rw-r--r--wallet/src/main/java/net/taler/wallet/history/HistoryEvent.kt199
-rw-r--r--wallet/src/main/java/net/taler/wallet/history/JsonDialogFragment.kt57
5 files changed, 0 insertions, 528 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/history/DevHistoryAdapter.kt b/wallet/src/main/java/net/taler/wallet/history/DevHistoryAdapter.kt
deleted file mode 100644
index a2684e1..0000000
--- a/wallet/src/main/java/net/taler/wallet/history/DevHistoryAdapter.kt
+++ /dev/null
@@ -1,110 +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.content.Context
-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.recyclerview.widget.RecyclerView.Adapter
-import androidx.recyclerview.widget.RecyclerView.ViewHolder
-import net.taler.common.exhaustive
-import net.taler.common.toRelativeTime
-import net.taler.wallet.R
-import net.taler.wallet.history.DevHistoryAdapter.HistoryViewHolder
-import net.taler.wallet.transactions.AmountType
-
-internal class DevHistoryAdapter(
- private val listener: OnEventClickListener
-) : Adapter<HistoryViewHolder>() {
-
- private var history: List<HistoryEvent> = ArrayList()
-
- init {
- setHasStableIds(false)
- }
-
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryViewHolder {
- val view = LayoutInflater.from(parent.context)
- .inflate(R.layout.list_item_history, parent, false)
- return HistoryViewHolder(view)
- }
-
- override fun getItemCount(): Int = history.size
-
- override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) {
- val transaction = history[position]
- holder.bind(transaction)
- }
-
- fun update(updatedHistory: List<HistoryEvent>) {
- this.history = updatedHistory
- this.notifyDataSetChanged()
- }
-
- internal open inner class HistoryViewHolder(private val v: View) : ViewHolder(v) {
-
- protected val context: Context = v.context
-
- 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)
- private val amount: TextView = v.findViewById(R.id.amount)
-
- private val amountColor = amount.currentTextColor
-
- open fun bind(historyEvent: HistoryEvent) {
- v.setOnClickListener { listener.onTransactionClicked(historyEvent) }
- icon.setImageResource(historyEvent.icon)
- title.text = historyEvent.title
- time.text = historyEvent.timestamp.ms.toRelativeTime(context)
- bindAmount(historyEvent.displayAmount)
- }
-
- private fun bindAmount(displayAmount: DisplayAmount?) {
- if (displayAmount == null) {
- amount.visibility = GONE
- } else {
- amount.visibility = VISIBLE
- when (displayAmount.type) {
- AmountType.Positive -> {
- amount.text = context.getString(
- R.string.amount_positive, displayAmount.amount.amountStr
- )
- amount.setTextColor(context.getColor(R.color.green))
- }
- AmountType.Negative -> {
- amount.text = context.getString(
- R.string.amount_negative, displayAmount.amount.amountStr
- )
- amount.setTextColor(context.getColor(R.color.red))
- }
- AmountType.Neutral -> {
- amount.text = displayAmount.amount.amountStr
- amount.setTextColor(amountColor)
- }
- }.exhaustive
- }
- }
-
- }
-
-}
diff --git a/wallet/src/main/java/net/taler/wallet/history/DevHistoryFragment.kt b/wallet/src/main/java/net/taler/wallet/history/DevHistoryFragment.kt
deleted file mode 100644
index c3c07a3..0000000
--- a/wallet/src/main/java/net/taler/wallet/history/DevHistoryFragment.kt
+++ /dev/null
@@ -1,87 +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.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.VERTICAL
-import kotlinx.android.synthetic.main.fragment_transactions.*
-import net.taler.common.fadeIn
-import net.taler.common.fadeOut
-import net.taler.wallet.MainViewModel
-import net.taler.wallet.R
-
-internal interface OnEventClickListener {
- fun onTransactionClicked(historyEvent: HistoryEvent)
-}
-
-class DevHistoryFragment : Fragment(),
- OnEventClickListener {
-
- private val model: MainViewModel by activityViewModels()
- private val historyManager by lazy { model.historyManager }
- private val historyAdapter by lazy { DevHistoryAdapter(this) }
-
- override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View? {
- return inflater.inflate(R.layout.fragment_transactions, container, false)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- if (savedInstanceState == null) historyManager.loadHistory()
-
- list.apply {
- adapter = historyAdapter
- addItemDecoration(DividerItemDecoration(context, VERTICAL))
- }
- historyManager.progress.observe(viewLifecycleOwner, Observer { show ->
- progressBar.visibility = if (show) VISIBLE else INVISIBLE
- })
- historyManager.history.observe(viewLifecycleOwner, Observer { result ->
- onHistoryResult(result)
- })
- }
-
- override fun onTransactionClicked(historyEvent: HistoryEvent) {
- JsonDialogFragment.new(historyEvent.json.toString(2))
- .show(parentFragmentManager, null)
- }
-
- private fun onHistoryResult(result: HistoryResult) = when (result) {
- HistoryResult.Error -> {
- list.fadeOut()
- emptyState.text = getString(R.string.transactions_error)
- emptyState.fadeIn()
- }
- is HistoryResult.Success -> {
- emptyState.visibility = if (result.history.isEmpty()) VISIBLE else INVISIBLE
- historyAdapter.update(result.history)
- list.fadeIn()
- }
- }
-
-}
diff --git a/wallet/src/main/java/net/taler/wallet/history/DevHistoryManager.kt b/wallet/src/main/java/net/taler/wallet/history/DevHistoryManager.kt
deleted file mode 100644
index 9052d6e..0000000
--- a/wallet/src/main/java/net/taler/wallet/history/DevHistoryManager.kt
+++ /dev/null
@@ -1,75 +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 androidx.annotation.UiThread
-import androidx.lifecycle.LiveData
-import androidx.lifecycle.MutableLiveData
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.fasterxml.jackson.module.kotlin.readValue
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import net.taler.wallet.backend.WalletBackendApi
-import org.json.JSONObject
-import java.util.*
-
-sealed class HistoryResult {
- object Error : HistoryResult()
- class Success(val history: List<HistoryEvent>) : HistoryResult()
-}
-
-class DevHistoryManager(
- private val walletBackendApi: WalletBackendApi,
- private val scope: CoroutineScope,
- private val mapper: ObjectMapper
-) {
-
- private val mProgress = MutableLiveData<Boolean>()
- val progress: LiveData<Boolean> = mProgress
-
- private val mHistory = MutableLiveData<HistoryResult>()
- val history: LiveData<HistoryResult> = mHistory
-
- @UiThread
- internal fun loadHistory() {
- mProgress.value = true
- walletBackendApi.sendRequest("getHistory", null) { isError, result ->
- scope.launch(Dispatchers.Default) {
- onEventsLoaded(isError, result)
- }
- }
- }
-
- private fun onEventsLoaded(isError: Boolean, result: JSONObject) {
- if (isError) {
- mHistory.postValue(HistoryResult.Error)
- return
- }
- val history = LinkedList<HistoryEvent>()
- val json = result.getJSONArray("history")
- for (i in 0 until json.length()) {
- val event: HistoryEvent = mapper.readValue(json.getString(i))
- event.json = json.getJSONObject(i)
- history.add(event)
- }
- history.reverse() // show latest first
- mProgress.postValue(false)
- mHistory.postValue(HistoryResult.Success(history))
- }
-
-}
diff --git a/wallet/src/main/java/net/taler/wallet/history/HistoryEvent.kt b/wallet/src/main/java/net/taler/wallet/history/HistoryEvent.kt
deleted file mode 100644
index 3cbe7d7..0000000
--- a/wallet/src/main/java/net/taler/wallet/history/HistoryEvent.kt
+++ /dev/null
@@ -1,199 +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 androidx.annotation.DrawableRes
-import com.fasterxml.jackson.annotation.JsonSubTypes
-import com.fasterxml.jackson.annotation.JsonSubTypes.Type
-import com.fasterxml.jackson.annotation.JsonTypeInfo
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY
-import com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME
-import com.fasterxml.jackson.annotation.JsonTypeName
-import net.taler.common.Amount
-import net.taler.common.Timestamp
-import net.taler.wallet.R
-import net.taler.wallet.transactions.AmountType
-import org.json.JSONObject
-
-class DisplayAmount(
- val amount: Amount,
- val type: AmountType
-)
-
-@JsonTypeInfo(
- use = NAME,
- include = PROPERTY,
- property = "type",
- defaultImpl = UnknownHistoryEvent::class
-)
-/** 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"),
- Type(value = ReserveBalanceUpdatedHistoryEvent::class, name = "reserve-balance-updated"),
- Type(value = WithdrawHistoryEvent::class, name = "withdrawn"),
- Type(value = OrderAcceptedHistoryEvent::class, name = "order-accepted"),
- Type(value = OrderRefusedHistoryEvent::class, name = "order-refused"),
- Type(value = OrderRedirectedHistoryEvent::class, name = "order-redirected"),
- Type(value = PaymentHistoryEvent::class, name = "payment-sent"),
- Type(value = PaymentAbortedHistoryEvent::class, name = "payment-aborted"),
- Type(value = TipAcceptedHistoryEvent::class, name = "tip-accepted"),
- Type(value = TipDeclinedHistoryEvent::class, name = "tip-declined"),
- Type(value = RefundHistoryEvent::class, name = "refund"),
- Type(value = RefreshHistoryEvent::class, name = "refreshed")
-)
-abstract class HistoryEvent(
- val timestamp: Timestamp,
- val eventId: String,
- @get:DrawableRes
- open val icon: Int = R.drawable.ic_account_balance
-) {
- val title: String get() = this::class.java.simpleName
- open val displayAmount: DisplayAmount? = null
- lateinit var json: JSONObject
-}
-
-class UnknownHistoryEvent(timestamp: Timestamp, eventId: String) : HistoryEvent(timestamp, eventId)
-
-@JsonTypeName("exchange-added")
-class ExchangeAddedEvent(
- timestamp: Timestamp,
- eventId: String
-) : HistoryEvent(timestamp, eventId)
-
-@JsonTypeName("exchange-updated")
-class ExchangeUpdatedEvent(
- timestamp: Timestamp,
- eventId: String
-) : HistoryEvent(timestamp, eventId)
-
-@JsonTypeName("reserve-balance-updated")
-class ReserveBalanceUpdatedHistoryEvent(
- timestamp: Timestamp,
- eventId: String,
- val reserveBalance: Amount
-) : HistoryEvent(timestamp, eventId) {
- override val displayAmount = DisplayAmount(reserveBalance, AmountType.Neutral)
-}
-
-@JsonTypeName("withdrawn")
-class WithdrawHistoryEvent(
- timestamp: Timestamp,
- eventId: String,
- val amountWithdrawnEffective: Amount
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.transaction_withdrawal
- override val displayAmount = DisplayAmount(amountWithdrawnEffective, AmountType.Positive)
-}
-
-@JsonTypeName("order-accepted")
-class OrderAcceptedHistoryEvent(
- timestamp: Timestamp,
- eventId: String
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.ic_add_circle
-}
-
-@JsonTypeName("order-refused")
-class OrderRefusedHistoryEvent(
- timestamp: Timestamp,
- eventId: String
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.ic_cancel
-}
-
-@JsonTypeName("payment-sent")
-class PaymentHistoryEvent(
- timestamp: Timestamp,
- eventId: String,
- val amountPaidWithFees: Amount
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.ic_cash_usd_outline
- override val displayAmount = DisplayAmount(amountPaidWithFees, AmountType.Negative)
-}
-
-@JsonTypeName("payment-aborted")
-class PaymentAbortedHistoryEvent(
- timestamp: Timestamp,
- eventId: String,
- amountLost: Amount
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.transaction_payment_aborted
- override val displayAmount = DisplayAmount(amountLost, AmountType.Negative)
-}
-
-@JsonTypeName("refreshed")
-class RefreshHistoryEvent(
- timestamp: Timestamp,
- eventId: String,
- val amountRefreshedEffective: Amount,
- val amountRefreshedRaw: Amount
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.transaction_refresh
- override val displayAmount =
- DisplayAmount(amountRefreshedRaw - amountRefreshedEffective, AmountType.Negative)
-}
-
-@JsonTypeName("order-redirected")
-class OrderRedirectedHistoryEvent(
- timestamp: Timestamp,
- eventId: String
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.ic_directions
-}
-
-@JsonTypeName("tip-accepted")
-class TipAcceptedHistoryEvent(
- timestamp: Timestamp,
- eventId: String,
- tipRaw: Amount
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.transaction_tip_accepted
- override val displayAmount = DisplayAmount(tipRaw, AmountType.Positive)
-}
-
-@JsonTypeName("tip-declined")
-class TipDeclinedHistoryEvent(
- timestamp: Timestamp,
- eventId: String,
- tipAmount: Amount
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.transaction_tip_declined
- override val displayAmount = DisplayAmount(tipAmount, AmountType.Neutral)
-}
-
-@JsonTypeName("refund")
-class RefundHistoryEvent(
- timestamp: Timestamp,
- eventId: String,
- val amountRefundedEffective: Amount
-) : HistoryEvent(timestamp, eventId) {
- override val icon = R.drawable.transaction_refund
- override val displayAmount = DisplayAmount(amountRefundedEffective, AmountType.Positive)
-}
diff --git a/wallet/src/main/java/net/taler/wallet/history/JsonDialogFragment.kt b/wallet/src/main/java/net/taler/wallet/history/JsonDialogFragment.kt
deleted file mode 100644
index 31c2b93..0000000
--- a/wallet/src/main/java/net/taler/wallet/history/JsonDialogFragment.kt
+++ /dev/null
@@ -1,57 +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.View
-import android.view.ViewGroup
-import android.view.ViewGroup.LayoutParams.MATCH_PARENT
-import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
-import androidx.fragment.app.DialogFragment
-import kotlinx.android.synthetic.main.fragment_json.*
-import net.taler.wallet.R
-
-class JsonDialogFragment : DialogFragment() {
-
- companion object {
- fun new(json: String): JsonDialogFragment {
- return JsonDialogFragment().apply {
- arguments = Bundle().apply { putString("json", json) }
- }
- }
- }
-
- override fun onCreateView(
- inflater: LayoutInflater,
- container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View? {
- return inflater.inflate(R.layout.fragment_json, container, false)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- val json = requireArguments().getString("json")
- jsonView.text = json
- }
-
- override fun onStart() {
- super.onStart()
- dialog?.window?.setLayout(MATCH_PARENT, WRAP_CONTENT)
- }
-
-}