summaryrefslogtreecommitdiff
path: root/app/src/main/java/net/taler/wallet/WalletViewModel.kt
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2019-12-27 11:13:19 -0300
committerTorsten Grote <t@grobox.de>2019-12-27 11:13:19 -0300
commit35ba17db04f48f4ec41f55ac6944051093f7b78b (patch)
tree4f315cfc5ffe5d386eb7b8d86666ceefbc82fcc4 /app/src/main/java/net/taler/wallet/WalletViewModel.kt
parent89037988ca55cdd68e3be6294125b04ebfc50e77 (diff)
downloadwallet-android-35ba17db04f48f4ec41f55ac6944051093f7b78b.tar.gz
wallet-android-35ba17db04f48f4ec41f55ac6944051093f7b78b.tar.bz2
wallet-android-35ba17db04f48f4ec41f55ac6944051093f7b78b.zip
Use special layout for withdraw event in wallet history
This is how it could be done for all event types.
Diffstat (limited to 'app/src/main/java/net/taler/wallet/WalletViewModel.kt')
-rw-r--r--app/src/main/java/net/taler/wallet/WalletViewModel.kt27
1 files changed, 9 insertions, 18 deletions
diff --git a/app/src/main/java/net/taler/wallet/WalletViewModel.kt b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
index 291321d..94d2d8a 100644
--- a/app/src/main/java/net/taler/wallet/WalletViewModel.kt
+++ b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
@@ -20,8 +20,11 @@ import android.app.Application
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.kotlin.KotlinModule
+import com.fasterxml.jackson.module.kotlin.readValue
import net.taler.wallet.backend.WalletBackendApi
-import net.taler.wallet.history.HistoryEntry
+import net.taler.wallet.history.History
import org.json.JSONObject
const val TAG = "taler-wallet"
@@ -94,10 +97,6 @@ open class WithdrawStatus {
data class Withdrawing(val talerWithdrawUri: String) : WithdrawStatus()
}
-open class HistoryResult(
- val history: List<HistoryEntry>
-)
-
open class PendingOperationInfo(
val type: String,
val detail: JSONObject
@@ -138,6 +137,7 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
private var currentWithdrawRequestId = 0
private val walletBackendApi = WalletBackendApi(app)
+ private val mapper = ObjectMapper().registerModule(KotlinModule())
fun init() {
if (initialized) {
@@ -214,23 +214,14 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
}
}
- fun getHistory(cb: (r: HistoryResult) -> Unit) {
+ fun getHistory(cb: (r: History) -> Unit) {
walletBackendApi.sendRequest("getHistory", null) { isError, result ->
if (isError) {
+ // TODO show error message in [WalletHistory] fragment
return@sendRequest
}
- val historyEntries = mutableListOf<HistoryEntry>()
- val historyList = result.getJSONArray("history")
- for (i in 0 until historyList.length()) {
- val h = historyList.getJSONObject(i)
- Log.v(TAG, "got history entry $h")
- val type = h.getString("type")
- Log.v(TAG, "got history entry type $type")
- val detail = h
- val timestamp = h.getJSONObject("timestamp")
- historyEntries.add(HistoryEntry(detail, type, timestamp))
- }
- cb(HistoryResult(historyEntries))
+ val history: History = mapper.readValue(result.getString("history"))
+ cb(history)
}
}