feat(ui): 新增油盆配置区,子设备1调料名改为动态配置
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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())
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user