feat(ui): 新增油盆配置区,子设备1调料名改为动态配置

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-21 18:18:22 +08:00
co-authored by Claude Sonnet 4.6
parent bbdebc0c9c
commit b6b5088107
8 changed files with 67 additions and 15 deletions
@@ -19,8 +19,9 @@ class ScaleRowAdapter : BaseQuickAdapter<ScaleRowAdapter.ScaleItem, ScaleRowAdap
* @param address 秤地址
* @param weight 重量(克)
* @param state 状态码
* @param name 调料名称,未配置时为空
*/
data class ScaleItem(val address: Int, val weight: Double, val state: Int)
data class ScaleItem(val address: Int, val weight: Double, val state: Int, val name: String = "")
inner class VH(val b: ListItemScaleRowBinding) : QuickViewHolder(b.root)
@@ -31,6 +32,7 @@ class ScaleRowAdapter : BaseQuickAdapter<ScaleRowAdapter.ScaleItem, ScaleRowAdap
override fun onBindViewHolder(holder: VH, position: Int, item: ScaleItem?) {
item ?: return
holder.b.tvScaleLabel.text = "${item.address}"
holder.b.tvName.text = item.name.ifEmpty { "-" }
holder.b.tvWeight.text = "${item.weight} g"
holder.b.tvState.text = when (item.state) {
WeightUtil.STATE_STABLE -> "稳定"
@@ -136,7 +136,7 @@ class SeasoningSelectDialog(
// TODO: 联调时注释掉下方模拟数据,取消注释真实接口调用
val nameList = listOf(
"", "白砂糖","冰糖", "鸡精", "味精", "陈醋", "老抽", "生抽", "番茄酱", "胡椒粉", "孜然", "十三香",
"料酒", "白醋", "蚝油", "辣椒面", "辣椒酱", "豆瓣酱", "淀粉", "", "", "", "香菜"
"料酒", "白醋", "蚝油", "辣椒面", "辣椒酱", "豆瓣酱", "淀粉", "", "", "", "香菜", ""
)
val mockData = mutableListOf<SeasoningEntity>()
nameList.forEachIndexed { index, name ->
@@ -195,6 +195,15 @@ class SlaveActivity : BaseActivity() {
val pos = ScaleDeviceConfig.SCALE_ORDER_18.indexOf(slot.address)
if (pos >= 0) scale18Adapter!!.updateItemName(pos, slot.goodsName)
}
else -> {
// 线性列表模式(子设备1):刷新已显示条目的名称
val list = linearAdapter.items.toMutableList()
val idx = list.indexOfFirst { it.address == slot.address }
if (idx >= 0) {
list[idx] = list[idx].copy(name = slot.goodsName)
linearAdapter.submitList(list)
}
}
}
}
}
@@ -233,7 +242,7 @@ class SlaveActivity : BaseActivity() {
scale18Adapter!!.updateByAddress(existing)
}
else -> {
val item = ScaleRowAdapter.ScaleItem(address, weight, state)
val item = ScaleRowAdapter.ScaleItem(address, weight, state, slotNameMap[address] ?: "")
val list = linearAdapter.items.toMutableList()
val idx = list.indexOfFirst { it.address == address }
if (idx >= 0) {
@@ -144,12 +144,8 @@ class SubmitFoodActivity : BaseActivity() {
// 排除主设备 2格秤
if (data.deviceId == ScaleDeviceConfig.DEVICE_ID_2) return@forEach
// 1格设备调料名固定为"油",其余从槽位配置读取
val (goodsId, goodsName) = if (data.deviceId == ScaleDeviceConfig.DEVICE_ID_1) {
"" to ""
} else {
slotMap[key] ?: return@forEach
}
// 从槽位配置读取调料名,未配置则跳过
val (goodsId, goodsName) = slotMap[key] ?: return@forEach
// 首次收到稳定数据时记录基准重量
val baseline = baselineMap[key]
@@ -64,10 +64,32 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
// initViewModel()
setupRecyclerViews()
bindAdapterClicks()
bindOilSlotClick()
addWeightListener()
loadData()
}
/** 绑定油盆格子点击,弹出调料选择弹窗并保存到 DEVICE_ID_1 */
private fun bindOilSlotClick() {
binding.tvOilSlot.setOnClickListener {
SeasoningSelectDialog(
activity = settingActivity,
clickIndex = 0,
onItemSelected = { item ->
binding.tvOilSlot.text = item.goodsName ?: "-"
saveSlotAndBroadcast(
SeasoningSlotEntity(
deviceId = ScaleDeviceConfig.DEVICE_ID_1,
address = 1,
goodsId = item.goodsId,
goodsName = item.goodsName ?: ""
)
)
}
).show()
}
}
/** 绑定两个 Adapter 的格子点击,弹出调料选择弹窗 */
private fun bindAdapterClicks() {
adapter22.onItemClick = { scaleData, position ->
@@ -171,6 +193,7 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
val dao = BaseApp.instance!!.database.seasoningSlotDao()
val slots22 = dao.queryByDeviceId(ScaleDeviceConfig.DEVICE_ID_22)
val slots18 = dao.queryByDeviceId(ScaleDeviceConfig.DEVICE_ID_18)
val slotsOil = dao.queryByDeviceId(ScaleDeviceConfig.DEVICE_ID_1)
withContext(Dispatchers.Main) {
slots22.forEach { slot ->
val pos = ScaleDeviceConfig.SCALE_ORDER_22.indexOf(slot.address)
@@ -180,12 +203,11 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
val pos = ScaleDeviceConfig.SCALE_ORDER_18.indexOf(slot.address)
if (pos >= 0) adapter18.updateItemName(pos, slot.goodsName)
}
// 加载油盆格子名称(address=1
val oilSlot = slotsOil.firstOrNull { it.address == 1 }
binding.tvOilSlot.text = if (oilSlot != null && oilSlot.goodsName.isNotEmpty()) oilSlot.goodsName else "-"
}
}
// appViewModel.loadSeasoning { list ->
// adapter22.update(list ?: emptyList())
// adapter18.update(list ?: emptyList())
// }
}
/**
@@ -74,5 +74,28 @@
android:layout_height="wrap_content"
android:overScrollMode="never" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="6dp"
android:text="油盆配置区"
android:textColor="@color/home_title"
android:textSize="28sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvOilSlot"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/shape_scale_cell"
android:gravity="center"
android:text="-"
android:textColor="@color/home_title"
android:textSize="28sp" />
</LinearLayout>
</LinearLayout>
@@ -26,7 +26,7 @@
android:layout_height="wrap_content"
android:textColor="@color/home_sub_title"
android:textSize="22sp"
android:text="" />
android:text="-" />
<!-- 重量 -->
<TextView
+1 -1
View File
@@ -52,7 +52,7 @@
android:textSize="22sp"
android:includeFontPadding="false"
android:textColor="@color/home_sub_title"
android:text="" />
android:text="-" />
<TextView
android:id="@+id/tvWeight"