功能优化

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
) {
companion object {
const val TAG = "BottomDialog"
const val TAG = "BottomDialog2"
}
private val goodsType: Int = 1
@@ -136,12 +136,14 @@ class BottomDialog2(
// WeightUtil.tareTwo(num+1)
// }
}
WeightUtil.addWeightListener { address, state, weight ->
WeightUtil.addWeightListener (
weightKey = TAG,
getWeight = { address, state, weight ->
if (weighAddress == address) {
this.currentWeight = weight.toDouble()
binding.tvWeight.text = getTextSpan(weight)
}
}
})
binding.tvWeight.text = getTextSpan(0)
if (clickName.isNullOrBlank().not()) {
@@ -132,17 +132,15 @@ class DeviceConfigActivity : BaseActivity() {
startActivity<SamplingListActivity> { }
finish()
}
addWeighListener()
addGridItemListener()
loadSeasoning()
addWeighListener()
}
private fun addWeighListener() {
WeightUtil.addWeightListener(onConnect = { state ->
binding.viewPoint.setBackgroundResource(
if (state) R.drawable.bg_circle_green else R.drawable.bg_circle_red
)
}, getWeight = { address, state, weight ->
WeightUtil.addWeightListener(
weightKey = TAG,
getWeight = { address, state, weight ->
Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight")
weightArray.put(address, weight)
val item = seasoningItems.firstOrNull { address == addressArray[it.sort] }
@@ -150,7 +148,7 @@ class DeviceConfigActivity : BaseActivity() {
it.useWeight = weight.toDouble()
updateGridData(it)
}
//setGridData(seasoningItems)
Log.d(TAG, "addWeighListener: update-----------------------")
})
}
@@ -61,6 +61,16 @@ class DishSamplingActivity : BaseActivity() {
initViewModel()
foodName = intent.getStringExtra(FOOD_NAME)
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() {
@@ -166,13 +176,6 @@ class DishSamplingActivity : BaseActivity() {
binding.ivWeightClear.setOnClickListener {
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 {
if (tempDishEntity == null) {
toast("请输入食材名称")
@@ -73,15 +73,17 @@ class PrepareCookActivity : BaseActivity() {
}
private fun addViewClickListener() {
binding.ivWeightClear.setOnClickListener {
WeightUtil.tareTwo(AddressUtil.ONE)
}
WeightUtil.addWeightListener(getWeight = { address, state, weight ->
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 {
WeightUtil.tareTwo(AddressUtil.ONE)
}
binding.ivWeightAdd.setOnClickListener {
if (clickIndex == -1) {
toast("请选择菜品构成")
@@ -99,8 +99,15 @@ class SubmitFoodActivity : BaseActivity() {
private fun loadSeasoningFromLocal() {
appViewModel.getCookFoodGoodsList(foodId = food!!.foodId!!, cookMode = food!!.cookMode) { it ->
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 }
@@ -166,7 +173,9 @@ class SubmitFoodActivity : BaseActivity() {
}
private fun addWeightListener() {
WeightUtil.addWeightListener(getWeight = { address, state, weight ->
WeightUtil.addWeightListener(
weightKey = TAG,
getWeight = { address, state, weight ->
if (address == AddressUtil.TWO) {
cookFoodEntity.foodWeight = weight.toDouble()
binding.tvTotalWeight.text = "${weight / 1000f}"
@@ -10,73 +10,25 @@ import com.wabon.wbintelligenthardwaresdk.api.SensorScale
object WeightUtil {
var isConnected = false
var weightFuncMap: MutableMap<String, ((address: Int, state: Int, weight: Int) -> Unit)?>? = null
fun init() {
Weigher.init()
// Weigher.setListener(object : WeightListenerImpl() {
// override fun onInit(connect: Boolean) {
// Log.d("WeightUtil", "connect=$connect")
// }
//
// override fun onZero() {
// Log.d("WeightUtil", "zero ok")
// }
//
// override fun onTare() {
// 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")
// }
// })
Weigher.setListener(object : WeightListenerImpl() {
override fun onInit(connect: Boolean) {
super.onInit(connect)
isConnected = connect
}
override fun onGetWeight(address: Int, state: Int, weight: Int) {
super.onGetWeight(address, state, weight)
weightFuncMap?.forEach { (key, value) ->
value?.invoke(address, state, weight)
}
}
})
}
fun getWeight() {
@@ -98,51 +50,46 @@ object WeightUtil {
}
fun addWeightListener(
onConnect: (state: Boolean) -> Unit = {},
zero: () -> Unit = {},
weightKey:String,
getWeight: ((address: Int, state: Int, weight: Int) -> Unit) = { _, _, _ -> }
) {
Weigher.setListener(object : WeightListenerImpl() {
override fun onInit(connect: Boolean) {
super.onInit(connect)
onConnect(connect)
if (weightFuncMap == null) {
weightFuncMap = mutableMapOf()
}
override fun onZero() {
zero()
weightFuncMap?.put(weightKey, getWeight)
}
override fun onGetWeight(address: Int, state: Int, weight: Int) {
getWeight(address, state, weight)
}
})
}
}
open class WeightListenerImpl : Weigher.Listener {
override fun onInit(connect: Boolean) {
Log.d("WeightUtil", "connect=$connect")
}
override fun onZero() {
Log.d("WeightUtil", "zero ok")
}
override fun onTare() {
Log.d("WeightUtil", "去皮置零操作成功")
}
override fun onSetIdentify() {
Log.d("WeightUtil", "鉴别率设置操作成功")
}
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) {
Log.d("WeightUtil", "读取鉴别率成功:rate=$rate")
}
override fun onFail(errCode: Int) {
@@ -158,19 +105,20 @@ open class WeightListenerImpl : Weigher.Listener {
}
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")
}
}
@@ -126,12 +126,12 @@
android:textColor="@color/gray_b4"
android:textSize="28sp" />
<View
android:id="@+id/viewPoint"
android:layout_width="5dp"
android:layout_height="5dp"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_circle_green"/>
<!-- <View-->
<!-- android:id="@+id/viewPoint"-->
<!-- android:layout_width="5dp"-->
<!-- android:layout_height="5dp"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:background="@drawable/bg_circle_green"/>-->
</LinearLayout>
<include
@@ -69,7 +69,7 @@
android:layout_gravity="end"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp"
android:background="@drawable/shape_green_stroke"
android:background="@drawable/ripple_effect_light"
android:gravity="center"
android:text="清零"
android:textColor="@color/dish_green"