feat(shelf): 支持格口列表下拉刷新和搜索食材验收状态显示
- 在格口列表布局中集成 SmartRefreshLayout,实现下拉刷新功能 - 新增 accepted_green 颜色资源用于验收状态标识 - FoodItem 数据类新增 materCode 和 todayAccepted 字段,支持显示食材编码及验收状态 - HomeV3Activity 中添加 refreshLayout 初始化和刷新逻辑,支持下拉刷新时不弹 Loading,失败时仅提示 - 空视图点击重试由重新拉取改为调用刷新接口 refreshSlots - 搜索食材列表项布局改为 MaterialCardView,增加显示食材编码副行和右上角验收绿色圆点 - PendingInboundAdapter 根据选中状态调整名称和编码文字颜色及边框颜色 - 根据今日是否已验收决定是否显示食材右上角绿色圆点
This commit is contained in:
@@ -11,6 +11,10 @@ import androidx.activity.addCallback
|
|||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
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.App
|
||||||
import com.shuwei.intelligent.shelves.R
|
import com.shuwei.intelligent.shelves.R
|
||||||
import com.shuwei.intelligent.shelves.base.BaseActivity
|
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.C_TEMP_CMD
|
||||||
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.START_TEMP_CTRL_CMD
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.START_TEMP_CTRL_CMD
|
||||||
import com.shuwei.intelligent.shelves.serial.ScaleManager
|
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.IntervalExecutor
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.dp
|
import com.shuwei.intelligent.shelves.utils.ext.dp
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.gone
|
import com.shuwei.intelligent.shelves.utils.ext.gone
|
||||||
@@ -129,13 +130,50 @@ class HomeV3Activity : BaseActivity() {
|
|||||||
saveGoodsTask()
|
saveGoodsTask()
|
||||||
overdueTask()
|
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(
|
viewModel.slots(
|
||||||
onLoading = { showProgress() },
|
onLoading = { if (!fromPull) showProgress() },
|
||||||
onSuccess = { record -> updateUI(record) },
|
onSuccess = { record ->
|
||||||
onError = { msg -> showError(msg) }
|
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() {
|
private fun showProgress() {
|
||||||
Loading.show(this)
|
Loading.show(this)
|
||||||
}
|
}
|
||||||
@@ -376,13 +414,7 @@ class HomeV3Activity : BaseActivity() {
|
|||||||
shelfAdapter.notifyDataSetChanged()
|
shelfAdapter.notifyDataSetChanged()
|
||||||
binding.include?.let {
|
binding.include?.let {
|
||||||
it.root.visible()
|
it.root.visible()
|
||||||
it.root.setOnClickListener {
|
it.root.setOnClickListener { refreshSlots() }
|
||||||
viewModel.slots(
|
|
||||||
onLoading = { showProgress() },
|
|
||||||
onSuccess = { record -> updateUI(record) },
|
|
||||||
onError = { msg -> showError(msg) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
it.ivEmptyIcon.setImageResource(R.drawable.ic_empty_white)
|
it.ivEmptyIcon.setImageResource(R.drawable.ic_empty_white)
|
||||||
it.tvEmptyContent.setTextColor(Color.WHITE)
|
it.tvEmptyContent.setTextColor(Color.WHITE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.sw.scalefusion.shelf.adapter
|
package com.sw.scalefusion.shelf.adapter
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.ColorStateList
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.ColorRes
|
import androidx.annotation.ColorRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
@@ -26,13 +26,23 @@ class PendingInboundAdapter(list: MutableList<FoodItem>) :
|
|||||||
override fun onBindViewHolder(holder: VH, position: Int, item: FoodItem?) {
|
override fun onBindViewHolder(holder: VH, position: Int, item: FoodItem?) {
|
||||||
item ?: return
|
item ?: return
|
||||||
val isSelected = item.isSelected
|
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
|
text = item.materName
|
||||||
setTextColor(getColor(if (isSelected) R.color.shelf_name_blue else R.color.black999))
|
setTextColor(nameColor)
|
||||||
strokeColor = ColorStateList.valueOf(
|
|
||||||
(if (isSelected) "#4969F5" else "#E6E6E6").toColorInt()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
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)
|
private fun getColor(@ColorRes id: Int) = ContextCompat.getColor(context, id)
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ import java.util.Date
|
|||||||
data class FoodItem(
|
data class FoodItem(
|
||||||
var materId:Long? = null,
|
var materId:Long? = null,
|
||||||
var materName:String? = null,
|
var materName:String? = null,
|
||||||
|
/** 食材编码(一级分类+二级分类+自编码,全局唯一) */
|
||||||
|
var materCode:String? = null,
|
||||||
|
/** 今日是否在验收秤有验收记录 */
|
||||||
|
var todayAccepted:Boolean? = null,
|
||||||
var materUrl:String? = null,
|
var materUrl:String? = null,
|
||||||
var vegTypeList:List<FoodType>? = null,
|
var vegTypeList:List<FoodType>? = null,
|
||||||
var isSelected:Boolean = false,
|
var isSelected:Boolean = false,
|
||||||
|
|||||||
@@ -6,6 +6,19 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:background="@color/bg_page">
|
tools:background="@color/bg_page">
|
||||||
|
|
||||||
|
<!-- 格口列表支持下拉刷新:重新拉取 /init 格口数据 -->
|
||||||
|
<com.scwang.smart.refresh.layout.SmartRefreshLayout
|
||||||
|
android:id="@+id/refreshLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
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
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/rvShelf"
|
android:id="@+id/rvShelf"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -16,6 +29,7 @@
|
|||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
tools:listitem="@layout/list_item_shelf_v3"/>
|
tools:listitem="@layout/list_item_shelf_v3"/>
|
||||||
|
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/include"
|
android:id="@+id/include"
|
||||||
|
|||||||
@@ -1,48 +1,60 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
|
<!-- 搜索食材列表 item:食材名 + 编码副行,今日已验收时右上角显示绿色圆点 -->
|
||||||
<!-- xmlns:tools="http://schemas.android.com/tools"-->
|
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<!-- 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"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/btnFoodName"
|
android:id="@+id/cardFood"
|
||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="80dp"
|
android:layout_height="96dp"
|
||||||
android:layout_margin="12dp"
|
android:layout_margin="12dp"
|
||||||
|
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:ellipsize="end"
|
||||||
android:fontFamily="sans-serif-medium"
|
android:fontFamily="sans-serif-medium"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:insetTop="0dp"
|
|
||||||
android:insetBottom="0dp"
|
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
app:paddingStart="5dp"
|
|
||||||
app:paddingEnd="5dp"
|
|
||||||
android:insetRight="0dp"
|
|
||||||
android:insetLeft="0dp"
|
|
||||||
android:paddingHorizontal="8dp"
|
|
||||||
android:textColor="@color/black999"
|
android:textColor="@color/black999"
|
||||||
android:textSize="30sp"
|
android:textSize="30sp"
|
||||||
app:cornerRadius="12dp"
|
tools:text="土豆丝土豆丝土豆丝" />
|
||||||
app:strokeWidth="2dp"
|
|
||||||
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>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
<color name="food_name_black">#0A143C</color>
|
<color name="food_name_black">#0A143C</color>
|
||||||
<color name="food_weight_blue">#C8C8FF</color>
|
<color name="food_weight_blue">#C8C8FF</color>
|
||||||
<color name="food_weight_orange">#FF6400</color>
|
<color name="food_weight_orange">#FF6400</color>
|
||||||
|
<color name="accepted_green">#34C77B</color>
|
||||||
<color name="black999">#999999</color>
|
<color name="black999">#999999</color>
|
||||||
<color name="black666">#666666</color>
|
<color name="black666">#666666</color>
|
||||||
<color name="white_f6">#F6F6F6</color>
|
<color name="white_f6">#F6F6F6</color>
|
||||||
|
|||||||
Reference in New Issue
Block a user