summaryrefslogtreecommitdiff
path: root/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt
diff options
context:
space:
mode:
Diffstat (limited to 'merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt')
-rw-r--r--merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt19
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)
}
-
}