设备联调优化
This commit is contained in:
@@ -20,6 +20,7 @@ import com.shuwei.intelligent.shelves.HomeActivity.Companion.DEVICE_INFO_CMD
|
||||
import com.shuwei.intelligent.shelves.adapter.SearchAdapter
|
||||
import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||
import com.shuwei.intelligent.shelves.databinding.ActivityShelfBinding
|
||||
import com.shuwei.intelligent.shelves.model.ClearShelfEvent
|
||||
import com.shuwei.intelligent.shelves.model.GoodsModel
|
||||
import com.shuwei.intelligent.shelves.model.GoodsRecord
|
||||
import com.shuwei.intelligent.shelves.model.SendWeightEvent
|
||||
@@ -135,27 +136,17 @@ class ShelfActivity : BaseActivity() {
|
||||
finish()
|
||||
}
|
||||
binding.root.setOnClickListener { v ->
|
||||
KeyboardUtil.hideKeyboard(v.context, v)
|
||||
KeyboardUtil.hideKeyboard(v)
|
||||
}
|
||||
binding.btnClearZero.setOnClickListener { v ->
|
||||
lifecycleScope.launch {
|
||||
val shelfNo = shelfModel?.deviceNo ?: 0
|
||||
val hex = shelfNo.toString(16).padStart(2, '0').uppercase()
|
||||
Log.d(TAG, "onCreate: hex=$hex")
|
||||
val zeroClearingCmd = "${HomeActivity.HEADER}0401${hex}${HomeActivity.FOOTER}"
|
||||
Log.d(TAG, "onCreate: zeroClearingCmd=$zeroClearingCmd")
|
||||
SerialPortManager.send(zeroClearingCmd)
|
||||
//清零
|
||||
realWeight = 0
|
||||
// binding.tvFoodWeight.text = "${realWeight}克"
|
||||
|
||||
SerialPortManager.send(DEVICE_INFO_CMD)
|
||||
Loading.show(this@ShelfActivity)
|
||||
v.postDelayed({ Loading.dismiss() }, 5000)
|
||||
}
|
||||
KeyboardUtil.hideKeyboard(v.context, v)
|
||||
binding.btnClearZero.setOnClickListener {
|
||||
clearZero()
|
||||
}
|
||||
binding.btnClearEmpty?.setOnClickListener {
|
||||
clearZero()
|
||||
binding.tvFoodName.text = "-"
|
||||
binding.tvFoodWeight.text = "0克"
|
||||
EventBus.getDefault().post(ClearShelfEvent(shelfModel!!.deviceNo))
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
SerialPortManager.send(DEVICE_INFO_CMD)
|
||||
|
||||
@@ -219,45 +210,44 @@ class ShelfActivity : BaseActivity() {
|
||||
finishRefresh()
|
||||
binding.root.postDelayed({ Loading.dismiss() }, 200)
|
||||
Log.d(TAG, "updateUI: ${data.toJsonString()}")
|
||||
if (data.result !is GoodsRecord) {
|
||||
|
||||
val goodsList = data.data as MutableList<GoodsModel>
|
||||
if (data.data.isNullOrEmpty()) {
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
return
|
||||
}
|
||||
if (data.result.records.isNullOrEmpty()) {
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
return
|
||||
}
|
||||
var firstOne:GoodsModel?=null
|
||||
if (pageNo == 1) {
|
||||
if (shelfModel?.goodsId.isNullOrBlank().not()) {
|
||||
firstOne = list.firstOrNull { it.goodsId == shelfModel?.goodsId }
|
||||
if (firstOne == null) {
|
||||
firstOne = GoodsModel(
|
||||
goodsId = shelfModel?.goodsId,
|
||||
goodsName = shelfModel?.goodsName,
|
||||
isClicked = true
|
||||
)
|
||||
}
|
||||
}
|
||||
if(pageNo == 1){
|
||||
list.clear()
|
||||
}
|
||||
val records = data.result.records
|
||||
if (pageNo == 1) {
|
||||
firstOne?.let { one ->
|
||||
val filterResult = records.firstOrNull{one.goodsId == it.goodsId }
|
||||
if (filterResult != null) {
|
||||
records.remove(filterResult)
|
||||
}
|
||||
clickIndex = 0
|
||||
list.add(one)
|
||||
}
|
||||
}
|
||||
list.addAll(records)
|
||||
val enableLoadMore = records.size >= PAGE_SIZE
|
||||
// var firstOne:GoodsModel?=null
|
||||
// if (pageNo == 1) {
|
||||
// if (shelfModel?.goodsId.isNullOrBlank().not()) {
|
||||
// firstOne = list.firstOrNull { it.goodsId == shelfModel?.goodsId }
|
||||
// if (firstOne == null) {
|
||||
// firstOne = GoodsModel(
|
||||
// goodsId = shelfModel?.goodsId,
|
||||
// goodsName = shelfModel?.goodsName,
|
||||
// isClicked = true
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// list.clear()
|
||||
// }
|
||||
// val records = data.data.records
|
||||
// if (pageNo == 1) {
|
||||
// firstOne?.let { one ->
|
||||
// val filterResult = records.firstOrNull{one.goodsId == it.goodsId }
|
||||
// if (filterResult != null) {
|
||||
// records.remove(filterResult)
|
||||
// }
|
||||
// clickIndex = 0
|
||||
// list.add(one)
|
||||
// }
|
||||
// }
|
||||
list.addAll(goodsList)
|
||||
val enableLoadMore = goodsList.size >= PAGE_SIZE
|
||||
binding.refreshLayout.setEnableLoadMore(enableLoadMore)
|
||||
if (enableLoadMore) {
|
||||
pageNo++
|
||||
@@ -371,4 +361,23 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearZero() {
|
||||
lifecycleScope.launch {
|
||||
val shelfNo = shelfModel?.deviceNo ?: 0
|
||||
val hex = shelfNo.toString(16).padStart(2, '0').uppercase()
|
||||
Log.d(TAG, "onCreate: hex=$hex")
|
||||
val zeroClearingCmd = "${HomeActivity.HEADER}0401${hex}${HomeActivity.FOOTER}"
|
||||
Log.d(TAG, "onCreate: zeroClearingCmd=$zeroClearingCmd")
|
||||
SerialPortManager.send(zeroClearingCmd)
|
||||
//清零
|
||||
realWeight = 0
|
||||
// binding.tvFoodWeight.text = "${realWeight}克"
|
||||
|
||||
SerialPortManager.send(DEVICE_INFO_CMD)
|
||||
Loading.show(this@ShelfActivity)
|
||||
window.decorView.postDelayed({ Loading.dismiss() }, 5000)
|
||||
}
|
||||
KeyboardUtil.hideKeyboard(window.decorView)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user