|
@@ -10,13 +10,13 @@ import androidx.lifecycle.ViewModel
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
import com.doverfuelingsolutions.issp.R
|
|
|
-import com.doverfuelingsolutions.issp.api.SystemApi
|
|
|
-import com.doverfuelingsolutions.issp.data.GlobalData
|
|
|
import com.doverfuelingsolutions.issp.databinding.FragmentNozzleOrdersBinding
|
|
|
import com.doverfuelingsolutions.issp.fusion.FusionManager
|
|
|
import com.doverfuelingsolutions.issp.utils.DFSToastUtil
|
|
|
+import com.doverfuelingsolutions.issp.utils.log.DFSLog
|
|
|
import com.doverfuelingsolutions.issp.utils.sp.SPUtil
|
|
|
import com.doverfuelingsolutions.issp.view.MainActivity
|
|
|
+import com.doverfuelingsolutions.issp.view.adapter.ChooseListAdapter
|
|
|
import com.doverfuelingsolutions.issp.view.adapter.OrderListAdapter
|
|
|
import com.scwang.smart.refresh.header.ClassicsHeader
|
|
|
import com.wayne.www.waynelib.fdc.message.DeviceClass
|
|
@@ -31,10 +31,21 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
private lateinit var binding: FragmentNozzleOrdersBinding
|
|
|
val viewModel = FragmentNozzleViewModel().apply {
|
|
|
pump.value = pumpId
|
|
|
+ isNozzle.value = pumpId != -1
|
|
|
}
|
|
|
|
|
|
private val orderList = arrayListOf<DeviceClass>()
|
|
|
- private val orderListAdapter = OrderListAdapter(orderList, this::select)
|
|
|
+ private val orderListAfterFilter = arrayListOf<DeviceClass>()
|
|
|
+ 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 })
|
|
|
+ private val chooseListAdapter: ChooseListAdapter by lazy {
|
|
|
+ ChooseListAdapter(
|
|
|
+ oilNameList,
|
|
|
+ this::selectOilName
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
@@ -44,12 +55,18 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
|
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
|
|
if (!this::binding.isInitialized) {
|
|
|
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_nozzle_orders, container, false)
|
|
|
|
|
|
- binding.orderList.layoutManager = GridLayoutManager(context, 2)
|
|
|
- binding.orderList.adapter = orderListAdapter
|
|
|
+ // 油品模式
|
|
|
+ if (pumpId == -1) {
|
|
|
+ binding.oilList.layoutManager = GridLayoutManager(context, 4)
|
|
|
+ binding.oilList.adapter = chooseListAdapter
|
|
|
+ }
|
|
|
+
|
|
|
+ binding.orderListView.layoutManager = GridLayoutManager(context, 2)
|
|
|
+ binding.orderListView.adapter = orderListAdapter
|
|
|
|
|
|
binding.smartRefreshLayout.setEnableLoadMore(false)
|
|
|
binding.smartRefreshLayout.setEnableRefresh(true)
|
|
@@ -64,31 +81,13 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
return binding.root
|
|
|
}
|
|
|
|
|
|
- private fun select(dc: DeviceClass) {
|
|
|
+ private fun selectOrder(dc: DeviceClass) {
|
|
|
lifecycleScope.launch {
|
|
|
when {
|
|
|
dc.releaseTokenElement == null || dc.releaseTokenAttribute == null -> {
|
|
|
DFSToastUtil.fail(R.string.wrong_order_info)
|
|
|
}
|
|
|
else -> {
|
|
|
- // 调试「锁单解锁」代码
|
|
|
- /*val position = orderList.indexOf(dc)
|
|
|
- val result = FusionManager.lockOrder(dc, !dc.isLock)
|
|
|
- if (result.success) {
|
|
|
- dc.state = if (dc.isLock) {
|
|
|
- SPUtil.unlockOrder(dc)
|
|
|
- ""
|
|
|
- } else {
|
|
|
- SPUtil.lockOrder(dc)
|
|
|
- "Locked"
|
|
|
- }
|
|
|
- orderListAdapter.notifyItemChanged(position)
|
|
|
- DFSToastUtil.success("操作成功")
|
|
|
- } else {
|
|
|
- DFSToastUtil.fail("操作失败")
|
|
|
- }
|
|
|
- return@launch*/
|
|
|
-
|
|
|
if (dc.isLock && !SPUtil.isLockByThis(dc)) {
|
|
|
DFSToastUtil.warn(R.string.order_lock_by_other)
|
|
|
} else {
|
|
@@ -99,6 +98,14 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun selectOilName(oilName: String, refreshView: Boolean = true) {
|
|
|
+ selectedName = oilName
|
|
|
+ filterOrderListByOilName()
|
|
|
+ if (refreshView) {
|
|
|
+ orderListAdapter.notifyDataSetChanged()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private fun handleRefresh() {
|
|
|
lifecycleScope.launch {
|
|
|
hideLoading()
|
|
@@ -108,7 +115,7 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
|
|
|
private suspend fun loadListData() {
|
|
|
if (orderList.isEmpty()) loading(R.string.in_get_order)
|
|
|
- if (this::binding.isInitialized) binding.orderList.scrollTo(0, 0)
|
|
|
+ if (this::binding.isInitialized) binding.orderListView.scrollTo(0, 0)
|
|
|
|
|
|
// -1 选油品,非 -1 选枪
|
|
|
// local cache
|
|
@@ -123,6 +130,7 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
}
|
|
|
sum.sortByDescending { it.releaseTokenAttribute }
|
|
|
orderList.addAll(sum)
|
|
|
+ selectOilName(oilNameList[0], false)
|
|
|
} else {
|
|
|
orderList.addAll(SPUtil.getOrderListByPump(pumpId))
|
|
|
}
|
|
@@ -149,6 +157,7 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
if (orderList.size != result.data.size || getOrderListHash(orderList) != getOrderListHash(result.data)) {
|
|
|
if (orderList.isNotEmpty()) orderList.clear()
|
|
|
orderList.addAll(result.data)
|
|
|
+ filterOrderListByOilName()
|
|
|
orderListAdapter.notifyDataSetChanged()
|
|
|
|
|
|
DFSToastUtil.success(R.string.data_refresh)
|
|
@@ -161,9 +170,14 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
|
|
|
return list.joinToString(",") { "${it.pumpNo}-${it.transactionSeqNo}" }
|
|
|
}
|
|
|
|
|
|
- class FragmentNozzleViewModel : ViewModel() {
|
|
|
+ private fun filterOrderListByOilName() {
|
|
|
+ if (orderListAfterFilter.isNotEmpty()) orderListAfterFilter.clear()
|
|
|
+ orderListAfterFilter.addAll(orderList.filter { it.productName == selectedName })
|
|
|
+ }
|
|
|
+
|
|
|
+ class FragmentNozzleViewModel() : ViewModel() {
|
|
|
val type = MutableLiveData(FragmentConstants.typeNozzle)
|
|
|
val pump = MutableLiveData(-1)
|
|
|
- val oilName = MutableLiveData("")
|
|
|
+ val isNozzle = MutableLiveData(true)
|
|
|
}
|
|
|
}
|