diff options
author | Torsten Grote <t@grobox.de> | 2020-03-04 16:14:29 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-03-04 16:14:29 -0300 |
commit | 1bbc48f7f9a893c13b07a5436a0b2b5f923de398 (patch) | |
tree | a84ba1a7fcc59c5a07dba7083e532726a9eea11a /app/src/main/java/net/taler/wallet/backend | |
parent | 30980bc83be99ea85205f44c815b78164b11f7b9 (diff) | |
download | wallet-android-1bbc48f7f9a893c13b07a5436a0b2b5f923de398.tar.gz wallet-android-1bbc48f7f9a893c13b07a5436a0b2b5f923de398.tar.bz2 wallet-android-1bbc48f7f9a893c13b07a5436a0b2b5f923de398.zip |
Move pending operations into their own fragment
They will be visible only in developer mode
and otherwise rendered nicely for the user where appropriate.
Diffstat (limited to 'app/src/main/java/net/taler/wallet/backend')
-rw-r--r-- | app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt index 8f37ff3..d447287 100644 --- a/app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +++ b/app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt @@ -22,21 +22,26 @@ import android.content.ComponentName import android.content.Context import android.content.Intent import android.content.ServiceConnection -import android.os.* +import android.os.Handler +import android.os.IBinder +import android.os.Message +import android.os.Messenger import android.util.Log import android.util.SparseArray import org.json.JSONObject import java.lang.ref.WeakReference import java.util.* -class WalletBackendApi(private val app: Application) { +class WalletBackendApi( + private val app: Application, + private val onConnected: (() -> Unit), + private val notificationHandler: (() -> Unit) +) { private var walletBackendMessenger: Messenger? = null private val queuedMessages = LinkedList<Message>() private val handlers = SparseArray<(isError: Boolean, message: JSONObject) -> Unit>() private var nextRequestID = 1 - var notificationHandler: (() -> Unit)? = null - var connectedHandler: (() -> Unit)? = null private val walletBackendConn = object : ServiceConnection { override fun onServiceDisconnected(p0: ComponentName?) { @@ -52,15 +57,12 @@ class WalletBackendApi(private val app: Application) { val msg = Message.obtain(null, WalletBackendService.MSG_SUBSCRIBE_NOTIFY) msg.replyTo = incomingMessenger bm.send(msg) - val ch = connectedHandler - if (ch != null) { - ch() - } + onConnected.invoke() } } private class IncomingHandler(strongApi: WalletBackendApi) : Handler() { - private val weakApi = WeakReference<WalletBackendApi>(strongApi) + private val weakApi = WeakReference(strongApi) override fun handleMessage(msg: Message) { val api = weakApi.get() ?: return when (msg.what) { @@ -83,10 +85,7 @@ class WalletBackendApi(private val app: Application) { h(isError, json) } WalletBackendService.MSG_NOTIFY -> { - val nh = api.notificationHandler - if (nh != null) { - nh() - } + api.notificationHandler.invoke() } } } @@ -139,4 +138,4 @@ class WalletBackendApi(private val app: Application) { companion object { const val TAG = "WalletBackendApi" } -}
\ No newline at end of file +} |