|
@@ -38,9 +38,13 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
private val orderListAdapter = OrderListAdapter(if (pumpId != -1) orderList else orderListAfterFilter, this::selectOrder)
|
|
|
|
|
|
private var selectedName = ""
|
|
|
- private val oilNameList: List<String> by lazyOf(FusionManager.pumpList.map { it.oilName }.filter { it.isNotBlank() })
|
|
|
- private val chooseListAdapter: ChooseListAdapter by lazy {
|
|
|
- ChooseListAdapter(oilNameList, this::selectOilName, true)
|
|
|
+ private val oilNameList = FusionManager.pumpList.map { it.oilName }.filter { it.isNotBlank() }
|
|
|
+ private val chooseListAdapter = ChooseListAdapter(oilNameList, this::selectOilName, true)
|
|
|
+
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
+
|
|
|
+ loadListData()
|
|
|
}
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
|
@@ -67,10 +71,6 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
setToolBar(binding.fragmentToolbar)
|
|
|
}
|
|
|
|
|
|
- lifecycleScope.launch {
|
|
|
- loadListData()
|
|
|
- }
|
|
|
-
|
|
|
return binding.root
|
|
|
}
|
|
|
|
|
@@ -106,35 +106,35 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private suspend fun loadListData() {
|
|
|
- val dialog = loading(R.string.in_get_order)
|
|
|
- binding.fragmentToolbar.stopCountdown()
|
|
|
-
|
|
|
- if (this::binding.isInitialized) binding.orderListView.scrollTo(0, 0)
|
|
|
+ private fun loadListData() {
|
|
|
+ lifecycleScope.launchWhenStarted {
|
|
|
+ val dialog = loading(R.string.in_get_order)
|
|
|
+ binding.fragmentToolbar.stopCountdown()
|
|
|
+ binding.orderListView.scrollTo(0, 0)
|
|
|
|
|
|
- // -1 选油品,非 -1 选枪
|
|
|
- // local cache
|
|
|
- if (orderList.isNotEmpty()) orderList.clear()
|
|
|
- if (pumpId == -1) {
|
|
|
- val allPumpOrderList = FusionManager.pumpList.map {
|
|
|
- SPUtil.getOrderListByPump(it.pumpId)
|
|
|
- }
|
|
|
- val sum = allPumpOrderList.reduce { acc, list ->
|
|
|
- acc.addAll(list)
|
|
|
- acc
|
|
|
+ // local cache
|
|
|
+ if (orderList.isNotEmpty()) orderList.clear()
|
|
|
+ if (pumpId == -1) {
|
|
|
+ val allPumpOrderList = FusionManager.pumpList.map {
|
|
|
+ SPUtil.getOrderListByPump(it.pumpId)
|
|
|
+ }
|
|
|
+ val sum = allPumpOrderList.reduce { acc, list ->
|
|
|
+ acc.addAll(list)
|
|
|
+ acc
|
|
|
+ }
|
|
|
+ sum.sortByDescending { it.releaseTokenAttribute }
|
|
|
+ orderList.addAll(sum)
|
|
|
+ selectOilName(oilNameList[0], false)
|
|
|
+ } else {
|
|
|
+ orderList.addAll(SPUtil.getOrderListByPump(pumpId))
|
|
|
}
|
|
|
- sum.sortByDescending { it.releaseTokenAttribute }
|
|
|
- orderList.addAll(sum)
|
|
|
- selectOilName(oilNameList[0], false)
|
|
|
- } else {
|
|
|
- orderList.addAll(SPUtil.getOrderListByPump(pumpId))
|
|
|
- }
|
|
|
- orderListAdapter.notifyDataSetChanged()
|
|
|
+ orderListAdapter.notifyDataSetChanged()
|
|
|
|
|
|
- // remote data
|
|
|
- loadRemoteData()
|
|
|
- dialog.dismiss()
|
|
|
- binding.fragmentToolbar.resumeCountdown()
|
|
|
+ // remote data
|
|
|
+ loadRemoteData()
|
|
|
+ dialog.dismiss()
|
|
|
+ binding.fragmentToolbar.resumeCountdown()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private suspend fun loadRemoteData() {
|