增加过期逻辑

This commit is contained in:
2025-08-15 17:59:40 +08:00
parent 2162ba0c9e
commit f8453c7d76
16 changed files with 211 additions and 62 deletions
@@ -1,16 +1,12 @@
package com.shuwei.intelligent.shelves
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.viewModels
import androidx.core.view.updateLayoutParams
import androidx.core.widget.addTextChangedListener
@@ -109,7 +105,7 @@ class ShelfActivity : BaseActivity() {
getGoodsList()
KeyboardUtil.hideKeyboard(context, this)
}
addTextChangedListener(afterTextChanged = {editable ->
addTextChangedListener(afterTextChanged = { editable ->
if (editable.isNullOrBlank()) {
pageNo = 1
getGoodsList()
@@ -122,12 +118,14 @@ class ShelfActivity : BaseActivity() {
toast("请选择食材")
return@clickWithDebounce
}
val currentGoodsId = list[clickIndex].goodsId ?: ""
val data = ShelfModel(
shelfName = shelfModel?.shelfName,
goodsId = list[clickIndex].goodsId ?: "",
goodsId = currentGoodsId,
goodsName = list[clickIndex].goodsName,
weight = realWeight / 1000.0,
createTime = DateTimeUtil.formatDateTime(dateTime = Date())
overdueDay = list[clickIndex].overdueDay,
createTime = if (shelfModel?.goodsId == currentGoodsId) null else DateTimeUtil.formatDateTime(dateTime = Date())
)
val intent = Intent().apply {
putExtra(SHELF_MODEL, data)
@@ -152,7 +150,7 @@ class ShelfActivity : BaseActivity() {
SerialPortManager.send(DEVICE_INFO_CMD)
Loading.show(this@ShelfActivity)
v.postDelayed({Loading.dismiss()}, 5000)
v.postDelayed({ Loading.dismiss() }, 5000)
}
KeyboardUtil.hideKeyboard(v.context, v)
}
@@ -173,7 +171,7 @@ class ShelfActivity : BaseActivity() {
}
// registerReceiver(receiver, IntentFilter(RECEIVER_DEVICE_INFO + shelfModel?.deviceNo))
binding.ivBack?.setOnClickListener { finish() }
binding.refreshLayout.let {
it.setEnableRefresh(true)
it.setEnableLoadMore(false)
@@ -232,10 +230,31 @@ class ShelfActivity : BaseActivity() {
}
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
)
}
}
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
binding.refreshLayout.setEnableLoadMore(enableLoadMore)
@@ -334,7 +353,7 @@ class ShelfActivity : BaseActivity() {
}
it.ivEmptyIcon.setImageResource(R.drawable.ic_empty_gray)
it.ivEmptyIcon.updateLayoutParams<LinearLayout.LayoutParams> {
val swDpValue = resources?.configuration?.smallestScreenWidthDp?:0
val swDpValue = resources?.configuration?.smallestScreenWidthDp ?: 0
width = if (swDpValue > 600) 200.dp else 120.dp
}
}
@@ -346,7 +365,7 @@ class ShelfActivity : BaseActivity() {
@Subscribe(threadMode = ThreadMode.MAIN)
public fun receiveWeightEvent(event: SendWeightEvent) {
if (event.shelfNo == (shelfModel?.deviceNo?:0)) {
if (event.shelfNo == (shelfModel?.deviceNo ?: 0)) {
binding.tvFoodWeight.text = "${event.weight}"
}
}