From b4720b103a30d37be462911455b4381dea2bb332 Mon Sep 17 00:00:00 2001 From: mazengfei <331023091@qq.com> Date: Thu, 17 Sep 2026 15:13:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(shelf):=20=E6=94=AF=E6=8C=81=E6=A0=BC?= =?UTF-8?q?=E5=8F=A3=E5=88=97=E8=A1=A8=E4=B8=8B=E6=8B=89=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=92=8C=E6=90=9C=E7=B4=A2=E9=A3=9F=E6=9D=90=E9=AA=8C=E6=94=B6?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在格口列表布局中集成 SmartRefreshLayout,实现下拉刷新功能 - 新增 accepted_green 颜色资源用于验收状态标识 - FoodItem 数据类新增 materCode 和 todayAccepted 字段,支持显示食材编码及验收状态 - HomeV3Activity 中添加 refreshLayout 初始化和刷新逻辑,支持下拉刷新时不弹 Loading,失败时仅提示 - 空视图点击重试由重新拉取改为调用刷新接口 refreshSlots - 搜索食材列表项布局改为 MaterialCardView,增加显示食材编码副行和右上角验收绿色圆点 - PendingInboundAdapter 根据选中状态调整名称和编码文字颜色及边框颜色 - 根据今日是否已验收决定是否显示食材右上角绿色圆点 --- .../sw/scalefusion/shelf/HomeV3Activity.kt | 58 ++++++++--- .../shelf/adapter/PendingInboundAdapter.kt | 22 +++-- .../sw/scalefusion/shelf/model/FoodItem.kt | 4 + app/src/main/res/layout/activity_home_v3.xml | 32 +++++-- app/src/main/res/layout/list_item_search.xml | 96 +++++++++++-------- app/src/main/res/values/colors.xml | 1 + 6 files changed, 143 insertions(+), 70 deletions(-) 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 cf9834b..d3d2738 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/HomeV3Activity.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/HomeV3Activity.kt @@ -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) } diff --git a/app/src/main/java/com/sw/scalefusion/shelf/adapter/PendingInboundAdapter.kt b/app/src/main/java/com/sw/scalefusion/shelf/adapter/PendingInboundAdapter.kt index 4af546e..d565a39 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/adapter/PendingInboundAdapter.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/adapter/PendingInboundAdapter.kt @@ -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) : 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) diff --git a/app/src/main/java/com/sw/scalefusion/shelf/model/FoodItem.kt b/app/src/main/java/com/sw/scalefusion/shelf/model/FoodItem.kt index b51a0a1..55c0207 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/model/FoodItem.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/model/FoodItem.kt @@ -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? = null, var isSelected:Boolean = false, diff --git a/app/src/main/res/layout/activity_home_v3.xml b/app/src/main/res/layout/activity_home_v3.xml index f2120e4..0635d24 100644 --- a/app/src/main/res/layout/activity_home_v3.xml +++ b/app/src/main/res/layout/activity_home_v3.xml @@ -6,16 +6,30 @@ xmlns:tools="http://schemas.android.com/tools" tools:background="@color/bg_page"> - + + android:layout_height="match_parent"> + + + + + - - - - - - - - - - - - - - - - - - - - - - + + app:cardBackgroundColor="@color/white" + app:cardCornerRadius="12dp" + app:cardElevation="0dp" + app:strokeColor="#E6E6E6" + app:strokeWidth="2dp"> + + + + + + + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cd23655..50bc003 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -17,6 +17,7 @@ #0A143C #C8C8FF #FF6400 + #34C77B #999999 #666666 #F6F6F6