From 5412f0b6b9e557f620ee9d56b1287ff1507ee812 Mon Sep 17 00:00:00 2001 From: lvmeng <848755140@qq.com> Date: Fri, 26 Jun 2026 16:24:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(shelf):=20=E6=9B=B4=E6=96=B0=E8=B4=A7?= =?UTF-8?q?=E6=9E=B6=E7=95=8C=E9=9D=A2=E5=92=8C=E8=8F=9C=E5=93=81=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重命名tvFoodType为tvVegTypeName以统一命名规范 - 新增bg_pressed.xml选择器用于按钮按下效果 - 在ChipSelectDialog中添加必选验证和改进布局参数 - 扩展HomeV3Activity传递菜品名称和蔬菜类型信息 - 调整list_item_shelf_v3.xml布局尺寸和权重配置 - 新增tvFoodType显示菜品分类并调整字体间距 - 更新ShelfV3Activity处理菜品分类数据传递和显示 - 修改SlotModel数据结构支持蔬菜类型ID和名称字段 - 优化适配器中菜品分类文本显示逻辑和颜色设置 --- .../shelves/dialog/ChipSelectDialog.kt | 23 ++++++++++++++----- .../sw/scalefusion/shelf/HomeV3Activity.kt | 2 ++ .../sw/scalefusion/shelf/ShelfV3Activity.kt | 22 ++++++++++++------ .../shelf/adapter/ShelfV3Adapter.kt | 3 +++ .../sw/scalefusion/shelf/model/SlotModel.kt | 3 ++- app/src/main/res/drawable/bg_pressed.xml | 5 ++++ app/src/main/res/layout/activity_shelf_v3.xml | 2 +- .../main/res/layout/dialog_chip_select.xml | 8 +++---- .../main/res/layout/list_item_shelf_v3.xml | 21 +++++++++++++---- app/src/main/res/values/colors.xml | 1 + 10 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 app/src/main/res/drawable/bg_pressed.xml diff --git a/app/src/main/java/com/shuwei/intelligent/shelves/dialog/ChipSelectDialog.kt b/app/src/main/java/com/shuwei/intelligent/shelves/dialog/ChipSelectDialog.kt index 9d2c366..bd57e81 100644 --- a/app/src/main/java/com/shuwei/intelligent/shelves/dialog/ChipSelectDialog.kt +++ b/app/src/main/java/com/shuwei/intelligent/shelves/dialog/ChipSelectDialog.kt @@ -7,12 +7,15 @@ import android.os.Bundle import android.view.Gravity import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup import com.google.android.material.chip.Chip +import com.google.android.material.chip.ChipGroup import com.shuwei.intelligent.shelves.R import com.shuwei.intelligent.shelves.base.BaseDialog import com.shuwei.intelligent.shelves.databinding.DialogChipSelectBinding import com.shuwei.intelligent.shelves.utils.ext.dp import com.shuwei.intelligent.shelves.utils.ext.hideKeyboard +import com.shuwei.intelligent.shelves.utils.ext.toast /** * 带ChipGroup选择的弹窗,支持传入选项列表,回调返回选中索引 @@ -55,9 +58,11 @@ class ChipSelectDialog(context: Context) : Dialog(context, R.style.DialogTheme) } binding.btnConfirm.setOnClickListener { - if (selectedIndex >= 0) { - onItemSelected?.invoke(selectedIndex) + if (binding.chipGroup.checkedChipId == -1) { + context.toast("请选择净菜分类") + return@setOnClickListener } + onItemSelected?.invoke(selectedIndex) dismiss() } } @@ -80,9 +85,9 @@ class ChipSelectDialog(context: Context) : Dialog(context, R.style.DialogTheme) text = label isCheckable = true isCheckedIconVisible = false - textSize = 20f - chipStartPadding = 15.dp.toFloat() - chipEndPadding = 15.dp.toFloat() + textSize = 22f + chipStartPadding = 18.dp.toFloat() + chipEndPadding = 18.dp.toFloat() textStartPadding = 8.dp.toFloat() textEndPadding = 8.dp.toFloat() chipMinHeight = 50.dp.toFloat() @@ -94,7 +99,13 @@ class ChipSelectDialog(context: Context) : Dialog(context, R.style.DialogTheme) selectedIndex = index } } - binding.chipGroup.addView(chip) + val params = ChipGroup.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ).apply { + setMargins(8, 5.dp, 8.dp, 5.dp) // left, top, right, bottom + } + binding.chipGroup.addView(chip, params) } } } diff --git a/app/src/main/java/com/sw/scalefusion/shelf/HomeV3Activity.kt b/app/src/main/java/com/sw/scalefusion/shelf/HomeV3Activity.kt index fc0f1b8..b70f599 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/HomeV3Activity.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/HomeV3Activity.kt @@ -249,6 +249,8 @@ class HomeV3Activity : BaseActivity() { it.putExtra(ShelfV3Activity.EXTRA_CABINET_ID, model.cabinetId) it.putExtra(ShelfV3Activity.EXTRA_SLOT_NO, model.slotNo) it.putExtra(ShelfV3Activity.EXTRA_CANTEEN_ID, canteenId) + it.putExtra(ShelfV3Activity.EXTRA_MATER_NAME, model.materName) + it.putExtra(ShelfV3Activity.EXTRA_VEG_TYPE_NAME, model.vegTypeName) }) { result -> result?.let { onShelfActivityResult(position, it) } } diff --git a/app/src/main/java/com/sw/scalefusion/shelf/ShelfV3Activity.kt b/app/src/main/java/com/sw/scalefusion/shelf/ShelfV3Activity.kt index aed75ce..4a0bf6c 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/ShelfV3Activity.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/ShelfV3Activity.kt @@ -28,8 +28,6 @@ import com.shuwei.intelligent.shelves.utils.ext.toast import com.shuwei.intelligent.shelves.utils.ext.visible import com.sw.scalefusion.shelf.adapter.PendingInboundAdapter import com.sw.scalefusion.shelf.model.FoodItem -import com.sw.scalefusion.shelf.model.PendingInboundItem -import com.sw.scalefusion.shelf.model.PendingInboundRequest import com.sw.scalefusion.shelf.model.PutSlotRequest import com.sw.scalefusion.shelf.model.SearchFoodRequest import com.sw.scalefusion.shelf.model.SlotDetailRequest @@ -52,6 +50,8 @@ class ShelfV3Activity : BaseActivity() { const val EXTRA_CABINET_ID = "cabinetId" const val EXTRA_CANTEEN_ID = "canteenId" const val EXTRA_SLOT_NO = "slotNo" + const val EXTRA_MATER_NAME = "materName" + const val EXTRA_VEG_TYPE_NAME = "vegTypeName" const val YYYY_MM_DD__EEEE_HH_MM_SS = "yyyy年MM月dd日 EEEE***HH:mm:ss" } @@ -96,7 +96,7 @@ class ShelfV3Activity : BaseActivity() { val index = optionList[position].typeSelectedIndex val typeList = optionList[position].vegTypeList ?: emptyList() val selectType = typeList.getOrNull(index)?.vegTypeName ?: "" - binding.tvFoodType.text = selectType + binding.tvVegTypeName.text = selectType KeyboardUtil.hideKeyboard(this@ShelfV3Activity.window.decorView) } @@ -104,6 +104,8 @@ class ShelfV3Activity : BaseActivity() { private var canteenId: Long = 0 private var cabinetId: String = "" private var slotNo: String = "" + private var materName: String = "" + private var vegTypeName: String = "" @Suppress("DEPRECATION") override fun onCreate(savedInstanceState: Bundle?) { @@ -117,9 +119,12 @@ class ShelfV3Activity : BaseActivity() { canteenId = intent.getLongExtra(EXTRA_CANTEEN_ID, 0) cabinetId = intent.getStringExtra(EXTRA_CABINET_ID) ?: "" slotNo = intent.getStringExtra(EXTRA_SLOT_NO) ?: "" + materName = intent.getStringExtra(EXTRA_MATER_NAME) ?: "" + vegTypeName = intent.getStringExtra(EXTRA_VEG_TYPE_NAME) ?: "" binding.tvShelfName.text = slotNo - + binding.tvFoodName.text = materName.ifBlank { "-" } + binding.tvVegTypeName.text = vegTypeName initRecyclerView() initSearchBox() initButtons() @@ -142,7 +147,7 @@ class ShelfV3Activity : BaseActivity() { /** 从 slotDetail 响应更新 UI */ private fun updateUI(model: SlotModel) { binding.tvFoodName.text = if (model.materName.isNullOrBlank()) "-" else model.materName - binding.tvFoodType.text = "" + binding.tvVegTypeName.text = model.vegTypeName val weightG = model.weight ?: 0.0 realWeight = (weightG * 1000.0).toInt() binding.tvFoodWeight.text = if (weightG >= 1.0) "%.3f千克".format(weightG) @@ -185,7 +190,7 @@ class ShelfV3Activity : BaseActivity() { binding.btnClearEmpty.setOnClickListener { v -> clearZero() binding.tvFoodName.text = "-" - binding.tvFoodType.text = "" + binding.tvVegTypeName.text = "" Loading.show(this@ShelfV3Activity) v.postDelayed({ Loading.dismiss() @@ -211,6 +216,7 @@ class ShelfV3Activity : BaseActivity() { return@clickWithDebounce } val model = shelfModel ?: return@clickWithDebounce + val vegType = item.vegTypeList?.getOrNull(item.typeSelectedIndex) viewModel.put( request = PutSlotRequest( cabinetType = cabinetType, @@ -220,7 +226,7 @@ class ShelfV3Activity : BaseActivity() { materName = item.materName, weight = shelfModel?.weight ?: 0.0 ).also { - it.vegTypeId = item.vegTypeList?.getOrNull(item.typeSelectedIndex)?.vegTypeId + it.vegTypeId = vegType?.vegTypeId }, onLoading = { showProgress() }, onSuccess = onSuccess@{ inboundNo -> @@ -231,6 +237,8 @@ class ShelfV3Activity : BaseActivity() { // } val resultModel = item.toSlotModel(model).also { // it.inboundNo = inboundNo + it.vegTypeId = vegType?.vegTypeId + it.vegTypeName = vegType?.vegTypeName } val result = Intent().apply { putExtra(SHELF_MODEL, resultModel) diff --git a/app/src/main/java/com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt b/app/src/main/java/com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt index c1618e1..493b1a0 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt @@ -65,6 +65,7 @@ class ShelfV3Adapter(list: MutableList) : setTextColor(getColor(R.color.food_weight_blue)) text = "-" } + binding.tvFoodType.text = "" return } @@ -78,6 +79,8 @@ class ShelfV3Adapter(list: MutableList) : setTextColor(getColor(R.color.black999)) text = item.storeTime } + binding.tvFoodType.text = item.vegTypeName + binding.tvFoodType.setTextColor(getColor(R.color.black666)) } private fun getColor(@ColorRes id: Int) = ContextCompat.getColor(context, id) diff --git a/app/src/main/java/com/sw/scalefusion/shelf/model/SlotModel.kt b/app/src/main/java/com/sw/scalefusion/shelf/model/SlotModel.kt index 48f36a3..aeb403c 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/model/SlotModel.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/model/SlotModel.kt @@ -15,7 +15,8 @@ data class SlotModel( val materId: Long? = null, val materName: String? = null, val traceCode: String? = null, - val vegTypeId: String? = null, + var vegTypeId: Long? = null, + var vegTypeName: String? = null, //weight单位千克 var weight: Double? = 0.0, var storeTime: String? = null, diff --git a/app/src/main/res/drawable/bg_pressed.xml b/app/src/main/res/drawable/bg_pressed.xml new file mode 100644 index 0000000..ef0053e --- /dev/null +++ b/app/src/main/res/drawable/bg_pressed.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_shelf_v3.xml b/app/src/main/res/layout/activity_shelf_v3.xml index b604eb1..00a8880 100644 --- a/app/src/main/res/layout/activity_shelf_v3.xml +++ b/app/src/main/res/layout/activity_shelf_v3.xml @@ -75,7 +75,7 @@ tools:text="金针菇" /> @@ -30,7 +30,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="30dp" - android:layout_marginVertical="40dp" + android:layout_marginVertical="50dp" app:selectionRequired="false" app:singleSelection="true" /> @@ -52,7 +52,7 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" - android:background="@color/white" + android:background="@drawable/bg_pressed" android:text="取消" android:textColor="@android:color/darker_gray" android:textSize="24sp" /> @@ -67,7 +67,7 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" - android:background="@color/white" + android:background="@drawable/bg_pressed" android:text="确定" android:textColor="@color/bg_card_blue" android:textSize="24sp" /> diff --git a/app/src/main/res/layout/list_item_shelf_v3.xml b/app/src/main/res/layout/list_item_shelf_v3.xml index eb5b251..2c6cbc0 100644 --- a/app/src/main/res/layout/list_item_shelf_v3.xml +++ b/app/src/main/res/layout/list_item_shelf_v3.xml @@ -3,8 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layoutCard" - android:layout_width="0dp" - android:layout_height="0dp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" android:layout_margin="12dp" app:cardBackgroundColor="@color/bg_card_blue" app:cardCornerRadius="12dp" @@ -38,15 +38,28 @@ android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="1" + android:includeFontPadding="false" android:textColor="@color/white" android:textSize="30sp" android:textStyle="bold" tools:text="空" /> + + + android:layout_weight="0.8" /> + android:layout_weight="0.9" /> #C8C8FF #FF6400 #999999 + #666666 #F6F6F6 #E6EBF0 \ No newline at end of file