修改熟重和菜品称重位置,菜品构成删除未生效问题优化

This commit is contained in:
2025-09-05 09:54:38 +08:00
parent 03d3785e2b
commit 8c6d1bae99
11 changed files with 271 additions and 246 deletions
@@ -69,6 +69,9 @@ class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
companion object {
fun loadCell(tvCell: TextView, item: SeasoningEntity) {
tvCell.text = getTextSpan(item)
}
fun loadCell2(tvCell: TextView, item: SeasoningEntity) {
if (item.goodsName.isNullOrBlank()) {
tvCell.run {
text = buildSpannableString {
@@ -97,14 +100,14 @@ class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
fun getTextSpan(item: SeasoningEntity): SpannableStringBuilder {
val endIndex = if (item.sort == 10 || item.sort == 14) 10 else 6
var name = item.goodsName!!
var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
if (name.length > endIndex) {
name = "${name.substring(0, endIndex)}"
}
return buildSpannableString {
appendText(
name,
ForegroundColorSpan("#000000".toColorInt()),
ForegroundColorSpan(if (item.goodsName.isNullOrBlank()) "#999999".toColorInt() else "#000000".toColorInt()),
StyleSpan(Typeface.BOLD),
AbsoluteSizeSpan(28, true),
LineHeightSpan { text, start, end, spanstartv, v, fm ->
@@ -7,6 +7,7 @@ import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import android.text.style.LineHeightSpan
import android.text.style.StyleSpan
import android.util.SparseIntArray
import android.widget.TextView
import androidx.core.graphics.toColorInt
import androidx.core.view.forEach
@@ -18,7 +19,7 @@ import com.shuwei.dish.match.db.AppRepository
import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.entity.SeasoningEntity
import com.shuwei.dish.match.entity.ResetReasoningRecord
import com.shuwei.dish.match.utils.DataUtil
import com.shuwei.dish.match.utils.AddressUtil
import com.shuwei.dish.match.utils.JsonAssetsLoader
import com.shuwei.dish.match.utils.MultiClickDetector
import com.shuwei.dish.match.utils.WeightUtil
@@ -61,6 +62,8 @@ class DeviceConfigActivity : BaseActivity() {
private lateinit var appViewModel: AppViewModel
private var cookMode: Int = 0
private val weightArray = SparseIntArray()
private val addressArray = AddressUtil.getWeighAddressArray()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -126,11 +129,21 @@ class DeviceConfigActivity : BaseActivity() {
}
addGridItemListener()
loadSeasoning()
addWeighListener()
}
private fun addWeighListener() {
WeightUtil.addWeightListener { address, state, weight ->
weightArray.put(address, weight)
val item = seasoningItems.firstOrNull { address == addressArray[it.sort]}
item?.useWeight = weight.toDouble()
setGridData(seasoningItems)
}
}
private var seasoningItems = mutableListOf<SeasoningEntity>()
private fun addGridItemListener() {
binding.include.root.forEach { child->
binding.include.root.forEach { child ->
(child as TextView).run {
clickWithDebounce {
val sort = tag.toString().toInt()
@@ -167,8 +180,7 @@ class DeviceConfigActivity : BaseActivity() {
this,
"default_seasoning_list.json"
)
val addressArray = DataUtil.getWeighAddressArray()
val weightArray = WeightUtil.weightArray
// val weightArray = WeightUtil.weightArray
appViewModel.clearAllSeasoning {
record?.list?.forEach { entity ->
entity.useWeight = weightArray[addressArray[entity.sort]].toDouble()
@@ -197,8 +209,8 @@ class DeviceConfigActivity : BaseActivity() {
}
private fun initConfigData() {
repeat(12) {num->
val firstOne = seasoningItems.firstOrNull {it.sort == num}
repeat(12) { num ->
val firstOne = seasoningItems.firstOrNull { it.sort == num }
if (firstOne == null) {
seasoningItems.add(SeasoningEntity().also { it.sort = num })
}
@@ -215,7 +227,7 @@ class DeviceConfigActivity : BaseActivity() {
}
private fun clickGridItem(sort: Int, entity: SeasoningEntity) {
val currentAddress = DataUtil.getWeighAddressArray().get(sort)
val currentAddress = AddressUtil.getWeighAddressArray().get(sort)
// val seasoningEntity = list.first{it.sort == sort}
BottomDialog2(
weighIndex = sort,
@@ -20,6 +20,7 @@ import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.entity.CookFoodEntity
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.utils.AddressUtil
import com.shuwei.dish.match.utils.KeyboardUtil
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
@@ -140,9 +141,11 @@ class DishSamplingActivity : BaseActivity() {
private val dishAdapter by lazy {
DishPartAdapter(list).apply {
addOnItemChildClickListener(R.id.ivOperateIcon) { _, _, positon ->
addOnItemChildClickListener(R.id.ivOperateIcon) { _, _, position ->
//删除操作
removeAt(positon)
list.removeAt(position)
notifyItemRemoved(position)
notifyItemRangeChanged(position, list.size - position)
}
}
}
@@ -178,7 +181,7 @@ class DishSamplingActivity : BaseActivity() {
}
binding.ivWeightClear.setOnClickListener {
Weigher.tareTwo(2)
Weigher.tareTwo(AddressUtil.ONE)
}
WeightUtil.addWeightListener(getWeight = { address, state, weight ->
Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
@@ -20,6 +20,7 @@ import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.http.HttpUtil
import com.shuwei.dish.match.http.UrlConfig
import com.shuwei.dish.match.utils.AddressUtil
import com.shuwei.dish.match.utils.SwipeCallback
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.clickWithDebounce
@@ -74,7 +75,7 @@ class PrepareCookActivity : BaseActivity() {
private fun addViewClickListener() {
binding.ivWeightClear.setOnClickListener {
Weigher.tareTwo(2)
Weigher.tareTwo(AddressUtil.ONE)
}
WeightUtil.addWeightListener(getWeight = { address, state, weight ->
Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
@@ -272,7 +273,10 @@ class PrepareCookActivity : BaseActivity() {
dishPartAdapter.notifyItemChanged(position)
return@SwipeCallback
}
dishPartAdapter.removeAt(position)
// dishPartAdapter.removeAt(position)
list.removeAt(position)
dishPartAdapter.notifyItemRemoved(position)
dishPartAdapter.notifyItemRangeChanged(position, list.size - position)
toast("已删除")
})
itemTouchHelper.attachToRecyclerView(this)
@@ -150,7 +150,7 @@
//
// private fun addViewListener() {
// addWeightListener()
// binding.btnWeightClear.setOnClickListener { Weigher.tareTwo(1) }
// binding.btnWeightClear.setOnClickListener { Weigher.tareTwo(AddressUtil.TWO) }
//
// binding.btnCook.clickWithDebounce {
// cook()
@@ -23,7 +23,7 @@ import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.entity.SeasoningEntity
import com.shuwei.dish.match.http.HttpUtil
import com.shuwei.dish.match.http.UrlConfig
import com.shuwei.dish.match.utils.DataUtil
import com.shuwei.dish.match.utils.AddressUtil
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.clickWithDebounce
import com.shuwei.dish.match.utils.ext.gone
@@ -150,7 +150,7 @@ class SubmitFoodActivity : BaseActivity() {
private fun addViewListener() {
addWeightListener()
binding.btnWeightClear.setOnClickListener { Weigher.tareTwo(1) }
binding.btnWeightClear.setOnClickListener { Weigher.tareTwo(AddressUtil.TWO) }
binding.btnCook.clickWithDebounce {
cook()
@@ -232,7 +232,7 @@ class SubmitFoodActivity : BaseActivity() {
}
private val weightRelateArray by lazy {
DataUtil.getWeighAddressArray()
AddressUtil.getWeighAddressArray()
}
// private fun prepareData(acton: () -> Unit) {
@@ -2,7 +2,10 @@ package com.shuwei.dish.match.utils
import android.util.SparseIntArray
object DataUtil {
object AddressUtil {
const val ONE = 1
const val TWO = 2
fun getWeighAddressArray(): SparseIntArray {
return SparseIntArray().apply {
@@ -12,7 +12,7 @@ import com.wabon.wbintelligenthardwaresdk.api.SensorScale
object WeightUtil {
val weightArray = SparseIntArray()
// val weightArray = SparseIntArray()
fun connect(initCallback: (connect: Boolean) -> Unit) {
Weigher.setListener(object : WeightListenerImpl() {
@@ -34,17 +34,17 @@ object 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)
}
// 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) {