summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2019-12-27 09:56:42 -0300
committerTorsten Grote <t@grobox.de>2019-12-27 09:56:42 -0300
commit89037988ca55cdd68e3be6294125b04ebfc50e77 (patch)
treee3ffefdece4adb423e834a2b84a2bca501543d51 /app/src/main/java
parentb1ae959666e2bdbdc6020e373c95e887fda13eb7 (diff)
downloadwallet-android-89037988ca55cdd68e3be6294125b04ebfc50e77.tar.gz
wallet-android-89037988ca55cdd68e3be6294125b04ebfc50e77.tar.bz2
wallet-android-89037988ca55cdd68e3be6294125b04ebfc50e77.zip
De-serialize first history events using Jackson
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/net/taler/wallet/WalletViewModel.kt8
-rw-r--r--app/src/main/java/net/taler/wallet/history/HistoryEvent.kt154
-rw-r--r--app/src/main/java/net/taler/wallet/history/ReserveTransaction.kt42
-rw-r--r--app/src/main/java/net/taler/wallet/history/WalletHistory.kt (renamed from app/src/main/java/net/taler/wallet/WalletHistory.kt)44
-rw-r--r--app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt41
5 files changed, 246 insertions, 43 deletions
diff --git a/app/src/main/java/net/taler/wallet/WalletViewModel.kt b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
index b933bf1..291321d 100644
--- a/app/src/main/java/net/taler/wallet/WalletViewModel.kt
+++ b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
@@ -20,8 +20,8 @@ import android.app.Application
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
-import com.google.android.material.snackbar.Snackbar
import net.taler.wallet.backend.WalletBackendApi
+import net.taler.wallet.history.HistoryEntry
import org.json.JSONObject
const val TAG = "taler-wallet"
@@ -98,12 +98,6 @@ open class HistoryResult(
val history: List<HistoryEntry>
)
-open class HistoryEntry(
- val detail: JSONObject,
- val type: String,
- val timestamp: JSONObject
-)
-
open class PendingOperationInfo(
val type: String,
val detail: JSONObject
diff --git a/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt b/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt
new file mode 100644
index 0000000..be48ac9
--- /dev/null
+++ b/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt
@@ -0,0 +1,154 @@
+package net.taler.wallet.history
+
+import com.fasterxml.jackson.annotation.*
+import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY
+import com.fasterxml.jackson.annotation.JsonSubTypes.Type
+import com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY
+import com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME
+import org.json.JSONObject
+
+open class HistoryEntry(
+ val detail: JSONObject,
+ val type: String,
+ val timestamp: JSONObject
+)
+
+enum class ReserveType {
+ /**
+ * Manually created.
+ */
+ @JsonProperty("manual")
+ MANUAL,
+ /**
+ * Withdrawn from a bank that has "tight" Taler integration
+ */
+ @JsonProperty("taler-bank-withdraw")
+ TALER_BANK_WITHDRAW,
+}
+
+@JsonInclude(NON_EMPTY)
+class ReserveCreationDetail(val type: ReserveType)
+
+
+@JsonInclude(NON_EMPTY)
+class Timestamp(
+ @JsonProperty("t_ms")
+ val ms: Long
+)
+
+@JsonInclude(NON_EMPTY)
+class ReserveShortInfo(
+ /**
+ * The exchange that the reserve will be at.
+ */
+ val exchangeBaseUrl: String,
+ /**
+ * Key to query more details
+ */
+ val reservePub: String,
+ /**
+ * Detail about how the reserve has been created.
+ */
+ val reserveCreationDetail: ReserveCreationDetail
+)
+
+class History: ArrayList<HistoryEvent>()
+
+@JsonTypeInfo(
+ use = NAME,
+ include = PROPERTY,
+ property = "type"
+)
+@JsonSubTypes(
+ Type(value = ExchangeAddedEvent::class, name = "exchange-added"),
+ Type(value = ExchangeUpdatedEvent::class, name = "exchange-updated"),
+ Type(value = ReserveBalanceUpdatedEvent::class, name = "reserve-balance-updated"),
+ Type(value = HistoryWithdrawnEvent::class, name = "withdrawn")
+)
+@JsonIgnoreProperties(
+ value = [
+ "eventId"
+ ]
+)
+abstract class HistoryEvent(
+ val timestamp: Timestamp
+)
+
+
+@JsonTypeName("exchange-added")
+class ExchangeAddedEvent(
+ timestamp: Timestamp,
+ val exchangeBaseUrl: String,
+ val builtIn: Boolean
+) : HistoryEvent(timestamp)
+
+@JsonTypeName("exchange-updated")
+class ExchangeUpdatedEvent(
+ timestamp: Timestamp,
+ val exchangeBaseUrl: String
+) : HistoryEvent(timestamp)
+
+
+@JsonTypeName("reserve-balance-updated")
+class ReserveBalanceUpdatedEvent(
+ timestamp: Timestamp,
+ val newHistoryTransactions: List<ReserveTransaction>,
+ /**
+ * Condensed information about the reserve.
+ */
+ val reserveShortInfo: ReserveShortInfo,
+ /**
+ * Amount currently left in the reserve.
+ */
+ val amountReserveBalance: String,
+ /**
+ * Amount we expected to be in the reserve at that time,
+ * considering ongoing withdrawals from that reserve.
+ */
+ val amountExpected: String
+) : HistoryEvent(timestamp)
+
+@JsonTypeName("withdrawn")
+class HistoryWithdrawnEvent(
+ timestamp: Timestamp,
+ /**
+ * Exchange that was withdrawn from.
+ */
+ val exchangeBaseUrl: String,
+ /**
+ * Unique identifier for the withdrawal session, can be used to
+ * query more detailed information from the wallet.
+ */
+ val withdrawSessionId: String,
+ val withdrawalSource: WithdrawalSource,
+ /**
+ * Amount that has been subtracted from the reserve's balance
+ * for this withdrawal.
+ */
+ val amountWithdrawnRaw: String,
+ /**
+ * Amount that actually was added to the wallet's balance.
+ */
+ val amountWithdrawnEffective: String
+) : HistoryEvent(timestamp)
+
+
+@JsonTypeInfo(
+ use = NAME,
+ include = PROPERTY,
+ property = "type"
+)
+@JsonSubTypes(
+ Type(value = WithdrawalSourceReserve::class, name = "reserve")
+)
+abstract class WithdrawalSource
+
+@JsonTypeName("tip")
+class WithdrawalSourceTip(
+ val tipId: String
+) : WithdrawalSource()
+
+@JsonTypeName("reserve")
+class WithdrawalSourceReserve(
+ val reservePub: String
+) : WithdrawalSource()
diff --git a/app/src/main/java/net/taler/wallet/history/ReserveTransaction.kt b/app/src/main/java/net/taler/wallet/history/ReserveTransaction.kt
new file mode 100644
index 0000000..880639f
--- /dev/null
+++ b/app/src/main/java/net/taler/wallet/history/ReserveTransaction.kt
@@ -0,0 +1,42 @@
+package net.taler.wallet.history
+
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.fasterxml.jackson.annotation.JsonSubTypes
+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
+
+
+@JsonTypeInfo(
+ use = NAME,
+ include = PROPERTY,
+ property = "type"
+)
+@JsonSubTypes(
+ JsonSubTypes.Type(value = ReserveDepositTransaction::class, name = "DEPOSIT")
+)
+abstract class ReserveTransaction
+
+
+@JsonTypeName("DEPOSIT")
+class ReserveDepositTransaction(
+ /**
+ * Amount withdrawn.
+ */
+ val amount: String,
+ /**
+ * Sender account payto://-URL
+ */
+ @JsonProperty("sender_account_url")
+ val senderAccountUrl: String,
+ /**
+ * Transfer details uniquely identifying the transfer.
+ */
+ @JsonProperty("wire_reference")
+ val wireReference: String,
+ /**
+ * Timestamp of the incoming wire transfer.
+ */
+ val timestamp: Timestamp
+) : ReserveTransaction()
diff --git a/app/src/main/java/net/taler/wallet/WalletHistory.kt b/app/src/main/java/net/taler/wallet/history/WalletHistory.kt
index b9db0c1..89c6b3f 100644
--- a/app/src/main/java/net/taler/wallet/WalletHistory.kt
+++ b/app/src/main/java/net/taler/wallet/history/WalletHistory.kt
@@ -14,49 +14,19 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-package net.taler.wallet
+package net.taler.wallet.history
import android.os.Bundle
import android.view.*
import androidx.fragment.app.Fragment
-import android.widget.TextView
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
-
-class WalletHistoryAdapter(private var myDataset: HistoryResult) : RecyclerView.Adapter<WalletHistoryAdapter.MyViewHolder>() {
-
- init {
- setHasStableIds(false)
- }
-
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
- val rowView = LayoutInflater.from(parent.context).inflate(R.layout.history_row, parent, false)
- return MyViewHolder(rowView)
- }
-
- override fun getItemCount(): Int {
- return myDataset.history.size
- }
-
- override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
- val h = myDataset.history[myDataset.history.size - position - 1]
- val text = holder.rowView.findViewById<TextView>(R.id.history_text)
- val subText = holder.rowView.findViewById<TextView>(R.id.history_subtext)
- text.text = h.type
- subText.text = h.timestamp.toString() + "\n" + h.detail.toString(1)
- }
-
- fun update(updatedHistory: HistoryResult) {
- this.myDataset = updatedHistory
- this.notifyDataSetChanged()
- }
-
- class MyViewHolder(val rowView: View) : RecyclerView.ViewHolder(rowView)
-}
-
+import net.taler.wallet.HistoryResult
+import net.taler.wallet.R
+import net.taler.wallet.WalletViewModel
/**
* Wallet history.
@@ -72,7 +42,9 @@ class WalletHistory : Fragment() {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
- historyAdapter = WalletHistoryAdapter(HistoryResult(listOf()))
+ historyAdapter = WalletHistoryAdapter(
+ HistoryResult(listOf())
+ )
model = activity?.run {
ViewModelProviders.of(this)[WalletViewModel::class.java]
@@ -96,7 +68,7 @@ class WalletHistory : Fragment() {
private fun updateHistory() {
model.getHistory {
- if (it.history.size == 0) {
+ if (it.history.isEmpty()) {
historyPlaceholder.visibility = View.VISIBLE
}
historyAdapter.update(it)
diff --git a/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt b/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt
new file mode 100644
index 0000000..46bca30
--- /dev/null
+++ b/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt
@@ -0,0 +1,41 @@
+package net.taler.wallet.history
+
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import androidx.recyclerview.widget.RecyclerView
+import net.taler.wallet.HistoryResult
+import net.taler.wallet.R
+
+
+class WalletHistoryAdapter(private var myDataset: HistoryResult) : RecyclerView.Adapter<WalletHistoryAdapter.MyViewHolder>() {
+
+ init {
+ setHasStableIds(false)
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
+ val rowView = LayoutInflater.from(parent.context).inflate(R.layout.history_row, parent, false)
+ return MyViewHolder(rowView)
+ }
+
+ override fun getItemCount(): Int {
+ return myDataset.history.size
+ }
+
+ override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
+ val h = myDataset.history[myDataset.history.size - position - 1]
+ val text = holder.rowView.findViewById<TextView>(R.id.history_text)
+ val subText = holder.rowView.findViewById<TextView>(R.id.history_subtext)
+ text.text = h.type
+ subText.text = h.timestamp.toString() + "\n" + h.detail.toString(1)
+ }
+
+ fun update(updatedHistory: HistoryResult) {
+ this.myDataset = updatedHistory
+ this.notifyDataSetChanged()
+ }
+
+ class MyViewHolder(val rowView: View) : RecyclerView.ViewHolder(rowView)
+}