feat(food): 优化食材识别功能并增加调料选择支持
- 将页面大小从30调整为100以提高加载效率 - 移除食材名称显示中的原始数据判断逻辑 - 在FoodRecognizeActivity中添加goodsId映射处理 - 修改GoodsItem实体类将goodsId和materId设为可变属性 - 新增oldGoodsId字段用于保存原始商品ID - 创建新的调料搜索适配器和布局文件 - 更新调料选择对话框中的数据处理逻辑
This commit is contained in:
@@ -36,11 +36,12 @@ class FoodMaterialAdapter(list: MutableList<GoodsItem>) :
|
||||
clBlock.setOnClickListener {
|
||||
onItemClick?.invoke(holder.bindingAdapterPosition)
|
||||
}
|
||||
if (data.isOriginalData) {
|
||||
tvDishName.text = data.goodsName
|
||||
} else {
|
||||
tvDishName.text = data.goodsName + "-${data.rawMaterialsType}"
|
||||
}
|
||||
tvDishName.text = data.goodsName
|
||||
//if (data.isOriginalData) {
|
||||
// tvDishName.text = data.goodsName
|
||||
//} else {
|
||||
// tvDishName.text = data.goodsName + "-${data.rawMaterialsType}"
|
||||
//}
|
||||
tvDishType.text = if (data.materialType == 1) "主辅材:主材" else if (data.materialType == 2) "主辅材:辅材" else ""
|
||||
tvDishWeight.text =
|
||||
if (data.useWeight == null || data.useWeight == 0.toDouble()) "" else "${data.useWeight!!.roundedOneDecimalPlace()}克"
|
||||
|
||||
@@ -7,7 +7,7 @@ import androidx.core.content.ContextCompat
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemFoodBinding
|
||||
import com.shuwei.dish.match.databinding.ListItemSeasoningBinding
|
||||
import com.shuwei.dish.match.entity.GoodsItem
|
||||
|
||||
/**
|
||||
@@ -23,10 +23,6 @@ class SeasoningSearchAdapter(private var list: MutableList<GoodsItem>) :
|
||||
) {
|
||||
holder.binding.tvGoodsInfo.run {
|
||||
text = item?.goodsName
|
||||
setBackgroundResource(
|
||||
if (item?.isClicked == true) R.drawable.shape_green_stroke
|
||||
else R.drawable.shape_white_12_corners
|
||||
)
|
||||
setTextColor(
|
||||
ContextCompat.getColor(
|
||||
context,
|
||||
@@ -35,6 +31,10 @@ class SeasoningSearchAdapter(private var list: MutableList<GoodsItem>) :
|
||||
)
|
||||
)
|
||||
}
|
||||
holder.binding.root.setBackgroundResource(
|
||||
if (item?.isClicked == true) R.drawable.shape_green_stroke
|
||||
else R.drawable.shape_white_12_corners
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(
|
||||
@@ -43,10 +43,10 @@ class SeasoningSearchAdapter(private var list: MutableList<GoodsItem>) :
|
||||
viewType: Int
|
||||
): VH {
|
||||
val binding =
|
||||
ListItemFoodBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||
ListItemSeasoningBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
inner class VH(var binding: ListItemFoodBinding) : QuickViewHolder(binding.root)
|
||||
inner class VH(var binding: ListItemSeasoningBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
}
|
||||
@@ -227,6 +227,11 @@ class SeasoningSelectDialog(
|
||||
binding.recyclerView.layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.VERTICAL, false)
|
||||
if (pageNo == 1) list.clear()
|
||||
list.addAll(records)
|
||||
list.forEach {
|
||||
it.oldGoodsId = it.goodsId
|
||||
//materId才是提交数据需要的goodsId数据
|
||||
it.goodsId = it.materId ?:""
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
|
||||
@@ -8,11 +8,11 @@ import java.io.Serializable
|
||||
*/
|
||||
data class GoodsItem(
|
||||
// 接口返回字段
|
||||
val goodsId: String = "",
|
||||
var goodsId: String = "",
|
||||
val goodsName: String? = null,
|
||||
val popularName: String? = null,
|
||||
val zjmCode: String? = null,
|
||||
val materId: String? = null,
|
||||
var materId: String? = null,
|
||||
val materCode: String? = null,
|
||||
|
||||
// 从 CookFoodGoodsEntity 迁移的数据字段(DishPartAdapter 显示及转换用)
|
||||
@@ -35,7 +35,8 @@ data class GoodsItem(
|
||||
// 净材种类(当前选中值)
|
||||
var rawMaterialsType: String? = null,
|
||||
// 净材种类候选列表(临时字段,逗号分隔,不持久化)
|
||||
var rawMaterialsTypes: String? = null
|
||||
var rawMaterialsTypes: String? = null,
|
||||
var oldGoodsId: String? = null
|
||||
) : Serializable {
|
||||
|
||||
/**
|
||||
|
||||
@@ -289,15 +289,16 @@ class FoodRecognizeActivity : BaseActivity() {
|
||||
binding.rvRecognizeList.visible()
|
||||
binding.tvNoData.gone()
|
||||
list.clear()
|
||||
goodsList.forEach {
|
||||
goodsList.forEach { goods ->
|
||||
var foodScore = -1
|
||||
nameScoreMap[it.goodsName]?.let { food ->
|
||||
nameScoreMap[goods.goodsName]?.let { food ->
|
||||
foodScore = ((1 - food.score) * 10000).toInt()
|
||||
}
|
||||
// // 将接口返回的 rawMaterialsType(全部种类)移存到 rawMaterialsTypes,供弹窗使用
|
||||
// it.rawMaterialsTypes = it.rawMaterialsType
|
||||
// it.rawMaterialsType = null
|
||||
list.add(it.also { it.foodScore = foodScore })
|
||||
//保存原goodsId
|
||||
goods.oldGoodsId = goods.goodsId
|
||||
//PrepareFoodActivity中的goodsId就是materId
|
||||
goods.goodsId = goods.materId ?:""
|
||||
list.add(goods.also { it.foodScore = foodScore })
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
updateRvParentLayoutHeight()
|
||||
|
||||
@@ -47,7 +47,7 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||
}
|
||||
|
||||
private var pageNo = 1
|
||||
private val pageSize = 30
|
||||
private val pageSize = 100
|
||||
|
||||
private var dinnerType = "0"
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout 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:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_margin="15dp"
|
||||
tools:background="@drawable/shape_white_12_corners">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvGoodsInfo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="5dp"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="30sp"
|
||||
android:layout_gravity="center"
|
||||
tools:text="椒盐" />
|
||||
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user