feat(shelf): 更新货架界面和菜品分类功能
- 重命名tvFoodType为tvVegTypeName以统一命名规范 - 新增bg_pressed.xml选择器用于按钮按下效果 - 在ChipSelectDialog中添加必选验证和改进布局参数 - 扩展HomeV3Activity传递菜品名称和蔬菜类型信息 - 调整list_item_shelf_v3.xml布局尺寸和权重配置 - 新增tvFoodType显示菜品分类并调整字体间距 - 更新ShelfV3Activity处理菜品分类数据传递和显示 - 修改SlotModel数据结构支持蔬菜类型ID和名称字段 - 优化适配器中菜品分类文本显示逻辑和颜色设置
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -65,6 +65,7 @@ class ShelfV3Adapter(list: MutableList<SlotModel>) :
|
||||
setTextColor(getColor(R.color.food_weight_blue))
|
||||
text = "-"
|
||||
}
|
||||
binding.tvFoodType.text = ""
|
||||
return
|
||||
}
|
||||
|
||||
@@ -78,6 +79,8 @@ class ShelfV3Adapter(list: MutableList<SlotModel>) :
|
||||
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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@color/white" android:state_pressed="false" />
|
||||
<item android:drawable="@color/gray_edit" android:state_pressed="true" />
|
||||
</selector>
|
||||
@@ -75,7 +75,7 @@
|
||||
tools:text="金针菇" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvFoodType"
|
||||
android:id="@+id/tvVegTypeName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
app:cardElevation="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="600dp"
|
||||
android:layout_width="500dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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="空" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvFoodType"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:includeFontPadding="false"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp"
|
||||
tools:text="切块" />
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0.833" />
|
||||
android:layout_weight="0.8" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvFoodWeight"
|
||||
@@ -62,7 +75,7 @@
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0.933" />
|
||||
android:layout_weight="0.9" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvStoreDate"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<color name="food_weight_blue">#C8C8FF</color>
|
||||
<color name="food_weight_orange">#FF6400</color>
|
||||
<color name="black999">#999999</color>
|
||||
<color name="black666">#666666</color>
|
||||
<color name="white_f6">#F6F6F6</color>
|
||||
<color name="gray_edit">#E6EBF0</color>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user