diff options
author | Torsten Grote <t@grobox.de> | 2020-08-11 09:41:40 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-08-11 09:41:40 -0300 |
commit | f0670e2f3936f0223c02e9ec0d0de52f31a3539f (patch) | |
tree | f50cfc07029a024f06b79ee6b5031f5ba668a0f5 /merchant-terminal/src/main/java/net/taler/merchantpos/history | |
parent | a20adabb2cfbaa2a78acac6560d81c27ca721731 (diff) | |
download | taler-android-f0670e2f3936f0223c02e9ec0d0de52f31a3539f.tar.gz taler-android-f0670e2f3936f0223c02e9ec0d0de52f31a3539f.tar.bz2 taler-android-f0670e2f3936f0223c02e9ec0d0de52f31a3539f.zip |
[pos] Improve coroutine-based merchant library access
Diffstat (limited to 'merchant-terminal/src/main/java/net/taler/merchantpos/history')
-rw-r--r-- | merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt index aabe4cc..d880eaa 100644 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt @@ -20,8 +20,8 @@ import androidx.annotation.UiThread import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import net.taler.common.assertUiThread import net.taler.merchantlib.MerchantApi import net.taler.merchantlib.OrderHistoryEntry import net.taler.merchantpos.config.ConfigManager @@ -44,20 +44,19 @@ class HistoryManager( val items: LiveData<HistoryResult> = mItems @UiThread - internal fun fetchHistory() { + internal fun fetchHistory() = scope.launch { mIsLoading.value = true val merchantConfig = configManager.merchantConfig!! - scope.launch(Dispatchers.IO) { - api.getOrderHistory(merchantConfig).handle(::onHistoryError) { - mIsLoading.postValue(false) - mItems.postValue(HistoryResult.Success(it.orders)) - } + api.getOrderHistory(merchantConfig).handle(::onHistoryError) { + assertUiThread() + mIsLoading.value = false + mItems.value = HistoryResult.Success(it.orders) } } private fun onHistoryError(msg: String) { - mIsLoading.postValue(false) - mItems.postValue(HistoryResult.Error(msg)) + assertUiThread() + mIsLoading.value = false + mItems.value = HistoryResult.Error(msg) } - } |