功能优化

This commit is contained in:
2025-09-17 09:58:33 +08:00
parent 812b95575e
commit 77b89c7009
8 changed files with 88 additions and 126 deletions
@@ -46,7 +46,7 @@ class BottomDialog2(
private var clickName: String? = null private var clickName: String? = null
) { ) {
companion object { companion object {
const val TAG = "BottomDialog" const val TAG = "BottomDialog2"
} }
private val goodsType: Int = 1 private val goodsType: Int = 1
@@ -136,12 +136,14 @@ class BottomDialog2(
// WeightUtil.tareTwo(num+1) // WeightUtil.tareTwo(num+1)
// } // }
} }
WeightUtil.addWeightListener { address, state, weight -> WeightUtil.addWeightListener (
if (weighAddress == address) { weightKey = TAG,
this.currentWeight = weight.toDouble() getWeight = { address, state, weight ->
binding.tvWeight.text = getTextSpan(weight) if (weighAddress == address) {
} this.currentWeight = weight.toDouble()
} binding.tvWeight.text = getTextSpan(weight)
}
})
binding.tvWeight.text = getTextSpan(0) binding.tvWeight.text = getTextSpan(0)
if (clickName.isNullOrBlank().not()) { if (clickName.isNullOrBlank().not()) {
@@ -132,17 +132,15 @@ class DeviceConfigActivity : BaseActivity() {
startActivity<SamplingListActivity> { } startActivity<SamplingListActivity> { }
finish() finish()
} }
addWeighListener()
addGridItemListener() addGridItemListener()
loadSeasoning() loadSeasoning()
addWeighListener()
} }
private fun addWeighListener() { private fun addWeighListener() {
WeightUtil.addWeightListener(onConnect = { state -> WeightUtil.addWeightListener(
binding.viewPoint.setBackgroundResource( weightKey = TAG,
if (state) R.drawable.bg_circle_green else R.drawable.bg_circle_red getWeight = { address, state, weight ->
)
}, getWeight = { address, state, weight ->
Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight") Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight")
weightArray.put(address, weight) weightArray.put(address, weight)
val item = seasoningItems.firstOrNull { address == addressArray[it.sort] } val item = seasoningItems.firstOrNull { address == addressArray[it.sort] }
@@ -150,7 +148,7 @@ class DeviceConfigActivity : BaseActivity() {
it.useWeight = weight.toDouble() it.useWeight = weight.toDouble()
updateGridData(it) updateGridData(it)
} }
//setGridData(seasoningItems) Log.d(TAG, "addWeighListener: update-----------------------")
}) })
} }
@@ -61,6 +61,16 @@ class DishSamplingActivity : BaseActivity() {
initViewModel() initViewModel()
foodName = intent.getStringExtra(FOOD_NAME) foodName = intent.getStringExtra(FOOD_NAME)
binding.etInputDish.setText(foodName) binding.etInputDish.setText(foodName)
WeightUtil.addWeightListener(
weightKey = TAG,
getWeight = { address, state, weight ->
//Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
if (address == AddressUtil.ONE) {
tempDishEntity?.useWeight = weight.toDouble()
binding.tvDishPartWeight.text = "${weight}"
}
})
} }
private fun setTitleBar() { private fun setTitleBar() {
@@ -166,13 +176,6 @@ class DishSamplingActivity : BaseActivity() {
binding.ivWeightClear.setOnClickListener { binding.ivWeightClear.setOnClickListener {
WeightUtil.tareTwo(AddressUtil.ONE) WeightUtil.tareTwo(AddressUtil.ONE)
} }
WeightUtil.addWeightListener(getWeight = { address, state, weight ->
//Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
if (address == AddressUtil.ONE) {
tempDishEntity?.useWeight = weight.toDouble()
binding.tvDishPartWeight.text = "${weight}"
}
})
binding.ivWeightAdd.setOnClickListener { binding.ivWeightAdd.setOnClickListener {
if (tempDishEntity == null) { if (tempDishEntity == null) {
toast("请输入食材名称") toast("请输入食材名称")
@@ -73,15 +73,17 @@ class PrepareCookActivity : BaseActivity() {
} }
private fun addViewClickListener() { private fun addViewClickListener() {
WeightUtil.addWeightListener(
weightKey = TAG,
getWeight = { address, state, weight ->
//Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
if (address == AddressUtil.ONE) {
binding.tvDishPartWeight.text = "${weight}"
}
})
binding.ivWeightClear.setOnClickListener { binding.ivWeightClear.setOnClickListener {
WeightUtil.tareTwo(AddressUtil.ONE) WeightUtil.tareTwo(AddressUtil.ONE)
} }
WeightUtil.addWeightListener(getWeight = { address, state, weight ->
//Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
if (address == AddressUtil.ONE) {
binding.tvDishPartWeight.text = "${weight}"
}
})
binding.ivWeightAdd.setOnClickListener { binding.ivWeightAdd.setOnClickListener {
if (clickIndex == -1) { if (clickIndex == -1) {
toast("请选择菜品构成") toast("请选择菜品构成")
@@ -99,8 +99,15 @@ class SubmitFoodActivity : BaseActivity() {
private fun loadSeasoningFromLocal() { private fun loadSeasoningFromLocal() {
appViewModel.getCookFoodGoodsList(foodId = food!!.foodId!!, cookMode = food!!.cookMode) { it -> appViewModel.getCookFoodGoodsList(foodId = food!!.foodId!!, cookMode = food!!.cookMode) { it ->
goodsList = mutableListOf() goodsList = mutableListOf()
val goodsIdList = mutableListOf<String>()
//设置主辅材数据 //设置主辅材数据
goodsList?.addAll(it.filter { goods -> goods.materialType != 3 }) val tempList = it.filter { goods -> goods.materialType != 3 }
tempList.forEach {
if (!goodsIdList.contains(it.goodsId)) {
goodsList?.add(it)
goodsIdList.add(it.goodsId)
}
}
//获取调料数据并展示 //获取调料数据并展示
val filterList: List<SeasoningEntity>? = it.filter { goods -> goods.materialType == 3 } val filterList: List<SeasoningEntity>? = it.filter { goods -> goods.materialType == 3 }
@@ -166,7 +173,9 @@ class SubmitFoodActivity : BaseActivity() {
} }
private fun addWeightListener() { private fun addWeightListener() {
WeightUtil.addWeightListener(getWeight = { address, state, weight -> WeightUtil.addWeightListener(
weightKey = TAG,
getWeight = { address, state, weight ->
if (address == AddressUtil.TWO) { if (address == AddressUtil.TWO) {
cookFoodEntity.foodWeight = weight.toDouble() cookFoodEntity.foodWeight = weight.toDouble()
binding.tvTotalWeight.text = "${weight / 1000f}" binding.tvTotalWeight.text = "${weight / 1000f}"
@@ -10,73 +10,25 @@ import com.wabon.wbintelligenthardwaresdk.api.SensorScale
object WeightUtil { object WeightUtil {
var isConnected = false var isConnected = false
var weightFuncMap: MutableMap<String, ((address: Int, state: Int, weight: Int) -> Unit)?>? = null
fun init() { fun init() {
Weigher.init() Weigher.init()
// Weigher.setListener(object : WeightListenerImpl() { Weigher.setListener(object : WeightListenerImpl() {
// override fun onInit(connect: Boolean) { override fun onInit(connect: Boolean) {
// Log.d("WeightUtil", "connect=$connect") super.onInit(connect)
// } isConnected = connect
// }
// override fun onZero() {
// Log.d("WeightUtil", "zero ok") override fun onGetWeight(address: Int, state: Int, weight: Int) {
// } super.onGetWeight(address, state, weight)
// weightFuncMap?.forEach { (key, value) ->
// override fun onTare() { value?.invoke(address, state, weight)
// Log.d("WeightUtil", "去皮置零操作成功") }
// }
// }
// override fun onSetIdentify() { })
// Log.d("WeightUtil", "鉴别率设置操作成功")
// }
//
// override fun onGetWeight(address: Int, state: Int, weight: Int) {
// runOnUiThread {
// val stateStr = when (state) {
// SensorScale.STATE_STABLE -> "稳定"
// SensorScale.STATE_UNSTABLE -> "不稳定"
// SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
// else -> ""
// }
// val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f)
// Log.d("WeightUtil", "ttlReturn, address:$address,$result1")
//// weightArray.put(address, weight)
// }
// }
//
// override fun onReadIdentify(rate: Int) {
// Log.d("WeightUtil", "读取鉴别率成功:rate=$rate")
// }
//
// override fun onFail(errCode: Int) {
// val str = when (errCode) {
// Weigher.ERR_001 -> "电子称未初始化"
// Weigher.ERR_002 -> "开机零位异常"
// Weigher.ERR_003 -> "传感器故障"
// Weigher.ERR_004 -> "鉴别率超出范围"
// Weigher.ERR_PCB_NOT_SUPPORT -> "主板不支持, " + Build.MODEL
// else -> ""
// }
// Log.d("WeightUtil", str)
// }
//
// override fun onFastFilter() {
// Log.d("WeightUtil", "快速滤波设置成功")
// }
//
// override fun onReadParam() {
// Log.d("WeightUtil", "prepare ok")
// }
//
// override fun onRangCal() {
// Log.d("WeightUtil", "rang cal ok")
// }
//
// override fun onSetParam() {
// Log.d("WeightUtil", "onSetParam")
// }
// })
} }
fun getWeight() { fun getWeight() {
@@ -98,51 +50,46 @@ object WeightUtil {
} }
fun addWeightListener( fun addWeightListener(
onConnect: (state: Boolean) -> Unit = {}, weightKey:String,
zero: () -> Unit = {},
getWeight: ((address: Int, state: Int, weight: Int) -> Unit) = { _, _, _ -> } getWeight: ((address: Int, state: Int, weight: Int) -> Unit) = { _, _, _ -> }
) { ) {
Weigher.setListener(object : WeightListenerImpl() { if (weightFuncMap == null) {
override fun onInit(connect: Boolean) { weightFuncMap = mutableMapOf()
super.onInit(connect) }
onConnect(connect) weightFuncMap?.put(weightKey, getWeight)
}
override fun onZero() {
zero()
}
override fun onGetWeight(address: Int, state: Int, weight: Int) {
getWeight(address, state, weight)
}
})
} }
} }
open class WeightListenerImpl : Weigher.Listener { open class WeightListenerImpl : Weigher.Listener {
override fun onInit(connect: Boolean) { override fun onInit(connect: Boolean) {
Log.d("WeightUtil", "connect=$connect")
} }
override fun onZero() { override fun onZero() {
Log.d("WeightUtil", "zero ok")
} }
override fun onTare() { override fun onTare() {
Log.d("WeightUtil", "去皮置零操作成功")
} }
override fun onSetIdentify() { override fun onSetIdentify() {
Log.d("WeightUtil", "鉴别率设置操作成功")
} }
override fun onGetWeight(address: Int, state: Int, weight: Int) { override fun onGetWeight(address: Int, state: Int, weight: Int) {
val stateStr = when (state) {
SensorScale.STATE_STABLE -> "稳定"
SensorScale.STATE_UNSTABLE -> "不稳定"
SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
else -> ""
}
val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f)
Log.d("WeightUtil", "ttlReturn, address:$address,$result1")
} }
override fun onReadIdentify(rate: Int) { override fun onReadIdentify(rate: Int) {
Log.d("WeightUtil", "读取鉴别率成功:rate=$rate")
} }
override fun onFail(errCode: Int) { override fun onFail(errCode: Int) {
@@ -158,19 +105,20 @@ open class WeightListenerImpl : Weigher.Listener {
} }
override fun onFastFilter() { override fun onFastFilter() {
Log.d("WeightUtil", "快速滤波设置成功")
} }
override fun onReadParam() { override fun onReadParam() {
Log.d("WeightUtil", "prepare ok")
} }
override fun onRangCal() { override fun onRangCal() {
Log.d("WeightUtil", "rang cal ok")
} }
override fun onSetParam() { override fun onSetParam() {
Log.d("WeightUtil", "onSetParam")
} }
} }
@@ -126,12 +126,12 @@
android:textColor="@color/gray_b4" android:textColor="@color/gray_b4"
android:textSize="28sp" /> android:textSize="28sp" />
<View <!-- <View-->
android:id="@+id/viewPoint" <!-- android:id="@+id/viewPoint"-->
android:layout_width="5dp" <!-- android:layout_width="5dp"-->
android:layout_height="5dp" <!-- android:layout_height="5dp"-->
android:layout_gravity="center_vertical" <!-- android:layout_gravity="center_vertical"-->
android:background="@drawable/bg_circle_green"/> <!-- android:background="@drawable/bg_circle_green"/>-->
</LinearLayout> </LinearLayout>
<include <include
@@ -69,7 +69,7 @@
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:layout_marginEnd="30dp" android:layout_marginEnd="30dp"
android:background="@drawable/shape_green_stroke" android:background="@drawable/ripple_effect_light"
android:gravity="center" android:gravity="center"
android:text="清零" android:text="清零"
android:textColor="@color/dish_green" android:textColor="@color/dish_green"