From 71be094780464c2b97a4cb6b33dd7f465647c082 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 7 Dec 2021 20:04:27 -0300 Subject: Set LiveData to be nullable after library update --- .../src/main/java/net/taler/merchantpos/order/LiveOrder.kt | 6 +++--- .../src/main/java/net/taler/merchantpos/order/OrderFragment.kt | 1 + .../src/main/java/net/taler/merchantpos/order/OrderStateFragment.kt | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'merchant-terminal') diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/order/LiveOrder.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/order/LiveOrder.kt index 10aabd4..f48c1db 100644 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/order/LiveOrder.kt +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/order/LiveOrder.kt @@ -31,7 +31,7 @@ import net.taler.merchantpos.order.RestartState.UNDO internal enum class RestartState { ENABLED, DISABLED, UNDO } internal interface LiveOrder { - val order: LiveData + val order: LiveData val orderTotal: LiveData val restartState: LiveData val modifyOrderAllowed: LiveData @@ -50,9 +50,9 @@ internal class MutableLiveOrder( ) : LiveOrder { private val availableCategories: Map get() = productsByCategory.keys.map { it.id to it }.toMap() - override val order: MutableLiveData = + override val order: MutableLiveData = MutableLiveData(Order(id, currency, availableCategories)) - override val orderTotal: LiveData = Transformations.map(order) { it.total } + override val orderTotal: LiveData = Transformations.map(order) { it?.total } override val restartState = MutableLiveData(DISABLED) private val selectedOrderLine = MutableLiveData() override val selectedProductKey: String? diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderFragment.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderFragment.kt index 1335b65..25a1874 100644 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderFragment.kt +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderFragment.kt @@ -75,6 +75,7 @@ class OrderFragment : Fragment() { private fun onOrderSwitched(orderId: Int, liveOrder: LiveOrder) { // order title liveOrder.order.observe(viewLifecycleOwner, { order -> + if (order == null) return@observe activity?.title = getString(R.string.order_label_title, order.title) }) // restart button diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderStateFragment.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderStateFragment.kt index 93c4f97..d86f504 100644 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderStateFragment.kt +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderStateFragment.kt @@ -83,6 +83,7 @@ class OrderStateFragment : Fragment() { } }) liveOrder.order.observe(viewLifecycleOwner, { order -> + if (order == null) return@observe onOrderChanged(order, tracker) }) liveOrder.orderTotal.observe(viewLifecycleOwner, { orderTotal -> -- cgit v1.2.3