refactor(ui): 重构 Scale2VH 使用 XML 布局,优化秤总览界面样式
- list_type_scale2.xml 替换动态格子为 include list_item_scale22_row,Scale2VH 删除 makeScaleCell/updateScaleCell/makeCellText - list_type_scale1.xml 布局调整为垂直居中,新增 tvName 展示调料名称 - list_type_scale18/22.xml 移除分割线 - SeasoningSelectDialog 搜索列表改为3列,扩充模拟调料数据 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -86,7 +86,7 @@ class SeasoningSelectDialog(
|
|||||||
|
|
||||||
// RecyclerView 初始化及滑动冲突处理
|
// RecyclerView 初始化及滑动冲突处理
|
||||||
binding.recyclerView.run {
|
binding.recyclerView.run {
|
||||||
layoutManager = GridLayoutManager(activity, 2, GridLayoutManager.VERTICAL, false)
|
layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.VERTICAL, false)
|
||||||
adapter = this@SeasoningSelectDialog.adapter
|
adapter = this@SeasoningSelectDialog.adapter
|
||||||
addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
override fun onScrolled(rv: RecyclerView, dx: Int, dy: Int) {
|
override fun onScrolled(rv: RecyclerView, dx: Int, dy: Int) {
|
||||||
@@ -134,19 +134,15 @@ class SeasoningSelectDialog(
|
|||||||
*/
|
*/
|
||||||
private fun getGoodsList() {
|
private fun getGoodsList() {
|
||||||
// TODO: 联调时注释掉下方模拟数据,取消注释真实接口调用
|
// TODO: 联调时注释掉下方模拟数据,取消注释真实接口调用
|
||||||
val mockData = mutableListOf(
|
val nameList = listOf(
|
||||||
SeasoningEntity(goodsId = "1", goodsName = "精盐"),
|
"盐", "白砂糖","冰糖", "鸡精", "味精", "陈醋", "老抽", "生抽", "番茄酱", "胡椒粉", "孜然", "十三香",
|
||||||
SeasoningEntity(goodsId = "2", goodsName = "鸡精"),
|
"料酒", "白醋", "蚝油", "辣椒面", "辣椒酱", "豆瓣酱", "淀粉", "葱", "蒜", "姜", "香菜"
|
||||||
SeasoningEntity(goodsId = "3", goodsName = "陈醋"),
|
|
||||||
SeasoningEntity(goodsId = "4", goodsName = "老抽"),
|
|
||||||
SeasoningEntity(goodsId = "5", goodsName = "生抽"),
|
|
||||||
SeasoningEntity(goodsId = "6", goodsName = "花生油"),
|
|
||||||
SeasoningEntity(goodsId = "7", goodsName = "菜籽油"),
|
|
||||||
SeasoningEntity(goodsId = "8", goodsName = "胡椒粉"),
|
|
||||||
SeasoningEntity(goodsId = "9", goodsName = "十三香"),
|
|
||||||
SeasoningEntity(goodsId = "10", goodsName = "料酒"),
|
|
||||||
SeasoningEntity(goodsId = "11", goodsName = "白醋")
|
|
||||||
)
|
)
|
||||||
|
val mockData = mutableListOf<SeasoningEntity>()
|
||||||
|
nameList.forEachIndexed { index, name ->
|
||||||
|
val padString = "${index + 1}".padStart(2, '0')
|
||||||
|
mockData.add(SeasoningEntity(goodsId = "1000$padString", goodsName = name))
|
||||||
|
}
|
||||||
loadGoodsList(mockData)
|
loadGoodsList(mockData)
|
||||||
|
|
||||||
// val param = mutableMapOf<String, Any>(
|
// val param = mutableMapOf<String, Any>(
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ package com.shuwei.dish.match.ui
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Gravity
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.LinearLayout
|
import androidx.core.view.updateLayoutParams
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@@ -28,6 +26,7 @@ import com.shuwei.dish.match.databinding.ListTypeScale18Binding
|
|||||||
import com.shuwei.dish.match.databinding.ListTypeScale2Binding
|
import com.shuwei.dish.match.databinding.ListTypeScale2Binding
|
||||||
import com.shuwei.dish.match.databinding.ListTypeScale22Binding
|
import com.shuwei.dish.match.databinding.ListTypeScale22Binding
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
|
import com.shuwei.dish.match.databinding.ListItemScale22RowBinding
|
||||||
import com.shuwei.dish.match.scale.ScaleData
|
import com.shuwei.dish.match.scale.ScaleData
|
||||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||||
@@ -40,10 +39,10 @@ import com.shuwei.dish.match.utils.ext.toast
|
|||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
private const val VIEW_TYPE_SCALE2 = 0
|
private const val VIEW_TYPE_SCALE2 = 0
|
||||||
private const val VIEW_TYPE_SCALE22 = 1
|
private const val VIEW_TYPE_SCALE22 = 1
|
||||||
private const val VIEW_TYPE_SCALE18 = 2
|
private const val VIEW_TYPE_SCALE18 = 2
|
||||||
private const val VIEW_TYPE_SCALE1 = 3
|
private const val VIEW_TYPE_SCALE1 = 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主设备秤数据总览页面
|
* 主设备秤数据总览页面
|
||||||
@@ -108,24 +107,30 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
.groupBy { it.deviceId }
|
.groupBy { it.deviceId }
|
||||||
.entries
|
.entries
|
||||||
.sortedWith(compareBy { entry ->
|
.sortedWith(compareBy { entry ->
|
||||||
ScaleDeviceConfig.DEVICE_ORDER.indexOf(entry.key).let { if (it == -1) Int.MAX_VALUE else it }
|
ScaleDeviceConfig.DEVICE_ORDER.indexOf(entry.key)
|
||||||
|
.let { if (it == -1) Int.MAX_VALUE else it }
|
||||||
})
|
})
|
||||||
.map { (deviceId, scales) ->
|
.map { (deviceId, scales) ->
|
||||||
DeviceGroup(
|
DeviceGroup(
|
||||||
deviceId = deviceId,
|
deviceId = deviceId,
|
||||||
ip = if (deviceId == localId) localIp
|
ip = if (deviceId == localId) localIp
|
||||||
else scales.firstOrNull { it.ip.isNotEmpty() }?.ip ?: "",
|
else scales.firstOrNull { it.ip.isNotEmpty() }?.ip ?: "",
|
||||||
scales = scales.map { it.withSlotName() }.sortedBy { it.address }
|
scales = scales.map { it.withSlotName() }.sortedBy { it.address }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val structureChanged = groups.size != groupList.size ||
|
val structureChanged = groups.size != groupList.size ||
|
||||||
groups.indices.any { groups[it].deviceId != groupList[it].deviceId }
|
groups.indices.any { groups[it].deviceId != groupList[it].deviceId }
|
||||||
|
|
||||||
if (structureChanged) {
|
if (structureChanged) {
|
||||||
updateList(groups)
|
updateList(groups)
|
||||||
} else {
|
} else {
|
||||||
groups.forEach { group -> adapter.updateScalesForDevice(group.deviceId, group.scales) }
|
groups.forEach { group ->
|
||||||
|
adapter.updateScalesForDevice(
|
||||||
|
group.deviceId,
|
||||||
|
group.scales
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStatusBar(scaleMap)
|
updateStatusBar(scaleMap)
|
||||||
@@ -167,8 +172,8 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
private inner class DeviceGroupAdapter(data: MutableList<DeviceGroup>) :
|
private inner class DeviceGroupAdapter(data: MutableList<DeviceGroup>) :
|
||||||
BaseMultiItemAdapter<DeviceGroup>(data) {
|
BaseMultiItemAdapter<DeviceGroup>(data) {
|
||||||
|
|
||||||
private val scale1VHMap = mutableMapOf<String, Scale1VH>()
|
private val scale1VHMap = mutableMapOf<String, Scale1VH>()
|
||||||
private val scale2VHMap = mutableMapOf<String, Scale2VH>()
|
private val scale2VHMap = mutableMapOf<String, Scale2VH>()
|
||||||
private val scale22VHMap = mutableMapOf<String, Scale22VH>()
|
private val scale22VHMap = mutableMapOf<String, Scale22VH>()
|
||||||
private val scale18VHMap = mutableMapOf<String, Scale18VH>()
|
private val scale18VHMap = mutableMapOf<String, Scale18VH>()
|
||||||
|
|
||||||
@@ -180,94 +185,164 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addItemType(VIEW_TYPE_SCALE2, object : BaseMultiItemAdapter.OnMultiItemAdapterListener<DeviceGroup, QuickViewHolder> {
|
addItemType(
|
||||||
override fun onCreate(context: Context, parent: ViewGroup, viewType: Int) =
|
VIEW_TYPE_SCALE2,
|
||||||
QuickViewHolder(ListTypeScale2Binding.inflate(LayoutInflater.from(context), parent, false).root)
|
object :
|
||||||
override fun onBind(holder: QuickViewHolder, position: Int, item: DeviceGroup?) {
|
BaseMultiItemAdapter.OnMultiItemAdapterListener<DeviceGroup, QuickViewHolder> {
|
||||||
item ?: return
|
override fun onCreate(context: Context, parent: ViewGroup, viewType: Int) =
|
||||||
val b = ListTypeScale2Binding.bind(holder.itemView)
|
QuickViewHolder(
|
||||||
val vh = Scale2VH(b)
|
ListTypeScale2Binding.inflate(
|
||||||
scale2VHMap[item.deviceId] = vh
|
LayoutInflater.from(context),
|
||||||
vh.bind(item)
|
parent,
|
||||||
|
false
|
||||||
|
).root
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun onBind(
|
||||||
|
holder: QuickViewHolder,
|
||||||
|
position: Int,
|
||||||
|
item: DeviceGroup?
|
||||||
|
) {
|
||||||
|
item ?: return
|
||||||
|
val b = ListTypeScale2Binding.bind(holder.itemView)
|
||||||
|
val vh = Scale2VH(b)
|
||||||
|
scale2VHMap[item.deviceId] = vh
|
||||||
|
vh.bind(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
addItemType(
|
||||||
|
VIEW_TYPE_SCALE22,
|
||||||
|
object :
|
||||||
|
BaseMultiItemAdapter.OnMultiItemAdapterListener<DeviceGroup, QuickViewHolder> {
|
||||||
|
override fun onCreate(context: Context, parent: ViewGroup, viewType: Int) =
|
||||||
|
QuickViewHolder(
|
||||||
|
ListTypeScale22Binding.inflate(
|
||||||
|
LayoutInflater.from(context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
).root
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun onBind(
|
||||||
|
holder: QuickViewHolder,
|
||||||
|
position: Int,
|
||||||
|
item: DeviceGroup?
|
||||||
|
) {
|
||||||
|
item ?: return
|
||||||
|
val b = ListTypeScale22Binding.bind(holder.itemView)
|
||||||
|
// 每次 onBind 时注册/更新 VH 缓存,后续数据更新直接走 VH,不再触发 notify
|
||||||
|
val vh = Scale22VH(b)
|
||||||
|
scale22VHMap[item.deviceId] = vh
|
||||||
|
vh.bind(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
addItemType(
|
||||||
|
VIEW_TYPE_SCALE18,
|
||||||
|
object :
|
||||||
|
BaseMultiItemAdapter.OnMultiItemAdapterListener<DeviceGroup, QuickViewHolder> {
|
||||||
|
override fun onCreate(context: Context, parent: ViewGroup, viewType: Int) =
|
||||||
|
QuickViewHolder(
|
||||||
|
ListTypeScale18Binding.inflate(
|
||||||
|
LayoutInflater.from(context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
).root
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun onBind(
|
||||||
|
holder: QuickViewHolder,
|
||||||
|
position: Int,
|
||||||
|
item: DeviceGroup?
|
||||||
|
) {
|
||||||
|
item ?: return
|
||||||
|
val b = ListTypeScale18Binding.bind(holder.itemView)
|
||||||
|
val vh = Scale18VH(b)
|
||||||
|
scale18VHMap[item.deviceId] = vh
|
||||||
|
vh.bind(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
addItemType(
|
||||||
|
VIEW_TYPE_SCALE1,
|
||||||
|
object :
|
||||||
|
BaseMultiItemAdapter.OnMultiItemAdapterListener<DeviceGroup, QuickViewHolder> {
|
||||||
|
override fun onCreate(context: Context, parent: ViewGroup, viewType: Int) =
|
||||||
|
QuickViewHolder(
|
||||||
|
ListTypeScale1Binding.inflate(
|
||||||
|
LayoutInflater.from(context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
).root
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun onBind(
|
||||||
|
holder: QuickViewHolder,
|
||||||
|
position: Int,
|
||||||
|
item: DeviceGroup?
|
||||||
|
) {
|
||||||
|
item ?: return
|
||||||
|
val b = ListTypeScale1Binding.bind(holder.itemView)
|
||||||
|
val vh = Scale1VH(b)
|
||||||
|
scale1VHMap[item.deviceId] = vh
|
||||||
|
vh.bind(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
onItemViewType { position, list ->
|
||||||
|
when (list.getOrNull(position)?.deviceId) {
|
||||||
|
ScaleDeviceConfig.DEVICE_ID_2 -> VIEW_TYPE_SCALE2
|
||||||
|
ScaleDeviceConfig.DEVICE_ID_22 -> VIEW_TYPE_SCALE22
|
||||||
|
ScaleDeviceConfig.DEVICE_ID_18 -> VIEW_TYPE_SCALE18
|
||||||
|
else -> VIEW_TYPE_SCALE1
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
addItemType(VIEW_TYPE_SCALE22, object : BaseMultiItemAdapter.OnMultiItemAdapterListener<DeviceGroup, QuickViewHolder> {
|
|
||||||
override fun onCreate(context: Context, parent: ViewGroup, viewType: Int) =
|
|
||||||
QuickViewHolder(ListTypeScale22Binding.inflate(LayoutInflater.from(context), parent, false).root)
|
|
||||||
override fun onBind(holder: QuickViewHolder, position: Int, item: DeviceGroup?) {
|
|
||||||
item ?: return
|
|
||||||
val b = ListTypeScale22Binding.bind(holder.itemView)
|
|
||||||
// 每次 onBind 时注册/更新 VH 缓存,后续数据更新直接走 VH,不再触发 notify
|
|
||||||
val vh = Scale22VH(b)
|
|
||||||
scale22VHMap[item.deviceId] = vh
|
|
||||||
vh.bind(item)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
addItemType(VIEW_TYPE_SCALE18, object : BaseMultiItemAdapter.OnMultiItemAdapterListener<DeviceGroup, QuickViewHolder> {
|
|
||||||
override fun onCreate(context: Context, parent: ViewGroup, viewType: Int) =
|
|
||||||
QuickViewHolder(ListTypeScale18Binding.inflate(LayoutInflater.from(context), parent, false).root)
|
|
||||||
override fun onBind(holder: QuickViewHolder, position: Int, item: DeviceGroup?) {
|
|
||||||
item ?: return
|
|
||||||
val b = ListTypeScale18Binding.bind(holder.itemView)
|
|
||||||
val vh = Scale18VH(b)
|
|
||||||
scale18VHMap[item.deviceId] = vh
|
|
||||||
vh.bind(item)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
addItemType(VIEW_TYPE_SCALE1, object : BaseMultiItemAdapter.OnMultiItemAdapterListener<DeviceGroup, QuickViewHolder> {
|
|
||||||
override fun onCreate(context: Context, parent: ViewGroup, viewType: Int) =
|
|
||||||
QuickViewHolder(ListTypeScale1Binding.inflate(LayoutInflater.from(context), parent, false).root)
|
|
||||||
override fun onBind(holder: QuickViewHolder, position: Int, item: DeviceGroup?) {
|
|
||||||
item ?: return
|
|
||||||
val b = ListTypeScale1Binding.bind(holder.itemView)
|
|
||||||
val vh = Scale1VH(b)
|
|
||||||
scale1VHMap[item.deviceId] = vh
|
|
||||||
vh.bind(item)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
onItemViewType { position, list -> when (list.getOrNull(position)?.deviceId) {
|
|
||||||
ScaleDeviceConfig.DEVICE_ID_2 -> VIEW_TYPE_SCALE2
|
|
||||||
ScaleDeviceConfig.DEVICE_ID_22 -> VIEW_TYPE_SCALE22
|
|
||||||
ScaleDeviceConfig.DEVICE_ID_18 -> VIEW_TYPE_SCALE18
|
|
||||||
else -> VIEW_TYPE_SCALE1
|
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── ViewHolder: 2个秤 ──────────────────────────────────────────────────
|
// ── ViewHolder: 2个秤 ──────────────────────────────────────────────────
|
||||||
|
|
||||||
private inner class Scale2VH(val b: ListTypeScale2Binding) : RecyclerView.ViewHolder(b.root) {
|
private inner class Scale2VH(val b: ListTypeScale2Binding) : RecyclerView.ViewHolder(b.root) {
|
||||||
private lateinit var cells: List<LinearLayout>
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
fun bind(group: DeviceGroup) {
|
fun bind(group: DeviceGroup) {
|
||||||
b.tvDeviceIp.text = "IP:${group.ip.ifEmpty { "未知" }}"
|
b.tvDeviceIp.text = "IP:${group.ip.ifEmpty { "未知" }}"
|
||||||
b.tvDeviceLabel.text = "设备:${group.deviceId}"
|
b.tvDeviceLabel.text = "设备:${group.deviceId}"
|
||||||
|
// 两个格子显示秤地址行,隐藏重量/状态(showAddress 通过 visibility 控制)
|
||||||
if (!::cells.isInitialized) {
|
listOf(b.cell1, b.cell2).forEach { cell ->
|
||||||
val cellSize = (resources.displayMetrics.widthPixels - 4 * 4.dp - 10.dp) / 2
|
cell.tvAddress.visibility = android.view.View.VISIBLE
|
||||||
cells = group.scales.take(2).map { scale ->
|
cell.tvWeight.visibility = android.view.View.VISIBLE
|
||||||
makeScaleCell(scale, cellSize).also { cell ->
|
cell.tvState.visibility = android.view.View.VISIBLE
|
||||||
cell.setOnClickListener {
|
cell.root.setOnClickListener {
|
||||||
val s = cell.tag as? ScaleData ?: return@setOnClickListener
|
val s = cell.root.tag as? ScaleData ?: return@setOnClickListener
|
||||||
showTareDialog(deviceId = s.deviceId, ip = s.ip, address = s.address)
|
showTareDialog(deviceId = s.deviceId, ip = s.ip, address = s.address)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
b.llScaleContainer.removeAllViews()
|
|
||||||
cells.forEach { b.llScaleContainer.addView(it) }
|
|
||||||
}
|
}
|
||||||
updateScales(group.scales)
|
updateScales(group.scales)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateScales(scales: List<ScaleData>) {
|
fun updateScales(scales: List<ScaleData>) {
|
||||||
if (!::cells.isInitialized) return
|
bindCell(b.cell1, scales.getOrNull(0))
|
||||||
scales.take(2).forEachIndexed { i, scale ->
|
bindCell(b.cell2, scales.getOrNull(1))
|
||||||
cells.getOrNull(i)?.let { cell ->
|
}
|
||||||
cell.tag = scale
|
|
||||||
updateScaleCell(cell, scale)
|
@SuppressLint("SetTextI18n")
|
||||||
}
|
private fun bindCell(cell: ListItemScale22RowBinding, scale: ScaleData?) {
|
||||||
|
cell.root.tag = scale
|
||||||
|
cell.tvAddress.run {
|
||||||
|
text = scale?.let { "秤${it.address}" } ?: ""
|
||||||
|
textSize = 18f
|
||||||
}
|
}
|
||||||
|
cell.tvName.run {
|
||||||
|
text = if (scale?.address == 1) "净材" else "熟食"
|
||||||
|
textSize = 22f
|
||||||
|
}
|
||||||
|
cell.tvWeight.run {
|
||||||
|
text = scale?.let { "${it.weight}g" } ?: ""
|
||||||
|
textSize = 22f
|
||||||
|
}
|
||||||
|
cell.tvState.run {
|
||||||
|
text = stateStr(scale?.state)
|
||||||
|
textSize = 22f
|
||||||
|
}
|
||||||
|
cell.root.updateLayoutParams { height = 400.dp }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,9 +369,18 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
alignItems = AlignItems.FLEX_START
|
alignItems = AlignItems.FLEX_START
|
||||||
}
|
}
|
||||||
b.rvScales.itemAnimator = null
|
b.rvScales.itemAnimator = null
|
||||||
innerAdapter = Seasoning22GridAdapter(largeSize, smallSize, showNameOnly = false, showAddress = true).apply {
|
innerAdapter = Seasoning22GridAdapter(
|
||||||
|
largeSize,
|
||||||
|
smallSize,
|
||||||
|
showNameOnly = false,
|
||||||
|
showAddress = true
|
||||||
|
).apply {
|
||||||
onItemClick = { scale, _ ->
|
onItemClick = { scale, _ ->
|
||||||
showTareDialog(deviceId = scale.deviceId, ip = scale.ip, address = scale.address)
|
showTareDialog(
|
||||||
|
deviceId = scale.deviceId,
|
||||||
|
ip = scale.ip,
|
||||||
|
address = scale.address
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.rvScales.adapter = innerAdapter
|
b.rvScales.adapter = innerAdapter
|
||||||
@@ -328,11 +412,16 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
b.rvScales.layoutManager = gridLayoutManager
|
b.rvScales.layoutManager = gridLayoutManager
|
||||||
b.rvScales.itemAnimator = null
|
b.rvScales.itemAnimator = null
|
||||||
innerAdapter = Seasoning18GridAdapter(showNameOnly = false, showAddress = true).apply {
|
innerAdapter =
|
||||||
onItemClick = { scale, _ ->
|
Seasoning18GridAdapter(showNameOnly = false, showAddress = true).apply {
|
||||||
showTareDialog(deviceId = scale.deviceId, ip = scale.ip, address = scale.address)
|
onItemClick = { scale, _ ->
|
||||||
|
showTareDialog(
|
||||||
|
deviceId = scale.deviceId,
|
||||||
|
ip = scale.ip,
|
||||||
|
address = scale.address
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
b.rvScales.adapter = innerAdapter
|
b.rvScales.adapter = innerAdapter
|
||||||
}
|
}
|
||||||
updateScales(group.scales)
|
updateScales(group.scales)
|
||||||
@@ -374,56 +463,13 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
// ── 工具方法 ───────────────────────────────────────────────────────────
|
// ── 工具方法 ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private fun stateStr(state: Int?) = when (state) {
|
private fun stateStr(state: Int?) = when (state) {
|
||||||
WeightUtil.STATE_STABLE -> "稳定"
|
WeightUtil.STATE_STABLE -> "稳定"
|
||||||
WeightUtil.STATE_UNSTABLE -> "不稳定"
|
WeightUtil.STATE_UNSTABLE -> "不稳定"
|
||||||
WeightUtil.STATE_OVER_WEIGHT -> "超量"
|
WeightUtil.STATE_OVER_WEIGHT -> "超量"
|
||||||
null -> ""
|
null -> ""
|
||||||
else -> "$state"
|
else -> "$state"
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建正方形秤格子(用于 Scale2VH 初始化) */
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
private fun makeScaleCell(scale: ScaleData, cellSize: Int): LinearLayout {
|
|
||||||
val margin = 2.dp
|
|
||||||
return LinearLayout(this).apply {
|
|
||||||
orientation = LinearLayout.VERTICAL
|
|
||||||
gravity = Gravity.CENTER
|
|
||||||
layoutParams = LinearLayout.LayoutParams(0, cellSize - margin * 2, 1f)
|
|
||||||
.also { it.setMargins(margin, margin, margin, margin) }
|
|
||||||
setPadding(4.dp, 2.dp, 4.dp, 2.dp)
|
|
||||||
setBackgroundResource(R.drawable.shape_scale_cell)
|
|
||||||
val baseSize = ((cellSize - margin * 2) / resources.displayMetrics.density).toInt()
|
|
||||||
addView(makeCellText("秤${scale.address}", (baseSize * 0.16f).coerceIn(9f, 14f).toInt()))
|
|
||||||
val foodType = if (scale.address == 1) "净材" else "熟食"
|
|
||||||
addView(makeCellText(foodType, (baseSize * 0.16f).coerceIn(9f, 14f).toInt()))
|
|
||||||
addView(makeCellText("${scale.weight}g", (baseSize * 0.22f).coerceIn(12f, 20f).toInt(), bold = true))
|
|
||||||
addView(makeCellText(stateStr(scale.state), (baseSize * 0.14f).coerceIn(8f, 12f).toInt()))
|
|
||||||
tag = scale
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 仅更新格子内文字,不重建 view(用于 Scale2VH 数据刷新) */
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
private fun updateScaleCell(cell: LinearLayout, scale: ScaleData) {
|
|
||||||
(cell.getChildAt(0) as? TextView)?.text = "秤${scale.address}"
|
|
||||||
(cell.getChildAt(1) as? TextView)?.text = if (scale.address == 1) "净材" else "熟食"
|
|
||||||
(cell.getChildAt(2) as? TextView)?.text = "${scale.weight}g"
|
|
||||||
(cell.getChildAt(3) as? TextView)?.text = stateStr(scale.state)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun makeCellText(text: String, spSize: Int, bold: Boolean = false): TextView =
|
|
||||||
TextView(this).apply {
|
|
||||||
this.text = text
|
|
||||||
textSize = spSize.toFloat()
|
|
||||||
if (bold) setTypeface(null, android.graphics.Typeface.BOLD)
|
|
||||||
setTextColor(if (bold) getColor(R.color.home_title) else getColor(R.color.home_sub_title))
|
|
||||||
layoutParams = LinearLayout.LayoutParams(
|
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT
|
|
||||||
)
|
|
||||||
gravity = Gravity.CENTER
|
|
||||||
includeFontPadding = false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 弹出清零确认对话框
|
* 弹出清零确认对话框
|
||||||
* @param deviceId 目标设备 ID
|
* @param deviceId 目标设备 ID
|
||||||
|
|||||||
@@ -29,48 +29,57 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/llScaleContainer"
|
android:id="@+id/llScaleContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="120dp"
|
android:layout_height="260dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="vertical"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center"
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
android:layout_marginBottom="2dp"
|
android:layout_marginBottom="2dp"
|
||||||
android:paddingStart="30dp"
|
|
||||||
android:background="@drawable/shape_scale_cell">
|
android:background="@drawable/shape_scale_cell">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvAddr"
|
android:id="@+id/tvAddr"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:textSize="18sp"
|
||||||
android:textSize="22sp"
|
android:includeFontPadding="false"
|
||||||
android:textColor="@color/home_sub_title"
|
android:textColor="@color/home_sub_title"
|
||||||
tools:text="秤 1" />
|
tools:text="秤 1" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/tvName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="22sp"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
android:textColor="@color/home_sub_title"
|
||||||
|
android:text="油" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
android:id="@+id/tvWeight"
|
android:id="@+id/tvWeight"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="2"
|
|
||||||
android:textSize="26sp"
|
android:textSize="26sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
android:layout_marginVertical="5dp"
|
||||||
android:textColor="@color/home_title"
|
android:textColor="@color/home_title"
|
||||||
tools:text="100.0 g" />
|
tools:text="100.0 g" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvState"
|
android:id="@+id/tvState"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
|
android:includeFontPadding="false"
|
||||||
android:textColor="@color/home_sub_title"
|
android:textColor="@color/home_sub_title"
|
||||||
tools:text="稳定" />
|
tools:text="稳定" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.divider.MaterialDivider
|
<!-- <com.google.android.material.divider.MaterialDivider-->
|
||||||
android:layout_width="match_parent"
|
<!-- android:layout_width="match_parent"-->
|
||||||
android:layout_height="1dp"
|
<!-- android:layout_height="1dp"-->
|
||||||
android:background="@color/gray_eb"
|
<!-- android:background="@color/gray_eb"-->
|
||||||
android:layout_marginTop="10dp" />
|
<!-- android:layout_marginTop="10dp" />-->
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -32,10 +32,10 @@
|
|||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
android:overScrollMode="never" />
|
android:overScrollMode="never" />
|
||||||
|
|
||||||
<com.google.android.material.divider.MaterialDivider
|
<!-- <com.google.android.material.divider.MaterialDivider-->
|
||||||
android:layout_width="match_parent"
|
<!-- android:layout_width="match_parent"-->
|
||||||
android:layout_height="1dp"
|
<!-- android:layout_height="1dp"-->
|
||||||
android:background="@color/gray_eb"
|
<!-- android:background="@color/gray_eb"-->
|
||||||
android:layout_marginTop="10dp" />
|
<!-- android:layout_marginTop="10dp" />-->
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -25,18 +25,29 @@
|
|||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
tools:text="设备:device_01" />
|
tools:text="设备:device_01" />
|
||||||
|
|
||||||
<!-- 水平排列2个秤格子,高度固定 400dp -->
|
<!-- 水平排列2个秤格子 -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/llScaleContainer"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="400dp"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_marginTop="5dp" />
|
android:layout_marginTop="5dp">
|
||||||
|
|
||||||
<com.google.android.material.divider.MaterialDivider
|
<include
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/cell1"
|
||||||
android:layout_height="1dp"
|
layout="@layout/list_item_scale22_row"
|
||||||
android:background="@color/gray_eb"
|
android:layout_width="0dp"
|
||||||
android:layout_marginTop="10dp" />
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_margin="2dp" />
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/cell2"
|
||||||
|
layout="@layout/list_item_scale22_row"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_margin="2dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -32,10 +32,10 @@
|
|||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
android:overScrollMode="never" />
|
android:overScrollMode="never" />
|
||||||
|
|
||||||
<com.google.android.material.divider.MaterialDivider
|
<!-- <com.google.android.material.divider.MaterialDivider-->
|
||||||
android:layout_width="match_parent"
|
<!-- android:layout_width="match_parent"-->
|
||||||
android:layout_height="1dp"
|
<!-- android:layout_height="1dp"-->
|
||||||
android:background="@color/gray_eb"
|
<!-- android:background="@color/gray_eb"-->
|
||||||
android:layout_marginTop="10dp" />
|
<!-- android:layout_marginTop="10dp" />-->
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user