diff options
author | Torsten Grote <t@grobox.de> | 2020-04-06 12:14:46 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-04-06 12:14:46 -0300 |
commit | 9ee202aebf6416bb336729cb3044e4921a94bee4 (patch) | |
tree | cb08740a3a71cfb3fa003872461ef8411bd52ee5 /wallet/src/main | |
parent | f1d4e51b7bddf93f12e431daf156025bb37222d1 (diff) | |
download | taler-android-9ee202aebf6416bb336729cb3044e4921a94bee4.tar.gz taler-android-9ee202aebf6416bb336729cb3044e4921a94bee4.tar.bz2 taler-android-9ee202aebf6416bb336729cb3044e4921a94bee4.zip |
[wallet] expose notification payloads to Android UI
also ignore ping notifications (to see if they are really needed)
Diffstat (limited to 'wallet/src/main')
5 files changed, 26 insertions, 28 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/WalletViewModel.kt b/wallet/src/main/java/net/taler/wallet/WalletViewModel.kt index fc17c7c..c16b6fc 100644 --- a/wallet/src/main/java/net/taler/wallet/WalletViewModel.kt +++ b/wallet/src/main/java/net/taler/wallet/WalletViewModel.kt @@ -47,16 +47,13 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) { val devMode = MutableLiveData(BuildConfig.DEBUG) val showProgressBar = MutableLiveData<Boolean>() - private var activeGetBalance = 0 - private val walletBackendApi = WalletBackendApi(app, { - activeGetBalance = 0 - loadBalances() - pendingOperationsManager.getPending() - }) { - Log.i(TAG, "Received notification from wallet-core") loadBalances() - pendingOperationsManager.getPending() + }) { payload -> + if (payload.getString("type") != "waiting-for-retry") { + Log.i(TAG, "Received notification from wallet-core: ${payload.toString(2)}") + loadBalances() + } } private val mapper = ObjectMapper() @@ -65,8 +62,7 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) { val withdrawManager = WithdrawManager(walletBackendApi) val paymentManager = PaymentManager(walletBackendApi, mapper) - val pendingOperationsManager: PendingOperationsManager = - PendingOperationsManager(walletBackendApi) + val pendingOperationsManager = PendingOperationsManager(walletBackendApi) val historyManager = HistoryManager(walletBackendApi, mapper) val refundManager = RefundManager(walletBackendApi) @@ -77,14 +73,10 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) { @UiThread fun loadBalances() { - if (activeGetBalance > 0) { - return - } - activeGetBalance++ showProgressBar.value = true walletBackendApi.sendRequest("getBalances", null) { isError, result -> - activeGetBalance-- if (isError) { + Log.e(TAG, "Error retrieving balances: ${result.toString(2)}") return@sendRequest } val balanceList = mutableListOf<BalanceItem>() diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt index d447287..3ffcd7b 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt @@ -35,7 +35,7 @@ import java.util.* class WalletBackendApi( private val app: Application, private val onConnected: (() -> Unit), - private val notificationHandler: (() -> Unit) + private val notificationHandler: ((payload: JSONObject) -> Unit) ) { private var walletBackendMessenger: Messenger? = null @@ -85,7 +85,13 @@ class WalletBackendApi( h(isError, json) } WalletBackendService.MSG_NOTIFY -> { - api.notificationHandler.invoke() + val payloadStr = msg.data.getString("payload") + if (payloadStr == null) { + Log.e(TAG, "Notification had no payload: $msg") + } else { + val payload = JSONObject(payloadStr) + api.notificationHandler.invoke(payload) + } } } } diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt index 0b71774..c0f7e9c 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt @@ -158,10 +158,12 @@ class WalletBackendService : Service() { return messenger.binder } - private fun sendNotify() { + private fun sendNotify(payload: String) { var rm: LinkedList<Messenger>? = null for (s in subscribers) { val m = Message.obtain(null, MSG_NOTIFY) + val b = m.data + b.putString("payload", payload) try { s.send(m) } catch (e: RemoteException) { @@ -184,7 +186,7 @@ class WalletBackendService : Service() { val message = JSONObject(messageStr) when (message.getString("type")) { "notification" -> { - sendNotify() + sendNotify(message.getString("payload")) } "tunnelHttp" -> { Log.v(TAG, "got http tunnel request!") @@ -197,8 +199,8 @@ class WalletBackendService : Service() { "response" -> { when (val operation = message.getString("operation")) { "init" -> { - Log.v(TAG, "got response for init operation") - sendNotify() + Log.v(TAG, "got response for init operation: ${message.toString(2)}") + sendNotify(message.toString(2)) } "reset" -> { exitProcess(1) diff --git a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt index 946e5ba..d8b0896 100644 --- a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt @@ -84,6 +84,11 @@ class PendingOperationsFragment : Fragment(), PendingOperationClickListener { }) } + override fun onStart() { + super.onStart() + pendingOperationsManager.getPending() + } + override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { R.id.retry_pending -> { diff --git a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt index 694c5da..6c58b81 100644 --- a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt +++ b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt @@ -29,17 +29,10 @@ open class PendingOperationInfo( class PendingOperationsManager(private val walletBackendApi: WalletBackendApi) { - private var activeGetPending = 0 - val pendingOperations = MutableLiveData<List<PendingOperationInfo>>() internal fun getPending() { - if (activeGetPending > 0) { - return - } - activeGetPending++ walletBackendApi.sendRequest("getPendingOperations", null) { isError, result -> - activeGetPending-- if (isError) { Log.i(TAG, "got getPending error result: $result") return@sendRequest |