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

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
+9 -9
View File
@@ -65,15 +65,15 @@
android:launchMode="singleTask"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.SubmitDishActivity"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.DeviceSettingActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<!-- <activity-->
<!-- android:name=".ui.SubmitDishActivity"-->
<!-- android:screenOrientation="portrait"-->
<!-- tools:ignore="DiscouragedApi,LockedOrientationActivity" />-->
<!-- <activity-->
<!-- android:name=".ui.DeviceSettingActivity"-->
<!-- android:launchMode="singleTask"-->
<!-- android:screenOrientation="portrait"-->
<!-- tools:ignore="DiscouragedApi,LockedOrientationActivity" />-->
<activity
android:name=".ui.FoodSearchActivity"
android:screenOrientation="portrait"
+181 -181
View File
@@ -1,208 +1,208 @@
{
"list": [
{
"id" : 1,
"goodsId" : "17899",
"goodsName" : "精盐",
"foodId" : "",
"goodsOrRelationCode" : "WP0278",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "食盐、精制盐",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 0,
"isDel" : 0,
"createTime" : "2025-08-18 10:16:17"
"id": 1,
"goodsId": "17899",
"goodsName": "精盐",
"foodId": "",
"goodsOrRelationCode": "WP0278",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "食盐、精制盐",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 0,
"isDel": 0,
"createTime": "2025-08-18 10:16:17"
},
{
"id" : 2,
"goodsId" : "17901",
"goodsName" : "鸡精",
"foodId" : "",
"goodsOrRelationCode" : "WP0280",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "鸡精、家乐鸡精",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 1,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:02"
"id": 2,
"goodsId": "17901",
"goodsName": "鸡精",
"foodId": "",
"goodsOrRelationCode": "WP0280",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "鸡精、家乐鸡精",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 1,
"isDel": 0,
"createTime": "2025-08-18 10:17:02"
},
{
"id" : 3,
"goodsId" : "17752",
"goodsName" : "味精",
"foodId" : "",
"goodsOrRelationCode" : "WP0131",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "双桥味精,莲花味精、味精",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 2,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:16"
"id": 3,
"goodsId": "17752",
"goodsName": "味精",
"foodId": "",
"goodsOrRelationCode": "WP0131",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "双桥味精,莲花味精、味精",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 2,
"isDel": 0,
"createTime": "2025-08-18 10:17:16"
},
{
"id" : 4,
"goodsId" : "17800",
"goodsName" : "老抽",
"foodId" : "",
"goodsOrRelationCode" : "WP0179",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "老抽",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 3,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:26"
"id": 4,
"goodsId": "17800",
"goodsName": "老抽",
"foodId": "",
"goodsOrRelationCode": "WP0179",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "老抽",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 3,
"isDel": 0,
"createTime": "2025-08-18 10:17:26"
},
{
"id" : 5,
"goodsId" : "17749",
"goodsName" : "白醋",
"foodId" : "",
"goodsOrRelationCode" : "WP0128",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "白醋,唯加白醋",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 4,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:38"
"id": 5,
"goodsId": "17749",
"goodsName": "白醋",
"foodId": "",
"goodsOrRelationCode": "WP0128",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "白醋,唯加白醋",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 4,
"isDel": 0,
"createTime": "2025-08-18 10:17:38"
},
{
"id" : 6,
"goodsId" : "17895",
"goodsName" : "胡椒粉",
"foodId" : "",
"goodsOrRelationCode" : "WP0274",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "胡椒粉",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 5,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:47"
"id": 6,
"goodsId": "17895",
"goodsName": "胡椒粉",
"foodId": "",
"goodsOrRelationCode": "WP0274",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "胡椒粉",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 5,
"isDel": 0,
"createTime": "2025-08-18 10:17:47"
},
{
"id" : 7,
"goodsId" : "329",
"goodsName" : "酱油",
"foodId" : "",
"goodsOrRelationCode" : "WP0329",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "酱油",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 6,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:55"
"id": 7,
"goodsId": "329",
"goodsName": "酱油",
"foodId": "",
"goodsOrRelationCode": "WP0329",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "酱油",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 6,
"isDel": 0,
"createTime": "2025-08-18 10:17:55"
},
{
"id" : 8,
"goodsId" : "17733",
"goodsName" : "料酒",
"foodId" : "",
"goodsOrRelationCode" : "WP0112",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "料酒",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 7,
"isDel" : 0,
"createTime" : "2025-08-18 10:18:14"
"id": 8,
"goodsId": "17733",
"goodsName": "料酒",
"foodId": "",
"goodsOrRelationCode": "WP0112",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "料酒",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 7,
"isDel": 0,
"createTime": "2025-08-18 10:18:14"
},
{
"id" : 9,
"goodsId" : "17889",
"goodsName" : "五香粉",
"foodId" : "",
"goodsOrRelationCode" : "WP0268",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "五香粉",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 8,
"isDel" : 0,
"createTime" : "2025-08-18 10:18:23"
"id": 9,
"goodsId": "17889",
"goodsName": "五香粉",
"foodId": "",
"goodsOrRelationCode": "WP0268",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "五香粉",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 8,
"isDel": 0,
"createTime": "2025-08-18 10:18:23"
},
{
"id" : 10,
"goodsId" : "17815",
"goodsName" : "豆瓣酱",
"foodId" : "",
"goodsOrRelationCode" : "WP0194",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "豆瓣酱、郫县豆瓣酱",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 9,
"isDel" : 0,
"createTime" : "2025-08-18 10:18:31"
"id": 10,
"goodsId": "18032",
"goodsName": "菜籽油[青油]",
"foodId": "",
"goodsOrRelationCode": "WP0411",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "菜籽油,爱菊菜籽油",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 9,
"isDel": 0,
"createTime": "2025-08-18 10:19:19"
},
{
"id" : 11,
"goodsId" : "17803",
"goodsName" : "生抽",
"foodId" : "",
"goodsOrRelationCode" : "WP0182",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "生抽",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 11,
"isDel" : 0,
"createTime" : "2025-08-18 10:19:08"
"id": 11,
"goodsId": "17815",
"goodsName": "豆瓣酱",
"foodId": "",
"goodsOrRelationCode": "WP0194",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "豆瓣酱、郫县豆瓣酱",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 10,
"isDel": 0,
"createTime": "2025-08-18 10:18:31"
},
{
"id" : 12,
"goodsId" : "18032",
"goodsName" : "菜籽油[青油]",
"foodId" : "",
"goodsOrRelationCode" : "WP0411",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "菜籽油,爱菊菜籽油",
"canteenId" : "0",
"relateionType_dictText" : "食材原材料",
"sort" : 10,
"isDel" : 0,
"createTime" : "2025-08-18 10:19:19"
"id": 12,
"goodsId": "17803",
"goodsName": "生抽",
"foodId": "",
"goodsOrRelationCode": "WP0182",
"relateionType": 1,
"materialType": 3,
"allEdible": 1,
"useWeight": 0,
"popularName": "生抽",
"canteenId": "0",
"relateionType_dictText": "食材原材料",
"sort": 11,
"isDel": 0,
"createTime": "2025-08-18 10:19:08"
}
]
]
}
@@ -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) {
@@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
tools:background="@drawable/bg_other_page">