feat(shelf): 支持格口列表下拉刷新和搜索食材验收状态显示

- 在格口列表布局中集成 SmartRefreshLayout,实现下拉刷新功能
- 新增 accepted_green 颜色资源用于验收状态标识
- FoodItem 数据类新增 materCode 和 todayAccepted 字段,支持显示食材编码及验收状态
- HomeV3Activity 中添加 refreshLayout 初始化和刷新逻辑,支持下拉刷新时不弹 Loading,失败时仅提示
- 空视图点击重试由重新拉取改为调用刷新接口 refreshSlots
- 搜索食材列表项布局改为 MaterialCardView,增加显示食材编码副行和右上角验收绿色圆点
- PendingInboundAdapter 根据选中状态调整名称和编码文字颜色及边框颜色
- 根据今日是否已验收决定是否显示食材右上角绿色圆点
This commit is contained in:
mazengfei
2026-09-17 15:13:07 +08:00
parent 9db8996d44
commit b4720b103a
6 changed files with 143 additions and 70 deletions
@@ -11,6 +11,10 @@ import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DefaultItemAnimator
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import com.scwang.smart.refresh.layout.constant.RefreshState
import com.shuwei.intelligent.shelves.App
import com.shuwei.intelligent.shelves.R
import com.shuwei.intelligent.shelves.base.BaseActivity
@@ -23,9 +27,6 @@ import com.shuwei.intelligent.shelves.serial.ProtocolConstants
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.C_TEMP_CMD
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.START_TEMP_CTRL_CMD
import com.shuwei.intelligent.shelves.serial.ScaleManager
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import com.shuwei.intelligent.shelves.utils.IntervalExecutor
import com.shuwei.intelligent.shelves.utils.ext.dp
import com.shuwei.intelligent.shelves.utils.ext.gone
@@ -129,13 +130,50 @@ class HomeV3Activity : BaseActivity() {
saveGoodsTask()
overdueTask()
initRefreshLayout()
refreshSlots()
}
/** 配置格口列表下拉刷新 */
private fun initRefreshLayout() {
binding.refreshLayout.run {
setEnableRefresh(true)
setEnableLoadMore(false)
setOnRefreshListener { refreshSlots(fromPull = true) }
}
}
/**
* 拉取格口列表并刷新 UI。
* @param fromPull true 表示由下拉刷新触发:不弹 Loading,失败时保留现有格口数据仅提示
*/
private fun refreshSlots(fromPull: Boolean = false) {
viewModel.slots(
onLoading = { showProgress() },
onSuccess = { record -> updateUI(record) },
onError = { msg -> showError(msg) }
onLoading = { if (!fromPull) showProgress() },
onSuccess = { record ->
if (fromPull) finishRefresh()
updateUI(record)
},
onError = { msg ->
if (fromPull) {
finishRefresh()
// 列表已有数据时刷新失败仅提示,保留现有格口展示;无数据则走空视图重试
if (list.isEmpty()) showError(msg) else toast(msg)
} else {
showError(msg)
}
}
)
}
/** 结束下拉刷新动画 */
private fun finishRefresh() {
binding.refreshLayout.let {
if (it.state == RefreshState.Refreshing) it.finishRefresh(500)
}
}
private fun showProgress() {
Loading.show(this)
}
@@ -376,13 +414,7 @@ class HomeV3Activity : BaseActivity() {
shelfAdapter.notifyDataSetChanged()
binding.include?.let {
it.root.visible()
it.root.setOnClickListener {
viewModel.slots(
onLoading = { showProgress() },
onSuccess = { record -> updateUI(record) },
onError = { msg -> showError(msg) }
)
}
it.root.setOnClickListener { refreshSlots() }
it.ivEmptyIcon.setImageResource(R.drawable.ic_empty_white)
it.tvEmptyContent.setTextColor(Color.WHITE)
}
@@ -1,8 +1,8 @@
package com.sw.scalefusion.shelf.adapter
import android.content.Context
import android.content.res.ColorStateList
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
@@ -26,13 +26,23 @@ class PendingInboundAdapter(list: MutableList<FoodItem>) :
override fun onBindViewHolder(holder: VH, position: Int, item: FoodItem?) {
item ?: return
val isSelected = item.isSelected
holder.binding.btnFoodName.run {
val binding = holder.binding
// 名称与编码:选中蓝字,未选中灰字
val nameColor = getColor(if (isSelected) R.color.shelf_name_blue else R.color.black999)
binding.tvFoodName.run {
text = item.materName
setTextColor(getColor(if (isSelected) R.color.shelf_name_blue else R.color.black999))
strokeColor = ColorStateList.valueOf(
(if (isSelected) "#4969F5" else "#E6E6E6").toColorInt()
)
setTextColor(nameColor)
}
binding.tvMaterCode.run {
text = item.materCode
setTextColor(nameColor)
}
// 选中蓝边框,未选中灰边框
binding.cardFood.strokeColor =
(if (isSelected) "#4969F5" else "#E6E6E6").toColorInt()
// 仅今日已验收的食材显示右上角绿色圆点
binding.viewAcceptedDot.visibility =
if (item.todayAccepted == true) View.VISIBLE else View.GONE
}
private fun getColor(@ColorRes id: Int) = ContextCompat.getColor(context, id)
@@ -6,6 +6,10 @@ import java.util.Date
data class FoodItem(
var materId:Long? = null,
var materName:String? = null,
/** 食材编码(一级分类+二级分类+自编码,全局唯一) */
var materCode:String? = null,
/** 今日是否在验收秤有验收记录 */
var todayAccepted:Boolean? = null,
var materUrl:String? = null,
var vegTypeList:List<FoodType>? = null,
var isSelected:Boolean = false,
+23 -9
View File
@@ -6,16 +6,30 @@
xmlns:tools="http://schemas.android.com/tools"
tools:background="@color/bg_page">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvShelf"
<!-- 格口列表支持下拉刷新:重新拉取 /init 格口数据 -->
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
android:overScrollMode="never"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
tools:listitem="@layout/list_item_shelf_v3"/>
android:layout_height="match_parent">
<com.scwang.smart.refresh.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlAccentColor="@color/white"
app:srlPrimaryColor="@color/bg_page"
app:srlEnableLastTime="false" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvShelf"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
android:overScrollMode="never"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
tools:listitem="@layout/list_item_shelf_v3"/>
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
<include
android:id="@+id/include"
+54 -42
View File
@@ -1,48 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!--<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
<!-- xmlns:tools="http://schemas.android.com/tools"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="80dp"-->
<!-- android:layout_margin="12dp">-->
<!-- <TextView-->
<!-- android:id="@+id/btnFoodName"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center"-->
<!-- android:ellipsize="end"-->
<!-- android:gravity="center"-->
<!-- android:maxLines="1"-->
<!-- android:paddingStart="5dp"-->
<!-- android:paddingEnd="5dp"-->
<!-- android:fontFamily="sans-serif-medium"-->
<!-- android:textColor="@color/black999"-->
<!-- android:textSize="30sp"-->
<!-- tools:text="土豆丝" />-->
<!--</FrameLayout>-->
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android"
<!-- 搜索食材列表 item:食材名 + 编码副行,今日已验收时右上角显示绿色圆点 -->
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/btnFoodName"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:id="@+id/cardFood"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_height="96dp"
android:layout_margin="12dp"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:insetTop="0dp"
android:insetBottom="0dp"
android:maxLines="1"
app:paddingStart="5dp"
app:paddingEnd="5dp"
android:insetRight="0dp"
android:insetLeft="0dp"
android:paddingHorizontal="8dp"
android:textColor="@color/black999"
android:textSize="30sp"
app:cornerRadius="12dp"
app:strokeWidth="2dp"
tools:text="土豆丝土豆丝土豆丝土豆丝土豆丝土豆丝"
/>
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="12dp"
app:cardElevation="0dp"
app:strokeColor="#E6E6E6"
app:strokeWidth="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingStart="5dp"
android:paddingTop="10dp"
android:paddingEnd="5dp">
<TextView
android:id="@+id/tvFoodName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:maxLines="1"
android:textColor="@color/black999"
android:textSize="30sp"
tools:text="土豆丝土豆丝土豆丝" />
<TextView
android:id="@+id/tvMaterCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:textColor="@color/black999"
android:textSize="16sp"
tools:text="0102003" />
</LinearLayout>
<!-- 今日已验收标识圆点,默认隐藏,由 Adapter 控制显示 -->
<View
android:id="@+id/viewAcceptedDot"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="top|end"
android:layout_margin="10dp"
android:background="@drawable/shape_accepted_dot"
android:visibility="gone"
tools:visibility="visible" />
</com.google.android.material.card.MaterialCardView>
+1
View File
@@ -17,6 +17,7 @@
<color name="food_name_black">#0A143C</color>
<color name="food_weight_blue">#C8C8FF</color>
<color name="food_weight_orange">#FF6400</color>
<color name="accepted_green">#34C77B</color>
<color name="black999">#999999</color>
<color name="black666">#666666</color>
<color name="white_f6">#F6F6F6</color>