Compare commits
57
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94bcdb3d9b | ||
|
|
7b66652c0b | ||
|
|
9e4b2bd009 | ||
|
|
6d3c5490a4 | ||
|
|
45543295e3 | ||
|
|
049c724303 | ||
|
|
acd1dd4605 | ||
|
|
17470bf12c | ||
|
|
0a3185fc9e | ||
|
|
9e41841086 | ||
|
|
80d80e7e63 | ||
|
|
2d88ce1479 | ||
|
|
d580040c55 | ||
|
|
00bf478185 | ||
|
|
ea79e584f3 | ||
|
|
1140d6bf91 | ||
|
|
f3dbb3fe68 | ||
|
|
dc91cdfa2e | ||
|
|
a6ce3a1ed3 | ||
|
|
292fdade81 | ||
|
|
aa539d87d0 | ||
|
|
e570707216 | ||
|
|
87ca6abe1b | ||
|
|
28784fa7c1 | ||
|
|
df01312577 | ||
|
|
7d3cb27b6e | ||
|
|
ef6a29ffb0 | ||
|
|
d7f9fb05fb | ||
|
|
d9cfd3007d | ||
|
|
c1f52c6337 | ||
|
|
5723209614 | ||
|
|
d080ca0690 | ||
|
|
1024d82958 | ||
|
|
8b19da2710 | ||
|
|
25167829cc | ||
|
|
e38f19ac1b | ||
|
|
ada83b64e6 | ||
|
|
d3f02620af | ||
|
|
deb03a0c37 | ||
|
|
b562694665 | ||
|
|
64586175ff | ||
|
|
e8431de53d | ||
|
|
4ccd4eaad0 | ||
|
|
b44f4aae5a | ||
|
|
fee9598689 | ||
|
|
b24435744c | ||
|
|
a257b03b9d | ||
|
|
89fff7c2b0 | ||
|
|
6392b76ac2 | ||
|
|
8398bd4fd3 | ||
|
|
535da33aab | ||
|
|
120f5432de | ||
|
|
61d11c6a78 | ||
|
|
301f470274 | ||
|
|
67d64848de | ||
|
|
ce7d2da6d8 | ||
|
|
65958bf637 |
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
// alias(libs.plugins.android.application)
|
// alias(libs.plugins.android.application)
|
||||||
// alias(libs.plugins.kotlin.android)
|
// alias(libs.plugins.kotlin.android)
|
||||||
@@ -24,9 +23,8 @@ android {
|
|||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
ndk {
|
ndk {
|
||||||
//设置支持的SO库架构
|
//设置支持的SO库架构;x86_64 仅用于在 Windows 模拟器上调试(秤功能不可用)
|
||||||
abiFilters.addAll(listOf("armeabi-v7a"))
|
abiFilters.addAll(listOf("armeabi-v7a"))
|
||||||
//, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置输出APK文件名格式
|
// 设置输出APK文件名格式
|
||||||
@@ -48,12 +46,13 @@ android {
|
|||||||
"proguard-rules.pro"
|
"proguard-rules.pro"
|
||||||
)
|
)
|
||||||
signingConfig = signingConfigs.getByName("debug_507")
|
signingConfig = signingConfigs.getByName("debug_507")
|
||||||
// buildConfigField("boolean", "DEBUG", "false")
|
buildConfigField("Boolean", "IS_TEST_DEVICE", "false")
|
||||||
}
|
}
|
||||||
debug {
|
debug {
|
||||||
//507扫码秤主板在android.buildTypes{}内增加
|
//507扫码秤主板在android.buildTypes{}内增加
|
||||||
signingConfig = signingConfigs.getByName("debug_507")
|
signingConfig = signingConfigs.getByName("debug_507")
|
||||||
// buildConfigField("boolean", "DEBUG", "true")
|
// 调试构建视为测试设备,使用固定的 DEVICE_ID_1 代替真实 UDID
|
||||||
|
buildConfigField("Boolean", "IS_TEST_DEVICE", "false")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
@@ -98,6 +97,7 @@ dependencies {
|
|||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
implementation(libs.androidx.activity.ktx)
|
implementation(libs.androidx.activity.ktx)
|
||||||
|
implementation(libs.androidx.fragment.ktx)
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||||
implementation(libs.androidx.lifecycle.viewmodel.ktx)
|
implementation(libs.androidx.lifecycle.viewmodel.ktx)
|
||||||
|
|
||||||
@@ -138,8 +138,8 @@ dependencies {
|
|||||||
implementation(libs.androidx.camera.extensions)
|
implementation(libs.androidx.camera.extensions)
|
||||||
|
|
||||||
//pytorch
|
//pytorch
|
||||||
implementation (libs.pytorch.android)
|
implementation(libs.pytorch.android)
|
||||||
implementation (libs.pytorch.android.torchvision)
|
implementation(libs.pytorch.android.torchvision)
|
||||||
|
|
||||||
// objectbox
|
// objectbox
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -6,7 +6,7 @@ import android.view.ViewGroup
|
|||||||
import com.chad.library.adapter4.BaseQuickAdapter
|
import com.chad.library.adapter4.BaseQuickAdapter
|
||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.databinding.ListItemCollectedFoodBinding
|
import com.shuwei.dish.match.databinding.ListItemCollectedFoodBinding
|
||||||
import com.shuwei.dish.match.entity.CollectedFoodItem
|
import com.shuwei.dish.match.model.CollectedFoodItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 已采集食材列表适配器
|
* 已采集食材列表适配器
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import android.view.ViewGroup
|
|||||||
import com.chad.library.adapter4.BaseQuickAdapter
|
import com.chad.library.adapter4.BaseQuickAdapter
|
||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.databinding.ListItemFood2Binding
|
import com.shuwei.dish.match.databinding.ListItemFood2Binding
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品搜索页面的适配器
|
* 菜品搜索页面的适配器
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import android.view.ViewGroup
|
|||||||
import com.chad.library.adapter4.BaseQuickAdapter
|
import com.chad.library.adapter4.BaseQuickAdapter
|
||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.databinding.ListItemFood3Binding
|
import com.shuwei.dish.match.databinding.ListItemFood3Binding
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向量采集页面的适配器
|
* 向量采集页面的适配器
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
|||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.databinding.ListItemFoodBinding
|
import com.shuwei.dish.match.databinding.ListItemFoodBinding
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.roundedDecimalPlace
|
import com.shuwei.dish.match.utils.ext.roundedDecimalPlace
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
|||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.databinding.ListItemFoodListBinding
|
import com.shuwei.dish.match.databinding.ListItemFoodListBinding
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
import com.shuwei.dish.match.model.SampleStatus
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
@@ -86,6 +87,16 @@ class FoodListAdapter(
|
|||||||
return@run
|
return@run
|
||||||
}
|
}
|
||||||
// 非烹饪中,采样模式
|
// 非烹饪中,采样模式
|
||||||
|
tvDishName.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.dish_green))
|
||||||
|
clBlock.setBackgroundResource(R.drawable.shape_white_fb_15_corners)
|
||||||
|
// 已提交采样列表(sample-list):展示实验状态 + 熟重(g)
|
||||||
|
val statusName = item.statusName
|
||||||
|
if (!statusName.isNullOrBlank()) {
|
||||||
|
tvDishCount.text = "熟重:${formatGram(foodWeight)}"
|
||||||
|
tvShowState.text = statusName
|
||||||
|
tvShowState.setTextColor(statusColor(holder, item.status))
|
||||||
|
return@run
|
||||||
|
}
|
||||||
val realTotalWeight = if (totalWeight > 0.0) totalWeight else foodWeight
|
val realTotalWeight = if (totalWeight > 0.0) totalWeight else foodWeight
|
||||||
val showTotalWeight = if (realTotalWeight == 0.0) "-" else df.format(realTotalWeight / 1000.0F)
|
val showTotalWeight = if (realTotalWeight == 0.0) "-" else df.format(realTotalWeight / 1000.0F)
|
||||||
tvDishCount.text = "累计统计:${showTotalWeight}kg(${item.count ?: "-"}次)"
|
tvDishCount.text = "累计统计:${showTotalWeight}kg(${item.count ?: "-"}次)"
|
||||||
@@ -94,5 +105,21 @@ class FoodListAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 熟重(g)格式化,整数不带小数,小数保留 2 位 */
|
||||||
|
private fun formatGram(weight: Double): String {
|
||||||
|
val gramDf = DecimalFormat("0.##")
|
||||||
|
return "${gramDf.format(weight)}g"
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 实验状态着色:1=实验中(灰) / 2=已评测(绿) / 9=已转化(绿) */
|
||||||
|
private fun statusColor(holder: VH, status: Int?): Int {
|
||||||
|
val context = holder.itemView.context
|
||||||
|
return when (status) {
|
||||||
|
SampleStatus.EVALUATED, SampleStatus.CONVERTED ->
|
||||||
|
ContextCompat.getColor(context, R.color.dish_green)
|
||||||
|
else -> ContextCompat.getColor(context, R.color.black999)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val df = DecimalFormat("0.000")
|
private val df = DecimalFormat("0.000")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
|||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.databinding.ListItemFoodMaterialBinding
|
import com.shuwei.dish.match.databinding.ListItemFoodMaterialBinding
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
@@ -36,11 +36,12 @@ class FoodMaterialAdapter(list: MutableList<GoodsItem>) :
|
|||||||
clBlock.setOnClickListener {
|
clBlock.setOnClickListener {
|
||||||
onItemClick?.invoke(holder.bindingAdapterPosition)
|
onItemClick?.invoke(holder.bindingAdapterPosition)
|
||||||
}
|
}
|
||||||
if (data.isOriginalData) {
|
tvDishName.text = data.goodsName
|
||||||
tvDishName.text = data.goodsName
|
//if (data.isOriginalData) {
|
||||||
} else {
|
// tvDishName.text = data.goodsName
|
||||||
tvDishName.text = data.goodsName + "-${data.rawMaterialsType}"
|
//} else {
|
||||||
}
|
// tvDishName.text = data.goodsName + "-${data.rawMaterialsType}"
|
||||||
|
//}
|
||||||
tvDishType.text = if (data.materialType == 1) "主辅材:主材" else if (data.materialType == 2) "主辅材:辅材" else ""
|
tvDishType.text = if (data.materialType == 1) "主辅材:主材" else if (data.materialType == 2) "主辅材:辅材" else ""
|
||||||
tvDishWeight.text =
|
tvDishWeight.text =
|
||||||
if (data.useWeight == null || data.useWeight == 0.toDouble()) "" else "${data.useWeight!!.roundedOneDecimalPlace()}克"
|
if (data.useWeight == null || data.useWeight == 0.toDouble()) "" else "${data.useWeight!!.roundedOneDecimalPlace()}克"
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.shuwei.dish.match.adapter
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.shuwei.dish.match.databinding.ItemGoodsPreviewBinding
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用料明细预览列表适配器
|
||||||
|
* 显示字段:foodId、goodsId、goodsCode、goodsName、materialType、useWeight
|
||||||
|
*/
|
||||||
|
class GoodsPreviewAdapter(
|
||||||
|
private val list: List<CookFoodGoodsEntity>
|
||||||
|
) : RecyclerView.Adapter<GoodsPreviewAdapter.VH>() {
|
||||||
|
|
||||||
|
inner class VH(val binding: ItemGoodsPreviewBinding) : RecyclerView.ViewHolder(binding.root)
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
|
||||||
|
val binding = ItemGoodsPreviewBinding.inflate(
|
||||||
|
LayoutInflater.from(parent.context), parent, false
|
||||||
|
)
|
||||||
|
return VH(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
override fun onBindViewHolder(holder: VH, position: Int) {
|
||||||
|
val item = list[position]
|
||||||
|
holder.binding.run {
|
||||||
|
tvGoodsId.text = item.goodsId
|
||||||
|
tvGoodsCode.text = item.goodsCode.orEmpty()
|
||||||
|
tvGoodsName.text = item.goodsName.orEmpty()
|
||||||
|
// materialType:1主料 2辅料 3调料
|
||||||
|
tvMaterialType.text = when (item.materialType) {
|
||||||
|
1 -> "主料"
|
||||||
|
2 -> "辅料"
|
||||||
|
3 -> "调料"
|
||||||
|
else -> "${item.materialType}"
|
||||||
|
}
|
||||||
|
tvUseWeight.text = "${item.useWeight ?: 0.0}g"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount() = list.size
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
|||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.databinding.ListItemHomeModeBinding
|
import com.shuwei.dish.match.databinding.ListItemHomeModeBinding
|
||||||
import com.shuwei.dish.match.entity.HomeModeBean
|
import com.shuwei.dish.match.model.HomeModeBean
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package com.shuwei.dish.match.adapter
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.chad.library.adapter4.BaseQuickAdapter
|
import com.chad.library.adapter4.BaseQuickAdapter
|
||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.databinding.ListItemScaleRowBinding
|
import com.shuwei.dish.match.databinding.ListItemScaleRowBinding
|
||||||
import com.shuwei.dish.match.utils.WeightUtil
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
|
|
||||||
@@ -40,11 +42,20 @@ class ScaleRowAdapter : BaseQuickAdapter<ScaleRowAdapter.ScaleItem, ScaleRowAdap
|
|||||||
holder.b.tvScaleLabel.text = "秤 ${item.address}"
|
holder.b.tvScaleLabel.text = "秤 ${item.address}"
|
||||||
holder.b.tvName.text = item.name.ifEmpty { "-" }
|
holder.b.tvName.text = item.name.ifEmpty { "-" }
|
||||||
holder.b.tvWeight.text = "${item.weight} g"
|
holder.b.tvWeight.text = "${item.weight} g"
|
||||||
holder.b.tvState.text = when (item.state) {
|
holder.b.tvState.text = WeightUtil.getStateStr(item.state)
|
||||||
WeightUtil.STATE_STABLE -> "稳定"
|
if (item.state == WeightUtil.STATE_OVER_WEIGHT) {
|
||||||
WeightUtil.STATE_UNSTABLE -> "不稳定"
|
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell_over_weight)
|
||||||
WeightUtil.STATE_OVER_WEIGHT -> "超量"
|
val white = ContextCompat.getColor(holder.b.root.context, R.color.white)
|
||||||
else -> "${item.state}"
|
holder.b.tvScaleLabel.setTextColor(white)
|
||||||
|
holder.b.tvName.setTextColor(white)
|
||||||
|
holder.b.tvWeight.setTextColor(white)
|
||||||
|
holder.b.tvState.setTextColor(white)
|
||||||
|
} else {
|
||||||
|
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell)
|
||||||
|
holder.b.tvScaleLabel.setTextColor(ContextCompat.getColor(holder.b.root.context, R.color.black))
|
||||||
|
holder.b.tvName.setTextColor(ContextCompat.getColor(holder.b.root.context, R.color.black))
|
||||||
|
holder.b.tvWeight.setTextColor(ContextCompat.getColor(holder.b.root.context, R.color.home_title))
|
||||||
|
holder.b.tvState.setTextColor(ContextCompat.getColor(holder.b.root.context, R.color.home_sub_title))
|
||||||
}
|
}
|
||||||
// 点击时通过 bindingAdapterPosition 取最新数据,避免闭包捕获过期 item
|
// 点击时通过 bindingAdapterPosition 取最新数据,避免闭包捕获过期 item
|
||||||
holder.b.root.setOnClickListener {
|
holder.b.root.setOnClickListener {
|
||||||
|
|||||||
@@ -90,24 +90,34 @@ class Seasoning18GridAdapter(
|
|||||||
holder.b.tvAddress.text = "秤${item!!.address}"
|
holder.b.tvAddress.text = "秤${item!!.address}"
|
||||||
holder.b.tvName.text = if (!item.name.isNullOrBlank()) item.name else "-"
|
holder.b.tvName.text = if (!item.name.isNullOrBlank()) item.name else "-"
|
||||||
holder.b.tvWeight.text = "${item.weight}g"
|
holder.b.tvWeight.text = "${item.weight}g"
|
||||||
holder.b.tvState.text = stateStr(item.state)
|
holder.b.tvState.text = WeightUtil.getStateStr(item.state)
|
||||||
}
|
}
|
||||||
if (position == highlightedPosition) {
|
val white = ContextCompat.getColor(holder.b.root.context, R.color.white)
|
||||||
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell_highlight)
|
when {
|
||||||
val white = ContextCompat.getColor(holder.b.root.context, R.color.white)
|
valid && item!!.state == WeightUtil.STATE_OVER_WEIGHT -> {
|
||||||
holder.b.tvAddress.setTextColor(white)
|
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell_over_weight)
|
||||||
holder.b.tvName.setTextColor(white)
|
holder.b.tvAddress.setTextColor(white)
|
||||||
holder.b.tvWeight.setTextColor(white)
|
holder.b.tvName.setTextColor(white)
|
||||||
holder.b.tvState.setTextColor(white)
|
holder.b.tvWeight.setTextColor(white)
|
||||||
} else {
|
holder.b.tvState.setTextColor(white)
|
||||||
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell)
|
}
|
||||||
val normal = ContextCompat.getColor(holder.b.root.context, R.color.home_title)
|
position == highlightedPosition -> {
|
||||||
val sub = ContextCompat.getColor(holder.b.root.context, R.color.home_sub_title)
|
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell_highlight)
|
||||||
val black = ContextCompat.getColor(holder.b.root.context, R.color.black)
|
holder.b.tvAddress.setTextColor(white)
|
||||||
holder.b.tvAddress.setTextColor(sub)
|
holder.b.tvName.setTextColor(white)
|
||||||
holder.b.tvName.setTextColor(black)
|
holder.b.tvWeight.setTextColor(white)
|
||||||
holder.b.tvWeight.setTextColor(normal)
|
holder.b.tvState.setTextColor(white)
|
||||||
holder.b.tvState.setTextColor(sub)
|
}
|
||||||
|
else -> {
|
||||||
|
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell)
|
||||||
|
val normal = ContextCompat.getColor(holder.b.root.context, R.color.home_title)
|
||||||
|
val sub = ContextCompat.getColor(holder.b.root.context, R.color.home_sub_title)
|
||||||
|
val black = ContextCompat.getColor(holder.b.root.context, R.color.black)
|
||||||
|
holder.b.tvAddress.setTextColor(sub)
|
||||||
|
holder.b.tvName.setTextColor(black)
|
||||||
|
holder.b.tvWeight.setTextColor(normal)
|
||||||
|
holder.b.tvState.setTextColor(sub)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,11 +174,4 @@ class Seasoning18GridAdapter(
|
|||||||
fun updateByAddress(scales: List<ScaleData>) {
|
fun updateByAddress(scales: List<ScaleData>) {
|
||||||
update(scales)
|
update(scales)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stateStr(state: Int) = when (state) {
|
|
||||||
WeightUtil.STATE_STABLE -> "稳定"
|
|
||||||
WeightUtil.STATE_UNSTABLE -> "不稳定"
|
|
||||||
WeightUtil.STATE_OVER_WEIGHT -> "超量"
|
|
||||||
else -> ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,25 +95,34 @@ class Seasoning22GridAdapter(
|
|||||||
holder.b.tvAddress.text = "秤${item!!.address}"
|
holder.b.tvAddress.text = "秤${item!!.address}"
|
||||||
holder.b.tvName.text = if (!item.name.isNullOrBlank()) item.name else "-"
|
holder.b.tvName.text = if (!item.name.isNullOrBlank()) item.name else "-"
|
||||||
holder.b.tvWeight.text = "${item.weight}g"
|
holder.b.tvWeight.text = "${item.weight}g"
|
||||||
holder.b.tvState.text = stateStr(item.state)
|
holder.b.tvState.text = WeightUtil.getStateStr(item.state)
|
||||||
}
|
}
|
||||||
// 高亮格子:红底白字;其余恢复默认
|
val white = ContextCompat.getColor(holder.b.root.context, R.color.white)
|
||||||
if (position == highlightedPosition) {
|
when {
|
||||||
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell_highlight)
|
valid && item!!.state == WeightUtil.STATE_OVER_WEIGHT -> {
|
||||||
val white = ContextCompat.getColor(holder.b.root.context, R.color.white)
|
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell_over_weight)
|
||||||
holder.b.tvAddress.setTextColor(white)
|
holder.b.tvAddress.setTextColor(white)
|
||||||
holder.b.tvName.setTextColor(white)
|
holder.b.tvName.setTextColor(white)
|
||||||
holder.b.tvWeight.setTextColor(white)
|
holder.b.tvWeight.setTextColor(white)
|
||||||
holder.b.tvState.setTextColor(white)
|
holder.b.tvState.setTextColor(white)
|
||||||
} else {
|
}
|
||||||
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell)
|
position == highlightedPosition -> {
|
||||||
val normal = ContextCompat.getColor(holder.b.root.context, R.color.home_title)
|
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell_highlight)
|
||||||
val sub = ContextCompat.getColor(holder.b.root.context, R.color.home_sub_title)
|
holder.b.tvAddress.setTextColor(white)
|
||||||
val black = ContextCompat.getColor(holder.b.root.context, R.color.black)
|
holder.b.tvName.setTextColor(white)
|
||||||
holder.b.tvAddress.setTextColor(sub)
|
holder.b.tvWeight.setTextColor(white)
|
||||||
holder.b.tvName.setTextColor(black)
|
holder.b.tvState.setTextColor(white)
|
||||||
holder.b.tvWeight.setTextColor(normal)
|
}
|
||||||
holder.b.tvState.setTextColor(sub)
|
else -> {
|
||||||
|
holder.b.root.setBackgroundResource(R.drawable.shape_scale_cell)
|
||||||
|
val normal = ContextCompat.getColor(holder.b.root.context, R.color.home_title)
|
||||||
|
val sub = ContextCompat.getColor(holder.b.root.context, R.color.home_sub_title)
|
||||||
|
val black = ContextCompat.getColor(holder.b.root.context, R.color.black)
|
||||||
|
holder.b.tvAddress.setTextColor(sub)
|
||||||
|
holder.b.tvName.setTextColor(black)
|
||||||
|
holder.b.tvWeight.setTextColor(normal)
|
||||||
|
holder.b.tvState.setTextColor(sub)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,11 +179,4 @@ class Seasoning22GridAdapter(
|
|||||||
fun updateByAddress(scales: List<ScaleData>) {
|
fun updateByAddress(scales: List<ScaleData>) {
|
||||||
update(scales)
|
update(scales)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stateStr(state: Int) = when (state) {
|
|
||||||
WeightUtil.STATE_STABLE -> "稳定"
|
|
||||||
WeightUtil.STATE_UNSTABLE -> "不稳定"
|
|
||||||
WeightUtil.STATE_OVER_WEIGHT -> "超量"
|
|
||||||
else -> ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import androidx.core.content.ContextCompat
|
|||||||
import com.chad.library.adapter4.BaseQuickAdapter
|
import com.chad.library.adapter4.BaseQuickAdapter
|
||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.R
|
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
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调料搜索弹窗适配器
|
* 调料搜索弹窗适配器
|
||||||
@@ -23,10 +23,6 @@ class SeasoningSearchAdapter(private var list: MutableList<GoodsItem>) :
|
|||||||
) {
|
) {
|
||||||
holder.binding.tvGoodsInfo.run {
|
holder.binding.tvGoodsInfo.run {
|
||||||
text = item?.goodsName
|
text = item?.goodsName
|
||||||
setBackgroundResource(
|
|
||||||
if (item?.isClicked == true) R.drawable.shape_green_stroke
|
|
||||||
else R.drawable.shape_white_12_corners
|
|
||||||
)
|
|
||||||
setTextColor(
|
setTextColor(
|
||||||
ContextCompat.getColor(
|
ContextCompat.getColor(
|
||||||
context,
|
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(
|
override fun onCreateViewHolder(
|
||||||
@@ -43,10 +43,10 @@ class SeasoningSearchAdapter(private var list: MutableList<GoodsItem>) :
|
|||||||
viewType: Int
|
viewType: Int
|
||||||
): VH {
|
): VH {
|
||||||
val binding =
|
val binding =
|
||||||
ListItemFoodBinding.inflate(LayoutInflater.from(context), parent, false)
|
ListItemSeasoningBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||||
return VH(binding)
|
return VH(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class VH(var binding: ListItemFoodBinding) : QuickViewHolder(binding.root)
|
inner class VH(var binding: ListItemSeasoningBinding) : QuickViewHolder(binding.root)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.shuwei.dish.match.adapter
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.chad.library.adapter4.BaseQuickAdapter
|
||||||
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
|
import com.shuwei.dish.match.databinding.ListItemSettingBinding
|
||||||
|
import com.shuwei.dish.match.model.SettingItem
|
||||||
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置页面列表适配器
|
||||||
|
* 点击事件直接调用 item.onClick(),无需在 Adapter 中分发业务逻辑
|
||||||
|
*/
|
||||||
|
class SettingAdapter : BaseQuickAdapter<SettingItem, SettingAdapter.VH>() {
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||||
|
val binding = ListItemSettingBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||||
|
return VH(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: VH, position: Int, item: SettingItem?) {
|
||||||
|
item ?: return
|
||||||
|
holder.binding.tvTitle.text = item.title
|
||||||
|
|
||||||
|
// 有副标题则显示,否则隐藏
|
||||||
|
val subtitle = item.subtitle
|
||||||
|
if (subtitle != null) {
|
||||||
|
holder.binding.tvSubtitle.visible()
|
||||||
|
holder.binding.tvSubtitle.text = subtitle
|
||||||
|
} else {
|
||||||
|
holder.binding.tvSubtitle.gone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class VH(val binding: ListItemSettingBinding) : QuickViewHolder(binding.root)
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
|||||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.databinding.ListItemVectorCollectionBinding
|
import com.shuwei.dish.match.databinding.ListItemVectorCollectionBinding
|
||||||
import com.shuwei.dish.match.entity.FoodCollectionBean
|
import com.shuwei.dish.match.model.FoodCollectionBean
|
||||||
import com.shuwei.dish.match.utils.ext.load
|
import com.shuwei.dish.match.utils.ext.load
|
||||||
|
|
||||||
class VectorCollectionAdapter (var list: MutableList<FoodCollectionBean>) :
|
class VectorCollectionAdapter (var list: MutableList<FoodCollectionBean>) :
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.content.pm.ActivityInfo
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
@@ -37,6 +38,7 @@ import kotlin.getValue
|
|||||||
open class BaseActivity : AppCompatActivity() {
|
open class BaseActivity : AppCompatActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val TAG = "BaseActivity"
|
||||||
/** 日期时间格式化器,复用避免每秒重复创建 */
|
/** 日期时间格式化器,复用避免每秒重复创建 */
|
||||||
private val DATE_FORMATTER =
|
private val DATE_FORMATTER =
|
||||||
DateTimeFormatter.ofPattern("yyyy年MM月dd日 EEEE***HH:mm:ss", Locale.CHINA)
|
DateTimeFormatter.ofPattern("yyyy年MM月dd日 EEEE***HH:mm:ss", Locale.CHINA)
|
||||||
@@ -71,7 +73,8 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
handler.removeCallbacksAndMessages(null)
|
handler.removeCallbacksAndMessages(null)
|
||||||
dismissLoading()
|
// 只关闭自己弹出的 Loading,防止误关其他 Activity 的 Loading
|
||||||
|
Loading.dismissIfOwnedBy(this)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
ActivityManager.removeActivity(this)
|
ActivityManager.removeActivity(this)
|
||||||
}
|
}
|
||||||
@@ -92,13 +95,13 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
titleBarAction: ((FrameLayout) -> Unit)? = null,
|
titleBarAction: ((FrameLayout) -> Unit)? = null,
|
||||||
backAction: ((ImageView) -> Unit)? = null,
|
backAction: ((ImageView) -> Unit)? = null,
|
||||||
titleAction: ((TextView) -> Unit)? = null,
|
titleAction: ((TextView) -> Unit)? = null,
|
||||||
rightIconActon: ((ImageView) -> Unit)? = null
|
rightIconAction: ((ImageView) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
binding.llTitleBar.visible()
|
binding.llTitleBar.visible()
|
||||||
titleBarAction?.invoke(binding.llTitleBar)
|
titleBarAction?.invoke(binding.llTitleBar)
|
||||||
backAction?.invoke(binding.ivBack)
|
backAction?.invoke(binding.ivBack)
|
||||||
titleAction?.invoke(binding.tvTitle)
|
titleAction?.invoke(binding.tvTitle)
|
||||||
rightIconActon?.invoke(binding.ivRightIcon)
|
rightIconAction?.invoke(binding.ivRightIcon)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setHeaderBgVisible(show: Boolean) {
|
fun setHeaderBgVisible(show: Boolean) {
|
||||||
@@ -150,22 +153,25 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
handler.removeCallbacks(updateTask)
|
handler.removeCallbacks(updateTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showLoading(msg: String = "加载中……") {
|
fun showLoading(msg: String = "加载中……", timeoutMs: Long = Loading.DEFAULT_TIMEOUT_MS) {
|
||||||
handler.post {
|
handler.post {
|
||||||
Loading.show(
|
Loading.show(
|
||||||
context = this,
|
context = this,
|
||||||
message = msg
|
message = msg,
|
||||||
|
timeoutMs = timeoutMs
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dismissLoading() {
|
fun dismissLoading() {
|
||||||
|
Log.d(TAG, "dismissLoading, ${this.javaClass.simpleName}")
|
||||||
handler.post {
|
handler.post {
|
||||||
Loading.dismiss()
|
Loading.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun delayDismissLoading() {
|
fun delayDismissLoading() {
|
||||||
|
Log.d(TAG, "delayDismissLoading, ${this.javaClass.simpleName}")
|
||||||
handler.postDelayed({
|
handler.postDelayed({
|
||||||
Loading.dismiss()
|
Loading.dismiss()
|
||||||
}, 500)
|
}, 500)
|
||||||
@@ -182,7 +188,7 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
|
|
||||||
val netViewModel: NetViewModel by viewModels()
|
val netViewModel: NetViewModel by viewModels()
|
||||||
val appViewModel: DbViewModel by viewModels()
|
val dbViewModel: DbViewModel by viewModels()
|
||||||
|
|
||||||
private var singlePermissionCallback: ((isGranted: Boolean) -> Unit)? = null
|
private var singlePermissionCallback: ((isGranted: Boolean) -> Unit)? = null
|
||||||
private var multiplePermissionsCallback: ((isGranted: Boolean) -> Unit)? = null
|
private var multiplePermissionsCallback: ((isGranted: Boolean) -> Unit)? = null
|
||||||
|
|||||||
@@ -1,41 +1,41 @@
|
|||||||
package com.shuwei.dish.match.base
|
package com.shuwei.dish.match.base
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.shuwei.dish.match.BuildConfig
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.db.DatabaseProvider
|
import com.shuwei.dish.match.db.DatabaseProvider
|
||||||
import com.shuwei.dish.match.objbox.ObjectBox
|
import com.shuwei.dish.match.objbox.ObjectBox
|
||||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||||
import com.shuwei.dish.match.utils.AppUtil
|
import com.shuwei.dish.match.utils.AppUtil
|
||||||
|
import com.shuwei.dish.match.utils.SpTool
|
||||||
import com.shuwei.dish.match.utils.BootReceiver
|
import com.shuwei.dish.match.utils.BootReceiver
|
||||||
import com.shuwei.dish.match.utils.CrashHandler
|
import com.shuwei.dish.match.utils.CrashHandler
|
||||||
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
import com.shuwei.dish.match.utils.Weigher2
|
import com.shuwei.dish.match.utils.Weigher2
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BaseApp is the main application class that extends Android's Application class.
|
|
||||||
* It handles initialization of core components, device role determination,
|
|
||||||
* and service management for the weighing system.
|
|
||||||
*/
|
|
||||||
class BaseApp : Application() {
|
class BaseApp : Application() {
|
||||||
|
|
||||||
// Lazy initialization of the database instance
|
|
||||||
val database by lazy { DatabaseProvider(this).instance }
|
val database by lazy { DatabaseProvider(this).instance }
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
// Set the application instance
|
|
||||||
instance = this
|
instance = this
|
||||||
// Initialize crash handler for error tracking
|
// 读取本地保存的环境地址,覆盖默认值
|
||||||
|
val savedBaseUrl = SpTool.baseUrl
|
||||||
|
if (savedBaseUrl.isNotEmpty()) {
|
||||||
|
GlobalData.appBaseUrl = savedBaseUrl
|
||||||
|
}
|
||||||
CrashHandler.init(this)
|
CrashHandler.init(this)
|
||||||
// Get and store the unique device ID
|
val deviceId = if (BuildConfig.IS_TEST_DEVICE) ScaleDeviceConfig.DEVICE_ID_2 else AppUtil.getUDID(this)
|
||||||
val deviceId = AppUtil.getUDID(this)
|
Log.d(TAG, "onCreate: deviceId=$deviceId, isTestDevice=${BuildConfig.IS_TEST_DEVICE}")
|
||||||
Log.d(TAG, "onCreate: deviceId=$deviceId")
|
|
||||||
GlobalData.deviceId = deviceId
|
GlobalData.deviceId = deviceId
|
||||||
|
|
||||||
// 根据设备 ID 判断角色:指定 ID 为主设备,其余为子设备
|
// 根据设备 ID 判断角色:指定 ID 为主设备,其余为子设备
|
||||||
@@ -51,6 +51,26 @@ class BaseApp : Application() {
|
|||||||
|
|
||||||
// 启动秤服务(主设备多启动发现+聚合,子设备只启动服务端+注册)
|
// 启动秤服务(主设备多启动发现+聚合,子设备只启动服务端+注册)
|
||||||
ScaleServiceManager.start(this)
|
ScaleServiceManager.start(this)
|
||||||
|
|
||||||
|
// 初始化秤,进程级生命周期管理:最后一个 Activity 销毁时才停止读取
|
||||||
|
WeightUtil.init()
|
||||||
|
WeightUtil.getWeight()
|
||||||
|
WeightUtil.startContinuousRead()
|
||||||
|
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
|
||||||
|
private var activityCount = 0
|
||||||
|
override fun onActivityCreated(a: Activity, b: Bundle?) { activityCount++ }
|
||||||
|
override fun onActivityDestroyed(a: Activity) {
|
||||||
|
if (--activityCount <= 0) {
|
||||||
|
WeightUtil.stopContinuousRead()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun onActivityStarted(a: Activity) {}
|
||||||
|
override fun onActivityResumed(a: Activity) {}
|
||||||
|
override fun onActivityPaused(a: Activity) {}
|
||||||
|
override fun onActivityStopped(a: Activity) {}
|
||||||
|
override fun onActivitySaveInstanceState(a: Activity, b: Bundle) {}
|
||||||
|
})
|
||||||
|
|
||||||
// GlobalData.deviceId = "39a7abdd06b3c7ab"
|
// GlobalData.deviceId = "39a7abdd06b3c7ab"
|
||||||
val filter = IntentFilter(Intent.ACTION_BOOT_COMPLETED)
|
val filter = IntentFilter(Intent.ACTION_BOOT_COMPLETED)
|
||||||
registerReceiver(BootReceiver(), filter)
|
registerReceiver(BootReceiver(), filter)
|
||||||
@@ -59,24 +79,21 @@ class BaseApp : Application() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val TAG = "BaseApp"
|
private val TAG = "BaseApp"
|
||||||
// const val canteenId = "1678234139391512577"
|
|
||||||
var canteenId = "0"
|
var canteenId = "0"
|
||||||
// var configUrl = ""
|
|
||||||
|
|
||||||
// var token: String? = null
|
|
||||||
// var deviceId: String? = null
|
|
||||||
var appVersion: String = "1"
|
var appVersion: String = "1"
|
||||||
@Volatile
|
@Volatile
|
||||||
private var sharedPref: SharedPreferences? = null
|
private var sharedPref: SharedPreferences? = null
|
||||||
|
|
||||||
public var instance: BaseApp? = null
|
lateinit var instance: BaseApp
|
||||||
fun getSharedPref(): SharedPreferences? {
|
|
||||||
if (sharedPref != null) {
|
/** 双重检查锁,保证多线程下只初始化一次 */
|
||||||
return sharedPref
|
fun getSharedPref(): SharedPreferences {
|
||||||
|
return sharedPref ?: synchronized(this) {
|
||||||
|
sharedPref ?: instance.getSharedPreferences(
|
||||||
|
instance.getString(R.string.sp_save_name),
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
).also { sharedPref = it }
|
||||||
}
|
}
|
||||||
val saveName = instance?.getString(R.string.sp_save_name)
|
|
||||||
sharedPref = instance?.getSharedPreferences(saveName, Context.MODE_PRIVATE)
|
|
||||||
return sharedPref
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ package com.shuwei.dish.match.base
|
|||||||
enum class DeviceRole { MASTER, SLAVE }
|
enum class DeviceRole { MASTER, SLAVE }
|
||||||
|
|
||||||
object GlobalData {
|
object GlobalData {
|
||||||
var appBaseUrl: String = TEST_BASE_URL
|
var appBaseUrl: String = PROD_BASE_URL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 具体业务 BaseUrl
|
* 具体业务 BaseUrl
|
||||||
*/
|
*/
|
||||||
const val TEST_BASE_URL = "http://192.168.1.201:14801"
|
const val TEST_BASE_URL = "http://192.168.10.101:24801"
|
||||||
const val UAT_BASE_URL = "https://dev.yixiong-tech.com:8081"
|
const val UAT_BASE_URL = "https://dev.yixiong-tech.com:8081"
|
||||||
const val PROD_BASE_URL = "https://api.dm.yixiong-tech.com:8443"
|
const val PROD_BASE_URL = "https://platform-api.uat.shuziweidao.com"
|
||||||
/**
|
/**
|
||||||
* 设备id
|
* 设备id
|
||||||
*/
|
*/
|
||||||
@@ -25,8 +25,6 @@ object GlobalData {
|
|||||||
* 当前设备角色,启动时从 SpTool 读取,默认为 SLAVE
|
* 当前设备角色,启动时从 SpTool 读取,默认为 SLAVE
|
||||||
*/
|
*/
|
||||||
var deviceRole: DeviceRole = DeviceRole.SLAVE
|
var deviceRole: DeviceRole = DeviceRole.SLAVE
|
||||||
var appId = "Hkz1rBk6PZXbS8KwKr67K2eZtsz8bRoMHLg64bUdgCZj"
|
|
||||||
var sdkKey = "AabXs3sHM8UhhE7oCGf4LVMLrdkGb1nJNksbjjTdVt7k"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,4 +35,5 @@ object GlobalKey {
|
|||||||
const val KEY_TOKEN = "tokenKey"
|
const val KEY_TOKEN = "tokenKey"
|
||||||
const val KEY_USER_INFO = "userInfoKey"
|
const val KEY_USER_INFO = "userInfoKey"
|
||||||
const val KEY_USER_NAME = "userNameKey"
|
const val KEY_USER_NAME = "userNameKey"
|
||||||
|
const val KEY_BASE_URL = "baseUrl"
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,10 @@ import com.shuwei.dish.match.db.dao.CookFoodDao
|
|||||||
import com.shuwei.dish.match.db.dao.CookFoodGoodsDao
|
import com.shuwei.dish.match.db.dao.CookFoodGoodsDao
|
||||||
import com.shuwei.dish.match.db.dao.SeasoningDao
|
import com.shuwei.dish.match.db.dao.SeasoningDao
|
||||||
import com.shuwei.dish.match.db.dao.SeasoningSlotDao
|
import com.shuwei.dish.match.db.dao.SeasoningSlotDao
|
||||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||||
import com.shuwei.dish.match.entity.SeasoningSlotEntity
|
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||||
|
|
||||||
|
|
||||||
// 步骤1:更新版本号
|
// 步骤1:更新版本号
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package com.shuwei.dish.match.db
|
package com.shuwei.dish.match.db
|
||||||
|
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||||
import com.shuwei.dish.match.entity.SeasoningSlotEntity
|
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||||
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@@ -233,6 +234,40 @@ class DbRepository {
|
|||||||
db.seasoningSlotDao().countSlotAll()
|
db.seasoningSlotDao().countSlotAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- 调试用:动态条件过滤分页查询 ----
|
||||||
|
|
||||||
|
suspend fun getCookFoodPagedFiltered(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
db.cookFoodDao().queryPagedFiltered(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun countCookFoodFiltered(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
db.cookFoodDao().countFiltered(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getCookFoodGoodsPagedFiltered(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
db.cookFoodGoodsDao().queryPagedFiltered(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun countCookFoodGoodsFiltered(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
db.cookFoodGoodsDao().countFiltered(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getSeasoningPagedFiltered(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
db.seasoningDao().queryPagedFiltered(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun countSeasoningFiltered(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
db.seasoningDao().countFiltered(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getSlotPagedFiltered(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
db.seasoningSlotDao().queryPagedFiltered(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun countSlotFiltered(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
db.seasoningSlotDao().countFiltered(query)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 物理清空全部 4 张表的测试数据
|
* 物理清空全部 4 张表的测试数据
|
||||||
* 清除顺序:先删子表(食材),再删主表(菜品),最后删配置表(调料、槽位)
|
* 清除顺序:先删子表(食材),再删主表(菜品),最后删配置表(调料、槽位)
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ package com.shuwei.dish.match.db
|
|||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.shuwei.dish.match.entity.CollectedFoodItem
|
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
import com.shuwei.dish.match.model.CollectedFoodItem
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
import com.shuwei.dish.match.objbox.ObjectBox
|
import com.shuwei.dish.match.objbox.ObjectBox
|
||||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||||
import com.shuwei.dish.match.entity.SeasoningSlotEntity
|
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
@@ -48,6 +49,30 @@ class DbViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询本地烹饪中数据(回调版本),结果通过 onResult 直接回调,不经过 StateFlow
|
||||||
|
* 适合不需要跨生命周期持续监听的一次性查询场景
|
||||||
|
*/
|
||||||
|
fun getCookFoodListWithCallback(
|
||||||
|
cookMode: Int,
|
||||||
|
dinnerType: String = "0",
|
||||||
|
onResult: (MutableList<CookFoodEntity>?) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onResult(rep.getCookFoodList(cookMode, dinnerType))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 直接返回本地烹饪中数据,供需要串行等待结果的场景使用(如先查库再发网络请求)
|
||||||
|
*/
|
||||||
|
suspend fun getCookFoodListDirect(
|
||||||
|
cookMode: Int,
|
||||||
|
dinnerType: String = "0"
|
||||||
|
): MutableList<CookFoodEntity>? {
|
||||||
|
return rep.getCookFoodList(cookMode, dinnerType)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun countCookFood(cookMode: Int): Int {
|
suspend fun countCookFood(cookMode: Int): Int {
|
||||||
return rep.countCookFood(cookMode)
|
return rep.countCookFood(cookMode)
|
||||||
}
|
}
|
||||||
@@ -73,6 +98,8 @@ class DbViewModel : ViewModel() {
|
|||||||
// 首次保存:主表 + 主辅材 + 调料 全量 insert
|
// 首次保存:主表 + 主辅材 + 调料 全量 insert
|
||||||
rep.insertCookFood(entity)
|
rep.insertCookFood(entity)
|
||||||
val newData = rep.getCookFoodById(entity.foodId, cookMode, entity.dinnerType ?: "0")
|
val newData = rep.getCookFoodById(entity.foodId, cookMode, entity.dinnerType ?: "0")
|
||||||
|
// 回填 id,防止下次调用时 getCookFoodById 查不到而重复插入主辅材
|
||||||
|
newData?.let { entity.id = it.id }
|
||||||
list?.let {
|
list?.let {
|
||||||
it.forEach { goods ->
|
it.forEach { goods ->
|
||||||
goods.id = 0
|
goods.id = 0
|
||||||
@@ -103,6 +130,17 @@ class DbViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口提交成功后删除本地菜品草稿(异步版本,绑定 viewModelScope)
|
||||||
|
* 与 [markSubmittedAndDelete] 的区别:不是 suspend,内部用 viewModelScope 启动协程,
|
||||||
|
* 不受调用方 Activity 生命周期影响,适合 singleTask 跳转前触发删除的场景
|
||||||
|
*/
|
||||||
|
fun markSubmittedAndDeleteAsync(cookMode: Int, foodId: String, dinnerType: String) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
markSubmittedAndDelete(cookMode, foodId, dinnerType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口提交成功后删除本地菜品草稿
|
* 接口提交成功后删除本地菜品草稿
|
||||||
* 与 [deleteCookFoodAndGoods] 的区别:主表 submitState 会被置 1,便于审计区分手动删除与接口删除
|
* 与 [deleteCookFoodAndGoods] 的区别:主表 submitState 会被置 1,便于审计区分手动删除与接口删除
|
||||||
@@ -295,71 +333,89 @@ class DbViewModel : ViewModel() {
|
|||||||
* @param totalCount 当前过滤条件下的总记录数
|
* @param totalCount 当前过滤条件下的总记录数
|
||||||
* @param hasMore 是否还有更多数据可加载
|
* @param hasMore 是否还有更多数据可加载
|
||||||
* @param isLoading 是否正在加载(首次加载或加载更多)
|
* @param isLoading 是否正在加载(首次加载或加载更多)
|
||||||
|
* @param filter 当前生效的筛选条件,供"加载更多"复用
|
||||||
*/
|
*/
|
||||||
data class DbInspectUiState(
|
data class DbInspectUiState(
|
||||||
val items: List<DbRecord> = emptyList(),
|
val items: List<DbRecord> = emptyList(),
|
||||||
val totalCount: Int = 0,
|
val totalCount: Int = 0,
|
||||||
val hasMore: Boolean = false,
|
val hasMore: Boolean = false,
|
||||||
val isLoading: Boolean = false
|
val isLoading: Boolean = false,
|
||||||
|
val filter: DbInspectFilter = DbInspectFilter()
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库调试页面筛选条件
|
||||||
|
* @param showDel 是否包含已删除记录
|
||||||
|
* @param exactFields 精确匹配字段:列名 → 值
|
||||||
|
* @param likeFields 模糊匹配字段:列名 → 值(自动加 %value%)
|
||||||
|
*/
|
||||||
|
data class DbInspectFilter(
|
||||||
|
val showDel: Boolean = true,
|
||||||
|
val exactFields: Map<String, String> = emptyMap(),
|
||||||
|
val likeFields: Map<String, String> = emptyMap()
|
||||||
)
|
)
|
||||||
|
|
||||||
private val _dbInspectState = MutableStateFlow(DbInspectUiState())
|
private val _dbInspectState = MutableStateFlow(DbInspectUiState())
|
||||||
val dbInspectState: StateFlow<DbInspectUiState> = _dbInspectState.asStateFlow()
|
val dbInspectState: StateFlow<DbInspectUiState> = _dbInspectState.asStateFlow()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载指定表的第一页数据(切换 Tab / 切换 isDel 过滤时调用)
|
* 加载指定表的第一页数据(切换 Tab / 修改筛选条件时调用)
|
||||||
* @param tableIndex 0=菜品 1=食材 2=调料 3=槽位
|
* @param tableIndex 0=菜品 1=食材 2=调料 3=槽位
|
||||||
* @param showDel true=包含已删除记录,false=只看有效记录
|
* @param filter 筛选条件,包含 showDel 和各字段过滤值
|
||||||
*/
|
*/
|
||||||
fun loadDbInspect(tableIndex: Int, showDel: Boolean) {
|
fun loadDbInspect(tableIndex: Int, filter: DbInspectFilter) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
// 立即清空旧数据并显示加载状态,避免切换 Tab 时旧数据闪现
|
// 立即清空旧数据并显示加载状态,避免切换 Tab 时旧数据闪现
|
||||||
_dbInspectState.value = DbInspectUiState(isLoading = true)
|
_dbInspectState.value = DbInspectUiState(isLoading = true, filter = filter)
|
||||||
val (items, total) = queryPage(tableIndex, showDel, offset = 0)
|
val (items, total) = queryPage(tableIndex, filter, offset = 0)
|
||||||
_dbInspectState.value = DbInspectUiState(
|
_dbInspectState.value = DbInspectUiState(
|
||||||
items = items,
|
items = items,
|
||||||
totalCount = total,
|
totalCount = total,
|
||||||
hasMore = items.size < total,
|
hasMore = items.size < total,
|
||||||
isLoading = false
|
isLoading = false,
|
||||||
|
filter = filter
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 追加加载下一页数据(点击"加载更多"时调用)
|
* 追加加载下一页数据(点击"加载更多"时调用)
|
||||||
|
* 筛选条件从当前 state 中复用,无需重新传入
|
||||||
* @param tableIndex 0=菜品 1=食材 2=调料 3=槽位
|
* @param tableIndex 0=菜品 1=食材 2=调料 3=槽位
|
||||||
* @param showDel true=包含已删除记录
|
|
||||||
*/
|
*/
|
||||||
fun loadMoreDbInspect(tableIndex: Int, showDel: Boolean) {
|
fun loadMoreDbInspect(tableIndex: Int) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val current = _dbInspectState.value
|
val current = _dbInspectState.value
|
||||||
// 已在加载中或无更多数据时直接返回,防止重复请求
|
// 已在加载中或无更多数据时直接返回,防止重复请求
|
||||||
if (!current.hasMore || current.isLoading) return@launch
|
if (!current.hasMore || current.isLoading) return@launch
|
||||||
_dbInspectState.value = current.copy(isLoading = true)
|
_dbInspectState.value = current.copy(isLoading = true)
|
||||||
val (newItems, total) = queryPage(tableIndex, showDel, offset = current.items.size)
|
val (newItems, total) = queryPage(tableIndex, current.filter, offset = current.items.size)
|
||||||
val merged = current.items + newItems
|
val merged = current.items + newItems
|
||||||
_dbInspectState.value = DbInspectUiState(
|
_dbInspectState.value = DbInspectUiState(
|
||||||
items = merged,
|
items = merged,
|
||||||
totalCount = total,
|
totalCount = total,
|
||||||
hasMore = merged.size < total,
|
hasMore = merged.size < total,
|
||||||
isLoading = false
|
isLoading = false,
|
||||||
|
filter = current.filter
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行分页查询,返回 DbRecord 列表和总记录数
|
* 执行分页查询,返回 DbRecord 列表和总记录数
|
||||||
|
* 通过 buildQueries 将 filter 转换为动态 SQL
|
||||||
*/
|
*/
|
||||||
private suspend fun queryPage(
|
private suspend fun queryPage(
|
||||||
tableIndex: Int,
|
tableIndex: Int,
|
||||||
showDel: Boolean,
|
filter: DbInspectFilter,
|
||||||
offset: Int
|
offset: Int
|
||||||
): Pair<List<DbRecord>, Int> {
|
): Pair<List<DbRecord>, Int> {
|
||||||
val limit = DB_INSPECT_PAGE_SIZE
|
val limit = DB_INSPECT_PAGE_SIZE
|
||||||
return when (tableIndex) {
|
return when (tableIndex) {
|
||||||
0 -> {
|
0 -> {
|
||||||
val total = rep.countCookFoodAll(showDel)
|
val (pageQ, countQ) = buildQueries("dm_cook_food", "createTime DESC", true, filter, limit, offset)
|
||||||
val rows = rep.getCookFoodPaged(showDel, limit, offset).map { e ->
|
val total = rep.countCookFoodFiltered(countQ)
|
||||||
|
val rows = rep.getCookFoodPagedFiltered(pageQ).map { e ->
|
||||||
DbRecord(
|
DbRecord(
|
||||||
isDel = e.isDel == 1,
|
isDel = e.isDel == 1,
|
||||||
fields = listOf(
|
fields = listOf(
|
||||||
@@ -373,8 +429,9 @@ class DbViewModel : ViewModel() {
|
|||||||
rows to total
|
rows to total
|
||||||
}
|
}
|
||||||
1 -> {
|
1 -> {
|
||||||
val total = rep.countCookFoodGoodsAll(showDel)
|
val (pageQ, countQ) = buildQueries("dm_cook_food_goods", "createTime DESC", true, filter, limit, offset)
|
||||||
val rows = rep.getCookFoodGoodsPaged(showDel, limit, offset).map { e ->
|
val total = rep.countCookFoodGoodsFiltered(countQ)
|
||||||
|
val rows = rep.getCookFoodGoodsPagedFiltered(pageQ).map { e ->
|
||||||
DbRecord(
|
DbRecord(
|
||||||
isDel = e.isDel == 1,
|
isDel = e.isDel == 1,
|
||||||
fields = listOf(
|
fields = listOf(
|
||||||
@@ -389,8 +446,9 @@ class DbViewModel : ViewModel() {
|
|||||||
rows to total
|
rows to total
|
||||||
}
|
}
|
||||||
2 -> {
|
2 -> {
|
||||||
val total = rep.countSeasoningAll(showDel)
|
val (pageQ, countQ) = buildQueries("dm_seasoning", "sort ASC", true, filter, limit, offset)
|
||||||
val rows = rep.getSeasoningPaged(showDel, limit, offset).map { e ->
|
val total = rep.countSeasoningFiltered(countQ)
|
||||||
|
val rows = rep.getSeasoningPagedFiltered(pageQ).map { e ->
|
||||||
DbRecord(
|
DbRecord(
|
||||||
isDel = e.isDel == 1,
|
isDel = e.isDel == 1,
|
||||||
fields = listOf(
|
fields = listOf(
|
||||||
@@ -404,15 +462,16 @@ class DbViewModel : ViewModel() {
|
|||||||
rows to total
|
rows to total
|
||||||
}
|
}
|
||||||
3 -> {
|
3 -> {
|
||||||
val total = rep.countSlotAll()
|
val (pageQ, countQ) = buildQueries("dm_seasoning_slot", "deviceId ASC, address ASC", false, filter, limit, offset)
|
||||||
val rows = rep.getSlotPaged(limit, offset).map { e ->
|
val total = rep.countSlotFiltered(countQ)
|
||||||
|
val rows = rep.getSlotPagedFiltered(pageQ).map { e ->
|
||||||
DbRecord(
|
DbRecord(
|
||||||
isDel = false,
|
isDel = false,
|
||||||
fields = listOf(
|
fields = listOf(
|
||||||
"deviceId" to e.deviceId, "address" to "${e.address}",
|
"deviceId" to e.deviceId, "address" to "${e.address}",
|
||||||
"goodsId" to e.goodsId, "goodsName" to e.goodsName
|
"goodsId" to e.goodsId, "goodsName" to e.goodsName
|
||||||
),
|
),
|
||||||
columnsPerRow = 1 // 槽位表字段少,保持单列显示
|
columnsPerRow = 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
rows to total
|
rows to total
|
||||||
@@ -421,6 +480,55 @@ class DbViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据筛选条件动态构建分页查询和计数查询的 SQL
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param orderBy ORDER BY 子句(不含关键字)
|
||||||
|
* @param hasIsDel 是否有 isDel 字段,无则忽略 showDel 参数
|
||||||
|
* @param filter 筛选条件
|
||||||
|
* @param limit 分页大小
|
||||||
|
* @param offset 偏移量
|
||||||
|
* @return Pair<分页查询, 计数查询>
|
||||||
|
*/
|
||||||
|
private fun buildQueries(
|
||||||
|
tableName: String,
|
||||||
|
orderBy: String,
|
||||||
|
hasIsDel: Boolean,
|
||||||
|
filter: DbInspectFilter,
|
||||||
|
limit: Int,
|
||||||
|
offset: Int
|
||||||
|
): Pair<SimpleSQLiteQuery, SimpleSQLiteQuery> {
|
||||||
|
val conditions = mutableListOf<String>()
|
||||||
|
val args = mutableListOf<Any>()
|
||||||
|
|
||||||
|
if (hasIsDel && !filter.showDel) {
|
||||||
|
conditions.add("isDel = 0")
|
||||||
|
}
|
||||||
|
filter.exactFields.forEach { (col, value) ->
|
||||||
|
if (value.isNotBlank()) {
|
||||||
|
conditions.add("$col = ?")
|
||||||
|
args.add(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter.likeFields.forEach { (col, value) ->
|
||||||
|
if (value.isNotBlank()) {
|
||||||
|
conditions.add("$col LIKE ?")
|
||||||
|
args.add("%$value%")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val where = if (conditions.isEmpty()) "" else "WHERE ${conditions.joinToString(" AND ")}"
|
||||||
|
val pageQuery = SimpleSQLiteQuery(
|
||||||
|
"SELECT * FROM $tableName $where ORDER BY $orderBy LIMIT ? OFFSET ?",
|
||||||
|
(args + limit + offset).toTypedArray()
|
||||||
|
)
|
||||||
|
val countQuery = SimpleSQLiteQuery(
|
||||||
|
"SELECT COUNT(*) FROM $tableName $where",
|
||||||
|
args.toTypedArray()
|
||||||
|
)
|
||||||
|
return pageQuery to countQuery
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// viewModelScope.launch {
|
// viewModelScope.launch {
|
||||||
@@ -500,5 +608,17 @@ class DbViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有向量采集数据,完成后刷新列表
|
||||||
|
* @param onDone 清除完成后在主线程执行的回调
|
||||||
|
*/
|
||||||
|
fun clearAllCollectedFood(onDone: (() -> Unit)? = null) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
ObjectBox.removeAll()
|
||||||
|
loadCollectedFoodList()
|
||||||
|
onDone?.invoke()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,10 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
|
import androidx.room.RawQuery
|
||||||
import androidx.room.Update
|
import androidx.room.Update
|
||||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CookFoodDao {
|
interface CookFoodDao {
|
||||||
@@ -48,4 +50,12 @@ interface CookFoodDao {
|
|||||||
/** 物理清空全表,用于清除测试数据 */
|
/** 物理清空全表,用于清除测试数据 */
|
||||||
@Query("DELETE FROM dm_cook_food")
|
@Query("DELETE FROM dm_cook_food")
|
||||||
suspend fun deleteAll()
|
suspend fun deleteAll()
|
||||||
|
|
||||||
|
/** 动态条件分页查询菜品记录,由 ViewModel 构建 SQL */
|
||||||
|
@RawQuery
|
||||||
|
suspend fun queryPagedFiltered(query: SupportSQLiteQuery): List<CookFoodEntity>
|
||||||
|
|
||||||
|
/** 动态条件统计菜品记录总数,由 ViewModel 构建 SQL */
|
||||||
|
@RawQuery
|
||||||
|
suspend fun countFiltered(query: SupportSQLiteQuery): Int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
|
import androidx.room.RawQuery
|
||||||
import androidx.room.Update
|
import androidx.room.Update
|
||||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CookFoodGoodsDao {
|
interface CookFoodGoodsDao {
|
||||||
@@ -48,4 +50,12 @@ interface CookFoodGoodsDao {
|
|||||||
/** 物理清空全表,用于清除测试数据 */
|
/** 物理清空全表,用于清除测试数据 */
|
||||||
@Query("DELETE FROM dm_cook_food_goods")
|
@Query("DELETE FROM dm_cook_food_goods")
|
||||||
suspend fun deleteAll()
|
suspend fun deleteAll()
|
||||||
|
|
||||||
|
/** 动态条件分页查询食材记录,由 ViewModel 构建 SQL */
|
||||||
|
@RawQuery
|
||||||
|
suspend fun queryPagedFiltered(query: SupportSQLiteQuery): List<CookFoodGoodsEntity>
|
||||||
|
|
||||||
|
/** 动态条件统计食材记录总数,由 ViewModel 构建 SQL */
|
||||||
|
@RawQuery
|
||||||
|
suspend fun countFiltered(query: SupportSQLiteQuery): Int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
|
import androidx.room.RawQuery
|
||||||
import androidx.room.Update
|
import androidx.room.Update
|
||||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
|
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface SeasoningDao {
|
interface SeasoningDao {
|
||||||
@@ -57,4 +59,12 @@ interface SeasoningDao {
|
|||||||
/** 物理清空全表,用于清除测试数据(比 clearAllSeasoning 的逻辑删除更彻底) */
|
/** 物理清空全表,用于清除测试数据(比 clearAllSeasoning 的逻辑删除更彻底) */
|
||||||
@Query("DELETE FROM dm_seasoning")
|
@Query("DELETE FROM dm_seasoning")
|
||||||
suspend fun deleteAll()
|
suspend fun deleteAll()
|
||||||
|
|
||||||
|
/** 动态条件分页查询调料记录,由 ViewModel 构建 SQL */
|
||||||
|
@RawQuery
|
||||||
|
suspend fun queryPagedFiltered(query: SupportSQLiteQuery): List<SeasoningEntity>
|
||||||
|
|
||||||
|
/** 动态条件统计调料记录总数,由 ViewModel 构建 SQL */
|
||||||
|
@RawQuery
|
||||||
|
suspend fun countFiltered(query: SupportSQLiteQuery): Int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import com.shuwei.dish.match.entity.SeasoningSlotEntity
|
import androidx.room.RawQuery
|
||||||
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
|
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调料槽位配置 DAO
|
* 调料槽位配置 DAO
|
||||||
@@ -64,4 +66,12 @@ interface SeasoningSlotDao {
|
|||||||
/** 物理清空全表,用于清除测试数据 */
|
/** 物理清空全表,用于清除测试数据 */
|
||||||
@Query("DELETE FROM dm_seasoning_slot")
|
@Query("DELETE FROM dm_seasoning_slot")
|
||||||
suspend fun deleteAll()
|
suspend fun deleteAll()
|
||||||
|
|
||||||
|
/** 动态条件分页查询槽位记录,由 ViewModel 构建 SQL */
|
||||||
|
@RawQuery
|
||||||
|
suspend fun queryPagedFiltered(query: SupportSQLiteQuery): List<SeasoningSlotEntity>
|
||||||
|
|
||||||
|
/** 动态条件统计槽位记录总数,由 ViewModel 构建 SQL */
|
||||||
|
@RawQuery
|
||||||
|
suspend fun countFiltered(query: SupportSQLiteQuery): Int
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.db.entity
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.Ignore
|
import androidx.room.Ignore
|
||||||
@@ -31,4 +31,4 @@ data class CookFoodEntity(
|
|||||||
var foodConstituteList: MutableList<CookFoodGoodsEntity>? = null
|
var foodConstituteList: MutableList<CookFoodGoodsEntity>? = null
|
||||||
|
|
||||||
constructor() : this(foodId = "") // 必需的空构造
|
constructor() : this(foodId = "") // 必需的空构造
|
||||||
}
|
}
|
||||||
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.db.entity
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.shuwei.dish.match.db.BaseEntity
|
import com.shuwei.dish.match.db.BaseEntity
|
||||||
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.utils.DateTimeUtil
|
import com.shuwei.dish.match.utils.DateTimeUtil
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@@ -94,4 +95,4 @@ class CookFoodGoodsEntity(
|
|||||||
goodsOrRelationCode = goodsOrRelationCode,
|
goodsOrRelationCode = goodsOrRelationCode,
|
||||||
rawMaterialsType = rawMaterialsType
|
rawMaterialsType = rawMaterialsType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.db.entity
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
@@ -72,4 +72,4 @@ var isDel: Int = 0,
|
|||||||
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now())
|
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now())
|
||||||
) : BaseEntity {
|
) : BaseEntity {
|
||||||
constructor() : this(goodsId = "") // 必需的空构造
|
constructor() : this(goodsId = "") // 必需的空构造
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.db.entity
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
|
||||||
@@ -26,10 +26,12 @@ open class CommonDialog(
|
|||||||
private var negativeText = "取消"
|
private var negativeText = "取消"
|
||||||
private var positiveText = "确认"
|
private var positiveText = "确认"
|
||||||
private var neutralText: String? = null
|
private var neutralText: String? = null
|
||||||
|
private var singleText: String? = null
|
||||||
private var negativeClick: (() -> Unit)? = null
|
private var negativeClick: (() -> Unit)? = null
|
||||||
// 返回 true 时关闭弹窗,返回 false 时保持弹窗显示(用于校验不通过的场景)
|
// 返回 true 时关闭弹窗,返回 false 时保持弹窗显示(用于校验不通过的场景)
|
||||||
private var positiveClick: (() -> Boolean)? = null
|
private var positiveClick: (() -> Boolean)? = null
|
||||||
private var neutralClick: (() -> Unit)? = null
|
private var neutralClick: (() -> Unit)? = null
|
||||||
|
private var singleClick: (() -> Unit)? = null
|
||||||
private var dismissCallback: (() -> Unit)? = null
|
private var dismissCallback: (() -> Unit)? = null
|
||||||
// 待添加到 llContent 的自定义 View,在 onCreate 后挂载
|
// 待添加到 llContent 的自定义 View,在 onCreate 后挂载
|
||||||
private var pendingContentView: View? = null
|
private var pendingContentView: View? = null
|
||||||
@@ -51,7 +53,7 @@ open class CommonDialog(
|
|||||||
/** 设置右侧确认按钮文字及点击回调(3按钮模式下对应底部按钮),点击后自动关闭弹窗 */
|
/** 设置右侧确认按钮文字及点击回调(3按钮模式下对应底部按钮),点击后自动关闭弹窗 */
|
||||||
fun setPositiveButton(text: String, onClick: (() -> Unit)? = null): CommonDialog = apply {
|
fun setPositiveButton(text: String, onClick: (() -> Unit)? = null): CommonDialog = apply {
|
||||||
positiveText = text
|
positiveText = text
|
||||||
positiveClick = onClick?.let { { it(); true } }
|
positiveClick = onClick?.let { cb -> { cb(); true } }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,6 +71,12 @@ open class CommonDialog(
|
|||||||
neutralClick = onClick
|
neutralClick = onClick
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 设置单按钮文字及点击回调,调用后自动切换为单按钮布局(优先级最高) */
|
||||||
|
fun setSingleButton(text: String, onClick: (() -> Unit)? = null): CommonDialog = apply {
|
||||||
|
singleText = text
|
||||||
|
singleClick = onClick
|
||||||
|
}
|
||||||
|
|
||||||
/** 设置弹窗消失回调 */
|
/** 设置弹窗消失回调 */
|
||||||
fun setOnDismissCallback(callback: () -> Unit): CommonDialog = apply {
|
fun setOnDismissCallback(callback: () -> Unit): CommonDialog = apply {
|
||||||
dismissCallback = callback
|
dismissCallback = callback
|
||||||
@@ -91,9 +99,9 @@ open class CommonDialog(
|
|||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
// 弹窗不允许点击外部关闭
|
// 弹窗不允许点击外部关闭
|
||||||
setCancelable(false)
|
setCancelable(false)
|
||||||
|
val isMaster = GlobalData.deviceRole == DeviceRole.MASTER
|
||||||
window?.run {
|
window?.run {
|
||||||
val screenWidth = context.resources.displayMetrics.widthPixels
|
val screenWidth = context.resources.displayMetrics.widthPixels
|
||||||
val isMaster = GlobalData.deviceRole == DeviceRole.MASTER
|
|
||||||
attributes = attributes.apply {
|
attributes = attributes.apply {
|
||||||
width = if (isMaster) (screenWidth * 0.72f).toInt() else (screenWidth * 0.60f).toInt()
|
width = if (isMaster) (screenWidth * 0.72f).toInt() else (screenWidth * 0.60f).toInt()
|
||||||
}
|
}
|
||||||
@@ -103,7 +111,7 @@ open class CommonDialog(
|
|||||||
setWindowAnimations(R.style.CommonDialogAnimation)
|
setWindowAnimations(R.style.CommonDialogAnimation)
|
||||||
}
|
}
|
||||||
// 主/从设备边距微调:主设备内容区域更大,适当增加上下留白
|
// 主/从设备边距微调:主设备内容区域更大,适当增加上下留白
|
||||||
val verticalMargin = if (GlobalData.deviceRole == DeviceRole.MASTER) 48.dp else 36.dp
|
val verticalMargin = if (isMaster) 48.dp else 36.dp
|
||||||
binding.tvTitle.updateLayoutParams<LinearLayout.LayoutParams> { topMargin = verticalMargin }
|
binding.tvTitle.updateLayoutParams<LinearLayout.LayoutParams> { topMargin = verticalMargin }
|
||||||
binding.tvContent.updateLayoutParams<LinearLayout.LayoutParams> { bottomMargin = verticalMargin }
|
binding.tvContent.updateLayoutParams<LinearLayout.LayoutParams> { bottomMargin = verticalMargin }
|
||||||
|
|
||||||
@@ -130,10 +138,17 @@ open class CommonDialog(
|
|||||||
if (positiveClick?.invoke() != false) dismiss()
|
if (positiveClick?.invoke() != false) dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 单按钮点击事件
|
||||||
|
binding.btnSingle.setOnClickListener {
|
||||||
|
singleClick?.invoke()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
setOnDismissListener { dismissCallback?.invoke() }
|
setOnDismissListener { dismissCallback?.invoke() }
|
||||||
|
|
||||||
// 挂载自定义内容 View,并执行 tvContent 的灵活控制回调
|
// 挂载自定义内容 View,并执行 tvContent 的灵活控制回调
|
||||||
pendingContentView?.let {
|
pendingContentView?.let {
|
||||||
|
binding.llContent.removeAllViews()
|
||||||
binding.llContent.addView(it)
|
binding.llContent.addView(it)
|
||||||
binding.llContent.visibility = View.VISIBLE
|
binding.llContent.visibility = View.VISIBLE
|
||||||
tvContentConfigurator?.invoke(binding.tvContent)
|
tvContentConfigurator?.invoke(binding.tvContent)
|
||||||
@@ -148,10 +163,15 @@ open class CommonDialog(
|
|||||||
binding.tvContent.visibility = if (contentText.isNullOrEmpty()) View.GONE else View.VISIBLE
|
binding.tvContent.visibility = if (contentText.isNullOrEmpty()) View.GONE else View.VISIBLE
|
||||||
|
|
||||||
val hasThreeButtons = !neutralText.isNullOrEmpty()
|
val hasThreeButtons = !neutralText.isNullOrEmpty()
|
||||||
binding.layoutButtonsHorizontal.visibility = if (hasThreeButtons) View.GONE else View.VISIBLE
|
val hasSingleButton = !singleText.isNullOrEmpty()
|
||||||
|
binding.btnSingle.visibility = if (hasSingleButton) View.VISIBLE else View.GONE
|
||||||
|
binding.layoutButtonsHorizontal.visibility = if (!hasSingleButton && !hasThreeButtons) View.VISIBLE else View.GONE
|
||||||
binding.layoutButtonsVertical.visibility = if (hasThreeButtons) View.VISIBLE else View.GONE
|
binding.layoutButtonsVertical.visibility = if (hasThreeButtons) View.VISIBLE else View.GONE
|
||||||
|
|
||||||
if (hasThreeButtons) {
|
if (hasSingleButton) {
|
||||||
|
// 单按钮模式
|
||||||
|
binding.btnSingle.text = singleText
|
||||||
|
} else if (hasThreeButtons) {
|
||||||
// 3按钮模式:顶部=取消,中间=中立,底部=确认
|
// 3按钮模式:顶部=取消,中间=中立,底部=确认
|
||||||
binding.btnTop.text = negativeText
|
binding.btnTop.text = negativeText
|
||||||
binding.btnMiddle.text = neutralText
|
binding.btnMiddle.text = neutralText
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.shuwei.dish.match.dialog
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import com.shuwei.dish.match.base.GlobalData
|
||||||
|
import com.shuwei.dish.match.databinding.DialogEnvSwitchContentBinding
|
||||||
|
import com.shuwei.dish.match.utils.SpTool
|
||||||
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境切换弹窗
|
||||||
|
*
|
||||||
|
* 基于 [CommonDialog] 实现,通过 addContentView 注入 RadioGroup 内容区。
|
||||||
|
* 提供 TEST / UAT / PROD 三套环境的切换功能,初始化时自动根据
|
||||||
|
* [GlobalData.appBaseUrl] 选中当前环境,确认后更新 [GlobalData.appBaseUrl]
|
||||||
|
* 并通过 [onEnvChanged] 回调通知外部。
|
||||||
|
*
|
||||||
|
* @param context 上下文
|
||||||
|
* @param onEnvChanged 确认切换后的回调,参数为新的 baseUrl
|
||||||
|
*/
|
||||||
|
class EnvSwitchDialog(
|
||||||
|
context: Context,
|
||||||
|
private val onEnvChanged: (newBaseUrl: String) -> Unit = {}
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val contentBinding = DialogEnvSwitchContentBinding.inflate(LayoutInflater.from(context))
|
||||||
|
|
||||||
|
private val dialog = CommonDialog(context)
|
||||||
|
.setTitle("切换环境")
|
||||||
|
.addContentView(contentBinding.root) { tvContent ->
|
||||||
|
// 内容区已由 RadioGroup 承载,隐藏默认文本
|
||||||
|
tvContent.visibility = View.GONE
|
||||||
|
}
|
||||||
|
.setNegativeButton("取消")
|
||||||
|
.setPositiveButtonInterceptable("确认") {
|
||||||
|
// 未选中任何选项时提示并阻止关闭
|
||||||
|
if (contentBinding.rgEnv.checkedRadioButtonId == -1) {
|
||||||
|
context.toast("请选择环境")
|
||||||
|
return@setPositiveButtonInterceptable false
|
||||||
|
}
|
||||||
|
val newUrl = when (contentBinding.rgEnv.checkedRadioButtonId) {
|
||||||
|
contentBinding.rbTest.id -> GlobalData.TEST_BASE_URL
|
||||||
|
contentBinding.rbUat.id -> GlobalData.UAT_BASE_URL
|
||||||
|
contentBinding.rbProd.id -> GlobalData.PROD_BASE_URL
|
||||||
|
else -> return@setPositiveButtonInterceptable false
|
||||||
|
}
|
||||||
|
GlobalData.appBaseUrl = newUrl
|
||||||
|
SpTool.baseUrl = newUrl
|
||||||
|
onEnvChanged(newUrl)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
// 根据当前 appBaseUrl 预选对应 RadioButton
|
||||||
|
when (GlobalData.appBaseUrl) {
|
||||||
|
GlobalData.TEST_BASE_URL -> contentBinding.rbTest.isChecked = true
|
||||||
|
GlobalData.UAT_BASE_URL -> contentBinding.rbUat.isChecked = true
|
||||||
|
GlobalData.PROD_BASE_URL -> contentBinding.rbProd.isChecked = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 显示弹窗 */
|
||||||
|
fun show() = dialog.show()
|
||||||
|
|
||||||
|
/** 关闭弹窗 */
|
||||||
|
fun dismiss() = dialog.dismiss()
|
||||||
|
}
|
||||||
@@ -10,14 +10,9 @@ import android.view.MotionEvent
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.core.view.isEmpty
|
|
||||||
import androidx.core.widget.addTextChangedListener
|
import androidx.core.widget.addTextChangedListener
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import com.chad.library.adapter4.util.setOnDebouncedItemClick
|
import com.chad.library.adapter4.util.setOnDebouncedItemClick
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
@@ -25,11 +20,10 @@ import com.shuwei.dish.match.adapter.FoodAdapter
|
|||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.databinding.DialogFoodSearchBinding
|
import com.shuwei.dish.match.databinding.DialogFoodSearchBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||||
import com.shuwei.dish.match.dialog.SeasoningSelectDialog.Companion.PAGE_SIZE
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.MaterSearchItem
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||||
import com.shuwei.dish.match.utils.buildMockGoodsList
|
|
||||||
import com.shuwei.dish.match.utils.showRawMaterialsDialog
|
import com.shuwei.dish.match.utils.showRawMaterialsDialog
|
||||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
@@ -57,16 +51,24 @@ class FoodSearchDialog(
|
|||||||
private val adapter = FoodAdapter(list).apply {
|
private val adapter = FoodAdapter(list).apply {
|
||||||
isStateViewEnable = true
|
isStateViewEnable = true
|
||||||
setOnDebouncedItemClick { _, _, position ->
|
setOnDebouncedItemClick { _, _, position ->
|
||||||
val item = list[position]
|
val item = list.getOrNull(position) ?: return@setOnDebouncedItemClick
|
||||||
// 弹出净材种类单选弹窗,确认后再回调并关闭弹窗
|
item.isClicked = true
|
||||||
|
notifyItemChanged(position)
|
||||||
|
// mater-search 不返回净材种类,rawMaterialsTypes 为空时直接选中返回,避免卡在净材弹窗
|
||||||
|
if (item.rawMaterialsTypes.isNullOrBlank()) {
|
||||||
|
binding.root.postDelayed({
|
||||||
|
onItemSelected(item)
|
||||||
|
dismiss()
|
||||||
|
}, 300)
|
||||||
|
return@setOnDebouncedItemClick
|
||||||
|
}
|
||||||
|
// 有净材种类时弹出单选弹窗,确认后再回调并关闭弹窗
|
||||||
showRawMaterialsDialog(
|
showRawMaterialsDialog(
|
||||||
context = activity,
|
context = activity,
|
||||||
types = item.rawMaterialsTypes,
|
types = item.rawMaterialsTypes,
|
||||||
checkedType = item.rawMaterialsType
|
checkedType = item.rawMaterialsType
|
||||||
) { selectedType ->
|
) { selectedType ->
|
||||||
item.rawMaterialsType = selectedType
|
item.rawMaterialsType = selectedType
|
||||||
item.isClicked = true
|
|
||||||
notifyItemChanged(position)
|
|
||||||
binding.root.postDelayed({
|
binding.root.postDelayed({
|
||||||
onItemSelected(item)
|
onItemSelected(item)
|
||||||
dismiss()
|
dismiss()
|
||||||
@@ -125,8 +127,6 @@ class FoodSearchDialog(
|
|||||||
binding.ivSearch.setOnClickListener { searchGoods(it) }
|
binding.ivSearch.setOnClickListener { searchGoods(it) }
|
||||||
binding.root.setOnClickListener { KeyboardUtil.hideKeyboard(it) }
|
binding.root.setOnClickListener { KeyboardUtil.hideKeyboard(it) }
|
||||||
|
|
||||||
initObserver()
|
|
||||||
|
|
||||||
// 若有默认食材名称,自动填充并触发搜索
|
// 若有默认食材名称,自动填充并触发搜索
|
||||||
//if (!defGoodsName.isNullOrBlank()) {
|
//if (!defGoodsName.isNullOrBlank()) {
|
||||||
//binding.etSheetInput.setText(defGoodsName)
|
//binding.etSheetInput.setText(defGoodsName)
|
||||||
@@ -174,27 +174,6 @@ class FoodSearchDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 收集 foodSearchGoodsListState,统一处理 Loading / Success / Error 状态
|
|
||||||
* 使用独立的 State,避免与 FoodRecognizeActivity 等页面共用 goodsListState 产生干扰
|
|
||||||
*/
|
|
||||||
private fun initObserver() {
|
|
||||||
activity.lifecycleScope.launch {
|
|
||||||
activity.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
||||||
activity.netViewModel.foodSearchGoodsListState.collect { state ->
|
|
||||||
when (state) {
|
|
||||||
is UiState.Success -> loadGoodsList(state.data)
|
|
||||||
is UiState.Error -> {
|
|
||||||
activity.toast(state.msg)
|
|
||||||
finishRefresh()
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 触发搜索:校验输入、隐藏键盘、发起请求
|
* 触发搜索:校验输入、隐藏键盘、发起请求
|
||||||
*/
|
*/
|
||||||
@@ -209,14 +188,24 @@ class FoodSearchDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求食材列表,使用弹窗专用接口,结果写入 foodSearchGoodsListState
|
* 请求食材列表(采样模式新配比秤接口 mater-search,回调版本)
|
||||||
*/
|
*/
|
||||||
private fun getGoodsList() {
|
private fun getGoodsList() {
|
||||||
activity.netViewModel.queryFoodSearchGoodsList(
|
activity.netViewModel.materSearch(
|
||||||
goodsType = "0",
|
keyword = goodsName.takeUnless { it.isNullOrBlank() },
|
||||||
pageNum = pageNo,
|
pageNum = pageNo,
|
||||||
pageSize = PAGE_SIZE,
|
pageSize = PAGE_SIZE,
|
||||||
goodsName = goodsName.takeUnless { it.isNullOrBlank() }
|
onResult = { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> loadGoodsList(state.data)
|
||||||
|
is UiState.Error -> {
|
||||||
|
activity.toast(state.msg)
|
||||||
|
finishRefresh()
|
||||||
|
if (pageNo == 1) loadEmptyView()
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +213,7 @@ class FoodSearchDialog(
|
|||||||
* 将返回数据填充到列表
|
* 将返回数据填充到列表
|
||||||
*/
|
*/
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun loadGoodsList(records: MutableList<GoodsItem>?) {
|
private fun loadGoodsList(records: List<MaterSearchItem>?) {
|
||||||
finishRefresh()
|
finishRefresh()
|
||||||
if (records.isNullOrEmpty()) {
|
if (records.isNullOrEmpty()) {
|
||||||
if (pageNo == 1) {
|
if (pageNo == 1) {
|
||||||
@@ -232,20 +221,34 @@ class FoodSearchDialog(
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
binding.recyclerView.layoutManager = GridLayoutManager(activity, 2, GridLayoutManager.VERTICAL, false)
|
// 仅当当前不是 GridLayoutManager 时才重新赋值(空态切回网格时)
|
||||||
if (pageNo == 1) list.clear()
|
binding.recyclerView.run {
|
||||||
// 将接口返回的 rawMaterialsType(全部种类)移存到 rawMaterialsTypes,供弹窗使用
|
if (layoutManager !is GridLayoutManager) {
|
||||||
records.forEach {
|
layoutManager = GridLayoutManager(activity, 2, GridLayoutManager.VERTICAL, false)
|
||||||
it.rawMaterialsTypes = it.rawMaterialsType
|
}
|
||||||
it.rawMaterialsType = null
|
|
||||||
}
|
}
|
||||||
list.addAll(records)
|
if (pageNo == 1) list.clear()
|
||||||
|
// mater-search 不返回净材种类,rawMaterialsTypes 保持 null,点击时直接选中返回
|
||||||
|
val goodsItems = records.map { it.toGoodsItem() }
|
||||||
|
list.addAll(goodsItems)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
||||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||||
if (isLoadMoreEnable) pageNo++
|
if (isLoadMoreEnable) pageNo++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MaterSearchItem → GoodsItem 映射
|
||||||
|
* id 即食材id,同时作为 goodsId 和 materId(提交 sample/save 时使用)
|
||||||
|
*/
|
||||||
|
private fun MaterSearchItem.toGoodsItem() = GoodsItem(
|
||||||
|
goodsId = id,
|
||||||
|
materId = id,
|
||||||
|
goodsName = materName,
|
||||||
|
materCode = materCode,
|
||||||
|
popularName = alias
|
||||||
|
)
|
||||||
|
|
||||||
private fun finishRefresh() {
|
private fun finishRefresh() {
|
||||||
if (pageNo == 1) binding.refreshLayout.finishRefresh()
|
if (pageNo == 1) binding.refreshLayout.finishRefresh()
|
||||||
else binding.refreshLayout.finishLoadMore()
|
else binding.refreshLayout.finishLoadMore()
|
||||||
@@ -270,7 +273,7 @@ class FoodSearchDialog(
|
|||||||
emptyViewBinding?.let {
|
emptyViewBinding?.let {
|
||||||
it.tvContent.text = "暂无数据"
|
it.tvContent.text = "暂无数据"
|
||||||
it.tvSubContent.text = "未查询到食材信息,请联系管理员添加"
|
it.tvSubContent.text = "未查询到食材信息,请联系管理员添加"
|
||||||
it.root.setOnClickListener { loadGoodsList(buildMockGoodsList().toMutableList()) }
|
// it.root.setOnClickListener { loadGoodsList(buildMockGoodsList().toMutableList()) }
|
||||||
it.root.layoutParams = FrameLayout.LayoutParams(
|
it.root.layoutParams = FrameLayout.LayoutParams(
|
||||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||||
FrameLayout.LayoutParams.MATCH_PARENT
|
FrameLayout.LayoutParams.MATCH_PARENT
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.shuwei.dish.match.dialog
|
||||||
|
|
||||||
|
import android.graphics.Rect
|
||||||
|
import android.view.KeyboardShortcutGroup
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
|
import com.shuwei.dish.match.R
|
||||||
|
import com.shuwei.dish.match.adapter.GoodsPreviewAdapter
|
||||||
|
import com.shuwei.dish.match.databinding.DialogGoodsPreviewBinding
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用料明细预览弹窗,以 BottomSheetDialog 形式展示当前 goodsList
|
||||||
|
* @param context 宿主 Context(Activity)
|
||||||
|
* @param goodsList 需要展示的物品列表
|
||||||
|
*/
|
||||||
|
class GoodsPreviewDialog(
|
||||||
|
context: android.content.Context,
|
||||||
|
private val goodsList: List<CookFoodGoodsEntity>
|
||||||
|
) : BottomSheetDialog(context, R.style.BottomSheet) {
|
||||||
|
|
||||||
|
private val binding = DialogGoodsPreviewBinding.inflate(LayoutInflater.from(context))
|
||||||
|
|
||||||
|
init {
|
||||||
|
setContentView(binding.root)
|
||||||
|
setCancelable(true)
|
||||||
|
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
|
|
||||||
|
binding.rvGoodsList.run {
|
||||||
|
layoutManager = LinearLayoutManager(context)
|
||||||
|
adapter = GoodsPreviewAdapter(goodsList)
|
||||||
|
}
|
||||||
|
// foodId 对同一菜品所有条目相同,统一显示在列表上方
|
||||||
|
val foodId = goodsList.firstOrNull()?.foodId.orEmpty()
|
||||||
|
binding.tvFoodId.text = "菜品ID:${foodId.ifEmpty { "-" }}"
|
||||||
|
if (goodsList.isEmpty()) {
|
||||||
|
binding.rvGoodsList.gone()
|
||||||
|
binding.tvEmpty.visible()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 弹出时注入 Window.Callback,解决 RecyclerView 与 BottomSheet 拖拽的滑动冲突 */
|
||||||
|
override fun show() {
|
||||||
|
super.show()
|
||||||
|
val originalCallback = window?.callback ?: return
|
||||||
|
window?.callback = object : android.view.Window.Callback by originalCallback {
|
||||||
|
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
when (event.actionMasked) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
val rect = Rect()
|
||||||
|
binding.rvGoodsList.getGlobalVisibleRect(rect)
|
||||||
|
behavior.isDraggable = !rect.contains(event.rawX.toInt(), event.rawY.toInt())
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
|
behavior.isDraggable = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return originalCallback.dispatchTouchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPointerCaptureChanged(hasCapture: Boolean) {
|
||||||
|
originalCallback.onPointerCaptureChanged(hasCapture)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onProvideKeyboardShortcuts(
|
||||||
|
data: List<KeyboardShortcutGroup?>?,
|
||||||
|
menu: Menu?,
|
||||||
|
deviceId: Int
|
||||||
|
) {
|
||||||
|
originalCallback.onProvideKeyboardShortcuts(data, menu, deviceId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,28 @@
|
|||||||
package com.shuwei.dish.match.dialog
|
package com.shuwei.dish.match.dialog
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.core.graphics.drawable.toDrawable
|
import androidx.core.graphics.drawable.toDrawable
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.databinding.DialogLoadingBinding
|
import com.shuwei.dish.match.databinding.DialogLoadingBinding
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
object Loading {
|
object Loading {
|
||||||
|
|
||||||
|
/** 默认超时兜底时长(毫秒):业务方未传值时使用 */
|
||||||
|
const val DEFAULT_TIMEOUT_MS = 15_000L
|
||||||
|
|
||||||
private var dialog: LoadingDialog? = null
|
private var dialog: LoadingDialog? = null
|
||||||
|
/** 当前持有 Loading 的 context,用于隔离 Activity 销毁时的误关 */
|
||||||
|
private var owner: Context? = null
|
||||||
|
private val timeoutHandler = Handler(Looper.getMainLooper())
|
||||||
|
private val timeoutRunnable = Runnable { dismiss() }
|
||||||
|
|
||||||
fun isShowing(): Boolean {
|
fun isShowing(): Boolean {
|
||||||
return dialog != null && dialog!!.isShowing
|
return dialog != null && dialog!!.isShowing
|
||||||
@@ -22,30 +33,71 @@ object Loading {
|
|||||||
dialog!!.updateContent(content)
|
dialog!!.updateContent(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun show(context: Context, message: String = "加载中……", onDismiss: () -> Unit = {}) {
|
/**
|
||||||
|
* 显示 Loading 弹窗
|
||||||
|
*
|
||||||
|
* @param context 上下文
|
||||||
|
* @param message 提示文案
|
||||||
|
* @param timeoutMs 超时兜底时长(毫秒):到期自动 dismiss;传 0 关闭兜底,由业务方自己负责
|
||||||
|
* @param onDismiss 关闭回调
|
||||||
|
*/
|
||||||
|
fun show(
|
||||||
|
context: Context,
|
||||||
|
message: String = "加载中……",
|
||||||
|
timeoutMs: Long = DEFAULT_TIMEOUT_MS,
|
||||||
|
onDismiss: () -> Unit = {}
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
|
// 节流:已显示中只更新文案 + 重置超时,不重新 attach 窗口
|
||||||
|
// 避免反复触发 FocusEvent 在主线程繁忙时引发 ANR
|
||||||
if (dialog?.isShowing == true) {
|
if (dialog?.isShowing == true) {
|
||||||
dialog?.dismiss()
|
dialog?.updateContent(message)
|
||||||
}
|
owner = context // 同一弹窗最后一次 show 决定 owner
|
||||||
if (dialog == null) {
|
resetTimeout(timeoutMs)
|
||||||
dialog = LoadingDialog(context = context, message = message, onDismiss = onDismiss)
|
return
|
||||||
}
|
}
|
||||||
|
dialog = LoadingDialog(context = context, message = message, onDismiss = onDismiss)
|
||||||
|
owner = context
|
||||||
dialog?.show()
|
dialog?.show()
|
||||||
|
resetTimeout(timeoutMs)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dismiss() {
|
fun dismiss() {
|
||||||
|
timeoutHandler.removeCallbacks(timeoutRunnable)
|
||||||
try {
|
try {
|
||||||
dialog?.let {
|
dialog?.let {
|
||||||
if (it.isShowing) {
|
if (it.isShowing) {
|
||||||
it.dismiss()
|
it.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dialog = null
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
} finally {
|
||||||
|
dialog = null
|
||||||
|
owner = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity 销毁专用:只关闭自己持有的 Loading,防止跨 Activity 误关
|
||||||
|
* 单例 Loading 在多 Activity 共享时,若每个 Activity 的 onDestroy 都无脑 dismiss,
|
||||||
|
* 会误关后启动 Activity 弹出的 Loading;由本方法做 owner 校验后才允许关闭
|
||||||
|
*/
|
||||||
|
fun dismissIfOwnedBy(context: Context) {
|
||||||
|
if (owner === context) dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置超时兜底定时器
|
||||||
|
* @param timeoutMs <=0 表示不安排定时器(关闭兜底)
|
||||||
|
*/
|
||||||
|
private fun resetTimeout(timeoutMs: Long) {
|
||||||
|
timeoutHandler.removeCallbacks(timeoutRunnable)
|
||||||
|
if (timeoutMs > 0) {
|
||||||
|
timeoutHandler.postDelayed(timeoutRunnable, timeoutMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import android.view.Window
|
|||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.core.widget.addTextChangedListener
|
import androidx.core.widget.addTextChangedListener
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
@@ -24,14 +23,12 @@ import com.shuwei.dish.match.adapter.SeasoningSearchAdapter
|
|||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.databinding.DialogSeasoningSelectBinding
|
import com.shuwei.dish.match.databinding.DialogSeasoningSelectBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调料选择弹窗,不含重量显示,继承 BottomSheetDialog 确保只初始化一次
|
* 调料选择弹窗,不含重量显示,继承 BottomSheetDialog 确保只初始化一次
|
||||||
* @param activity 宿主 Activity
|
* @param activity 宿主 Activity
|
||||||
@@ -52,10 +49,11 @@ class SeasoningSelectDialog(
|
|||||||
private val adapter = SeasoningSearchAdapter(list).apply {
|
private val adapter = SeasoningSearchAdapter(list).apply {
|
||||||
isStateViewEnable = true
|
isStateViewEnable = true
|
||||||
setOnItemClickListener { _, v, position ->
|
setOnItemClickListener { _, v, position ->
|
||||||
list[position].isClicked = true
|
val item = list.getOrNull(position) ?: return@setOnItemClickListener
|
||||||
|
item.isClicked = true
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
v.postDelayed({
|
v.postDelayed({
|
||||||
onItemSelected(list[position])
|
onItemSelected(item)
|
||||||
dismiss()
|
dismiss()
|
||||||
}, 300)
|
}, 300)
|
||||||
}
|
}
|
||||||
@@ -63,7 +61,6 @@ class SeasoningSelectDialog(
|
|||||||
|
|
||||||
private var goodsName: String? = null
|
private var goodsName: String? = null
|
||||||
private var pageNo = 1
|
private var pageNo = 1
|
||||||
private var collectJob: Job? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
@@ -76,7 +73,6 @@ class SeasoningSelectDialog(
|
|||||||
window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||||
|
|
||||||
setOnDismissListener {
|
setOnDismissListener {
|
||||||
collectJob?.cancel()
|
|
||||||
activity.hideStatusBar()
|
activity.hideStatusBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,23 +111,6 @@ class SeasoningSelectDialog(
|
|||||||
/** 弹窗显示时自动加载默认调料列表,并在 Window.Callback 层提前拦截触摸以解决滑动冲突 */
|
/** 弹窗显示时自动加载默认调料列表,并在 Window.Callback 层提前拦截触摸以解决滑动冲突 */
|
||||||
override fun show() {
|
override fun show() {
|
||||||
super.show()
|
super.show()
|
||||||
// 启动 StateFlow 收集,弹窗关闭时由 setOnDismissListener 取消
|
|
||||||
collectJob = activity.lifecycleScope.launch {
|
|
||||||
activity.netViewModel.foodSearchGoodsListState.collect { state ->
|
|
||||||
when (state) {
|
|
||||||
is UiState.Loading -> {}
|
|
||||||
is UiState.Success -> loadGoodsList(state.data)
|
|
||||||
is UiState.Error -> {
|
|
||||||
activity.toast(state.msg)
|
|
||||||
finishRefresh()
|
|
||||||
if (pageNo == 1) {
|
|
||||||
loadEmptyView()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is UiState.Idle -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
getGoodsList()
|
getGoodsList()
|
||||||
// Window.Callback.dispatchTouchEvent 在整个 View 树的 onInterceptTouchEvent 之前执行,
|
// Window.Callback.dispatchTouchEvent 在整个 View 树的 onInterceptTouchEvent 之前执行,
|
||||||
@@ -183,14 +162,24 @@ class SeasoningSelectDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求调料列表
|
* 请求调料列表(新配比秤接口,回调版本)
|
||||||
*/
|
*/
|
||||||
private fun getGoodsList() {
|
private fun getGoodsList() {
|
||||||
activity.netViewModel.queryFoodSearchGoodsList(
|
activity.netViewModel.querySeasoningSearch(
|
||||||
goodsType = "1",
|
keyword = goodsName.takeUnless { it.isNullOrBlank() },
|
||||||
pageNum = pageNo,
|
pageNum = pageNo,
|
||||||
pageSize = PAGE_SIZE,
|
pageSize = PAGE_SIZE,
|
||||||
goodsName = goodsName.takeUnless { it.isNullOrBlank() }
|
onResult = { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> loadGoodsList(state.data)
|
||||||
|
is UiState.Error -> {
|
||||||
|
activity.toast(state.msg)
|
||||||
|
finishRefresh()
|
||||||
|
if (pageNo == 1) loadEmptyView()
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,23 +191,22 @@ class SeasoningSelectDialog(
|
|||||||
"盐", "白砂糖", "冰糖", "鸡精", "味精", "陈醋", "老抽", "生抽", "番茄酱", "胡椒粉", "孜然", "十三香",
|
"盐", "白砂糖", "冰糖", "鸡精", "味精", "陈醋", "老抽", "生抽", "番茄酱", "胡椒粉", "孜然", "十三香",
|
||||||
"料酒", "白醋", "蚝油", "辣椒面", "辣椒酱", "豆瓣酱", "淀粉", "葱", "蒜", "姜", "香菜", "油"
|
"料酒", "白醋", "蚝油", "辣椒面", "辣椒酱", "豆瓣酱", "淀粉", "葱", "蒜", "姜", "香菜", "油"
|
||||||
)
|
)
|
||||||
val mockData = mutableListOf<GoodsItem>()
|
val mockData = nameList.mapIndexed { index, name ->
|
||||||
nameList.forEachIndexed { index, name ->
|
|
||||||
val padString = "${index + 1}".padStart(2, '0')
|
val padString = "${index + 1}".padStart(2, '0')
|
||||||
mockData.add(GoodsItem(goodsId = "1000$padString", goodsName = name))
|
SeasoningSearchItem(id = "1000$padString", materName = name)
|
||||||
}
|
}
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
loadGoodsList(mockData)
|
loadGoodsList(mockData)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将返回数据转换并填充到列表
|
* 将新接口返回的 SeasoningSearchItem 映射为 GoodsItem 并填充到列表
|
||||||
|
* 新接口的 id 即食材id,同时用作 goodsId 和 materId,无需再交换
|
||||||
*/
|
*/
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun loadGoodsList(records: MutableList<GoodsItem>?) {
|
private fun loadGoodsList(records: List<SeasoningSearchItem>?) {
|
||||||
finishRefresh()
|
finishRefresh()
|
||||||
if (records.isNullOrEmpty()) {
|
if (records.isNullOrEmpty()) {
|
||||||
//activity.toast("暂未搜索到调料信息")
|
|
||||||
if (pageNo == 1) {
|
if (pageNo == 1) {
|
||||||
loadEmptyView()
|
loadEmptyView()
|
||||||
}
|
}
|
||||||
@@ -226,13 +214,26 @@ class SeasoningSelectDialog(
|
|||||||
}
|
}
|
||||||
binding.recyclerView.layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.VERTICAL, false)
|
binding.recyclerView.layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.VERTICAL, false)
|
||||||
if (pageNo == 1) list.clear()
|
if (pageNo == 1) list.clear()
|
||||||
list.addAll(records)
|
val goodsItems = records.map { it.toGoodsItem() }
|
||||||
|
list.addAll(goodsItems)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
||||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||||
if (isLoadMoreEnable) pageNo++
|
if (isLoadMoreEnable) pageNo++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SeasoningSearchItem → GoodsItem 映射
|
||||||
|
* id 既是食材id也是提交时的 goodsId,不需要 oldGoodsId 交换
|
||||||
|
*/
|
||||||
|
private fun SeasoningSearchItem.toGoodsItem() = GoodsItem(
|
||||||
|
goodsId = id,
|
||||||
|
materId = id,
|
||||||
|
goodsName = materName,
|
||||||
|
materCode = materCode,
|
||||||
|
popularName = alias
|
||||||
|
)
|
||||||
|
|
||||||
private fun finishRefresh() {
|
private fun finishRefresh() {
|
||||||
if (pageNo == 1) binding.refreshLayout.finishRefresh()
|
if (pageNo == 1) binding.refreshLayout.finishRefresh()
|
||||||
else binding.refreshLayout.finishLoadMore()
|
else binding.refreshLayout.finishLoadMore()
|
||||||
@@ -259,7 +260,7 @@ class SeasoningSelectDialog(
|
|||||||
it.tvContent.text = "暂无数据"
|
it.tvContent.text = "暂无数据"
|
||||||
it.tvSubContent.text = "未查询到调料信息,请联系管理员添加"
|
it.tvSubContent.text = "未查询到调料信息,请联系管理员添加"
|
||||||
// 点击空布局加载本地模拟数据,方便联调时验证 UI
|
// 点击空布局加载本地模拟数据,方便联调时验证 UI
|
||||||
it.root.setOnClickListener { loadMockData() }
|
//it.root.setOnClickListener { loadMockData() }
|
||||||
it.root.layoutParams = FrameLayout.LayoutParams(
|
it.root.layoutParams = FrameLayout.LayoutParams(
|
||||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||||
FrameLayout.LayoutParams.MATCH_PARENT
|
FrameLayout.LayoutParams.MATCH_PARENT
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 已采集食材列表项数据模型
|
* 已采集食材列表项数据模型
|
||||||
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当日烹饪任务列表(按餐次分组)请求参数
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/cook-orders/page
|
||||||
|
*/
|
||||||
|
data class CookOrderPageRequest(
|
||||||
|
/** 计划日期 yyyy-MM-dd,默认当天 */
|
||||||
|
val date: String? = null,
|
||||||
|
/** 餐次筛选: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐,不传返回全部 */
|
||||||
|
val mealType: Int? = null,
|
||||||
|
/** 菜品名称模糊搜索 */
|
||||||
|
val keyword: String? = null,
|
||||||
|
/** 保留字段,当前不使用 */
|
||||||
|
val pageNum: Int? = null,
|
||||||
|
/** 保留字段,当前不使用 */
|
||||||
|
val pageSize: Int? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 餐次分组,包含该餐次下的烹制单列表
|
||||||
|
*/
|
||||||
|
data class CookOrderMealGroup(
|
||||||
|
/** 餐次: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐 */
|
||||||
|
val mealType: Int = 0,
|
||||||
|
/** 餐次中文名称 */
|
||||||
|
val mealTypeName: String = "",
|
||||||
|
/** 该餐次下的烹制单列表 */
|
||||||
|
val cookOrders: List<CookOrderItem> = emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单个烹制单,对应接口响应中 cookOrders 数组的条目
|
||||||
|
* 注意: Long 类型字段服务端序列化为 String
|
||||||
|
*/
|
||||||
|
data class CookOrderItem(
|
||||||
|
/** 烹制单id(Long → String) */
|
||||||
|
val cookOrderId: String = "",
|
||||||
|
/** 烹制单号 */
|
||||||
|
val cookNo: String = "",
|
||||||
|
/** 菜品名称 */
|
||||||
|
val dishName: String = "",
|
||||||
|
/** 菜品id(关联 nut_food) */
|
||||||
|
val foodId: String = "",
|
||||||
|
/** 餐次: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐 */
|
||||||
|
val mealType: Int = 0,
|
||||||
|
/** 餐次中文名称 */
|
||||||
|
val mealTypeName: String = "",
|
||||||
|
/** 烹制状态: 0=待烹制 / 1=烹制中 / 2=已完成 / 3=异常 */
|
||||||
|
val cookStatus: Int = 0,
|
||||||
|
/** 烹制状态中文 */
|
||||||
|
val cookStatusName: String = "",
|
||||||
|
/** 生重(kg),烹制完成后才有值 */
|
||||||
|
val rawWeight: Double? = null,
|
||||||
|
/** 熟重(kg),烹制完成后才有值 */
|
||||||
|
val cookedWeight: Double? = null,
|
||||||
|
/** 需求份数 */
|
||||||
|
val needPortions: Int = 0,
|
||||||
|
/** 烹制份数,烹制完成后才有值 */
|
||||||
|
val cookedPortions: Int? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品食材构成(主材+辅材),对应接口响应中单个食材
|
||||||
|
* 对应接口: GET /neglect/ratio-scale/cook-orders/{cookOrderId}/composition
|
||||||
|
* 注意: 此接口仅返回主材(ingredientClass=1)和辅材(ingredientClass=2),不含调料
|
||||||
|
*/
|
||||||
|
data class CookOrderCompositionItem(
|
||||||
|
/** 食材id */
|
||||||
|
val materId: String = "",
|
||||||
|
/** 食材名称 */
|
||||||
|
val ingredientName: String = "",
|
||||||
|
/** 食材分类: 1=主材 / 2=辅材 */
|
||||||
|
val ingredientClass: Int = 0,
|
||||||
|
/** 食材分类中文名称 */
|
||||||
|
val ingredientClassName: String = "",
|
||||||
|
/** 标准用量(g) */
|
||||||
|
val useWeight: Double = 0.0,
|
||||||
|
/** 净菜类型id */
|
||||||
|
val vegTypeId: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 调料模糊搜索 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料模糊搜索请求参数
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/seasoning-search
|
||||||
|
* 数据源: nut_mater_base 一级分类为 18(糖蜜饯)、19(油脂)、20(调味品)
|
||||||
|
*/
|
||||||
|
data class SeasoningSearchRequest(
|
||||||
|
/** 模糊匹配食材名称和别名,为空时返回全部 */
|
||||||
|
val keyword: String? = null,
|
||||||
|
/** 页码 */
|
||||||
|
val pageNum: Int = 1,
|
||||||
|
/** 每页条数 */
|
||||||
|
val pageSize: Int = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料模糊搜索结果条目
|
||||||
|
* 注意: Long 类型字段服务端序列化为 String
|
||||||
|
*/
|
||||||
|
data class SeasoningSearchItem(
|
||||||
|
/** 食材id(Long → String) */
|
||||||
|
val id: String = "",
|
||||||
|
/** 食材名称 */
|
||||||
|
val materName: String = "",
|
||||||
|
/** 食材编码 */
|
||||||
|
val materCode: String = "",
|
||||||
|
/** 别名 */
|
||||||
|
val alias: String = "",
|
||||||
|
/** 归属食堂id(Long → String) */
|
||||||
|
val canteenId: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 烹饪完成 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 烹饪完成 — 单个食材用量条目
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/cook-orders/complete
|
||||||
|
*/
|
||||||
|
data class CookCompleteItem(
|
||||||
|
/** 食材id */
|
||||||
|
val materId: String = "",
|
||||||
|
/** 实际用量(g) */
|
||||||
|
val actualQty: Double = 0.0,
|
||||||
|
/** 调料首次使用时间 yyyy-MM-dd HH:mm:ss,仅调料需要,主辅材留空 */
|
||||||
|
val putTime: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 烹饪完成请求,一次性提交主辅材用量+熟重+调料
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/cook-orders/complete
|
||||||
|
*/
|
||||||
|
data class CookCompleteRequest(
|
||||||
|
/** 烹制单id */
|
||||||
|
val cookOrderId: String = "",
|
||||||
|
/** 烹饪开始时间 yyyy-MM-dd HH:mm:ss,进入提交页面时刻 */
|
||||||
|
val cookStart: String? = null,
|
||||||
|
/** 主辅材实际用量列表,至少1条 */
|
||||||
|
val items: List<CookCompleteItem> = emptyList(),
|
||||||
|
/** 熟重(kg) */
|
||||||
|
val cookedWeight: Double = 0.0,
|
||||||
|
/** 调料用量列表,选填 */
|
||||||
|
val seasonings: List<CookCompleteItem>? = null
|
||||||
|
)
|
||||||
+1
-3
@@ -1,4 +1,4 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@@ -50,5 +50,3 @@ data class FoodCollectionBean(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
+9
-3
@@ -1,4 +1,4 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
@@ -15,6 +15,12 @@ data class FoodRecord(
|
|||||||
var dinnerType: String = "0",
|
var dinnerType: String = "0",
|
||||||
//true-原始数据,false-非原始数据
|
//true-原始数据,false-非原始数据
|
||||||
var isOriginalData: Boolean = true,
|
var isOriginalData: Boolean = true,
|
||||||
var sort: Int = 0
|
var sort: Int = 0,
|
||||||
|
// ===== 已提交采样列表(sample-list)扩展字段,制作模式不涉及 =====
|
||||||
|
/** 实验编号(innovNo) */
|
||||||
|
var innovNo: String? = null,
|
||||||
|
/** 实验状态: 1=实验中 / 2=已评测 / 9=已转化 */
|
||||||
|
var status: Int? = null,
|
||||||
|
/** 实验状态中文 */
|
||||||
|
var statusName: String? = null
|
||||||
) : Serializable
|
) : Serializable
|
||||||
|
|
||||||
+9
-4
@@ -1,5 +1,7 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
|
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,11 +10,11 @@ import java.io.Serializable
|
|||||||
*/
|
*/
|
||||||
data class GoodsItem(
|
data class GoodsItem(
|
||||||
// 接口返回字段
|
// 接口返回字段
|
||||||
val goodsId: String = "",
|
var goodsId: String = "",
|
||||||
val goodsName: String? = null,
|
val goodsName: String? = null,
|
||||||
val popularName: String? = null,
|
val popularName: String? = null,
|
||||||
val zjmCode: String? = null,
|
val zjmCode: String? = null,
|
||||||
val materId: String? = null,
|
var materId: String? = null,
|
||||||
val materCode: String? = null,
|
val materCode: String? = null,
|
||||||
|
|
||||||
// 从 CookFoodGoodsEntity 迁移的数据字段(DishPartAdapter 显示及转换用)
|
// 从 CookFoodGoodsEntity 迁移的数据字段(DishPartAdapter 显示及转换用)
|
||||||
@@ -30,12 +32,15 @@ data class GoodsItem(
|
|||||||
var isClicked: Boolean = false,
|
var isClicked: Boolean = false,
|
||||||
// true-原始数据,false-非原始数据(识图新增)
|
// true-原始数据,false-非原始数据(识图新增)
|
||||||
var isOriginalData: Boolean = true,
|
var isOriginalData: Boolean = true,
|
||||||
|
// true-用户手动指定了主辅材,updateMaterialTypes 自动分配时跳过
|
||||||
|
var isMaterialTypeManual: Boolean = false,
|
||||||
// 识图匹配分数,-1 表示不显示
|
// 识图匹配分数,-1 表示不显示
|
||||||
var foodScore: Int = -1,
|
var foodScore: Int = -1,
|
||||||
// 净材种类(当前选中值)
|
// 净材种类(当前选中值)
|
||||||
var rawMaterialsType: String? = null,
|
var rawMaterialsType: String? = null,
|
||||||
// 净材种类候选列表(临时字段,逗号分隔,不持久化)
|
// 净材种类候选列表(临时字段,逗号分隔,不持久化)
|
||||||
var rawMaterialsTypes: String? = null
|
var rawMaterialsTypes: String? = null,
|
||||||
|
var oldGoodsId: String? = null
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.shuwei.dish.match.entity
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 物品名称批量查询入参 DTO
|
* 物品名称批量查询入参 DTO
|
||||||
@@ -0,0 +1,259 @@
|
|||||||
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采样与制作模式相关模型,对应配比秤接口(Controller: NutRatioScaleController)
|
||||||
|
* 路径前缀: /neglect/ratio-scale
|
||||||
|
* 序列化规则: Long 字段服务端返回字符串;请求体字段按后端约定(id 类字段用 String 与现有代码一致)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** 采样实验状态(味养创新 nut_innovation.status) */
|
||||||
|
object SampleStatus {
|
||||||
|
/** 实验中 */
|
||||||
|
const val EXPERIMENTING = 1
|
||||||
|
/** 已评测 */
|
||||||
|
const val EVALUATED = 2
|
||||||
|
/** 已转化 */
|
||||||
|
const val CONVERTED = 9
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 一、食材模糊搜索 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 食材模糊搜索请求参数
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/mater-search
|
||||||
|
* 数据源: nut_mater_base,限定设备对应食堂
|
||||||
|
*/
|
||||||
|
data class MaterSearchRequest(
|
||||||
|
/** 模糊匹配食材名称和别名,为空时返回全部 */
|
||||||
|
val keyword: String? = null,
|
||||||
|
/** 页码 */
|
||||||
|
val pageNum: Int = 1,
|
||||||
|
/** 每页条数 */
|
||||||
|
val pageSize: Int = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 食材模糊搜索结果条目
|
||||||
|
* 注意: id / canteenId 为 Long 类型,服务端序列化为 String
|
||||||
|
*/
|
||||||
|
data class MaterSearchItem(
|
||||||
|
/** 食材id(Long → String,提交构成 items.materId 使用) */
|
||||||
|
val id: String = "",
|
||||||
|
/** 食材名称 */
|
||||||
|
val materName: String = "",
|
||||||
|
/** 食材编码(一级+二级+自编码,全局唯一) */
|
||||||
|
val materCode: String = "",
|
||||||
|
/** 别名,可能为 null */
|
||||||
|
val alias: String? = null,
|
||||||
|
/** 食材一级分类 */
|
||||||
|
val materFirstClass: String? = null,
|
||||||
|
/** 食材二级分类 */
|
||||||
|
val materSecondClass: String? = null,
|
||||||
|
/** 食材图片url */
|
||||||
|
val materUrl: String? = null,
|
||||||
|
/** 归属食堂id(Long → String) */
|
||||||
|
val canteenId: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 二、搜菜品 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜菜品请求参数(制作模式选已有菜品)
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/food-search
|
||||||
|
* 数据源: nut_food(status=1 上架)
|
||||||
|
*/
|
||||||
|
data class FoodSearchRequest(
|
||||||
|
/** 菜品名称或编号模糊搜索 */
|
||||||
|
val keyword: String? = null,
|
||||||
|
/** 页码 */
|
||||||
|
val pageNum: Int = 1,
|
||||||
|
/** 每页条数 */
|
||||||
|
val pageSize: Int = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜菜品结果条目
|
||||||
|
* 注意: foodId 为 Long 类型,服务端序列化为 String
|
||||||
|
*/
|
||||||
|
data class FoodSearchItem(
|
||||||
|
/** 菜品id(Long → String) */
|
||||||
|
val foodId: String = "",
|
||||||
|
/** 菜品编号 */
|
||||||
|
val foodCode: String = "",
|
||||||
|
/** 菜品名称 */
|
||||||
|
val foodName: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 三、查菜品构成 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查菜品构成响应 — 单个食材
|
||||||
|
* 对应接口: GET /neglect/ratio-scale/food/{foodId}/composition
|
||||||
|
*/
|
||||||
|
data class FoodCompositionIngredient(
|
||||||
|
/** 食材id(Long → String) */
|
||||||
|
val materId: String = "",
|
||||||
|
/** 食材名称 */
|
||||||
|
val materName: String = "",
|
||||||
|
/** 用量(g) */
|
||||||
|
val useWeight: Double = 0.0,
|
||||||
|
/** 1=主材 / 2=辅材 / 3=调料 */
|
||||||
|
val isMain: Int = 0,
|
||||||
|
/** 分类中文名 */
|
||||||
|
val isMainName: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查菜品构成响应(主辅料+调料 + 熟重)
|
||||||
|
* 对应接口: GET /neglect/ratio-scale/food/{foodId}/composition
|
||||||
|
*/
|
||||||
|
data class FoodCompositionResponse(
|
||||||
|
/** 菜品id(Long → String) */
|
||||||
|
val foodId: String = "",
|
||||||
|
/** 菜品名称 */
|
||||||
|
val foodName: String = "",
|
||||||
|
/** 熟重(g),从 nut_food_cook.output_weight 反查 */
|
||||||
|
val foodWeight: Double = 0.0,
|
||||||
|
/** 食材构成列表 */
|
||||||
|
val ingredients: List<FoodCompositionIngredient> = emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 四、提交采样 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交采样 — 单个食材构成条目
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/constitute/save
|
||||||
|
*/
|
||||||
|
data class ConstituteSaveItem(
|
||||||
|
/** 食材id(nut_mater_base.id) */
|
||||||
|
val materId: String = "",
|
||||||
|
/** 食材称量用量(g),必须 > 0 */
|
||||||
|
val useWeight: Double = 0.0,
|
||||||
|
/** 食材分类: 1=主材 / 2=辅材 / 3=调料 */
|
||||||
|
val isMain: Int = 0,
|
||||||
|
/** 调料首次使用时间 yyyy-MM-dd HH:mm:ss,仅调料需要,主辅材留空;字段与制作模式 CookCompleteItem 对齐 */
|
||||||
|
val putTime: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交采样请求(落库味养创新实验,status=1 实验中)
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/constitute/save
|
||||||
|
* 制作模式已废弃本接口,统一为提交采样,不再传 cookMode/foodId
|
||||||
|
*/
|
||||||
|
data class ConstituteSaveRequest(
|
||||||
|
/** 菜品名称 */
|
||||||
|
val foodName: String? = null,
|
||||||
|
/** 烹饪开始时间 yyyy-MM-dd HH:mm:ss,进入提交页面时刻;字段与制作模式 CookCompleteRequest 对齐 */
|
||||||
|
val cookStart: String? = null,
|
||||||
|
/** 熟重(g),必须 > 0 */
|
||||||
|
val foodWeight: Double = 0.0,
|
||||||
|
/** 食材构成列表,至少 1 条 */
|
||||||
|
val items: List<ConstituteSaveItem> = emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 五、已提交采样列表 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已提交采样列表查询请求参数
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/sample-list
|
||||||
|
* 数据源: nut_innovation(source=2 配比秤采样),按提交时间倒序,不分日期
|
||||||
|
*/
|
||||||
|
data class SampleHistoryRequest(
|
||||||
|
/** 页码 */
|
||||||
|
val pageNum: Int = 1,
|
||||||
|
/** 每页条数 */
|
||||||
|
val pageSize: Int = 10
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已提交采样列表结果条目
|
||||||
|
* 注意: innovId 为 Long 类型,服务端序列化为 String
|
||||||
|
*/
|
||||||
|
data class SampleHistoryItem(
|
||||||
|
/** 味养创新实验id(Long → String) */
|
||||||
|
val innovId: String = "",
|
||||||
|
/** 实验编号 */
|
||||||
|
val innovNo: String = "",
|
||||||
|
/** 餐品名称 */
|
||||||
|
val foodName: String = "",
|
||||||
|
/** 熟重(g) */
|
||||||
|
val foodWeight: Double = 0.0,
|
||||||
|
/** 烹饪开始时间,提交时未传则为 null */
|
||||||
|
val cookStart: String? = null,
|
||||||
|
/** 烹饪时长(分钟),后端按 提交时间-烹饪开始时间 向上取整计算;未传 cookStart 则为 null */
|
||||||
|
val cookDuration: Int? = null,
|
||||||
|
/** 状态: 1=实验中 / 2=已评测 / 9=已转化 */
|
||||||
|
val status: Int = 0,
|
||||||
|
/** 状态中文 */
|
||||||
|
val statusName: String = "",
|
||||||
|
/** 提交时间 */
|
||||||
|
val createTime: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 六、制作历史 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史查询请求参数
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/make/history
|
||||||
|
* 数据源: nut_food_matching_use,按设备过滤
|
||||||
|
*/
|
||||||
|
data class MakeHistoryRequest(
|
||||||
|
/** 页码 */
|
||||||
|
val pageNum: Int = 1,
|
||||||
|
/** 每页条数 */
|
||||||
|
val pageSize: Int = 10,
|
||||||
|
/** 制作日期 yyyy-MM-dd,不传查全部 */
|
||||||
|
val day: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史结果条目
|
||||||
|
* 注意: id / foodId 为 Long 类型,服务端序列化为 String
|
||||||
|
*/
|
||||||
|
data class MakeHistoryItem(
|
||||||
|
/** 制作记录id(Long → String) */
|
||||||
|
val id: String = "",
|
||||||
|
/** 菜品id(Long → String) */
|
||||||
|
val foodId: String = "",
|
||||||
|
/** 菜品名称 */
|
||||||
|
val foodName: String = "",
|
||||||
|
/** 熟重(g) */
|
||||||
|
val foodWeight: Double = 0.0,
|
||||||
|
/** 餐次: 1=早餐/2=午餐/3=晚餐/4=加餐 */
|
||||||
|
val mealType: Int = 0,
|
||||||
|
/** 餐次中文 */
|
||||||
|
val mealTypeName: String = "",
|
||||||
|
/** 制作日期 */
|
||||||
|
val day: String = "",
|
||||||
|
/** 制作时间 */
|
||||||
|
val createTime: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 七、制作历史图表 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史图表 — 横轴项
|
||||||
|
* 对应接口: GET /neglect/ratio-scale/make/history/{foodId}
|
||||||
|
*/
|
||||||
|
data class MakeHistoryChartAxis(
|
||||||
|
/** 食材id(时间/熟重项为空字符串) */
|
||||||
|
val goodId: String = "",
|
||||||
|
/** 项名称(时间/熟重/食材名称) */
|
||||||
|
val goodName: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史图表 — 纵轴值
|
||||||
|
* value 为 String(时间项) 或 Double(数值项)
|
||||||
|
*/
|
||||||
|
data class MakeHistoryChartValue(
|
||||||
|
val value: Any? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史图表 — 单条记录(xAxes 与 yAxes 一一对应)
|
||||||
|
*/
|
||||||
|
data class MakeHistoryChartRow(
|
||||||
|
val xAxes: List<MakeHistoryChartAxis> = emptyList(),
|
||||||
|
val yAxes: List<MakeHistoryChartValue> = emptyList()
|
||||||
|
)
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.shuwei.dish.match.model
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置页面的列表项实体类
|
||||||
|
*
|
||||||
|
* @param type 菜单项类型,用于唯一标识每一项
|
||||||
|
* @param title 主标题文字
|
||||||
|
* @param subtitle 副标题文字,仅部分项目(如菜品模式)有值
|
||||||
|
* @param isHidden 是否为隐藏项,隐藏项需触发开发者模式后才显示
|
||||||
|
* @param onClick 点击回调,初始化时直接注入对应的业务逻辑
|
||||||
|
*/
|
||||||
|
data class SettingItem(
|
||||||
|
val type: Type,
|
||||||
|
val title: String,
|
||||||
|
val subtitle: String? = null,
|
||||||
|
val isHidden: Boolean = false,
|
||||||
|
val onClick: () -> Unit
|
||||||
|
) {
|
||||||
|
/** 设置菜单项类型枚举 */
|
||||||
|
enum class Type {
|
||||||
|
/** 菜品模式切换 */
|
||||||
|
COOK_MODE,
|
||||||
|
/** 调料区设置 */
|
||||||
|
SEASONING_CONFIG,
|
||||||
|
/** 食材采集 */
|
||||||
|
FOOD_COLLECT,
|
||||||
|
/** 减重配置 */
|
||||||
|
WEIGHT_CONFIG,
|
||||||
|
/** 数据库查看(隐藏项) */
|
||||||
|
DB_INSPECT,
|
||||||
|
/** 秤数据监控(隐藏项) */
|
||||||
|
SCALE_OBSERVE,
|
||||||
|
/** 切换环境(隐藏项) */
|
||||||
|
ENV_SWITCH,
|
||||||
|
/** 数据清除(隐藏项) */
|
||||||
|
CLEAR_DATA,
|
||||||
|
/** 测试调料拿取(隐藏项) */
|
||||||
|
TEST_SEASONING,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,26 @@
|
|||||||
package com.shuwei.dish.match.net
|
package com.shuwei.dish.match.net
|
||||||
|
|
||||||
import com.shuwei.dish.match.base.GlobalData
|
import com.shuwei.dish.match.base.GlobalData
|
||||||
import com.shuwei.dish.match.entity.CookFoodDTO
|
import com.shuwei.dish.match.model.CookFoodDTO
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||||
|
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||||
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
import com.shuwei.dish.match.model.ConstituteSaveRequest
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||||
|
import com.shuwei.dish.match.model.FoodCompositionResponse
|
||||||
|
import com.shuwei.dish.match.model.FoodSearchItem
|
||||||
|
import com.shuwei.dish.match.model.FoodSearchRequest
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryChartRow
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryItem
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryRequest
|
||||||
|
import com.shuwei.dish.match.model.MaterSearchItem
|
||||||
|
import com.shuwei.dish.match.model.MaterSearchRequest
|
||||||
|
import com.shuwei.dish.match.model.SampleHistoryItem
|
||||||
|
import com.shuwei.dish.match.model.SampleHistoryRequest
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
@@ -12,6 +29,7 @@ import retrofit2.http.Multipart
|
|||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
import retrofit2.http.Part
|
import retrofit2.http.Part
|
||||||
import retrofit2.http.PartMap
|
import retrofit2.http.PartMap
|
||||||
|
import retrofit2.http.Path
|
||||||
import retrofit2.http.Query
|
import retrofit2.http.Query
|
||||||
import retrofit2.http.Url
|
import retrofit2.http.Url
|
||||||
|
|
||||||
@@ -22,7 +40,7 @@ interface ApiService {
|
|||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
suspend fun getFoodDetail(
|
suspend fun getFoodDetail(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/getConstituteByFoodId",
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/getConstituteByFoodId",
|
||||||
@Query("foodId") foodId: String
|
@Query("foodId") foodId: String
|
||||||
): ApiResponse<CookFoodDTO?>
|
): ApiResponse<CookFoodDTO?>
|
||||||
|
|
||||||
@@ -32,16 +50,16 @@ interface ApiService {
|
|||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
suspend fun submitCookFood(
|
suspend fun submitCookFood(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/saveConstitute",
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/saveConstitute",
|
||||||
@Body param: CookFoodDTO
|
@Body param: CookFoodDTO
|
||||||
): ApiResponse<Any?>
|
): ApiResponse<Any?>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索菜品
|
* 搜索菜品(旧接口,采样模式仍在使用)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
suspend fun searchFoodList(
|
suspend fun searchFoodList(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryPageList",
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/queryPageList",
|
||||||
@Body param: MutableMap<String, Any>
|
@Body param: MutableMap<String, Any>
|
||||||
): ApiResponse<MutableList<FoodRecord>?>
|
): ApiResponse<MutableList<FoodRecord>?>
|
||||||
|
|
||||||
@@ -50,7 +68,7 @@ interface ApiService {
|
|||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
suspend fun getSamplingList(
|
suspend fun getSamplingList(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryHistoryGoodsInfoList",
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/queryHistoryGoodsInfoList",
|
||||||
@Body param: MutableMap<String, Any>
|
@Body param: MutableMap<String, Any>
|
||||||
): ApiResponse<MutableList<FoodRecord>?>
|
): ApiResponse<MutableList<FoodRecord>?>
|
||||||
|
|
||||||
@@ -59,7 +77,7 @@ interface ApiService {
|
|||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
suspend fun queryGoodsList(
|
suspend fun queryGoodsList(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryGoodsInfoList",
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/queryGoodsInfoList",
|
||||||
@Body param: MutableMap<String, Any>
|
@Body param: MutableMap<String, Any>
|
||||||
): ApiResponse<MutableList<GoodsItem>?>
|
): ApiResponse<MutableList<GoodsItem>?>
|
||||||
|
|
||||||
@@ -69,8 +87,110 @@ interface ApiService {
|
|||||||
@Multipart
|
@Multipart
|
||||||
@POST
|
@POST
|
||||||
suspend fun uploadFoodVectorData(
|
suspend fun uploadFoodVectorData(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/addWeighingCollectionData",
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/addWeighingCollectionData",
|
||||||
@PartMap params: MutableMap<String, RequestBody>,
|
@PartMap params: MutableMap<String, RequestBody>,
|
||||||
@Part foodPics: List<MultipartBody.Part>
|
@Part foodPics: List<MultipartBody.Part>
|
||||||
): ApiResponse<List<String>?>
|
): ApiResponse<List<String>?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当日烹饪任务列表(按餐次分组),新配比秤接口
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun getCookOrderPage(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/cook-orders/list",
|
||||||
|
@Body request: CookOrderPageRequest
|
||||||
|
): ApiResponse<List<CookOrderMealGroup>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询菜品食材构成(主材+辅材,不含调料),新配比秤接口
|
||||||
|
*/
|
||||||
|
@GET("nutrition/neglect/ratio-scale/cook-orders/{cookOrderId}/composition")
|
||||||
|
suspend fun getCookOrderComposition(
|
||||||
|
@Path("cookOrderId") cookOrderId: String
|
||||||
|
): ApiResponse<List<CookOrderCompositionItem>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料模糊搜索,新配比秤接口
|
||||||
|
* 数据源: nut_mater_base 一级分类为 18(糖蜜饯)、19(油脂)、20(调味品)
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun getSeasoningSearch(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/seasoning-search",
|
||||||
|
@Body request: SeasoningSearchRequest
|
||||||
|
): ApiResponse<List<SeasoningSearchItem>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 烹饪完成:提交主辅材用量+熟重+调料,一次性完成烹制
|
||||||
|
* 新配比秤接口,替代旧 saveConstitute
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun cookOrderComplete(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/cook-orders/complete",
|
||||||
|
@Body request: CookCompleteRequest
|
||||||
|
): ApiResponse<Any?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 食材模糊搜索(采样/制作通用,称量前检索食材)
|
||||||
|
* 数据源: nut_mater_base,限定设备对应食堂,模糊匹配名称和别名
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun materSearch(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/mater-search",
|
||||||
|
@Body request: MaterSearchRequest
|
||||||
|
): ApiResponse<MutableList<MaterSearchItem>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜菜品(制作模式选已有上架菜品)
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun foodSearch(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/food-search",
|
||||||
|
@Body request: FoodSearchRequest
|
||||||
|
): ApiResponse<MutableList<FoodSearchItem>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查菜品构成(制作模式查看已有菜品主辅料+调料 + 熟重)
|
||||||
|
*/
|
||||||
|
@GET("nutrition/neglect/ratio-scale/food/{foodId}/composition")
|
||||||
|
suspend fun getFoodComposition(
|
||||||
|
@Path("foodId") foodId: String
|
||||||
|
): ApiResponse<FoodCompositionResponse?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交采样(落库味养创新实验,制作模式已废弃本接口)
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun constituteSave(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/constitute/save",
|
||||||
|
@Body request: ConstituteSaveRequest
|
||||||
|
): ApiResponse<Any?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已提交采样列表(本食堂 source=2,按提交时间倒序,不分日期)
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun sampleHistory(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/sample-list",
|
||||||
|
@Body request: SampleHistoryRequest
|
||||||
|
): ApiResponse<MutableList<SampleHistoryItem>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史(本设备,按日期可选过滤)
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun makeHistory(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/make/history",
|
||||||
|
@Body request: MakeHistoryRequest
|
||||||
|
): ApiResponse<MutableList<MakeHistoryItem>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史图表(按菜品id)
|
||||||
|
*/
|
||||||
|
@GET("nutrition/neglect/ratio-scale/make/history/{foodId}")
|
||||||
|
suspend fun makeHistoryChart(
|
||||||
|
@Path("foodId") foodId: String
|
||||||
|
): ApiResponse<MutableList<MakeHistoryChartRow>?>
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,33 @@ package com.shuwei.dish.match.net
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
import com.shuwei.dish.match.entity.CookFoodDTO
|
import com.shuwei.dish.match.model.CookFoodDTO
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||||
import com.shuwei.dish.match.entity.GoodsNameQueryDTO
|
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||||
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
import com.shuwei.dish.match.model.GoodsNameQueryDTO
|
||||||
|
import com.shuwei.dish.match.model.ConstituteSaveRequest
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||||
|
import com.shuwei.dish.match.model.FoodCompositionResponse
|
||||||
|
import com.shuwei.dish.match.model.FoodSearchItem
|
||||||
|
import com.shuwei.dish.match.model.FoodSearchRequest
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryChartRow
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryItem
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryRequest
|
||||||
|
import com.shuwei.dish.match.model.MaterSearchItem
|
||||||
|
import com.shuwei.dish.match.model.MaterSearchRequest
|
||||||
|
import com.shuwei.dish.match.model.SampleHistoryItem
|
||||||
|
import com.shuwei.dish.match.model.SampleHistoryRequest
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
@@ -62,23 +82,99 @@ class NetViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索菜品列表的 UI 状态流,UI 层通过 collect 监听
|
* 查询菜品食材构成的 UI 状态流(新配比秤接口),UI 层通过 collect 监听
|
||||||
*/
|
*/
|
||||||
private val _searchFoodState = MutableStateFlow<UiState<MutableList<FoodRecord>?>>(UiState.Idle)
|
private val _cookOrderCompositionState = MutableStateFlow<UiState<List<CookOrderCompositionItem>?>>(UiState.Idle)
|
||||||
val searchFoodState: StateFlow<UiState<MutableList<FoodRecord>?>> = _searchFoodState.asStateFlow()
|
val cookOrderCompositionState: StateFlow<UiState<List<CookOrderCompositionItem>?>> = _cookOrderCompositionState.asStateFlow()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询菜品食材构成(新配比秤接口,仅返回主材+辅材)
|
||||||
|
* @param cookOrderId 烹制单 ID
|
||||||
|
*/
|
||||||
|
fun getCookOrderComposition(cookOrderId: String) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_cookOrderCompositionState.value = UiState.Loading
|
||||||
|
_cookOrderCompositionState.value = repository.getCookOrderComposition(cookOrderId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索菜品列表的 UI 状态流。
|
||||||
|
* 使用 replay=1 保证 Fragment 重建后能收到最近一次结果;
|
||||||
|
* emit 时包一层 Event wrapper 打破 equals 去重,确保相同数据也能触发 collect。
|
||||||
|
*/
|
||||||
|
private val _searchFoodState = MutableSharedFlow<UiState<MutableList<FoodRecord>?>>(
|
||||||
|
replay = 1,
|
||||||
|
extraBufferCapacity = 1
|
||||||
|
)
|
||||||
|
val searchFoodState: SharedFlow<UiState<MutableList<FoodRecord>?>> = _searchFoodState.asSharedFlow()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索菜品列表
|
* 搜索菜品列表
|
||||||
*/
|
*/
|
||||||
fun searchFoodList(param: MutableMap<String, Any>) {
|
fun searchFoodList(param: MutableMap<String, Any>) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_searchFoodState.value = UiState.Loading
|
// pageNum=1 时先 emit Idle 重置 replay 缓存,防止相同数据导致 SharedFlow 去重不触发
|
||||||
_searchFoodState.value = repository.searchFoodList(param)
|
if (param["pageNum"] == 1) {
|
||||||
|
_searchFoodState.emit(UiState.Idle)
|
||||||
|
}
|
||||||
|
_searchFoodState.emit(UiState.Loading)
|
||||||
|
_searchFoodState.emit(repository.searchFoodList(param))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索菜品列表(回调版本),结果通过 onResult 直接回调,不经过 StateFlow/SharedFlow
|
||||||
|
* 适合需要每次都能触发的场景(下拉刷新、上拉加载更多)
|
||||||
|
*/
|
||||||
|
fun searchFoodListWithCallback(
|
||||||
|
param: MutableMap<String, Any>,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<MutableList<FoodRecord>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.searchFoodList(param))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当日烹饪任务列表的 UI 状态流(新配比秤接口),UI 层通过 collect 监听
|
||||||
|
* 使用 SharedFlow(replay=1) 保证 Fragment 重建后收到最近一次结果
|
||||||
|
*/
|
||||||
|
private val _cookOrderPageState = MutableSharedFlow<UiState<List<CookOrderMealGroup>?>>(
|
||||||
|
replay = 1,
|
||||||
|
extraBufferCapacity = 1
|
||||||
|
)
|
||||||
|
val cookOrderPageState: SharedFlow<UiState<List<CookOrderMealGroup>?>> = _cookOrderPageState.asSharedFlow()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当日烹饪任务列表(新配比秤接口,StateFlow 版本)
|
||||||
|
* 适合 FoodSearchActivity 等通过 collect 监听结果的场景
|
||||||
|
*/
|
||||||
|
fun getCookOrderPage(request: CookOrderPageRequest) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_cookOrderPageState.emit(UiState.Loading)
|
||||||
|
_cookOrderPageState.emit(repository.getCookOrderPage(request))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当日烹饪任务列表(新配比秤接口,回调版本)
|
||||||
|
* 适合 FoodListFragment 下拉刷新、Tab 切换等需要每次都能触发的场景
|
||||||
|
*/
|
||||||
|
fun getCookOrderPageWithCallback(
|
||||||
|
request: CookOrderPageRequest,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<List<CookOrderMealGroup>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.getCookOrderPage(request))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询采样数据列表的 UI 状态流,UI 层通过 collect 监听
|
|
||||||
*/
|
*/
|
||||||
private val _samplingListState = MutableStateFlow<UiState<MutableList<FoodRecord>?>>(UiState.Idle)
|
private val _samplingListState = MutableStateFlow<UiState<MutableList<FoodRecord>?>>(UiState.Idle)
|
||||||
val samplingListState: StateFlow<UiState<MutableList<FoodRecord>?>> = _samplingListState.asStateFlow()
|
val samplingListState: StateFlow<UiState<MutableList<FoodRecord>?>> = _samplingListState.asStateFlow()
|
||||||
@@ -96,6 +192,21 @@ class NetViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询采样数据列表(回调版本),结果通过 onResult 直接回调,不经过 StateFlow
|
||||||
|
* 适合不需要跨生命周期持续监听的一次性查询场景
|
||||||
|
*/
|
||||||
|
fun getSamplingListWithCallback(
|
||||||
|
param: MutableMap<String, Any>,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<MutableList<FoodRecord>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.getSamplingList(param))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询物品信息列表的 UI 状态流(食材/调料共用),UI 层通过 collect 监听
|
* 查询物品信息列表的 UI 状态流(食材/调料共用),UI 层通过 collect 监听
|
||||||
*/
|
*/
|
||||||
@@ -108,6 +219,10 @@ class NetViewModel(
|
|||||||
private val _foodSearchGoodsListState = MutableStateFlow<UiState<MutableList<GoodsItem>?>>(UiState.Idle)
|
private val _foodSearchGoodsListState = MutableStateFlow<UiState<MutableList<GoodsItem>?>>(UiState.Idle)
|
||||||
val foodSearchGoodsListState: StateFlow<UiState<MutableList<GoodsItem>?>> = _foodSearchGoodsListState.asStateFlow()
|
val foodSearchGoodsListState: StateFlow<UiState<MutableList<GoodsItem>?>> = _foodSearchGoodsListState.asStateFlow()
|
||||||
|
|
||||||
|
fun resetGoodsListState() {
|
||||||
|
_goodsListState.value = UiState.Idle
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询物品信息列表(食材 goodsType=0,调料 goodsType=1 共用)
|
* 查询物品信息列表(食材 goodsType=0,调料 goodsType=1 共用)
|
||||||
* @param goodsType 物品类型:0=食材,1=调料
|
* @param goodsType 物品类型:0=食材,1=调料
|
||||||
@@ -170,6 +285,166 @@ class NetViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料模糊搜索(新配比秤接口,回调版本)
|
||||||
|
* 替代旧 queryGoodsList(goodsType=1) 调用
|
||||||
|
* @param keyword 模糊匹配食材名称和别名,为 null 时不传该字段
|
||||||
|
* @param pageNum 页码,默认第 1 页
|
||||||
|
* @param pageSize 每页条数,默认 50
|
||||||
|
* @param onLoading 请求发起前的回调
|
||||||
|
* @param onResult 结果回调,直接接收 UiState<List<SeasoningSearchItem>?>
|
||||||
|
*/
|
||||||
|
fun querySeasoningSearch(
|
||||||
|
keyword: String? = null,
|
||||||
|
pageNum: Int = 1,
|
||||||
|
pageSize: Int = 50,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<List<SeasoningSearchItem>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.getSeasoningSearch(
|
||||||
|
SeasoningSearchRequest(keyword = keyword, pageNum = pageNum, pageSize = pageSize)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 烹饪完成(新配比秤接口,回调版本),替代旧 submitCookFood
|
||||||
|
* 仅在制作模式下 cookOrderId 可用的场景调用
|
||||||
|
*/
|
||||||
|
fun cookOrderComplete(
|
||||||
|
request: CookCompleteRequest,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<Any?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.cookOrderComplete(request))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 食材模糊搜索(回调版本)
|
||||||
|
* @param keyword 模糊匹配食材名称和别名,为 null 时不传该字段
|
||||||
|
* @param pageNum 页码,默认第 1 页
|
||||||
|
* @param pageSize 每页条数,默认 20
|
||||||
|
*/
|
||||||
|
fun materSearch(
|
||||||
|
keyword: String? = null,
|
||||||
|
pageNum: Int = 1,
|
||||||
|
pageSize: Int = 20,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<MutableList<MaterSearchItem>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.materSearch(
|
||||||
|
MaterSearchRequest(keyword = keyword, pageNum = pageNum, pageSize = pageSize)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜菜品(回调版本,制作模式选已有上架菜品)
|
||||||
|
*/
|
||||||
|
fun foodSearch(
|
||||||
|
keyword: String? = null,
|
||||||
|
pageNum: Int = 1,
|
||||||
|
pageSize: Int = 20,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<MutableList<FoodSearchItem>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.foodSearch(
|
||||||
|
FoodSearchRequest(keyword = keyword, pageNum = pageNum, pageSize = pageSize)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查菜品构成(回调版本,制作模式)
|
||||||
|
*/
|
||||||
|
fun getFoodComposition(
|
||||||
|
foodId: String,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<FoodCompositionResponse?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.getFoodComposition(foodId))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交采样(回调版本,落库味养创新实验,制作模式已废弃本接口)
|
||||||
|
*/
|
||||||
|
fun constituteSave(
|
||||||
|
request: ConstituteSaveRequest,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<Any?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.constituteSave(request))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已提交采样列表(回调版本,本食堂 source=2,不分日期)
|
||||||
|
* @param pageNum 页码,默认第 1 页
|
||||||
|
* @param pageSize 每页条数,默认 10
|
||||||
|
*/
|
||||||
|
fun sampleHistory(
|
||||||
|
pageNum: Int = 1,
|
||||||
|
pageSize: Int = 10,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<MutableList<SampleHistoryItem>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.sampleHistory(
|
||||||
|
SampleHistoryRequest(
|
||||||
|
pageNum = pageNum,
|
||||||
|
pageSize = pageSize
|
||||||
|
)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史(回调版本,本设备按日期可选过滤)
|
||||||
|
*/
|
||||||
|
fun makeHistory(
|
||||||
|
pageNum: Int = 1,
|
||||||
|
pageSize: Int = 10,
|
||||||
|
day: String? = null,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<MutableList<MakeHistoryItem>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.makeHistory(
|
||||||
|
MakeHistoryRequest(pageNum = pageNum, pageSize = pageSize, day = day)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作历史图表(回调版本,按菜品id)
|
||||||
|
*/
|
||||||
|
fun makeHistoryChart(
|
||||||
|
foodId: String,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<MutableList<MakeHistoryChartRow>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.makeHistoryChart(foodId))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传采集菜品信息 UI 状态流,UI 层通过 collect 监听
|
* 上传采集菜品信息 UI 状态流,UI 层通过 collect 监听
|
||||||
*/
|
*/
|
||||||
@@ -184,7 +459,7 @@ class NetViewModel(
|
|||||||
params: MutableMap<String, RequestBody>
|
params: MutableMap<String, RequestBody>
|
||||||
) {
|
) {
|
||||||
val fileParts = fileList.map { file ->
|
val fileParts = fileList.map { file ->
|
||||||
file.asRequestBody("image/jpeg".toMediaTypeOrNull())
|
file.asRequestBody("multipart/form-data".toMediaTypeOrNull())
|
||||||
.let { MultipartBody.Part.createFormData("foodPics", file.name, it) }
|
.let { MultipartBody.Part.createFormData("foodPics", file.name, it) }
|
||||||
}
|
}
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|||||||
@@ -1,11 +1,27 @@
|
|||||||
package com.shuwei.dish.match.net
|
package com.shuwei.dish.match.net
|
||||||
|
|
||||||
import com.shuwei.dish.match.entity.CookFoodDTO
|
import com.shuwei.dish.match.model.CookFoodDTO
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||||
|
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||||
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
import com.shuwei.dish.match.model.ConstituteSaveRequest
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||||
|
import com.shuwei.dish.match.model.FoodCompositionResponse
|
||||||
|
import com.shuwei.dish.match.model.FoodSearchItem
|
||||||
|
import com.shuwei.dish.match.model.FoodSearchRequest
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryChartRow
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryItem
|
||||||
|
import com.shuwei.dish.match.model.MakeHistoryRequest
|
||||||
|
import com.shuwei.dish.match.model.MaterSearchItem
|
||||||
|
import com.shuwei.dish.match.model.MaterSearchRequest
|
||||||
|
import com.shuwei.dish.match.model.SampleHistoryItem
|
||||||
|
import com.shuwei.dish.match.model.SampleHistoryRequest
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网络数据仓库,封装所有 ApiService 调用
|
* 网络数据仓库,封装所有 ApiService 调用
|
||||||
@@ -13,104 +29,86 @@ import java.io.File
|
|||||||
*/
|
*/
|
||||||
class RemoteRepository {
|
class RemoteRepository {
|
||||||
|
|
||||||
/**
|
/** 统一封装 API 调用:处理响应映射和异常转换,返回 UiState */
|
||||||
* 提交制作菜品
|
private suspend fun <T> safeApiCall(call: suspend () -> ApiResponse<T>): UiState<T?> {
|
||||||
* @param entity 菜品实体
|
|
||||||
* @return UiState 包装的结果,Success 表示提交成功,Error 携带错误信息
|
|
||||||
*/
|
|
||||||
suspend fun submitCookFood(entity: CookFoodDTO): UiState<Any?> {
|
|
||||||
return try {
|
return try {
|
||||||
val resp = apiService.submitCookFood(param = entity)
|
val resp = call()
|
||||||
if (resp.isSuccess()) UiState.Success(resp.data)
|
if (resp.isSuccess()) UiState.Success(resp.data)
|
||||||
else UiState.Error(resp.code, resp.msg ?: "")
|
else UiState.Error(resp.code, resp.msg ?: "")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
val ex = getApiException(e)
|
UiState.Error("-1", getApiException(e).errorMsg)
|
||||||
UiState.Error("-1", ex.errorMsg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** 提交制作菜品 */
|
||||||
* 查询菜品详情
|
suspend fun submitCookFood(entity: CookFoodDTO): UiState<Any?> =
|
||||||
* @param foodId 菜品 ID
|
safeApiCall { apiService.submitCookFood(param = entity) }
|
||||||
* @return UiState 包装的结果,Success 携带详情数据,Error 携带错误信息
|
|
||||||
*/
|
|
||||||
suspend fun getFoodDetail(foodId: String): UiState<CookFoodDTO?> {
|
|
||||||
return try {
|
|
||||||
val resp = apiService.getFoodDetail(foodId = foodId)
|
|
||||||
if (resp.isSuccess()) UiState.Success(resp.data)
|
|
||||||
else UiState.Error(resp.code, resp.msg ?: "")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
val ex = getApiException(e)
|
|
||||||
UiState.Error("-1", ex.errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/** 查询菜品详情 */
|
||||||
* 搜索菜品列表
|
suspend fun getFoodDetail(foodId: String): UiState<CookFoodDTO?> =
|
||||||
* @param param 查询参数
|
safeApiCall { apiService.getFoodDetail(foodId = foodId) }
|
||||||
* @return UiState 包装的结果,Success 携带列表数据,Error 携带错误信息
|
|
||||||
*/
|
|
||||||
suspend fun searchFoodList(param: MutableMap<String, Any>): UiState<MutableList<FoodRecord>?> {
|
|
||||||
return try {
|
|
||||||
val resp = apiService.searchFoodList(param = param)
|
|
||||||
if (resp.isSuccess()) UiState.Success(resp.data)
|
|
||||||
else UiState.Error(resp.code, resp.msg ?: "")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
val ex = getApiException(e)
|
|
||||||
UiState.Error("-1", ex.errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/** 查询当日烹饪任务列表(按餐次分组),新配比秤接口 */
|
||||||
* 查询采样数据列表
|
suspend fun getCookOrderPage(request: CookOrderPageRequest): UiState<List<CookOrderMealGroup>?> =
|
||||||
* @param param 查询参数
|
safeApiCall { apiService.getCookOrderPage(request = request) }
|
||||||
* @return UiState 包装的结果,Success 携带列表数据,Error 携带错误信息
|
|
||||||
*/
|
|
||||||
suspend fun getSamplingList(param: MutableMap<String, Any>): UiState<MutableList<FoodRecord>?> {
|
|
||||||
return try {
|
|
||||||
val resp = apiService.getSamplingList(param = param)
|
|
||||||
if (resp.isSuccess()) UiState.Success(resp.data)
|
|
||||||
else UiState.Error(resp.code, resp.msg ?: "")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
val ex = getApiException(e)
|
|
||||||
UiState.Error("-1", ex.errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/** 查询菜品食材构成(主材+辅材),新配比秤接口 */
|
||||||
* 查询物品信息列表(食材 goodsType=0,调料 goodsType=1 共用)
|
suspend fun getCookOrderComposition(cookOrderId: String): UiState<List<CookOrderCompositionItem>?> =
|
||||||
* @param param 查询参数
|
safeApiCall { apiService.getCookOrderComposition(cookOrderId = cookOrderId) }
|
||||||
* @return UiState 包装的结果,Success 携带列表数据,Error 携带错误信息
|
|
||||||
*/
|
|
||||||
suspend fun queryGoodsList(param: MutableMap<String, Any>): UiState<MutableList<GoodsItem>?> {
|
|
||||||
return try {
|
|
||||||
val resp = apiService.queryGoodsList(param = param)
|
|
||||||
if (resp.isSuccess()) UiState.Success(resp.data)
|
|
||||||
else UiState.Error(resp.code, resp.msg ?: "")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
val ex = getApiException(e)
|
|
||||||
UiState.Error("-1", ex.errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/** 搜索菜品列表 */
|
||||||
* 上次采集数据
|
suspend fun searchFoodList(param: MutableMap<String, Any>): UiState<MutableList<FoodRecord>?> =
|
||||||
* @param params 参数
|
safeApiCall { apiService.searchFoodList(param = param) }
|
||||||
* @param foodPics 图片
|
|
||||||
* @return UiState 包装的结果,Success 携带列表数据,Error 携带错误信息
|
/** 查询采样数据列表 */
|
||||||
*/
|
suspend fun getSamplingList(param: MutableMap<String, Any>): UiState<MutableList<FoodRecord>?> =
|
||||||
|
safeApiCall { apiService.getSamplingList(param = param) }
|
||||||
|
|
||||||
|
/** 查询物品信息列表(食材 goodsType=0,调料 goodsType=1 共用) */
|
||||||
|
suspend fun queryGoodsList(param: MutableMap<String, Any>): UiState<MutableList<GoodsItem>?> =
|
||||||
|
safeApiCall { apiService.queryGoodsList(param = param) }
|
||||||
|
|
||||||
|
/** 调料模糊搜索,新配比秤接口 */
|
||||||
|
suspend fun getSeasoningSearch(request: SeasoningSearchRequest): UiState<List<SeasoningSearchItem>?> =
|
||||||
|
safeApiCall { apiService.getSeasoningSearch(request = request) }
|
||||||
|
|
||||||
|
/** 烹饪完成,新配比秤接口,替代旧 submitCookFood */
|
||||||
|
suspend fun cookOrderComplete(request: CookCompleteRequest): UiState<Any?> =
|
||||||
|
safeApiCall { apiService.cookOrderComplete(request = request) }
|
||||||
|
|
||||||
|
/** 食材模糊搜索 */
|
||||||
|
suspend fun materSearch(request: MaterSearchRequest): UiState<MutableList<MaterSearchItem>?> =
|
||||||
|
safeApiCall { apiService.materSearch(request = request) }
|
||||||
|
|
||||||
|
/** 搜菜品(制作模式选已有上架菜品) */
|
||||||
|
suspend fun foodSearch(request: FoodSearchRequest): UiState<MutableList<FoodSearchItem>?> =
|
||||||
|
safeApiCall { apiService.foodSearch(request = request) }
|
||||||
|
|
||||||
|
/** 查菜品构成(制作模式) */
|
||||||
|
suspend fun getFoodComposition(foodId: String): UiState<FoodCompositionResponse?> =
|
||||||
|
safeApiCall { apiService.getFoodComposition(foodId = foodId) }
|
||||||
|
|
||||||
|
/** 提交采样(落库味养创新实验,制作模式已废弃本接口) */
|
||||||
|
suspend fun constituteSave(request: ConstituteSaveRequest): UiState<Any?> =
|
||||||
|
safeApiCall { apiService.constituteSave(request = request) }
|
||||||
|
|
||||||
|
/** 已提交采样列表(本食堂 source=2,按提交时间倒序,不分日期) */
|
||||||
|
suspend fun sampleHistory(request: SampleHistoryRequest): UiState<MutableList<SampleHistoryItem>?> =
|
||||||
|
safeApiCall { apiService.sampleHistory(request = request) }
|
||||||
|
|
||||||
|
/** 制作历史(本设备,按日期可选过滤) */
|
||||||
|
suspend fun makeHistory(request: MakeHistoryRequest): UiState<MutableList<MakeHistoryItem>?> =
|
||||||
|
safeApiCall { apiService.makeHistory(request = request) }
|
||||||
|
|
||||||
|
/** 制作历史图表(按菜品id) */
|
||||||
|
suspend fun makeHistoryChart(foodId: String): UiState<MutableList<MakeHistoryChartRow>?> =
|
||||||
|
safeApiCall { apiService.makeHistoryChart(foodId = foodId) }
|
||||||
|
|
||||||
|
/** 上传采集数据 */
|
||||||
suspend fun uploadFoodVectorData(
|
suspend fun uploadFoodVectorData(
|
||||||
params: MutableMap<String, RequestBody>,
|
params: MutableMap<String, RequestBody>,
|
||||||
foodPics: List<MultipartBody.Part>
|
foodPics: List<MultipartBody.Part>
|
||||||
): UiState<List<String>?> {
|
): UiState<List<String>?> =
|
||||||
return try {
|
safeApiCall { apiService.uploadFoodVectorData(params = params, foodPics = foodPics) }
|
||||||
val resp = apiService.uploadFoodVectorData(params = params, foodPics = foodPics)
|
|
||||||
if (resp.isSuccess()) UiState.Success(resp.data)
|
|
||||||
else UiState.Error(resp.code, resp.msg ?: "")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
val ex = getApiException(e)
|
|
||||||
UiState.Error("-1", ex.errorMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class RequestInterceptor : Interceptor {
|
|||||||
val requestBuilder = originalRequest.newBuilder()
|
val requestBuilder = originalRequest.newBuilder()
|
||||||
.header("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjYW50ZWVuSWQiOiJiZTE1NDgzMS0zNDY2LTNiYTItYTJlYS01NzY1MmM5MTlmZWQiLCJ0eXBlIjoiNCIsInVzZXJJZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDEifQ.sN40cOC-O5WQFrF4IDUs8fFlkNdUKLbJt_rHyTsgYYM")
|
.header("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjYW50ZWVuSWQiOiJiZTE1NDgzMS0zNDY2LTNiYTItYTJlYS01NzY1MmM5MTlmZWQiLCJ0eXBlIjoiNCIsInVzZXJJZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDEifQ.sN40cOC-O5WQFrF4IDUs8fFlkNdUKLbJt_rHyTsgYYM")
|
||||||
.header("X-DEVICE-CODE", GlobalData.deviceId)
|
.header("X-DEVICE-CODE", GlobalData.deviceId)
|
||||||
|
.header("X-DEVICE-TOKEN", GlobalData.deviceId)
|
||||||
.header("authorization", "57ee87183f2a4fa59683ec9ef41c8f5d")
|
.header("authorization", "57ee87183f2a4fa59683ec9ef41c8f5d")
|
||||||
|
|
||||||
val newRequest = requestBuilder.build()
|
val newRequest = requestBuilder.build()
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package com.shuwei.dish.match.net
|
|||||||
data class ApiResponse<T>(
|
data class ApiResponse<T>(
|
||||||
val code: String,
|
val code: String,
|
||||||
val msg: String? = "",
|
val msg: String? = "",
|
||||||
val data: T? = null
|
val data: T? = null,
|
||||||
|
/** 分页总条数,仅新配比秤接口返回(如 seasoning-search),旧接口为 null */
|
||||||
|
val total: Int? = null
|
||||||
) {
|
) {
|
||||||
fun isSuccess() = code == "00000"
|
/** 兼容旧接口成功码 "00000" 和新配比秤接口成功码 "200" */
|
||||||
|
fun isSuccess() = code == "00000" || code == "200"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,6 +213,11 @@ object ObjectBox {
|
|||||||
getBox<Food>()?.query(Food_.name.equal(name))?.build()?.remove()
|
getBox<Food>()?.query(Food_.name.equal(name))?.build()?.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清除所有向量采集数据
|
||||||
|
suspend fun removeAll() = safeDbOp {
|
||||||
|
getBox<Food>()?.removeAll()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按名称分组统计采集数量
|
* 按名称分组统计采集数量
|
||||||
* 使用属性查询只加载 name 字段,不加载 foodVector,节省大量内存
|
* 使用属性查询只加载 name 字段,不加载 foodVector,节省大量内存
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class MdnsDiscoveryManager(private val context: Context) {
|
|||||||
|
|
||||||
/** 待解析队列,串行处理避免并发解析失败 */
|
/** 待解析队列,串行处理避免并发解析失败 */
|
||||||
private val resolveQueue = LinkedList<NsdServiceInfo>()
|
private val resolveQueue = LinkedList<NsdServiceInfo>()
|
||||||
@Volatile
|
|
||||||
private var isResolving = false
|
private var isResolving = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ package com.shuwei.dish.match.scale
|
|||||||
*/
|
*/
|
||||||
object ScaleDeviceConfig {
|
object ScaleDeviceConfig {
|
||||||
|
|
||||||
const val DEVICE_ID_2 = "8fc2ab34-2137-3112-acca-f884ea8736d4"
|
const val DEVICE_ID_2 = "0bd74d78-c221-3182-b5ee-55d86dd79283"//测试0bd74d78-c221-3182-b5ee-55d86dd79283 正式8fc2ab34-2137-3112-acca-f884ea8736d4
|
||||||
const val DEVICE_ID_22 = "a46fa55c-113c-3511-bb1f-41e5eff77c4b"
|
const val DEVICE_ID_22 = "a46fa55c-113c-3511-bb1f-41e5eff77c4b"
|
||||||
const val DEVICE_ID_18 = "1038da9f-c6eb-326e-a1d9-d6d3af978b22"
|
const val DEVICE_ID_18 = "1038da9f-c6eb-326e-a1d9-d6d3af978b22"
|
||||||
const val DEVICE_ID_1 = "7cc0f6ea-f13d-3013-a867-fc998eb554ac"
|
const val DEVICE_ID_1 = "7cc0f6ea-f13d-3013-a867-fc998eb554ac"
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import com.shuwei.dish.match.utils.NetworkUtil
|
|||||||
import com.shuwei.dish.match.utils.WeightUtil
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@@ -34,6 +36,9 @@ object ScaleServiceManager {
|
|||||||
|
|
||||||
private const val TAG = "ScaleServiceManager"
|
private const val TAG = "ScaleServiceManager"
|
||||||
|
|
||||||
|
@Volatile private var isStarted = false
|
||||||
|
private var serviceScope: CoroutineScope? = null
|
||||||
|
|
||||||
private var mdnsRegister: MdnsRegisterManager? = null
|
private var mdnsRegister: MdnsRegisterManager? = null
|
||||||
private var wsServer: ScaleWebSocketServer? = null
|
private var wsServer: ScaleWebSocketServer? = null
|
||||||
private var udpSender: UdpBroadcastSender? = null
|
private var udpSender: UdpBroadcastSender? = null
|
||||||
@@ -135,6 +140,9 @@ object ScaleServiceManager {
|
|||||||
* 启动所有秤服务,在 Application.onCreate() 中调用
|
* 启动所有秤服务,在 Application.onCreate() 中调用
|
||||||
*/
|
*/
|
||||||
fun start(context: Context) {
|
fun start(context: Context) {
|
||||||
|
if (isStarted) return
|
||||||
|
isStarted = true
|
||||||
|
serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||||
val deviceId = GlobalData.deviceId
|
val deviceId = GlobalData.deviceId
|
||||||
val role = GlobalData.deviceRole
|
val role = GlobalData.deviceRole
|
||||||
Log.d(TAG, "启动秤服务, deviceId=$deviceId, role=$role")
|
Log.d(TAG, "启动秤服务, deviceId=$deviceId, role=$role")
|
||||||
@@ -180,14 +188,14 @@ object ScaleServiceManager {
|
|||||||
}
|
}
|
||||||
it.onDeviceConnected = { remoteId ->
|
it.onDeviceConnected = { remoteId ->
|
||||||
// 子设备连接成功时,从 Room 读取全量配置并单独推送给该设备
|
// 子设备连接成功时,从 Room 读取全量配置并单独推送给该设备
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
serviceScope?.launch {
|
||||||
val slots = BaseApp.instance!!.database.seasoningSlotDao()
|
val slots = BaseApp.instance?.database?.seasoningSlotDao()
|
||||||
.queryAll()
|
?.queryAll()
|
||||||
.map { slot ->
|
?.map { slot ->
|
||||||
ScaleEvent.SlotConfig(
|
ScaleEvent.SlotConfig(
|
||||||
slot.deviceId, slot.address, slot.goodsId, slot.goodsName
|
slot.deviceId, slot.address, slot.goodsId, slot.goodsName
|
||||||
)
|
)
|
||||||
}
|
} ?: return@launch
|
||||||
if (slots.isNotEmpty()) sendSeasoningConfigTo(remoteId, slots)
|
if (slots.isNotEmpty()) sendSeasoningConfigTo(remoteId, slots)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,6 +254,9 @@ object ScaleServiceManager {
|
|||||||
* 停止所有秤服务,在 Application.onTerminate() 或退出时调用
|
* 停止所有秤服务,在 Application.onTerminate() 或退出时调用
|
||||||
*/
|
*/
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
serviceScope?.cancel()
|
||||||
|
serviceScope = null
|
||||||
|
isStarted = false
|
||||||
mdnsDiscovery?.stopDiscovery()
|
mdnsDiscovery?.stopDiscovery()
|
||||||
udpReceiver?.stop()
|
udpReceiver?.stop()
|
||||||
udpSender?.stop()
|
udpSender?.stop()
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ class ScaleWebSocketClient {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
connections[deviceId] = ws
|
// 写入新连接前先关闭旧连接,避免 IP 变化时旧 ws 对象悬空造成 TCP 资源泄漏
|
||||||
|
connections.put(deviceId, ws)?.close(1000, "新连接替换")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import org.java_websocket.WebSocket
|
|||||||
import org.java_websocket.handshake.ClientHandshake
|
import org.java_websocket.handshake.ClientHandshake
|
||||||
import org.java_websocket.server.WebSocketServer
|
import org.java_websocket.server.WebSocketServer
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.ScheduledFuture
|
import java.util.concurrent.ScheduledFuture
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 秤数据 WebSocket 服务端(主设备和子设备均运行)
|
* 秤数据 WebSocket 服务端(主设备和子设备均运行)
|
||||||
@@ -46,13 +48,13 @@ class ScaleWebSocketServer(private val deviceId: String, private val context: Co
|
|||||||
get() = server?.connections?.isNotEmpty() == true
|
get() = server?.connections?.isNotEmpty() == true
|
||||||
|
|
||||||
/** 每个秤地址的最近一次推送时间,用于节流 */
|
/** 每个秤地址的最近一次推送时间,用于节流 */
|
||||||
private val lastPushTime = mutableMapOf<Int, Long>()
|
private val lastPushTime = ConcurrentHashMap<Int, Long>()
|
||||||
|
|
||||||
/** 缓存各秤最新数据,新客户端连接时立即同步当前状态 */
|
/** 缓存各秤最新数据,新客户端连接时立即同步当前状态 */
|
||||||
private val latestData = mutableMapOf<Int, ScaleData>()
|
private val latestData = ConcurrentHashMap<Int, ScaleData>()
|
||||||
|
|
||||||
/** 节流窗口内的延迟推送任务,key=address;保证窗口结束时最新数据被推送 */
|
/** 节流窗口内的延迟推送任务,key=address;保证窗口结束时最新数据被推送 */
|
||||||
private val pendingPushTasks = mutableMapOf<Int, ScheduledFuture<*>>()
|
private val pendingPushTasks = ConcurrentHashMap<Int, ScheduledFuture<*>>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动 WebSocket 服务器,并注册 WeightUtil 回调
|
* 启动 WebSocket 服务器,并注册 WeightUtil 回调
|
||||||
@@ -67,7 +69,7 @@ class ScaleWebSocketServer(private val deviceId: String, private val context: Co
|
|||||||
WeightUtil.addWeightListener(TAG) { address, state, weight ->
|
WeightUtil.addWeightListener(TAG) { address, state, weight ->
|
||||||
Log.d(TAG, "WebSocket 设备${deviceId}推送数据, address=$address, state=$state, weight=$weight")
|
Log.d(TAG, "WebSocket 设备${deviceId}推送数据, address=$address, state=$state, weight=$weight")
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
// 方案三:数据未变化时直接跳过,避免无效推送
|
// 数据未变化时直接跳过,避免无效推送
|
||||||
val last = latestData[address]
|
val last = latestData[address]
|
||||||
if (last?.weight == weight && last.state == state) return@addWeightListener
|
if (last?.weight == weight && last.state == state) return@addWeightListener
|
||||||
|
|
||||||
@@ -89,7 +91,7 @@ class ScaleWebSocketServer(private val deviceId: String, private val context: Co
|
|||||||
pendingPushTasks.remove(address)?.cancel(false)
|
pendingPushTasks.remove(address)?.cancel(false)
|
||||||
broadcast(gson.toJson(data))
|
broadcast(gson.toJson(data))
|
||||||
} else if (pendingPushTasks[address] == null) {
|
} else if (pendingPushTasks[address] == null) {
|
||||||
// 方案一:窗口内首次触发时安排一个 trailing 推送,保证窗口末尾推最新值
|
// 窗口内首次触发:安排 trailing 推送,保证窗口末尾推最新值
|
||||||
val delay = THROTTLE_MS - (now - lastPush)
|
val delay = THROTTLE_MS - (now - lastPush)
|
||||||
if (!scheduler.isShutdown) {
|
if (!scheduler.isShutdown) {
|
||||||
pendingPushTasks[address] = scheduler.schedule({
|
pendingPushTasks[address] = scheduler.schedule({
|
||||||
@@ -156,10 +158,10 @@ class ScaleWebSocketServer(private val deviceId: String, private val context: Co
|
|||||||
WebSocketServer(InetSocketAddress(port)) {
|
WebSocketServer(InetSocketAddress(port)) {
|
||||||
|
|
||||||
/** 当前活跃连接计数,用于替代 connections.isNullOrEmpty() 避免竞态 */
|
/** 当前活跃连接计数,用于替代 connections.isNullOrEmpty() 避免竞态 */
|
||||||
private var connectionCount = 0
|
private val connectionCount = AtomicInteger(0)
|
||||||
|
|
||||||
override fun onOpen(conn: WebSocket, handshake: ClientHandshake) {
|
override fun onOpen(conn: WebSocket, handshake: ClientHandshake) {
|
||||||
connectionCount++
|
connectionCount.incrementAndGet()
|
||||||
Log.d(TAG, "主设备已连接: ${conn.remoteSocketAddress}")
|
Log.d(TAG, "主设备已连接: ${conn.remoteSocketAddress}")
|
||||||
onConnectionChanged?.invoke(true)
|
onConnectionChanged?.invoke(true)
|
||||||
|
|
||||||
@@ -194,8 +196,8 @@ class ScaleWebSocketServer(private val deviceId: String, private val context: Co
|
|||||||
override fun onClose(conn: WebSocket, code: Int, reason: String, remote: Boolean) {
|
override fun onClose(conn: WebSocket, code: Int, reason: String, remote: Boolean) {
|
||||||
Log.d(TAG, "主设备已断开: ${conn.remoteSocketAddress}, reason=$reason")
|
Log.d(TAG, "主设备已断开: ${conn.remoteSocketAddress}, reason=$reason")
|
||||||
// 用计数器判断是否还有活跃连接,避免依赖 connections 集合的移除时机导致竞态
|
// 用计数器判断是否还有活跃连接,避免依赖 connections 集合的移除时机导致竞态
|
||||||
if (--connectionCount <= 0) {
|
if (connectionCount.decrementAndGet() <= 0) {
|
||||||
connectionCount = 0
|
connectionCount.set(0)
|
||||||
onConnectionChanged?.invoke(false)
|
onConnectionChanged?.invoke(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,16 @@ import com.shuwei.dish.match.base.BaseActivity
|
|||||||
import com.shuwei.dish.match.databinding.ActivityCollectedFoodBinding
|
import com.shuwei.dish.match.databinding.ActivityCollectedFoodBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.entity.CollectedFoodItem
|
import com.shuwei.dish.match.model.CollectedFoodItem
|
||||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||||
import com.shuwei.dish.match.utils.ext.appendText
|
import com.shuwei.dish.match.utils.ext.appendText
|
||||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||||
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.collections.getOrNull
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 已采集食材列表页面
|
* 已采集食材列表页面
|
||||||
@@ -45,7 +47,8 @@ class CollectedFoodActivity : BaseActivity() {
|
|||||||
isStateViewEnable = true
|
isStateViewEnable = true
|
||||||
// 点击删除按钮,移除对应食材
|
// 点击删除按钮,移除对应食材
|
||||||
addOnItemChildClickListener(R.id.ivDelete) { _, _, position ->
|
addOnItemChildClickListener(R.id.ivDelete) { _, _, position ->
|
||||||
showDeleteDialog(foodList[position].foodName)
|
val item = foodList.getOrNull(position) ?: return@addOnItemChildClickListener
|
||||||
|
showDeleteDialog(item.foodName)
|
||||||
}
|
}
|
||||||
setOnItemClickListener { _, _, _ ->
|
setOnItemClickListener { _, _, _ ->
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
@@ -53,6 +56,22 @@ class CollectedFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有采集数据确认弹窗
|
||||||
|
*/
|
||||||
|
private fun showClearAllDialog() {
|
||||||
|
CommonDialog(this)
|
||||||
|
.setTitle("清除提示")
|
||||||
|
.setContent("清除后无法恢复,确认要清除所有采集数据吗?")
|
||||||
|
.setNegativeButton("取消")
|
||||||
|
.setPositiveButton("确认") {
|
||||||
|
dbViewModel.clearAllCollectedFood {
|
||||||
|
toast("已清除所有采集数据")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除弹窗
|
* 删除弹窗
|
||||||
*/
|
*/
|
||||||
@@ -69,7 +88,7 @@ class CollectedFoodActivity : BaseActivity() {
|
|||||||
.setContent(content)
|
.setContent(content)
|
||||||
.setNegativeButton("取消")
|
.setNegativeButton("取消")
|
||||||
.setPositiveButton("确认") {
|
.setPositiveButton("确认") {
|
||||||
appViewModel.removeCollectedFood(
|
dbViewModel.removeCollectedFood(
|
||||||
foodName = foodName,
|
foodName = foodName,
|
||||||
nameFilter = binding.editSearch.text.toString()
|
nameFilter = binding.editSearch.text.toString()
|
||||||
)
|
)
|
||||||
@@ -93,8 +112,13 @@ class CollectedFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}, titleAction = {
|
}, titleAction = {
|
||||||
it.text = "已采集食材"
|
it.text = "已采集食材"
|
||||||
}, rightIconActon = {
|
}, rightIconAction = {
|
||||||
it.gone()
|
it.visible()
|
||||||
|
it.setPaddingRelative(25.dp ,0 ,25.dp ,0)
|
||||||
|
it.setImageResource(R.drawable.ic_trash_white)
|
||||||
|
it.setOnClickListener {
|
||||||
|
showClearAllDialog()
|
||||||
|
}
|
||||||
}, backAction = {
|
}, backAction = {
|
||||||
it.visible()
|
it.visible()
|
||||||
it.setOnClickListener {
|
it.setOnClickListener {
|
||||||
@@ -108,7 +132,7 @@ class CollectedFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun loadCollectedFoodList(name: String = "") {
|
private fun loadCollectedFoodList(name: String = "") {
|
||||||
appViewModel.loadCollectedFoodList(nameFilter = name)
|
dbViewModel.loadCollectedFoodList(nameFilter = name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,7 +142,7 @@ class CollectedFoodActivity : BaseActivity() {
|
|||||||
private fun initObserver() {
|
private fun initObserver() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
appViewModel.collectedFoodListState.collect { items ->
|
dbViewModel.collectedFoodListState.collect { items ->
|
||||||
foodList.clear()
|
foodList.clear()
|
||||||
foodList.addAll(items)
|
foodList.addAll(items)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.shuwei.dish.match.ui
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.addCallback
|
import androidx.activity.addCallback
|
||||||
|
import androidx.core.widget.addTextChangedListener
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
@@ -46,7 +47,7 @@ class CookingModeActivity : BaseActivity() {
|
|||||||
it.visible()
|
it.visible()
|
||||||
}, titleAction = {
|
}, titleAction = {
|
||||||
it.text = "选择菜品"
|
it.text = "选择菜品"
|
||||||
}, rightIconActon = {
|
}, rightIconAction = {
|
||||||
it.visible()
|
it.visible()
|
||||||
it.setImageResource(R.drawable.ic_setting)
|
it.setImageResource(R.drawable.ic_setting)
|
||||||
it.setOnClickListener {
|
it.setOnClickListener {
|
||||||
@@ -62,7 +63,7 @@ class CookingModeActivity : BaseActivity() {
|
|||||||
|
|
||||||
|
|
||||||
fun getCookFoodList() {
|
fun getCookFoodList() {
|
||||||
appViewModel.getCookFoodList(cookMode = 0, dinnerType = dinnerType)
|
dbViewModel.getCookFoodList(cookMode = 0, dinnerType = dinnerType)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var configFinished = false
|
private var configFinished = false
|
||||||
@@ -72,7 +73,7 @@ class CookingModeActivity : BaseActivity() {
|
|||||||
// block()
|
// block()
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
// appViewModel.loadSeasoning {
|
// dbViewModel.loadSeasoning {
|
||||||
// if (it.isEmpty()) {
|
// if (it.isEmpty()) {
|
||||||
// showDeviceConfigDialog()
|
// showDeviceConfigDialog()
|
||||||
// return@loadSeasoning
|
// return@loadSeasoning
|
||||||
@@ -92,22 +93,44 @@ class CookingModeActivity : BaseActivity() {
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addViewListener() {
|
/** 切换餐次时清空输入框,用此标志跳过 afterTextChanged 的查询触发 */
|
||||||
binding.dishRadioGroup.setOnCheckedChangeListener { _, checkedId ->
|
private var isClearingByTabSwitch = false
|
||||||
dinnerType = when (checkedId) {
|
|
||||||
R.id.rbBreakfast -> "1"
|
private fun addViewListener() {
|
||||||
R.id.rbLunch -> "2"
|
binding.tvBreakfast.setOnClickListener { selectTab("1") }
|
||||||
R.id.rbDinner -> "3"
|
binding.tvLunch.setOnClickListener { selectTab("2") }
|
||||||
else -> "1"
|
binding.tvDinner.setOnClickListener { selectTab("3") }
|
||||||
}
|
|
||||||
loadFragment()
|
|
||||||
}
|
|
||||||
binding.etInputDish.addOnActionSearchListener {
|
binding.etInputDish.addOnActionSearchListener {
|
||||||
jumpSearch()
|
jumpSearch()
|
||||||
}
|
}
|
||||||
binding.ivDishSearch.setOnClickListener {
|
binding.ivDishSearch.setOnClickListener {
|
||||||
jumpSearch()
|
jumpSearch()
|
||||||
}
|
}
|
||||||
|
// 输入框清空时自动查询全部数据(切换餐次触发的清空除外,由 loadFragment 负责刷新)
|
||||||
|
binding.etInputDish.addTextChangedListener(afterTextChanged = { text ->
|
||||||
|
if (!isClearingByTabSwitch && text.isNullOrBlank()) {
|
||||||
|
currentFragment()?.getDishList(pageNo = 1, dinnerType = dinnerType)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换餐次 Tab:更新选中态、清空搜索框、切换 Fragment
|
||||||
|
* 由点击事件调用,不触发额外的 getDishList(),由 onHiddenChanged 负责刷新
|
||||||
|
*/
|
||||||
|
private fun selectTab(type: String) {
|
||||||
|
if (dinnerType == type) return
|
||||||
|
dinnerType = type
|
||||||
|
binding.tvBreakfast.isChecked = type == "1"
|
||||||
|
binding.tvLunch.isChecked = type == "2"
|
||||||
|
binding.tvDinner.isChecked = type == "3"
|
||||||
|
clearSearchText()
|
||||||
|
loadFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取当前显示的 FoodListFragment */
|
||||||
|
private fun currentFragment(): FoodListFragment? {
|
||||||
|
return runCatching { fragmentList[dinnerType.toInt() - 1] }.getOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun jumpSearch() {
|
private fun jumpSearch() {
|
||||||
@@ -116,24 +139,22 @@ class CookingModeActivity : BaseActivity() {
|
|||||||
toast(binding.etInputDish.hint.toString())
|
toast(binding.etInputDish.hint.toString())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
startActivity<FoodSearchActivity> {
|
currentFragment()?.getDishList(pageNo = 1, dinnerType = dinnerType, foodName = searchText)
|
||||||
putExtra(FoodSearchActivity.DINNER_TYPE, dinnerType)
|
|
||||||
putExtra(FoodSearchActivity.FOOD_NAME, searchText)
|
|
||||||
}
|
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadFragment() {
|
private fun loadFragment() {
|
||||||
runCatching {
|
runCatching {
|
||||||
fragmentList[dinnerType.toInt() - 1].let {
|
val target = fragmentList[dinnerType.toInt() - 1]
|
||||||
supportFragmentManager.beginTransaction().apply {
|
supportFragmentManager.beginTransaction().apply {
|
||||||
if (fragmentList.contains(it)) {
|
fragmentList.forEach { fragment ->
|
||||||
replace(R.id.flSubPage, it)
|
if (fragment.isAdded) {
|
||||||
|
if (fragment == target) show(fragment) else hide(fragment)
|
||||||
} else {
|
} else {
|
||||||
add(R.id.flSubPage, it)
|
if (fragment == target) add(R.id.flSubPage, fragment)
|
||||||
}
|
}
|
||||||
commit()
|
|
||||||
}
|
}
|
||||||
|
commit()
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
it.printStackTrace()
|
it.printStackTrace()
|
||||||
@@ -142,7 +163,7 @@ class CookingModeActivity : BaseActivity() {
|
|||||||
|
|
||||||
fun deleteCookFoodAndGoods(foodId: String, dinnerType: String, action: () -> Unit) {
|
fun deleteCookFoodAndGoods(foodId: String, dinnerType: String, action: () -> Unit) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
appViewModel.deleteCookFoodAndGoods(cookMode = 0, foodId = foodId, dinnerType = dinnerType)
|
dbViewModel.deleteCookFoodAndGoods(cookMode = 0, foodId = foodId, dinnerType = dinnerType)
|
||||||
action()
|
action()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,19 +171,19 @@ class CookingModeActivity : BaseActivity() {
|
|||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
runCatching {
|
runCatching {
|
||||||
val isConfigPage = intent?.getBooleanExtra(IS_CONFIG_PAGE, false) ?: false
|
val isConfigPage = intent.getBooleanExtra(IS_CONFIG_PAGE, false)
|
||||||
if (isConfigPage) {
|
if (isConfigPage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
|
val lastDinnerType = intent.getStringExtra(DINNER_TYPE) ?: "0"
|
||||||
val lastDinnerType = intent?.getStringExtra(DINNER_TYPE) ?: "0"
|
if (lastDinnerType !in listOf("1", "2", "3")) return
|
||||||
if (lastDinnerType == "1" || lastDinnerType == "2" || lastDinnerType == "3") {
|
if (lastDinnerType == dinnerType) {
|
||||||
fragmentList[lastDinnerType.toInt() - 1].getDishList(1, lastDinnerType)
|
// 同一 Tab:onHiddenChanged 不会触发,直接刷新
|
||||||
}
|
clearSearchText()
|
||||||
when (lastDinnerType) {
|
currentFragment()?.getDishList(1, lastDinnerType)
|
||||||
"1" -> binding.dishRadioGroup.check(R.id.rbBreakfast)
|
} else {
|
||||||
"2" -> binding.dishRadioGroup.check(R.id.rbLunch)
|
// 不同 Tab:selectTab → loadFragment → show → onHiddenChanged 负责刷新,无需直接调用
|
||||||
"3" -> binding.dishRadioGroup.check(R.id.rbDinner)
|
selectTab(lastDinnerType)
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
it.printStackTrace()
|
it.printStackTrace()
|
||||||
@@ -180,8 +201,10 @@ class CookingModeActivity : BaseActivity() {
|
|||||||
isVisible = false
|
isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getFoodList(param: MutableMap<String, Any>) {
|
fun clearSearchText() {
|
||||||
netViewModel.searchFoodList(param = param)
|
isClearingByTabSwitch = true
|
||||||
|
binding.etInputDish.text?.clear()
|
||||||
|
isClearingByTabSwitch = false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
// it.visible()
|
// it.visible()
|
||||||
// }, titleAction = {
|
// }, titleAction = {
|
||||||
// it.text = "设备配置"
|
// it.text = "设备配置"
|
||||||
// }, rightIconActon = {
|
// }, rightIconAction = {
|
||||||
// it.gone()
|
// it.gone()
|
||||||
//// it.alpha = 0.0F
|
//// it.alpha = 0.0F
|
||||||
//// it.setImageResource(R.drawable.ic_setting)
|
//// it.setImageResource(R.drawable.ic_setting)
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.shuwei.dish.match.adapter.FoodAdapter
|
import com.shuwei.dish.match.adapter.FoodAdapter
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.databinding.ActivityFoodRecognizeBinding
|
import com.shuwei.dish.match.databinding.ActivityFoodRecognizeBinding
|
||||||
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.dialog.FoodSearchDialog
|
import com.shuwei.dish.match.dialog.FoodSearchDialog
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.entity.GoodsNameQueryDTO
|
import com.shuwei.dish.match.model.GoodsNameQueryDTO
|
||||||
import com.shuwei.dish.match.utils.ActivityManager
|
import com.shuwei.dish.match.utils.ActivityManager
|
||||||
|
import com.shuwei.dish.match.utils.AddressUtil
|
||||||
import com.shuwei.dish.match.utils.WeightUtil
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
@@ -38,6 +40,7 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
private const val TAG = "FoodRecognizeActivity"
|
private const val TAG = "FoodRecognizeActivity"
|
||||||
private const val EXTRA_IMAGE_URI = "extra_image_uri"
|
private const val EXTRA_IMAGE_URI = "extra_image_uri"
|
||||||
private const val EXTRA_CURRENT_WEIGHT = "extra_current_weight"
|
private const val EXTRA_CURRENT_WEIGHT = "extra_current_weight"
|
||||||
|
private const val EXTRA_INITIAL_WEIGHT = "extra_initial_weight"
|
||||||
const val EXTRA_SELECTED_ITEM = "extra_selected_item"
|
const val EXTRA_SELECTED_ITEM = "extra_selected_item"
|
||||||
const val IS_MANUAL_CANCEL = "isManualCancel"
|
const val IS_MANUAL_CANCEL = "isManualCancel"
|
||||||
|
|
||||||
@@ -54,6 +57,7 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
activity: BaseActivity,
|
activity: BaseActivity,
|
||||||
imageUri: String? = null,
|
imageUri: String? = null,
|
||||||
currentWeight: Double = 0.0,
|
currentWeight: Double = 0.0,
|
||||||
|
initialWeight: Double = 0.0,
|
||||||
nameScoreList: ArrayList<FoodModule.IdNameScore> = arrayListOf(),
|
nameScoreList: ArrayList<FoodModule.IdNameScore> = arrayListOf(),
|
||||||
finishCallback: (Boolean, GoodsItem?) -> Unit = { _, _ -> }
|
finishCallback: (Boolean, GoodsItem?) -> Unit = { _, _ -> }
|
||||||
) {
|
) {
|
||||||
@@ -61,6 +65,7 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
val launchIntent = Intent(activity, FoodRecognizeActivity::class.java).apply {
|
val launchIntent = Intent(activity, FoodRecognizeActivity::class.java).apply {
|
||||||
putExtra(EXTRA_IMAGE_URI, imageUri)
|
putExtra(EXTRA_IMAGE_URI, imageUri)
|
||||||
putExtra(EXTRA_CURRENT_WEIGHT, currentWeight)
|
putExtra(EXTRA_CURRENT_WEIGHT, currentWeight)
|
||||||
|
putExtra(EXTRA_INITIAL_WEIGHT, initialWeight)
|
||||||
}
|
}
|
||||||
activity.startActivity(launchIntent) { resultIntent ->
|
activity.startActivity(launchIntent) { resultIntent ->
|
||||||
val isManualCancel = resultIntent?.getBooleanExtra(IS_MANUAL_CANCEL, false) ?: false
|
val isManualCancel = resultIntent?.getBooleanExtra(IS_MANUAL_CANCEL, false) ?: false
|
||||||
@@ -94,14 +99,17 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
/** 当前选中的列表位置,-1 表示无选中 */
|
/** 当前选中的列表位置,-1 表示无选中 */
|
||||||
private var selectedPosition = -1
|
private var selectedPosition = -1
|
||||||
|
|
||||||
/** 秤1当前实时重量 */
|
/** 秤1当前实时净重(已减去初始读数) */
|
||||||
private var currentWeight = 0.0
|
private var currentWeight = 0.0
|
||||||
|
|
||||||
/** 重量减少时延迟更新的任务,页面关闭前取消可防止用错误重量 */
|
/** 初始秤读数,净重 = 秤读数 - initialWeight */
|
||||||
private var pendingWeightRunnable: Runnable? = null
|
private var initialWeight = 0.0
|
||||||
|
|
||||||
/** 当前待延迟更新的目标重量,避免相同重量重复重置计时器 */
|
/**
|
||||||
private var pendingWeight = 0.0
|
* 滑动窗口:保存最近 10 条稳定帧净重,用于关闭页面时判断数据是否稳定
|
||||||
|
* 超过 10 条时移除队头,保持最新数据
|
||||||
|
*/
|
||||||
|
private val weightWindow = ArrayDeque<Double>(10)
|
||||||
|
|
||||||
/** 右侧自定义滚动指示条最小高度 */
|
/** 右侧自定义滚动指示条最小高度 */
|
||||||
private val scrollIndicatorMinHeightPx by lazy { (24 * resources.displayMetrics.density).toInt() }
|
private val scrollIndicatorMinHeightPx by lazy { (24 * resources.displayMetrics.density).toInt() }
|
||||||
@@ -109,6 +117,9 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
/** 食材搜索弹窗,持有引用防止重复打开 */
|
/** 食材搜索弹窗,持有引用防止重复打开 */
|
||||||
private var foodSearchDialog: FoodSearchDialog? = null
|
private var foodSearchDialog: FoodSearchDialog? = null
|
||||||
|
|
||||||
|
/** 数据不稳定提示弹窗,持有引用通过 isShowing 防止重复弹出 */
|
||||||
|
private var unstableDialog: CommonDialog? = null
|
||||||
|
|
||||||
/** 通过name查询IdNameScore */
|
/** 通过name查询IdNameScore */
|
||||||
private val nameScoreMap = mutableMapOf<String, FoodModule.IdNameScore>()
|
private val nameScoreMap = mutableMapOf<String, FoodModule.IdNameScore>()
|
||||||
|
|
||||||
@@ -124,7 +135,7 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
private val adapter = FoodAdapter(list).apply {
|
private val adapter = FoodAdapter(list).apply {
|
||||||
setOnItemClickListener { _, _, position ->
|
setOnItemClickListener { _, _, position ->
|
||||||
// rawMaterialsRemind(position)
|
// rawMaterialsRemind(position)
|
||||||
val item = list[position]
|
val item = list.getOrNull(position) ?: return@setOnItemClickListener
|
||||||
list.forEachIndexed { i, it -> it.isClicked = (i == position) }
|
list.forEachIndexed { i, it -> it.isClicked = (i == position) }
|
||||||
// 点击选择时记录当前秤重量
|
// 点击选择时记录当前秤重量
|
||||||
item.useWeight = currentWeight
|
item.useWeight = currentWeight
|
||||||
@@ -135,7 +146,7 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun rawMaterialsRemind(position: Int) {
|
private fun rawMaterialsRemind(position: Int) {
|
||||||
val item = list[position]
|
val item = list.getOrNull(position) ?: return
|
||||||
// 弹出净材种类单选弹窗,确认后再选中该食材
|
// 弹出净材种类单选弹窗,确认后再选中该食材
|
||||||
showRawMaterialsDialog(
|
showRawMaterialsDialog(
|
||||||
context = this@FoodRecognizeActivity,
|
context = this@FoodRecognizeActivity,
|
||||||
@@ -199,37 +210,23 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
binding.ivFoodPhoto.setImageURI(imageUri.toUri())
|
binding.ivFoodPhoto.setImageURI(imageUri.toUri())
|
||||||
}
|
}
|
||||||
currentWeight = intent.getDoubleExtra(EXTRA_CURRENT_WEIGHT, 0.0)
|
currentWeight = intent.getDoubleExtra(EXTRA_CURRENT_WEIGHT, 0.0)
|
||||||
|
initialWeight = intent.getDoubleExtra(EXTRA_INITIAL_WEIGHT, 0.0)
|
||||||
binding.tvWeight.text = "${currentWeight}g"
|
binding.tvWeight.text = "${currentWeight}g"
|
||||||
// val tempList = arrayListOf<GoodsItem>()
|
|
||||||
// Process recognized name list if available
|
|
||||||
recognizeNameList?.apply {
|
recognizeNameList?.apply {
|
||||||
// Iterate through each recognized item
|
|
||||||
forEach {
|
forEach {
|
||||||
// Extract goods name by splitting "WP" and taking the first part
|
|
||||||
val goodsName = it.name.split("WP").first()
|
val goodsName = it.name.split("WP").first()
|
||||||
val rawMaterialsType = it.rawMaterialsType
|
val rawMaterialsType = it.rawMaterialsType
|
||||||
// Add to goods name list and name-score mapping
|
|
||||||
goodsNameList.add(GoodsNameQueryDTO(goodsName, rawMaterialsType))
|
goodsNameList.add(GoodsNameQueryDTO(goodsName, rawMaterialsType))
|
||||||
nameScoreMap.put(goodsName, it)
|
nameScoreMap.put(goodsName, it)
|
||||||
|
|
||||||
// // TODO: 测试数据,临时使用-------------------------
|
|
||||||
// val testData = buildTestData(it)
|
|
||||||
// tempList.add(testData)
|
|
||||||
// // TODO: 测试数据,临时使用-------------------------
|
|
||||||
}
|
}
|
||||||
// // TODO: 测试数据,临时使用-------------------------
|
|
||||||
// loadRecognizeList(tempList)
|
|
||||||
// // TODO: 测试数据,临时使用-------------------------
|
|
||||||
// Clear the recognize name list after processing
|
|
||||||
recognizeNameList = null
|
recognizeNameList = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// If goods name list is not empty, query goods list from network
|
if (goodsNameList.isNotEmpty()) {
|
||||||
// if (goodsNameList.isNotEmpty()){
|
netViewModel.queryGoodsList(goodsType = "0", goodsNames = goodsNameList)
|
||||||
netViewModel.queryGoodsList(goodsType = "0", goodsNames = goodsNameList)
|
} else {
|
||||||
// } else {
|
loadRecognizeList(emptyList())
|
||||||
// loadRecognizeList(emptyList())
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildTestData(item: FoodModule.IdNameScore): GoodsItem {
|
private fun buildTestData(item: FoodModule.IdNameScore): GoodsItem {
|
||||||
@@ -289,15 +286,16 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
binding.rvRecognizeList.visible()
|
binding.rvRecognizeList.visible()
|
||||||
binding.tvNoData.gone()
|
binding.tvNoData.gone()
|
||||||
list.clear()
|
list.clear()
|
||||||
goodsList.forEach {
|
goodsList.forEach { goods ->
|
||||||
var foodScore = -1
|
var foodScore = -1
|
||||||
nameScoreMap[it.goodsName]?.let { food ->
|
nameScoreMap[goods.goodsName]?.let { food ->
|
||||||
foodScore = ((1 - food.score) * 10000).toInt()
|
foodScore = ((1 - food.score) * 10000).toInt()
|
||||||
}
|
}
|
||||||
// // 将接口返回的 rawMaterialsType(全部种类)移存到 rawMaterialsTypes,供弹窗使用
|
//保存原goodsId
|
||||||
// it.rawMaterialsTypes = it.rawMaterialsType
|
goods.oldGoodsId = goods.goodsId
|
||||||
// it.rawMaterialsType = null
|
//PrepareFoodActivity中的goodsId就是materId
|
||||||
list.add(it.also { it.foodScore = foodScore })
|
goods.goodsId = goods.materId ?: ""
|
||||||
|
list.add(goods.also { it.foodScore = foodScore })
|
||||||
}
|
}
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
updateRvParentLayoutHeight()
|
updateRvParentLayoutHeight()
|
||||||
@@ -435,58 +433,87 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
* 低于阈值说明食材已被取走,保留上次有效值等待页面关闭
|
* 低于阈值说明食材已被取走,保留上次有效值等待页面关闭
|
||||||
*/
|
*/
|
||||||
private fun registerWeightListener() {
|
private fun registerWeightListener() {
|
||||||
// WeightUtil.addWeightListener(TAG) { address, state, weight ->
|
WeightUtil.addWeightListener(TAG) { address, state, weight ->
|
||||||
// if (address == AddressUtil.ONE && state == WeightUtil.STATE_STABLE) {
|
if (address == AddressUtil.ONE && state == WeightUtil.STATE_STABLE) {
|
||||||
// runOnUiThread {
|
runOnUiThread {
|
||||||
// currentWeight = weight
|
// 净重 = 秤读数 - 初始读数
|
||||||
// binding.tvWeight.run {
|
val netWeight = weight - initialWeight
|
||||||
// if (tag != weight) {
|
currentWeight = netWeight
|
||||||
// text = "$weight g"
|
binding.tvWeight.run {
|
||||||
// tag = weight
|
if (tag != netWeight) {
|
||||||
// }
|
text = "${netWeight}g"
|
||||||
// }
|
tag = netWeight
|
||||||
// if (weight >= PrepareCookActivity.WEIGHT_RECOGNIZE_VALUE) {
|
}
|
||||||
// adapter.items.firstOrNull { it.isClicked }?.let { item ->
|
}
|
||||||
// if (pendingWeight != weight) {
|
// 入队,超过 10 条移除队头
|
||||||
// // 无论增减,均延迟更新,避免手拿物品时的瞬时增重干扰
|
if (weightWindow.size >= 10) weightWindow.removeFirst()
|
||||||
// cancelPendingWeightUpdate()
|
weightWindow.addLast(netWeight)
|
||||||
// pendingWeight = weight
|
// 实时更新选中食材重量
|
||||||
// pendingWeightRunnable = Runnable {
|
list.getOrNull(selectedPosition)?.useWeight = netWeight
|
||||||
// item.useWeight = weight
|
}
|
||||||
// pendingWeightRunnable = null
|
}
|
||||||
// }.also { handler.postDelayed(it, 3000) }
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取消待执行的延迟重量更新任务
|
* 从滑动窗口尾部向前查找连续稳定值:
|
||||||
|
* 跳过尾部不稳定的过渡帧,找到第一段连续相同且大于阈值的序列
|
||||||
|
* 连续条数 >= 3 时返回该值,否则返回 null(数据不稳定)
|
||||||
*/
|
*/
|
||||||
private fun cancelPendingWeightUpdate() {
|
private fun getStableWeightFromWindow(): Double? {
|
||||||
// pendingWeightRunnable?.let { handler.removeCallbacks(it) }
|
val threshold = PrepareFoodActivity.WEIGHT_RECOGNIZE_VALUE
|
||||||
// pendingWeightRunnable = null
|
var i = weightWindow.indices.last
|
||||||
|
while (i >= 0) {
|
||||||
|
val candidate = weightWindow[i]
|
||||||
|
// 跳过低于阈值的过渡帧
|
||||||
|
if (candidate <= threshold) {
|
||||||
|
i--
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// 以 candidate 为基准,向前统计连续相同条数
|
||||||
|
var count = 0
|
||||||
|
var j = i
|
||||||
|
while (j >= 0 && weightWindow[j] == candidate) {
|
||||||
|
count++
|
||||||
|
j--
|
||||||
|
}
|
||||||
|
if (count >= 3) return candidate
|
||||||
|
// 不足 3 条,继续向前找
|
||||||
|
i = j
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 携带当前选中食材关闭页面
|
* 携带当前选中食材关闭页面
|
||||||
|
* @param isManualCancel true=用户手动返回;false=被动关闭(重量低于阈值)
|
||||||
*/
|
*/
|
||||||
private fun finishWithResult(isManualCancel: Boolean) {
|
private fun finishWithResult(isManualCancel: Boolean) {
|
||||||
cancelPendingWeightUpdate()
|
val item = list.getOrNull(selectedPosition)
|
||||||
|
if (!isManualCancel && item != null) {
|
||||||
|
// 被动关闭:从窗口取稳定值
|
||||||
|
val stableWeight = getStableWeightFromWindow()
|
||||||
|
if (stableWeight == null) {
|
||||||
|
// 数据不稳定,不关闭页面,弹窗提示(通过 isShowing 防止重复弹出)
|
||||||
|
if (unstableDialog?.isShowing == true) return
|
||||||
|
if (unstableDialog == null) {
|
||||||
|
unstableDialog = CommonDialog(this)
|
||||||
|
.setTitle("提示")
|
||||||
|
.setContent("秤数据不稳定,请放置食材进行重新识别")
|
||||||
|
.setSingleButton("确认") {
|
||||||
|
finishWithResult(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unstableDialog?.show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
item.useWeight = stableWeight
|
||||||
|
}
|
||||||
|
|
||||||
val intent = Intent().apply {
|
val intent = Intent().apply {
|
||||||
putExtra(IS_MANUAL_CANCEL, isManualCancel)
|
putExtra(IS_MANUAL_CANCEL, isManualCancel)
|
||||||
if (isManualCancel.not()) {
|
if (!isManualCancel) {
|
||||||
list.getOrNull(selectedPosition)?.let {
|
item?.let { putExtra(EXTRA_SELECTED_ITEM, it) }
|
||||||
// 兜底:若 useWeight 仍为空或0,使用当前实时重量
|
|
||||||
if ((it.useWeight ?: 0.0) <= 0.0) {
|
|
||||||
it.useWeight = currentWeight
|
|
||||||
}
|
|
||||||
putExtra(EXTRA_SELECTED_ITEM, it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setResult(RESULT_OK, intent)
|
setResult(RESULT_OK, intent)
|
||||||
@@ -495,7 +522,6 @@ class FoodRecognizeActivity : BaseActivity() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
cancelPendingWeightUpdate()
|
|
||||||
WeightUtil.removeWeightListener(TAG)
|
WeightUtil.removeWeightListener(TAG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,30 +4,26 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.adapter.Food2Adapter
|
import com.shuwei.dish.match.adapter.Food2Adapter
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
|
||||||
import com.shuwei.dish.match.databinding.ActivityFoodSearchBinding
|
import com.shuwei.dish.match.databinding.ActivityFoodSearchBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
import com.shuwei.dish.match.model.FoodSearchItem
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||||
import com.shuwei.dish.match.utils.SpTool
|
|
||||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.startActivity
|
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import kotlinx.coroutines.launch
|
import kotlin.collections.getOrNull
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品搜索页面
|
* 菜品搜索页面(采样模式:搜索已有上架菜品作为称量模板)
|
||||||
|
* 数据源: POST /neglect/ratio-scale/food-search
|
||||||
*/
|
*/
|
||||||
class FoodSearchActivity : BaseActivity() {
|
class FoodSearchActivity : BaseActivity() {
|
||||||
|
|
||||||
@@ -36,26 +32,18 @@ class FoodSearchActivity : BaseActivity() {
|
|||||||
const val FOOD_ITEM = "foodItem"
|
const val FOOD_ITEM = "foodItem"
|
||||||
const val FOOD_ID = "foodId"
|
const val FOOD_ID = "foodId"
|
||||||
const val FOOD_NAME = "foodName"
|
const val FOOD_NAME = "foodName"
|
||||||
const val DINNER_TYPE = "dinnerType"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var binding: ActivityFoodSearchBinding
|
private lateinit var binding: ActivityFoodSearchBinding
|
||||||
|
|
||||||
private var list: MutableList<FoodRecord> = mutableListOf()
|
private var list: MutableList<FoodRecord> = mutableListOf()
|
||||||
private var dinnerType = "1"
|
|
||||||
private val recordAdapter by lazy {
|
private val recordAdapter by lazy {
|
||||||
Food2Adapter(list).apply {
|
Food2Adapter(list).apply {
|
||||||
isStateViewEnable = true
|
isStateViewEnable = true
|
||||||
setOnItemClickListener { adapter, view, position ->
|
setOnItemClickListener { adapter, view, position ->
|
||||||
if (SpTool.cookMode == 0) {
|
val jumpItem = list.getOrNull(position) ?: return@setOnItemClickListener
|
||||||
val jumpItem = list[position].also { it.dinnerType = dinnerType }
|
|
||||||
startActivity<PrepareFoodActivity> {
|
|
||||||
putExtra(PrepareFoodActivity.FOOD_ITEM, jumpItem as Serializable)
|
|
||||||
}
|
|
||||||
return@setOnItemClickListener
|
|
||||||
}
|
|
||||||
setResult(RESULT_OK, Intent().apply {
|
setResult(RESULT_OK, Intent().apply {
|
||||||
putExtra(FOOD_ITEM, list[position] as Serializable)
|
putExtra(FOOD_ITEM, jumpItem as Serializable)
|
||||||
})
|
})
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
@@ -68,7 +56,6 @@ class FoodSearchActivity : BaseActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityFoodSearchBinding.inflate(layoutInflater)
|
binding = ActivityFoodSearchBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
dinnerType = intent.getStringExtra(DINNER_TYPE) ?: "0"
|
|
||||||
setHeaderBackground()
|
setHeaderBackground()
|
||||||
foodName = intent.getStringExtra(FOOD_NAME)
|
foodName = intent.getStringExtra(FOOD_NAME)
|
||||||
binding.etInputDish.setText(foodName)
|
binding.etInputDish.setText(foodName)
|
||||||
@@ -76,7 +63,7 @@ class FoodSearchActivity : BaseActivity() {
|
|||||||
it.visible()
|
it.visible()
|
||||||
}, titleAction = {
|
}, titleAction = {
|
||||||
it.text = "菜品搜索"
|
it.text = "菜品搜索"
|
||||||
}, rightIconActon = {
|
}, rightIconAction = {
|
||||||
it.gone()
|
it.gone()
|
||||||
it.setImageResource(R.drawable.ic_setting)
|
it.setImageResource(R.drawable.ic_setting)
|
||||||
it.setOnClickListener {
|
it.setOnClickListener {
|
||||||
@@ -89,31 +76,6 @@ class FoodSearchActivity : BaseActivity() {
|
|||||||
adapter = recordAdapter
|
adapter = recordAdapter
|
||||||
}
|
}
|
||||||
addViewListener()
|
addViewListener()
|
||||||
initObserver()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 收集 searchFoodState,统一处理 Loading / Success / Error 状态
|
|
||||||
*/
|
|
||||||
private fun initObserver() {
|
|
||||||
lifecycleScope.launch {
|
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
||||||
netViewModel.searchFoodState.collect { state ->
|
|
||||||
when (state) {
|
|
||||||
is UiState.Loading -> showLoading()
|
|
||||||
is UiState.Success -> handleSearchResult(state.data)
|
|
||||||
is UiState.Error -> {
|
|
||||||
delayDismissLoading()
|
|
||||||
finishRefresh()
|
|
||||||
binding.refreshLayout.setEnableRefresh(true)
|
|
||||||
toast(state.msg)
|
|
||||||
if (pageNo == 1) loadEmptyView()
|
|
||||||
}
|
|
||||||
is UiState.Idle -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addViewListener() {
|
private fun addViewListener() {
|
||||||
@@ -159,54 +121,65 @@ class FoodSearchActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var pageNo = 1
|
private var pageNo = 1
|
||||||
private var pageSize = 10
|
private var pageSize = 20
|
||||||
fun getDinnerTypeText(): String {
|
|
||||||
return when (dinnerType) {
|
|
||||||
"1" -> "早餐"
|
|
||||||
"2" -> "午餐"
|
|
||||||
"3" -> "晚餐"
|
|
||||||
else -> "早餐"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun queryListInfo(input: String) {
|
private fun queryListInfo(input: String) {
|
||||||
val map = mutableMapOf<String, Any>(
|
netViewModel.foodSearch(
|
||||||
"foodName" to input.trim(),
|
keyword = input.trim(),
|
||||||
"pageNum" to pageNo,
|
pageNum = pageNo,
|
||||||
"pageSize" to pageSize,
|
pageSize = pageSize,
|
||||||
"placeId" to BaseApp.canteenId,
|
onLoading = { showLoading() },
|
||||||
"dinnerType" to getDinnerTypeText()
|
onResult = { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> handleSearchResult(state.data)
|
||||||
|
is UiState.Error -> {
|
||||||
|
delayDismissLoading()
|
||||||
|
finishRefresh()
|
||||||
|
binding.refreshLayout.setEnableRefresh(true)
|
||||||
|
toast(state.msg)
|
||||||
|
if (pageNo == 1) loadEmptyView()
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
netViewModel.searchFoodList(param = map)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理搜索结果,填充列表或展示空视图
|
* FoodSearchItem → FoodRecord 映射,供 Food2Adapter 展示
|
||||||
|
* 采样模式下返回给 PrepareFoodActivity 作为称量模板
|
||||||
|
*/
|
||||||
|
private fun FoodSearchItem.toFoodRecord(): FoodRecord = FoodRecord(
|
||||||
|
foodId = foodId,
|
||||||
|
foodName = foodName,
|
||||||
|
cookMode = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理搜索结果:FoodSearchItem → FoodRecord 填充列表
|
||||||
*/
|
*/
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun handleSearchResult(records: MutableList<FoodRecord>?) {
|
private fun handleSearchResult(items: List<FoodSearchItem>?) {
|
||||||
delayDismissLoading()
|
delayDismissLoading()
|
||||||
finishRefresh()
|
finishRefresh()
|
||||||
binding.refreshLayout.setEnableRefresh(true)
|
binding.refreshLayout.setEnableRefresh(true)
|
||||||
if (records.isNullOrEmpty()) {
|
if (items.isNullOrEmpty()) {
|
||||||
if (pageNo == 1) loadEmptyView()
|
if (pageNo == 1) {
|
||||||
|
loadEmptyView()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (pageNo == 1) list.clear()
|
if (pageNo == 1) list.clear()
|
||||||
list.addAll(records)
|
list.addAll(items.map { it.toFoodRecord() })
|
||||||
recordAdapter.notifyDataSetChanged()
|
recordAdapter.notifyDataSetChanged()
|
||||||
val isLoadMoreEnable = records.size >= pageSize
|
val isLoadMoreEnable = items.size >= pageSize
|
||||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||||
if (isLoadMoreEnable) pageNo++
|
if (isLoadMoreEnable) pageNo++
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun finishRefresh() {
|
private fun finishRefresh() {
|
||||||
if (pageNo == 1) {
|
binding.refreshLayout.finishRefresh(1200)
|
||||||
binding.refreshLayout.finishRefresh(1200)
|
|
||||||
} else {
|
|
||||||
binding.refreshLayout.finishLoadMore(1200)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var emptyViewBinding: LayoutEmptyViewBinding? = null
|
private var emptyViewBinding: LayoutEmptyViewBinding? = null
|
||||||
@@ -231,4 +204,4 @@ class FoodSearchActivity : BaseActivity() {
|
|||||||
setEnableLoadMore(false)
|
setEnableLoadMore(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ import com.shuwei.dish.match.adapter.HomeModeAdapter
|
|||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
import com.shuwei.dish.match.databinding.ActivityHomeBinding
|
import com.shuwei.dish.match.databinding.ActivityHomeBinding
|
||||||
import com.shuwei.dish.match.entity.HomeModeBean
|
import com.shuwei.dish.match.model.HomeModeBean
|
||||||
import com.shuwei.dish.match.utils.SpTool
|
import com.shuwei.dish.match.utils.SpTool
|
||||||
import com.shuwei.dish.match.utils.ext.startActivity
|
import com.shuwei.dish.match.utils.ext.startActivity
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.collections.getOrNull
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主页,包括三种模式:制作模式、采样模式、品控模式
|
* 主页,包括三种模式:制作模式、采样模式、品控模式
|
||||||
@@ -65,18 +66,18 @@ class HomeActivity : BaseActivity() {
|
|||||||
// startActivity<SamplingListActivity>()
|
// startActivity<SamplingListActivity>()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// appViewModel.deleteSeasoningBySort(12)
|
// dbViewModel.deleteSeasoningBySort(12)
|
||||||
// appViewModel.deleteSeasoningBySort(11)
|
// dbViewModel.deleteSeasoningBySort(11)
|
||||||
// appViewModel.deleteSeasoningBySort(13)
|
// dbViewModel.deleteSeasoningBySort(13)
|
||||||
// appViewModel.deleteSeasoningBySort(14)
|
// dbViewModel.deleteSeasoningBySort(14)
|
||||||
// appViewModel.deleteCookFoodAndGoods(0,"") {}
|
// dbViewModel.deleteCookFoodAndGoods(0,"") {}
|
||||||
// appViewModel.getCookFoodGoodsList("") {goodsList->
|
// dbViewModel.getCookFoodGoodsList("") {goodsList->
|
||||||
// goodsList.forEach {
|
// goodsList.forEach {
|
||||||
// it.foodId = "1594990392084779010"
|
// it.foodId = "1594990392084779010"
|
||||||
// appViewModel.updateGoods(it)
|
// dbViewModel.updateGoods(it)
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// appViewModel.clearAllSeasoning(){}
|
// dbViewModel.clearAllSeasoning(){}
|
||||||
|
|
||||||
|
|
||||||
// binding.btnDeviceConfig.setOnClickListener {
|
// binding.btnDeviceConfig.setOnClickListener {
|
||||||
@@ -97,7 +98,7 @@ class HomeActivity : BaseActivity() {
|
|||||||
private val modeAdapter by lazy {
|
private val modeAdapter by lazy {
|
||||||
HomeModeAdapter(modeList).apply {
|
HomeModeAdapter(modeList).apply {
|
||||||
addOnItemChildClickListener(R.id.layoutCard) { adapter, view, position ->
|
addOnItemChildClickListener(R.id.layoutCard) { adapter, view, position ->
|
||||||
modeList[position].onClick?.invoke()
|
modeList.getOrNull(position)?.onClick?.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,14 +141,14 @@ class HomeActivity : BaseActivity() {
|
|||||||
|
|
||||||
private fun goSampling() {
|
private fun goSampling() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val slots = appViewModel.loadSeasoningSlot()
|
val slots = dbViewModel.loadSeasoningSlot()
|
||||||
if (slots.isEmpty()) {
|
if (slots.isEmpty()) {
|
||||||
// 无调料信息,打开采样历史列表页面,点击设置配置调料信息
|
// 无调料信息,打开采样历史列表页面,点击设置配置调料信息
|
||||||
startActivity<SamplingModeActivity>()
|
startActivity<SamplingModeActivity>()
|
||||||
finish()
|
finish()
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
val count = appViewModel.countCookFood(cookMode = 1)
|
val count = dbViewModel.countCookFood(cookMode = 1)
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
// 有烹饪中数据,打开采样历史列表页面
|
// 有烹饪中数据,打开采样历史列表页面
|
||||||
startActivity<SamplingModeActivity>()
|
startActivity<SamplingModeActivity>()
|
||||||
|
|||||||
@@ -18,9 +18,8 @@ import com.shuwei.dish.match.objbox.FoodModule
|
|||||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||||
import com.shuwei.dish.match.utils.AddressUtil
|
import com.shuwei.dish.match.utils.AddressUtil
|
||||||
import com.shuwei.dish.match.utils.AppUtil
|
import com.shuwei.dish.match.utils.AppUtil
|
||||||
import com.shuwei.dish.match.utils.NetworkUtils
|
import com.shuwei.dish.match.utils.NetworkUtil
|
||||||
import com.shuwei.dish.match.utils.SpTool
|
import com.shuwei.dish.match.utils.SpTool
|
||||||
import com.shuwei.dish.match.utils.WeightUtil
|
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.startActivity
|
import com.shuwei.dish.match.utils.ext.startActivity
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
@@ -55,7 +54,7 @@ class InitActivity : BaseActivity() {
|
|||||||
countdownHandler.postDelayed(this, 100)
|
countdownHandler.postDelayed(this, 100)
|
||||||
} else {
|
} else {
|
||||||
// 倒计时结束,最后检测一次网络
|
// 倒计时结束,最后检测一次网络
|
||||||
if (NetworkUtils.isNetworkConnected(this@InitActivity)) {
|
if (NetworkUtil.isNetworkConnected(this@InitActivity)) {
|
||||||
startNextPage()
|
startNextPage()
|
||||||
} else {
|
} else {
|
||||||
// 网络未连接,显示"连接网络"按钮
|
// 网络未连接,显示"连接网络"按钮
|
||||||
@@ -82,12 +81,6 @@ class InitActivity : BaseActivity() {
|
|||||||
|
|
||||||
BaseApp.canteenId = SpTool.canteenId
|
BaseApp.canteenId = SpTool.canteenId
|
||||||
|
|
||||||
WeightUtil.init()
|
|
||||||
WeightUtil.getWeight()
|
|
||||||
WeightUtil.startContinuousRead()
|
|
||||||
//对净材秤1和熟食秤2称进行清零
|
|
||||||
WeightUtil.tareTwo(AddressUtil.ONE)
|
|
||||||
WeightUtil.tareTwo(AddressUtil.TWO)
|
|
||||||
initViews()
|
initViews()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +93,9 @@ class InitActivity : BaseActivity() {
|
|||||||
// 子设备:直接进入小屏专属页面,不走原有大屏业务流程
|
// 子设备:直接进入小屏专属页面,不走原有大屏业务流程
|
||||||
if (GlobalData.deviceRole == DeviceRole.SLAVE) {
|
if (GlobalData.deviceRole == DeviceRole.SLAVE) {
|
||||||
startActivity<SlaveActivity>()
|
startActivity<SlaveActivity>()
|
||||||
|
// 延迟到下一帧 finish,避免与 LaunchActivityItem 事务竞态导致
|
||||||
|
// "Activity client record must not be null" 偶发崩溃
|
||||||
|
window.decorView.post { finish() }
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
// 主设备:走原有路由逻辑
|
// 主设备:走原有路由逻辑
|
||||||
@@ -116,35 +112,38 @@ class InitActivity : BaseActivity() {
|
|||||||
startActivity<HomeActivity>()
|
startActivity<HomeActivity>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 延迟到下一帧 finish,避免与 LaunchActivityItem 事务竞态导致
|
||||||
|
// "Activity client record must not be null" 偶发崩溃
|
||||||
|
window.decorView.post { finish() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goSampling() {
|
/**
|
||||||
lifecycleScope.launch {
|
* 采样模式启动路由:根据本地调料配置和烹饪中数据决定跳转目标
|
||||||
val slots = appViewModel.loadSeasoningSlot()
|
* 改为 suspend 后由外层协程串行等待,保证 startActivity 早于 finish() 执行,
|
||||||
if (slots.isEmpty()) {
|
* 避免内部再嵌一层 lifecycleScope.launch 导致 finish 抢跑、跳转失败
|
||||||
// 无调料信息,打开采样历史列表页面,点击设置配置调料信息
|
*/
|
||||||
startActivity<SamplingModeActivity>()
|
private suspend fun goSampling() {
|
||||||
return@launch
|
val slots = dbViewModel.loadSeasoningSlot()
|
||||||
}
|
if (slots.isEmpty()) {
|
||||||
val count = appViewModel.countCookFood(cookMode = 1)
|
// 无调料信息,打开采样历史列表页面,点击设置配置调料信息
|
||||||
if (count > 0) {
|
startActivity<SamplingModeActivity>()
|
||||||
// 有烹饪中数据,打开采样历史列表页面
|
return
|
||||||
startActivity<SamplingModeActivity>()
|
}
|
||||||
return@launch
|
val count = dbViewModel.countCookFood(cookMode = 1)
|
||||||
}
|
if (count > 0) {
|
||||||
// 无烹饪数据,打开新增采样页面
|
// 有烹饪中数据,打开采样历史列表页面
|
||||||
startActivity<PrepareFoodActivity> {
|
startActivity<SamplingModeActivity>()
|
||||||
putExtra(PrepareFoodActivity.PAGE_FROM, PrepareFoodActivity.HOME)
|
return
|
||||||
}
|
}
|
||||||
|
// 无烹饪数据,打开新增采样页面
|
||||||
|
startActivity<PrepareFoodActivity> {
|
||||||
|
putExtra(PrepareFoodActivity.PAGE_FROM, PrepareFoodActivity.HOME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
countdownHandler.removeCallbacksAndMessages(null)
|
countdownHandler.removeCallbacksAndMessages(null)
|
||||||
WeightUtil.stopContinuousRead()
|
|
||||||
// 秤服务伴随进程生命周期,无需在 Activity 销毁时停止;进程退出时 OS 会自动回收所有资源
|
|
||||||
// ScaleServiceManager.stop()
|
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +176,7 @@ class InitActivity : BaseActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (NetworkUtils.isNetworkConnected(this)) {
|
if (NetworkUtil.isNetworkConnected(this)) {
|
||||||
// 有网络时隐藏网络检测区域,直接跳转
|
// 有网络时隐藏网络检测区域,直接跳转
|
||||||
binding.llNetwork.gone()
|
binding.llNetwork.gone()
|
||||||
startNextPage(withDelay = false)
|
startNextPage(withDelay = false)
|
||||||
@@ -221,7 +220,7 @@ class InitActivity : BaseActivity() {
|
|||||||
* 检测网络连接
|
* 检测网络连接
|
||||||
*/
|
*/
|
||||||
private fun checkNetworkConnection() {
|
private fun checkNetworkConnection() {
|
||||||
if (NetworkUtils.isNetworkConnected(this)) {
|
if (NetworkUtil.isNetworkConnected(this)) {
|
||||||
// 网络连接成功,停止倒计时并跳转到 HomeActivity
|
// 网络连接成功,停止倒计时并跳转到 HomeActivity
|
||||||
countdownHandler.removeCallbacks(countdownTask)
|
countdownHandler.removeCallbacks(countdownTask)
|
||||||
startNextPage()
|
startNextPage()
|
||||||
@@ -252,4 +251,8 @@ class InitActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
hasNavigated = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ import com.shuwei.dish.match.R
|
|||||||
import com.shuwei.dish.match.adapter.Seasoning18GridAdapter
|
import com.shuwei.dish.match.adapter.Seasoning18GridAdapter
|
||||||
import com.shuwei.dish.match.adapter.Seasoning22GridAdapter
|
import com.shuwei.dish.match.adapter.Seasoning22GridAdapter
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
|
import com.shuwei.dish.match.base.GlobalData
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.databinding.ActivityMasterScaleBinding
|
import com.shuwei.dish.match.databinding.ActivityMasterScaleBinding
|
||||||
import com.shuwei.dish.match.databinding.ListTypeScale1Binding
|
import com.shuwei.dish.match.databinding.ListTypeScale1Binding
|
||||||
@@ -81,7 +82,7 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
/** 从 Room 加载槽位配置到 slotNameMap,加载完成后启动数据观测 */
|
/** 从 Room 加载槽位配置到 slotNameMap,加载完成后启动数据观测 */
|
||||||
private fun loadSlotNames() {
|
private fun loadSlotNames() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val slots = appViewModel.loadSeasoningSlot()
|
val slots = dbViewModel.loadSeasoningSlot()
|
||||||
slots.forEach { slot ->
|
slots.forEach { slot ->
|
||||||
slotNameMap["${slot.deviceId}#${slot.address}"] = slot.goodsName
|
slotNameMap["${slot.deviceId}#${slot.address}"] = slot.goodsName
|
||||||
}
|
}
|
||||||
@@ -99,7 +100,7 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
val flow = ScaleServiceManager.allScales ?: return
|
val flow = ScaleServiceManager.allScales ?: return
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
flow.collectLatest { scaleMap ->
|
flow.collectLatest { scaleMap ->
|
||||||
val localId = com.shuwei.dish.match.base.GlobalData.deviceId
|
val localId = GlobalData.deviceId
|
||||||
val localIp = NetworkUtil.getLocalIpAddress(this@MasterScaleActivity)
|
val localIp = NetworkUtil.getLocalIpAddress(this@MasterScaleActivity)
|
||||||
val groups = scaleMap.values
|
val groups = scaleMap.values
|
||||||
.groupBy { it.deviceId }
|
.groupBy { it.deviceId }
|
||||||
@@ -337,7 +338,7 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
textSize = 22f
|
textSize = 22f
|
||||||
}
|
}
|
||||||
cell.tvState.run {
|
cell.tvState.run {
|
||||||
text = stateStr(scale?.state)
|
text = WeightUtil.getStateStr(scale?.state ?: -1)
|
||||||
textSize = 22f
|
textSize = 22f
|
||||||
}
|
}
|
||||||
cell.root.updateLayoutParams { height = 400.dp }
|
cell.root.updateLayoutParams { height = 400.dp }
|
||||||
@@ -450,20 +451,12 @@ class MasterScaleActivity : BaseActivity() {
|
|||||||
b.tvAddr.text = scale?.let { "秤 ${it.address}" } ?: ""
|
b.tvAddr.text = scale?.let { "秤 ${it.address}" } ?: ""
|
||||||
b.tvName.text = scale?.name?.takeIf { it.isNotBlank() } ?: "-"
|
b.tvName.text = scale?.name?.takeIf { it.isNotBlank() } ?: "-"
|
||||||
b.tvWeight.text = scale?.let { "${it.weight} g" } ?: ""
|
b.tvWeight.text = scale?.let { "${it.weight} g" } ?: ""
|
||||||
b.tvState.text = stateStr(scale?.state)
|
b.tvState.text = scale?.let { WeightUtil.getStateStr(it.state) } ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 工具方法 ───────────────────────────────────────────────────────────
|
// ── 工具方法 ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private fun stateStr(state: Int?) = when (state) {
|
|
||||||
WeightUtil.STATE_STABLE -> "稳定"
|
|
||||||
WeightUtil.STATE_UNSTABLE -> "不稳定"
|
|
||||||
WeightUtil.STATE_OVER_WEIGHT -> "超量"
|
|
||||||
null -> ""
|
|
||||||
else -> "$state"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 弹出清零确认对话框
|
* 弹出清零确认对话框
|
||||||
* @param deviceId 目标设备 ID
|
* @param deviceId 目标设备 ID
|
||||||
|
|||||||
@@ -19,10 +19,12 @@ import com.shuwei.dish.match.base.BaseActivity
|
|||||||
import com.shuwei.dish.match.databinding.ActivityPrepareFoodBinding
|
import com.shuwei.dish.match.databinding.ActivityPrepareFoodBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
|
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.entity.CookFoodDTO
|
import com.shuwei.dish.match.dialog.FoodSearchDialog
|
||||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.FoodCompositionResponse
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.objbox.FoodModule
|
import com.shuwei.dish.match.objbox.FoodModule
|
||||||
import com.shuwei.dish.match.utils.AddressUtil
|
import com.shuwei.dish.match.utils.AddressUtil
|
||||||
@@ -34,6 +36,7 @@ import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
|||||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
|
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||||
import com.shuwei.dish.match.utils.ext.startActivity
|
import com.shuwei.dish.match.utils.ext.startActivity
|
||||||
import com.shuwei.dish.match.utils.ext.toJsonString
|
import com.shuwei.dish.match.utils.ext.toJsonString
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
@@ -53,6 +56,7 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
companion object {
|
companion object {
|
||||||
const val TAG = "PrepareFoodActivity"
|
const val TAG = "PrepareFoodActivity"
|
||||||
const val FOOD_ITEM = "foodItem"
|
const val FOOD_ITEM = "foodItem"
|
||||||
|
const val COOK_ORDER_ID = "cookOrderId"
|
||||||
const val PAGE_FROM = "pageFrom"
|
const val PAGE_FROM = "pageFrom"
|
||||||
const val HOME = "home"
|
const val HOME = "home"
|
||||||
const val WEIGHT_CHANGE_VALUE = 5
|
const val WEIGHT_CHANGE_VALUE = 5
|
||||||
@@ -68,10 +72,19 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
|
|
||||||
private var food: FoodRecord? = null
|
private var food: FoodRecord? = null
|
||||||
|
|
||||||
|
/** 烹制单 ID,制作模式从菜品列表传入,用于调用新配比秤接口 */
|
||||||
|
private var cookOrderId: String? = null
|
||||||
|
|
||||||
/** 来源页面标识,HOME 时返回跳转 SamplingListActivity */
|
/** 来源页面标识,HOME 时返回跳转 SamplingListActivity */
|
||||||
private var pageFrom: String? = null
|
private var pageFrom: String? = null
|
||||||
|
|
||||||
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
||||||
|
|
||||||
|
/** 食材检索弹窗,手动新增构成时复用 */
|
||||||
|
private var foodSearchDialog: FoodSearchDialog? = null
|
||||||
|
|
||||||
|
/** 手动录入卡当前选中的食材(含 materId),点击搜索后回填 */
|
||||||
|
private var selectedIngredient: GoodsItem? = null
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
@@ -79,13 +92,14 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
pageFrom = intent.getStringExtra(PAGE_FROM)
|
pageFrom = intent.getStringExtra(PAGE_FROM)
|
||||||
//food = intent.extras?.getSerializable(FOOD_ITEM) as FoodRecord?
|
//food = intent.extras?.getSerializable(FOOD_ITEM) as FoodRecord?
|
||||||
food = IntentCompat.getSerializableExtra(intent, FOOD_ITEM, FoodRecord::class.java)
|
food = IntentCompat.getSerializableExtra(intent, FOOD_ITEM, FoodRecord::class.java)
|
||||||
|
cookOrderId = intent.getStringExtra(COOK_ORDER_ID)
|
||||||
val isSamplingMode = SpTool.cookMode == 1
|
val isSamplingMode = SpTool.cookMode == 1
|
||||||
val titleText = if (isSamplingMode) "菜品采集" else "菜品制作"
|
val titleText = if (isSamplingMode) "菜品采集" else "菜品制作"
|
||||||
setTitleBar(titleBarAction = {
|
setTitleBar(titleBarAction = {
|
||||||
it.visible()
|
it.visible()
|
||||||
}, titleAction = {
|
}, titleAction = {
|
||||||
it.text = titleText
|
it.text = titleText
|
||||||
}, rightIconActon = {
|
}, rightIconAction = {
|
||||||
it.gone()
|
it.gone()
|
||||||
}, backAction = {
|
}, backAction = {
|
||||||
it.setOnClickListener {
|
it.setOnClickListener {
|
||||||
@@ -105,20 +119,30 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
binding.etInputDish.let {
|
binding.etInputDish.let {
|
||||||
it.setSelection(it.length())
|
it.setSelection(it.length())
|
||||||
}
|
}
|
||||||
|
// 采集模式:启用食材信息录入卡(手动新增构成)
|
||||||
|
initIngredientInput()
|
||||||
} else {
|
} else {
|
||||||
// 制作模式:不可编辑,仅展示菜名
|
// 制作模式:不可编辑,仅展示菜名
|
||||||
binding.etInputDish.isFocusable = false
|
binding.etInputDish.isFocusable = false
|
||||||
binding.etInputDish.isFocusableInTouchMode = false
|
binding.etInputDish.isFocusableInTouchMode = false
|
||||||
binding.ivDishSearch.gone()
|
binding.ivDishSearch.gone()
|
||||||
|
// 制作模式:不展示手动新增卡
|
||||||
|
binding.llIngredientInput.gone()
|
||||||
}
|
}
|
||||||
|
|
||||||
addViewClickListener()
|
addViewClickListener()
|
||||||
addBackKeyListener()
|
addBackKeyListener()
|
||||||
initCamera(binding.flCameraContainer)
|
// 仅采样模式启用摄像头识别,制作模式不需要
|
||||||
|
// if (isSamplingMode) {
|
||||||
|
// initCamera(binding.flCameraContainer)
|
||||||
|
// }
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
initObserver()
|
initObserver()
|
||||||
|
|
||||||
if (food?.foodId.isNullOrBlank().not()) {
|
// 制作模式优先用 cookOrderId 调新接口,采样模式回退到旧 foodId
|
||||||
|
if (!cookOrderId.isNullOrBlank()) {
|
||||||
|
getCookOrderComposition(cookOrderId!!)
|
||||||
|
} else if (food?.foodId.isNullOrBlank().not()) {
|
||||||
getDishDetail(food!!.foodId!!)
|
getDishDetail(food!!.foodId!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,29 +153,43 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
WeightUtil.tareTwo(AddressUtil.ONE)
|
WeightUtil.tareTwo(AddressUtil.ONE)
|
||||||
delayDismissLoading()
|
delayDismissLoading()
|
||||||
}
|
}
|
||||||
// TODO: 测试功能-------------------------------
|
// // TODO: 测试功能-------------------------------
|
||||||
binding.btnTestConfirm.clickWithDebounce {
|
// binding.btnTestConfirm.clickWithDebounce {
|
||||||
if (currentWeight <= 0.0) return@clickWithDebounce
|
// if (currentWeight <= 0.0) return@clickWithDebounce
|
||||||
val (index, item) = list.withIndex().find { (_, it) -> it.isOriginalData && it.isClicked && (it.useWeight?:0.0) <= 0.0 } ?: return@clickWithDebounce
|
// val (index, item) = list.withIndex().find { (_, it) -> it.isOriginalData && it.isClicked && (it.useWeight?:0.0) <= 0.0 } ?: return@clickWithDebounce
|
||||||
item.useWeight = currentWeight
|
// item.useWeight = currentWeight
|
||||||
item.isSetFinished = true
|
// item.isSetFinished = true
|
||||||
list.forEachIndexed { i, it -> it.isClicked = i == index }
|
// list.forEachIndexed { i, it -> it.isClicked = i == index }
|
||||||
materialAdapter.notifyDataSetChanged()
|
// materialAdapter.notifyDataSetChanged()
|
||||||
}
|
// }
|
||||||
// TODO: 测试功能-------------------------------
|
// // TODO: 测试功能-------------------------------
|
||||||
//binding.root.setOnClickListener { hideKeyboard() }
|
//binding.root.setOnClickListener { hideKeyboard() }
|
||||||
WeightUtil.addWeightListener(
|
WeightUtil.addWeightListener(
|
||||||
weightKey = TAG,
|
weightKey = TAG,
|
||||||
getWeight = { address, state, weight ->
|
getWeight = { address, state, weight ->
|
||||||
if (address == AddressUtil.ONE && state == WeightUtil.STATE_STABLE) {
|
if (address == AddressUtil.ONE && state == WeightUtil.STATE_STABLE) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
// 首次收到稳定读数时,将其作为初始值(去皮基准)
|
||||||
|
// if (!initialWeightReady) {
|
||||||
|
// initialWeight = weight
|
||||||
|
// initialWeightReady = true
|
||||||
|
// }
|
||||||
|
// 净重 = 秤读数 - 初始读数
|
||||||
|
val netWeight = weight - initialWeight
|
||||||
|
currentWeight = netWeight
|
||||||
binding.tvShowWeight.run {
|
binding.tvShowWeight.run {
|
||||||
if (tag != weight) {
|
if (tag != netWeight) {
|
||||||
text = "称重:${weight}g"
|
text = "称重:${netWeight}g"
|
||||||
tag = weight
|
tag = netWeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recognizeFood(weight)
|
// 仅采样模式:用量自动回填秤重 + 触发食材识别
|
||||||
|
if (SpTool.cookMode == 1) {
|
||||||
|
val displayWeight =
|
||||||
|
if (netWeight > 0) netWeight.roundedOneDecimalPlace().toString() else ""
|
||||||
|
binding.etAmount.setText(displayWeight)
|
||||||
|
recognizeFood(netWeight)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -216,6 +254,12 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
private var lastWeight = 0.0
|
private var lastWeight = 0.0
|
||||||
private var currentWeight = 0.0
|
private var currentWeight = 0.0
|
||||||
|
|
||||||
|
/** 初始秤读数,净重 = 秤读数 - initialWeight,从 SpTool.configWeight 读取 */
|
||||||
|
private var initialWeight = SpTool.configWeight.toDouble()
|
||||||
|
|
||||||
|
/** 初始读数是否已从秤获取 */
|
||||||
|
// private var initialWeightReady = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重量稳定时触发菜品识别
|
* 重量稳定时触发菜品识别
|
||||||
* @param weight 当前稳定重量
|
* @param weight 当前稳定重量
|
||||||
@@ -257,11 +301,11 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
val filterValue = list.withIndex().find { (_, it) -> it.goodsId == entity.goodsId }
|
val filterValue = list.withIndex().find { (_, it) -> it.goodsId == entity.goodsId }
|
||||||
if (filterValue != null) {
|
if (filterValue != null) {
|
||||||
val index = filterValue.index
|
val index = filterValue.index
|
||||||
val item = filterValue.value
|
val goods = filterValue.value
|
||||||
item.useWeight = (item.useWeight ?: 0.0) + (entity.useWeight ?: 0.0)
|
goods.useWeight = (goods.useWeight ?: 0.0) + (entity.useWeight ?: 0.0)
|
||||||
item.isSetFinished = true
|
goods.isSetFinished = true
|
||||||
list.forEachIndexed { i, it ->
|
list.forEachIndexed { i, it ->
|
||||||
item.isClicked = i == index
|
it.isClicked = i == index
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list.forEach { it.isClicked = false }
|
list.forEach { it.isClicked = false }
|
||||||
@@ -291,8 +335,8 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
val hasOriginalData = list.any { it.isOriginalData }
|
val hasOriginalData = list.any { it.isOriginalData }
|
||||||
// 接口数据中主材数量
|
// 接口数据中主材数量
|
||||||
val n = list.count { it.isOriginalData && it.materialType == 1 }
|
val n = list.count { it.isOriginalData && it.materialType == 1 }
|
||||||
// 待分配的非接口数据
|
// 待分配的非接口数据(跳过手动指定过主辅材的项)
|
||||||
val nonOriginalList = list.filter { !it.isOriginalData }
|
val nonOriginalList = list.filter { !it.isOriginalData && !it.isMaterialTypeManual }
|
||||||
|
|
||||||
if (hasOriginalData && MATERIAL_COUNT - n <= 0) {
|
if (hasOriginalData && MATERIAL_COUNT - n <= 0) {
|
||||||
// 主材已满,所有非接口数据均为辅材
|
// 主材已满,所有非接口数据均为辅材
|
||||||
@@ -309,6 +353,79 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
materialAdapter.notifyDataSetChanged()
|
materialAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 食材信息录入卡初始化(仅采样模式):
|
||||||
|
* 搜索食材 → 选中回填名称并暂存 GoodsItem(含 materId)→ 选择主辅材 → 输入用量 → 添加
|
||||||
|
*/
|
||||||
|
private fun initIngredientInput() {
|
||||||
|
binding.ivIngredientSearch.setOnClickListener { openIngredientSearch() }
|
||||||
|
binding.etIngredientName.setOnClickListener { openIngredientSearch() }
|
||||||
|
binding.btnReset.setOnClickListener {
|
||||||
|
binding.etAmount.setText("")
|
||||||
|
}
|
||||||
|
binding.btnAdd.clickWithDebounce {
|
||||||
|
addManualIngredient()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 打开食材检索弹窗(食材名称不可手输,点击即搜索) */
|
||||||
|
private fun openIngredientSearch() {
|
||||||
|
if (foodSearchDialog?.isShowing == true) return
|
||||||
|
foodSearchDialog = FoodSearchDialog(
|
||||||
|
activity = this,
|
||||||
|
onItemSelected = { item -> onIngredientSelected(item) }
|
||||||
|
).also { it.show() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 食材检索选中回调:回填名称,暂存 GoodsItem(materId 用于提交)
|
||||||
|
*/
|
||||||
|
private fun onIngredientSelected(item: GoodsItem) {
|
||||||
|
selectedIngredient = item
|
||||||
|
binding.etIngredientName.setText(item.goodsName)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手动添加食材到构成列表:名称(materId)+ 主辅材 + 用量(克,取自秤重)
|
||||||
|
*/
|
||||||
|
private fun addManualIngredient() {
|
||||||
|
val ingredient = selectedIngredient
|
||||||
|
if (ingredient == null || ingredient.materId.isNullOrBlank()) {
|
||||||
|
toast("请先搜索选择食材")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val amount = currentWeight.roundedOneDecimalPlace()
|
||||||
|
if (amount <= 0) {
|
||||||
|
toast("请先称重获取用量")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val type = if (binding.rbAux.isChecked) 2 else 1
|
||||||
|
val existing = list.firstOrNull { it.goodsId == ingredient.goodsId }
|
||||||
|
if (existing != null) {
|
||||||
|
// 已存在同食材:累加用量并同步主辅材
|
||||||
|
existing.useWeight = (existing.useWeight ?: 0.0) + amount
|
||||||
|
existing.materialType = type
|
||||||
|
existing.isMaterialTypeManual = true
|
||||||
|
existing.isSetFinished = true
|
||||||
|
existing.isNewDishType = true
|
||||||
|
} else {
|
||||||
|
ingredient.materialType = type
|
||||||
|
ingredient.useWeight = amount
|
||||||
|
ingredient.isMaterialTypeManual = true
|
||||||
|
ingredient.isNewDishType = true
|
||||||
|
ingredient.isOriginalData = false
|
||||||
|
ingredient.isSetFinished = true
|
||||||
|
ingredient.isClicked = false
|
||||||
|
list.add(ingredient)
|
||||||
|
binding.rvMaterialList.smoothScrollToPosition(list.size - 1)
|
||||||
|
}
|
||||||
|
// 清空录入区
|
||||||
|
selectedIngredient = null
|
||||||
|
binding.etIngredientName.setText("")
|
||||||
|
binding.etAmount.setText("")
|
||||||
|
updateMaterialTypes()
|
||||||
|
}
|
||||||
|
|
||||||
private fun openSubmitPage() {
|
private fun openSubmitPage() {
|
||||||
getGoodsList()
|
getGoodsList()
|
||||||
if (goodsList.isNullOrEmpty()) {
|
if (goodsList.isNullOrEmpty()) {
|
||||||
@@ -319,12 +436,15 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
startActivity<SubmitFoodActivity> {
|
startActivity<SubmitFoodActivity> {
|
||||||
putExtra(SubmitFoodActivity.GOODS_LIST, goodsList as Serializable)
|
putExtra(SubmitFoodActivity.GOODS_LIST, goodsList as Serializable)
|
||||||
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
|
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
|
||||||
|
putExtra(SubmitFoodActivity.COOK_ORDER_ID, cookOrderId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getGoodsList() {
|
private fun getGoodsList() {
|
||||||
if (goodsList == null) {
|
if (goodsList == null) {
|
||||||
goodsList = mutableListOf()
|
goodsList = mutableListOf()
|
||||||
|
} else {
|
||||||
|
goodsList!!.clear()
|
||||||
}
|
}
|
||||||
// 将 GoodsItem 转换为 CookFoodGoodsEntity 并补充菜品相关字段
|
// 将 GoodsItem 转换为 CookFoodGoodsEntity 并补充菜品相关字段
|
||||||
list.filter { it.isSetFinished }.forEach {
|
list.filter { it.isSetFinished }.forEach {
|
||||||
@@ -346,16 +466,17 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
|
|
||||||
|
|
||||||
private fun initObserver() {
|
private fun initObserver() {
|
||||||
|
// 新配比秤接口 observer(制作模式使用)
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
netViewModel.foodDetailState.collect { state ->
|
netViewModel.cookOrderCompositionState.collect { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
is UiState.Success -> {
|
is UiState.Success -> {
|
||||||
val detail = state.data
|
val items = state.data
|
||||||
if (detail == null) {
|
if (items.isNullOrEmpty()) {
|
||||||
toast("查询菜品信息为空")
|
toast("查询菜品构成为空")
|
||||||
return@collect
|
return@collect
|
||||||
}
|
}
|
||||||
loadDishDetail(detail)
|
loadDishComposition(items)
|
||||||
}
|
}
|
||||||
is UiState.Error -> toast(state.msg)
|
is UiState.Error -> toast(state.msg)
|
||||||
else -> {}
|
else -> {}
|
||||||
@@ -364,22 +485,74 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 新接口:通过 foodId 查询菜品构成(采样模式称量模板) */
|
||||||
private fun getDishDetail(foodId: String) {
|
private fun getDishDetail(foodId: String) {
|
||||||
netViewModel.getFoodDetail(foodId)
|
netViewModel.getFoodComposition(
|
||||||
|
foodId = foodId,
|
||||||
|
onResult = { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> {
|
||||||
|
val response = state.data
|
||||||
|
if (response == null) {
|
||||||
|
toast("查询菜品构成为空")
|
||||||
|
} else {
|
||||||
|
loadFoodComposition(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is UiState.Error -> toast(state.msg)
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新接口:通过 cookOrderId 查询菜品食材构成(制作模式使用) */
|
||||||
|
private fun getCookOrderComposition(cookOrderId: String) {
|
||||||
|
netViewModel.getCookOrderComposition(cookOrderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun loadDishDetail(detail: CookFoodDTO) {
|
/**
|
||||||
// val voList = detail.stFoodInfoConstituteList
|
* 采样模式:将 food/{foodId}/composition 返回的构成映射为 GoodsItem 并刷新 UI
|
||||||
val voList = detail.foodConstituteList
|
* 筛选主材(1)/辅材(2),调料(3)仍走槽位秤;useWeight 置零待重新称量
|
||||||
if (voList.isNullOrEmpty()) {
|
*/
|
||||||
return
|
private fun loadFoodComposition(response: FoodCompositionResponse) {
|
||||||
|
val tempData = response.ingredients
|
||||||
|
.filter { it.isMain == 1 || it.isMain == 2 }
|
||||||
|
.map {
|
||||||
|
GoodsItem(
|
||||||
|
goodsId = it.materId,
|
||||||
|
materId = it.materId,
|
||||||
|
goodsName = it.materName,
|
||||||
|
materialType = it.isMain,
|
||||||
|
useWeight = 0.0,
|
||||||
|
isOriginalData = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
list.clear()
|
||||||
|
list.addAll(tempData)
|
||||||
|
materialAdapter.items = list
|
||||||
|
materialAdapter.notifyDataSetChanged()
|
||||||
|
firstReqSize = list.size
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将新配比秤接口的食材构成列表映射为 GoodsItem 并刷新 UI
|
||||||
|
* 新接口天然仅返回主材(ingredientClass=1)和辅材(ingredientClass=2),不含调料
|
||||||
|
* useWeight 保留接口返回值,不再强制置零
|
||||||
|
*/
|
||||||
|
private fun loadDishComposition(items: List<CookOrderCompositionItem>) {
|
||||||
|
val tempData = items.map { item ->
|
||||||
|
GoodsItem(
|
||||||
|
goodsId = item.materId,
|
||||||
|
goodsName = item.ingredientName,
|
||||||
|
materId = item.materId,
|
||||||
|
materialType = item.ingredientClass,
|
||||||
|
useWeight = item.useWeight,
|
||||||
|
rawMaterialsType = item.vegTypeId,
|
||||||
|
isOriginalData = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
// 筛选出主材和辅材,转换为 GoodsItem(useWeight 置零)
|
|
||||||
val tempData = voList.filter { it.materialType == 1 || it.materialType == 2 }
|
|
||||||
.map { it.toGoodsItem().also { item -> item.useWeight = 0.0 } }
|
|
||||||
// 直接替换 adapter.items,确保 adapter 数据源被完全替换
|
|
||||||
// 同时同步外部 list,保证后续 updateMaterialTypes/removeFood 等操作正确
|
|
||||||
list.clear()
|
list.clear()
|
||||||
list.addAll(tempData)
|
list.addAll(tempData)
|
||||||
materialAdapter.items = list
|
materialAdapter.items = list
|
||||||
@@ -391,15 +564,21 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
private val list = mutableListOf<GoodsItem>()
|
private val list = mutableListOf<GoodsItem>()
|
||||||
private val materialAdapter by lazy {
|
private val materialAdapter by lazy {
|
||||||
FoodMaterialAdapter(list).apply {
|
FoodMaterialAdapter(list).apply {
|
||||||
onItemClick = { positon ->
|
onItemClick = { position ->
|
||||||
list.forEachIndexed { index, entity ->
|
list.forEachIndexed { index, entity ->
|
||||||
entity.isClicked = index == positon
|
entity.isClicked = index == position
|
||||||
|
}
|
||||||
|
// 选中食材时同步当前秤重(制作/采样均支持)
|
||||||
|
val item = list.getOrNull(position)
|
||||||
|
if (item != null && currentWeight > 0) {
|
||||||
|
item.useWeight = currentWeight
|
||||||
|
item.isSetFinished = true
|
||||||
}
|
}
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
addOnItemChildClickListener(R.id.ivClearIcon) { _, _, position ->
|
addOnItemChildClickListener(R.id.ivClearIcon) { _, _, position ->
|
||||||
Log.d(TAG, "onFoodItemClick: ${list[position].toJsonString()}")
|
val item = list.getOrNull(position) ?:return@addOnItemChildClickListener
|
||||||
val item = list[position]
|
Log.d(TAG, "onFoodItemClick: ${item.toJsonString()}")
|
||||||
if (item.isOriginalData) {
|
if (item.isOriginalData) {
|
||||||
// 无重量信息时转为 item 整体点击(触发选中效果)
|
// 无重量信息时转为 item 整体点击(触发选中效果)
|
||||||
if (item.useWeight == null || item.useWeight == 0.0) {
|
if (item.useWeight == null || item.useWeight == 0.0) {
|
||||||
@@ -431,9 +610,9 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
private fun initRecyclerView() {
|
private fun initRecyclerView() {
|
||||||
binding.rvMaterialList.let {
|
binding.rvMaterialList.let {
|
||||||
it.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
it.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
||||||
// 仅 isNewDishType=true 的 item 显示侧滑删除菜单(必须在 setAdapter 之前调用)
|
// 采样模式下所有食材均可侧滑删除(必须在 setAdapter 之前调用)
|
||||||
it.setSwipeMenuCreator { _, rightMenu, position ->
|
it.setSwipeMenuCreator { _, rightMenu, position ->
|
||||||
if (list.getOrNull(position)?.isNewDishType == true) {
|
if (SpTool.cookMode == 1) {
|
||||||
rightMenu.addMenuItem(buildDeleteMenuItem())
|
rightMenu.addMenuItem(buildDeleteMenuItem())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -492,13 +671,17 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
pageVisible = true
|
pageVisible = true
|
||||||
showRecognizePage = false
|
showRecognizePage = false
|
||||||
cameraUtils.bind()
|
if (SpTool.cookMode == 1) {
|
||||||
|
cameraUtils.bind()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
pageVisible = false
|
pageVisible = false
|
||||||
cameraUtils.unbind()
|
if (SpTool.cookMode == 1) {
|
||||||
|
cameraUtils.unbind()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -595,7 +778,12 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
notRecognizeDialog = CommonDialog(this)
|
notRecognizeDialog = CommonDialog(this)
|
||||||
.setTitle("提示")
|
.setTitle("提示")
|
||||||
.setContent("未识别到食材,请稍后重试")
|
.setContent("未识别到食材,请稍后重试")
|
||||||
.setNegativeButton("取消")
|
.setNegativeButton("取消") {
|
||||||
|
manualCancelFlag = true
|
||||||
|
}
|
||||||
|
.setNeutralButton("重新识别") {
|
||||||
|
recognizeFood(currentWeight)
|
||||||
|
}
|
||||||
.setPositiveButton("手动设置"){
|
.setPositiveButton("手动设置"){
|
||||||
loadRecognizeResultPage(emptyList())
|
loadRecognizeResultPage(emptyList())
|
||||||
}
|
}
|
||||||
@@ -629,6 +817,7 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
activity = this,
|
activity = this,
|
||||||
imageUri = lastPhotoUri?.toString(),
|
imageUri = lastPhotoUri?.toString(),
|
||||||
currentWeight = currentWeight,
|
currentWeight = currentWeight,
|
||||||
|
initialWeight = initialWeight,
|
||||||
nameScoreList = ArrayList(nameScoreList),
|
nameScoreList = ArrayList(nameScoreList),
|
||||||
finishCallback = { isManualCancel, entity ->
|
finishCallback = { isManualCancel, entity ->
|
||||||
Log.d(
|
Log.d(
|
||||||
|
|||||||
@@ -3,22 +3,21 @@ package com.shuwei.dish.match.ui
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.activity.addCallback
|
import androidx.activity.addCallback
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.adapter.FoodListAdapter
|
import com.shuwei.dish.match.adapter.FoodListAdapter
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
|
||||||
import com.shuwei.dish.match.databinding.ActivitySamplingModeBinding
|
import com.shuwei.dish.match.databinding.ActivitySamplingModeBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
import com.shuwei.dish.match.model.SampleHistoryItem
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.utils.DateTimeUtil
|
import com.shuwei.dish.match.utils.DateTimeUtil
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
@@ -49,83 +48,16 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
setHeaderBackground()
|
setHeaderBackground()
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
addViewListener()
|
addViewListener()
|
||||||
initObserver()
|
|
||||||
requestData(true)
|
requestData(true)
|
||||||
onBackPressedDispatcher.addCallback(this) { }
|
onBackPressedDispatcher.addCallback(this) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 收集 cookFoodListState,将本地烹饪中数据渲染到列表
|
|
||||||
*/
|
|
||||||
private fun initObserver() {
|
|
||||||
lifecycleScope.launch {
|
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
||||||
appViewModel.cookFoodListState.collect { cookFoodEntities ->
|
|
||||||
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingCooking) return@collect
|
|
||||||
delayDismissLoading()
|
|
||||||
if (cookFoodEntities.isNullOrEmpty()) {
|
|
||||||
loadEmptyView()
|
|
||||||
return@collect
|
|
||||||
}
|
|
||||||
val tempList = mutableListOf<FoodRecord>()
|
|
||||||
cookFoodEntities.sortedByDescending { DateTimeUtil.convert(dateStr = it.createTime) }
|
|
||||||
.forEach { entity ->
|
|
||||||
tempList.add(FoodRecord().apply {
|
|
||||||
foodId = entity.foodId
|
|
||||||
foodName = entity.foodName
|
|
||||||
cookMode = 1
|
|
||||||
isCooking = true
|
|
||||||
dinnerType = entity.dinnerType ?: "0"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
list.clear()
|
|
||||||
list.addAll(tempList)
|
|
||||||
dishAdapter.notifyDataSetChanged()
|
|
||||||
finishRefresh()
|
|
||||||
binding.refreshLayout.run {
|
|
||||||
setEnableRefresh(false)
|
|
||||||
setEnableLoadMore(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lifecycleScope.launch {
|
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
||||||
netViewModel.samplingListState.collect { state ->
|
|
||||||
when (state) {
|
|
||||||
is UiState.Loading -> showLoading()
|
|
||||||
is UiState.Success -> {
|
|
||||||
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingFinished) {
|
|
||||||
delayDismissLoading()
|
|
||||||
return@collect
|
|
||||||
}
|
|
||||||
loadDishList(state.data)
|
|
||||||
}
|
|
||||||
is UiState.Error -> {
|
|
||||||
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingFinished) {
|
|
||||||
delayDismissLoading()
|
|
||||||
return@collect
|
|
||||||
}
|
|
||||||
binding.refreshLayout.setEnableRefresh(true)
|
|
||||||
toast(state.msg)
|
|
||||||
finishRefresh()
|
|
||||||
delayDismissLoading()
|
|
||||||
if (pageNo == 1) loadEmptyView()
|
|
||||||
}
|
|
||||||
is UiState.Idle -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun setTitleBar() {
|
private fun setTitleBar() {
|
||||||
setTitleBar(titleBarAction = {
|
setTitleBar(titleBarAction = {
|
||||||
it.visible()
|
it.visible()
|
||||||
}, titleAction = {
|
}, titleAction = {
|
||||||
it.text = "采样历史"
|
it.text = "采样历史"
|
||||||
}, rightIconActon = {
|
}, rightIconAction = {
|
||||||
it.visible()
|
it.visible()
|
||||||
it.setImageResource(R.drawable.ic_setting)
|
it.setImageResource(R.drawable.ic_setting)
|
||||||
it.setOnClickListener {
|
it.setOnClickListener {
|
||||||
@@ -134,22 +66,44 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
}, backAction = {
|
}, backAction = {
|
||||||
it.gone()
|
it.gone()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
|
|
||||||
fun getCookFoodList() {
|
fun getCookFoodList() {
|
||||||
val checkedId = binding.dishRadioGroup.checkedRadioButtonId
|
dbViewModel.getCookFoodListWithCallback(cookMode = 1) { cookFoodEntities ->
|
||||||
if (checkedId == R.id.rbSamplingCooking) {
|
// 回调期间用户可能已切换 Tab,需再次校验
|
||||||
appViewModel.getCookFoodList(cookMode = 1)
|
if (binding.rbSamplingCooking.isChecked.not()) return@getCookFoodListWithCallback
|
||||||
}
|
delayDismissLoading()
|
||||||
|
if (cookFoodEntities.isNullOrEmpty()) {
|
||||||
|
loadEmptyView()
|
||||||
|
return@getCookFoodListWithCallback
|
||||||
|
}
|
||||||
|
val tempList = mutableListOf<FoodRecord>()
|
||||||
|
cookFoodEntities.sortedByDescending { DateTimeUtil.convert(dateStr = it.createTime) }
|
||||||
|
.forEach { entity ->
|
||||||
|
tempList.add(FoodRecord().apply {
|
||||||
|
foodId = entity.foodId
|
||||||
|
foodName = entity.foodName
|
||||||
|
cookMode = 1
|
||||||
|
isCooking = true
|
||||||
|
dinnerType = entity.dinnerType ?: "0"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
list.clear()
|
||||||
|
list.addAll(tempList)
|
||||||
|
dishAdapter.notifyDataSetChanged()
|
||||||
|
finishRefresh()
|
||||||
|
binding.refreshLayout.run {
|
||||||
|
setEnableRefresh(false)
|
||||||
|
setEnableLoadMore(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteCookFoodAndGoods(foodId: String, dinnerType: String, action: () -> Unit) {
|
fun deleteCookFoodAndGoods(foodId: String, dinnerType: String, action: () -> Unit) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
appViewModel.deleteCookFoodAndGoods(cookMode = 1, foodId = foodId, dinnerType = dinnerType)
|
dbViewModel.deleteCookFoodAndGoods(cookMode = 1, foodId = foodId, dinnerType = dinnerType)
|
||||||
action()
|
action()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,11 +111,13 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
val isConfigPage = intent?.getBooleanExtra(IS_CONFIG_PAGE, false) ?: false
|
val isConfigPage = intent?.getBooleanExtra(IS_CONFIG_PAGE, false) ?: false
|
||||||
|
Log.d(TAG, "onNewIntent, isConfigPage=$isConfigPage")
|
||||||
if (isConfigPage) {
|
if (isConfigPage) {
|
||||||
getCookFoodList()
|
getCookFoodList()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
|
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
|
||||||
|
Log.d(TAG, "onNewIntent, isCooking=$isCooking")
|
||||||
//toast("isCooking=$isCooking")
|
//toast("isCooking=$isCooking")
|
||||||
refreshPage(isCooking)
|
refreshPage(isCooking)
|
||||||
}
|
}
|
||||||
@@ -252,7 +208,7 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
binding.refreshLayout.setOnRefreshListener {
|
binding.refreshLayout.setOnRefreshListener {
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
if (binding.dishRadioGroup.checkedRadioButtonId == R.id.rbSamplingFinished) {
|
if (binding.rbSamplingFinished.isChecked) {
|
||||||
getSamplingList()
|
getSamplingList()
|
||||||
} else {
|
} else {
|
||||||
finishRefresh()
|
finishRefresh()
|
||||||
@@ -260,30 +216,33 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.refreshLayout.setOnLoadMoreListener {
|
binding.refreshLayout.setOnLoadMoreListener {
|
||||||
if (binding.dishRadioGroup.checkedRadioButtonId == R.id.rbSamplingFinished) {
|
if (binding.rbSamplingFinished.isChecked) {
|
||||||
getSamplingList()
|
getSamplingList()
|
||||||
} else {
|
} else {
|
||||||
finishRefresh()
|
finishRefresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.rbSamplingCooking.setOnClickListener {
|
binding.rbSamplingCooking.let {
|
||||||
// Log.d(TAG, "addViewListener: cooking:${binding.rbSamplingCooking.isChecked}")
|
it.setOnClickListener { _ ->
|
||||||
if (it.tag == true) {
|
if (it.isChecked) {
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
binding.rbSamplingCooking.isChecked = true
|
||||||
|
binding.rbSamplingFinished.isChecked = false
|
||||||
|
requestData(true)
|
||||||
}
|
}
|
||||||
requestData(true)
|
|
||||||
binding.rbSamplingCooking.tag = binding.rbSamplingCooking.isChecked
|
|
||||||
binding.rbSamplingFinished.tag = binding.rbSamplingFinished.isChecked
|
|
||||||
}
|
}
|
||||||
binding.rbSamplingFinished.setOnClickListener {
|
binding.rbSamplingFinished.let {
|
||||||
|
it.setOnClickListener { _ ->
|
||||||
// Log.d(TAG, "addViewListener: finish:${binding.rbSamplingFinished.isChecked}")
|
// Log.d(TAG, "addViewListener: finish:${binding.rbSamplingFinished.isChecked}")
|
||||||
if (it.tag == true) {
|
if (it.isChecked) {
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
binding.rbSamplingCooking.isChecked = false
|
||||||
|
binding.rbSamplingFinished.isChecked = true
|
||||||
|
requestData(false)
|
||||||
}
|
}
|
||||||
requestData(false)
|
|
||||||
binding.rbSamplingCooking.tag = binding.rbSamplingCooking.isChecked
|
|
||||||
binding.rbSamplingFinished.tag = binding.rbSamplingFinished.isChecked
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,15 +251,47 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
fun getSamplingList() {
|
fun getSamplingList() {
|
||||||
netViewModel.getSamplingList(
|
netViewModel.sampleHistory(
|
||||||
param = mutableMapOf(
|
pageNum = pageNo,
|
||||||
"pageNum" to pageNo,
|
pageSize = pageSize,
|
||||||
"pageSize" to pageSize,
|
onLoading = { showLoading() }
|
||||||
"placeId" to BaseApp.canteenId
|
) { state ->
|
||||||
)
|
when (state) {
|
||||||
)
|
is UiState.Success -> {
|
||||||
|
// 回调期间用户可能已切换 Tab,需再次校验
|
||||||
|
if (binding.rbSamplingFinished.isChecked.not()) {
|
||||||
|
delayDismissLoading()
|
||||||
|
return@sampleHistory
|
||||||
|
}
|
||||||
|
loadDishList(state.data?.map { it.toFoodRecord() }?.toMutableList())
|
||||||
|
}
|
||||||
|
is UiState.Error -> {
|
||||||
|
if (binding.rbSamplingFinished.isChecked.not()) {
|
||||||
|
delayDismissLoading()
|
||||||
|
return@sampleHistory
|
||||||
|
}
|
||||||
|
binding.refreshLayout.setEnableRefresh(true)
|
||||||
|
toast(state.msg)
|
||||||
|
finishRefresh()
|
||||||
|
delayDismissLoading()
|
||||||
|
if (pageNo == 1) loadEmptyView()
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 已提交采样列表条目 → FoodRecord 映射,供 FoodListAdapter(SAMPLING_MODE) 展示 */
|
||||||
|
private fun SampleHistoryItem.toFoodRecord(): FoodRecord = FoodRecord(
|
||||||
|
foodId = innovId,
|
||||||
|
foodName = foodName,
|
||||||
|
foodWeight = foodWeight,
|
||||||
|
cookMode = 1,
|
||||||
|
innovNo = innovNo,
|
||||||
|
status = status,
|
||||||
|
statusName = statusName
|
||||||
|
)
|
||||||
|
|
||||||
private fun finishRefresh() {
|
private fun finishRefresh() {
|
||||||
if (pageNo == 1) {
|
if (pageNo == 1) {
|
||||||
binding.refreshLayout.finishRefresh(1200)
|
binding.refreshLayout.finishRefresh(1200)
|
||||||
@@ -321,7 +312,7 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
emptyViewBinding!!.tvContent.text = "暂无数据"
|
emptyViewBinding!!.tvContent.text = "暂无数据"
|
||||||
emptyViewBinding!!.tvSubContent.text = "今日暂无采样数据,点击下方按钮新增采样"
|
emptyViewBinding!!.tvSubContent.text = "暂无采样数据,点击下方按钮新增采样"
|
||||||
|
|
||||||
// 方案B:沿用 adapter stateView,使用 FrameLayout.LayoutParams + minimumHeight 避免空态贴顶
|
// 方案B:沿用 adapter stateView,使用 FrameLayout.LayoutParams + minimumHeight 避免空态贴顶
|
||||||
emptyViewBinding!!.root.layoutParams = FrameLayout.LayoutParams(
|
emptyViewBinding!!.root.layoutParams = FrameLayout.LayoutParams(
|
||||||
@@ -336,18 +327,18 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
//dishAdapter.setStateViewLayout(requireContext(), R.layout-sw800dp.layout_empty_view)
|
//dishAdapter.setStateViewLayout(requireContext(), R.layout-sw800dp.layout_empty_view)
|
||||||
|
|
||||||
binding.refreshLayout.run {
|
binding.refreshLayout.run {
|
||||||
setEnableRefresh(binding.dishRadioGroup.checkedRadioButtonId == R.id.rbSamplingFinished)
|
setEnableRefresh(binding.rbSamplingFinished.isChecked)
|
||||||
setEnableLoadMore(false)
|
setEnableLoadMore(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshPage(isCooking: Boolean) {
|
fun refreshPage(isCooking: Boolean) {
|
||||||
val checkedId = binding.dishRadioGroup.checkedRadioButtonId
|
if (binding.rbSamplingFinished.isChecked) {
|
||||||
if (checkedId == R.id.rbSamplingFinished) {
|
|
||||||
//当前是已采样
|
//当前是已采样
|
||||||
if (isCooking) {
|
if (isCooking) {
|
||||||
//需要切换到烹饪中
|
//需要切换到烹饪中
|
||||||
binding.dishRadioGroup.check(R.id.rbSamplingCooking)
|
binding.rbSamplingCooking.isChecked = true
|
||||||
|
binding.rbSamplingFinished.isChecked = false
|
||||||
requestData(true)
|
requestData(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -358,7 +349,8 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
//当前是烹饪中
|
//当前是烹饪中
|
||||||
if (isCooking.not()) {
|
if (isCooking.not()) {
|
||||||
//需要切换到已采样
|
//需要切换到已采样
|
||||||
binding.dishRadioGroup.check(R.id.rbSamplingFinished)
|
binding.rbSamplingCooking.isChecked = false
|
||||||
|
binding.rbSamplingFinished.isChecked = true
|
||||||
requestData(false)
|
requestData(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -366,21 +358,17 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
requestData(true)
|
requestData(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
|
||||||
fun refreshLocalData() {
|
fun refreshLocalData() {
|
||||||
showLoading()
|
showLoading()
|
||||||
appViewModel.resetCookFoodList()
|
|
||||||
getCookFoodList()
|
getCookFoodList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun requestData(isCooking: Boolean) {
|
private fun requestData(isCooking: Boolean) {
|
||||||
|
list.clear()
|
||||||
|
dishAdapter.notifyDataSetChanged()
|
||||||
if (isCooking) {
|
if (isCooking) {
|
||||||
// 清除上次网络请求的残留状态
|
|
||||||
netViewModel.resetSamplingListState()
|
|
||||||
refreshLocalData()
|
refreshLocalData()
|
||||||
} else {
|
} else {
|
||||||
// 同理,清除本地数据残留状态
|
|
||||||
appViewModel.resetCookFoodList()
|
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
getSamplingList()
|
getSamplingList()
|
||||||
}
|
}
|
||||||
@@ -419,7 +407,7 @@ class SamplingModeActivity : BaseActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val slots = appViewModel.loadSeasoningSlot()
|
val slots = dbViewModel.loadSeasoningSlot()
|
||||||
if (slots.isEmpty()) {
|
if (slots.isEmpty()) {
|
||||||
showDeviceConfigDialog()
|
showDeviceConfigDialog()
|
||||||
return@launch
|
return@launch
|
||||||
|
|||||||
@@ -9,19 +9,23 @@ import android.os.Build
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.chad.library.adapter4.util.setOnDebouncedItemClick
|
||||||
|
import com.shuwei.dish.match.adapter.SettingAdapter
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.databinding.ActivitySettingBinding
|
import com.shuwei.dish.match.databinding.ActivitySettingBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
|
import com.shuwei.dish.match.dialog.EnvSwitchDialog
|
||||||
|
import com.shuwei.dish.match.model.SettingItem
|
||||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||||
import com.shuwei.dish.match.utils.SpTool
|
import com.shuwei.dish.match.utils.SpTool
|
||||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
import com.shuwei.dish.match.utils.ext.startActivity
|
import com.shuwei.dish.match.utils.ext.startActivity
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置Activity
|
* 设置页面
|
||||||
* 功能:管理多个设置相关的Fragment,支持Fragment切换
|
* 使用 RecyclerView 展示设置菜单项,点击逻辑内聚在各 SettingItem 的 onClick 中
|
||||||
*/
|
*/
|
||||||
class SettingActivity : BaseActivity() {
|
class SettingActivity : BaseActivity() {
|
||||||
|
|
||||||
@@ -30,10 +34,15 @@ class SettingActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var binding: ActivitySettingBinding
|
private lateinit var binding: ActivitySettingBinding
|
||||||
// private val cameraUtils: CameraUtils by lazy {
|
|
||||||
// CameraUtils(this)
|
/** 包含全部菜单项的完整列表(含隐藏项) */
|
||||||
// }
|
private val allItems: List<SettingItem> by lazy { buildAllItems() }
|
||||||
// private lateinit var previewView: PreviewView
|
|
||||||
|
private val adapter = SettingAdapter().apply {
|
||||||
|
setOnDebouncedItemClick { _, _, position ->
|
||||||
|
getItem(position)?.onClick()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -43,53 +52,93 @@ class SettingActivity : BaseActivity() {
|
|||||||
setTitleBar(titleBarAction = {
|
setTitleBar(titleBarAction = {
|
||||||
it.visible()
|
it.visible()
|
||||||
}, titleAction = {
|
}, titleAction = {
|
||||||
it.text = "设备设置"
|
it.text = "设置"
|
||||||
}, rightIconActon = {
|
}, rightIconAction = {
|
||||||
it.visible()
|
it.visible()
|
||||||
|
// 点击右上角图标,展示全部隐藏的开发者选项
|
||||||
it.clickWithDebounce {
|
it.clickWithDebounce {
|
||||||
binding.llDbInspect.visible()
|
adapter.submitList(allItems.toList())
|
||||||
binding.llScaleObserve.visible()
|
|
||||||
binding.llClearData.visible()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
initView()
|
initView()
|
||||||
|
|
||||||
// // 默认显示设备配置Fragment
|
|
||||||
// if (savedInstanceState == null) {
|
|
||||||
// showDeviceConfigFragment()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// initUI()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
binding.tvCurrentMode.text = when (SpTool.cookMode) {
|
binding.rvSettings.layoutManager = LinearLayoutManager(this)
|
||||||
0 -> "当前:制作模式"
|
binding.rvSettings.adapter = adapter
|
||||||
1 -> "当前:采样模式"
|
// 默认只展示非隐藏项
|
||||||
else -> "当前:未知模式"
|
adapter.submitList(allItems.filter { !it.isHidden })
|
||||||
}
|
|
||||||
binding.llCookMode.clickWithDebounce {
|
|
||||||
SingleFragmentActivity.start(this, SingleFragmentActivity.PageType.COOK_MODE)
|
|
||||||
}
|
|
||||||
binding.llSeasoningConfig.clickWithDebounce {
|
|
||||||
SingleFragmentActivity.start(this, SingleFragmentActivity.PageType.SEASONING_CONFIG)
|
|
||||||
}
|
|
||||||
binding.llFoodCollect.clickWithDebounce {
|
|
||||||
checkCameraPermission()
|
|
||||||
}
|
|
||||||
binding.llDbInspect.clickWithDebounce {
|
|
||||||
SingleFragmentActivity.start(this, SingleFragmentActivity.PageType.DB_INSPECT)
|
|
||||||
}
|
|
||||||
binding.llScaleObserve.clickWithDebounce {
|
|
||||||
startActivity<MasterScaleActivity>()
|
|
||||||
}
|
|
||||||
binding.llClearData.clickWithDebounce {
|
|
||||||
showClearDataDialog()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建完整的设置菜单列表,每项的 onClick 直接注入对应业务逻辑
|
||||||
|
*/
|
||||||
|
private fun buildAllItems(): List<SettingItem> = listOf(
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.COOK_MODE,
|
||||||
|
title = "菜品模式",
|
||||||
|
subtitle = when (SpTool.cookMode) {
|
||||||
|
0 -> "当前:制作模式"
|
||||||
|
1 -> "当前:采样模式"
|
||||||
|
else -> "当前:未知模式"
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
SingleFragmentActivity.start(this, SingleFragmentActivity.PageType.COOK_MODE)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.SEASONING_CONFIG,
|
||||||
|
title = "调料区设置",
|
||||||
|
onClick = {
|
||||||
|
SingleFragmentActivity.start(this, SingleFragmentActivity.PageType.SEASONING_CONFIG)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.FOOD_COLLECT,
|
||||||
|
title = "食材采集",
|
||||||
|
onClick = { checkCameraPermission() }
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.WEIGHT_CONFIG,
|
||||||
|
title = "减重配置",
|
||||||
|
onClick = {
|
||||||
|
SingleFragmentActivity.start(this, SingleFragmentActivity.PageType.WEIGHT_CONFIG)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.DB_INSPECT,
|
||||||
|
title = "数据库查看",
|
||||||
|
isHidden = true,
|
||||||
|
onClick = {
|
||||||
|
SingleFragmentActivity.start(this, SingleFragmentActivity.PageType.DB_INSPECT)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.SCALE_OBSERVE,
|
||||||
|
title = "秤数据监控",
|
||||||
|
isHidden = true,
|
||||||
|
onClick = { startActivity<MasterScaleActivity>() }
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.ENV_SWITCH,
|
||||||
|
title = "切换环境",
|
||||||
|
onClick = { EnvSwitchDialog(this).show() }
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.CLEAR_DATA,
|
||||||
|
title = "数据清除",
|
||||||
|
isHidden = true,
|
||||||
|
onClick = { showClearDataDialog() }
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
type = SettingItem.Type.TEST_SEASONING,
|
||||||
|
title = "测试调料拿取",
|
||||||
|
isHidden = true,
|
||||||
|
onClick = { startActivity<SubmitFoodActivity> { } }
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 弹出清除测试数据的二次确认弹窗
|
* 弹出清除测试数据的二次确认弹窗
|
||||||
*/
|
*/
|
||||||
@@ -99,14 +148,12 @@ class SettingActivity : BaseActivity() {
|
|||||||
.setContent("将物理删除全部 4 张表数据(菜品、食材、调料、槽位),此操作不可恢复,同时重置菜品模式和食堂id,确认继续?")
|
.setContent("将物理删除全部 4 张表数据(菜品、食材、调料、槽位),此操作不可恢复,同时重置菜品模式和食堂id,确认继续?")
|
||||||
.setNegativeButton("取消")
|
.setNegativeButton("取消")
|
||||||
.setPositiveButton("确认") {
|
.setPositiveButton("确认") {
|
||||||
appViewModel.clearAllData {
|
dbViewModel.clearAllData {
|
||||||
SpTool.cookMode = -1
|
SpTool.cookMode = -1
|
||||||
SpTool.canteenId = "0"
|
SpTool.canteenId = "0"
|
||||||
// 通知所有已连接子设备同步清除数据
|
// 通知所有已连接子设备同步清除数据
|
||||||
ScaleServiceManager.sendClearData()
|
ScaleServiceManager.sendClearData()
|
||||||
startActivity<HomeActivity> {
|
startActivity<InitActivity>()
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
@@ -117,12 +164,11 @@ class SettingActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查相机权限并显示 CollectFragment
|
* 检查相机权限,有权限则直接打开采集页,否则发起授权请求
|
||||||
*/
|
*/
|
||||||
@SuppressLint("ObsoleteSdkInt")
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
private fun checkCameraPermission() {
|
private fun checkCameraPermission() {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||||
// Android 6.0 以下,直接打开
|
|
||||||
openCollectPage()
|
openCollectPage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -131,16 +177,12 @@ class SettingActivity : BaseActivity() {
|
|||||||
Manifest.permission.CAMERA
|
Manifest.permission.CAMERA
|
||||||
) == PackageManager.PERMISSION_GRANTED
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
) {
|
) {
|
||||||
// 权限已授予,直接打开
|
|
||||||
openCollectPage()
|
openCollectPage()
|
||||||
} else {
|
} else {
|
||||||
// 权限未授予,申请权限
|
|
||||||
requestPermission(Manifest.permission.CAMERA) { isGranted ->
|
requestPermission(Manifest.permission.CAMERA) { isGranted ->
|
||||||
if (isGranted) {
|
if (isGranted) {
|
||||||
// 权限已授予,直接打开
|
|
||||||
openCollectPage()
|
openCollectPage()
|
||||||
} else {
|
} else {
|
||||||
// 权限被拒绝
|
|
||||||
showNotGrantedCameraPermissionDialog()
|
showNotGrantedCameraPermissionDialog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,197 +204,4 @@ class SettingActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 初始化UI和事件监听
|
|
||||||
// */
|
|
||||||
// private fun initUI() {
|
|
||||||
// // 设备配置按钮点击事件
|
|
||||||
// binding.btnDeviceConfig.setOnClickListener {
|
|
||||||
// showDeviceConfigFragment()
|
|
||||||
//
|
|
||||||
// loadTabStyle(button = binding.btnDeviceConfig, isSelected = true)
|
|
||||||
// loadTabStyle(button = binding.btnSeasoningConfig, isSelected = false)
|
|
||||||
// loadTabStyle(button = binding.btnFoodCollect, isSelected = false)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 调料配置按钮点击事件
|
|
||||||
// binding.btnSeasoningConfig.setOnClickListener {
|
|
||||||
// showSeasoningConfigFragment()
|
|
||||||
//
|
|
||||||
// loadTabStyle(button = binding.btnDeviceConfig, isSelected = false)
|
|
||||||
// loadTabStyle(button = binding.btnSeasoningConfig, isSelected = true)
|
|
||||||
// loadTabStyle(button = binding.btnFoodCollect, isSelected = false)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 菜品采集按钮点击事件
|
|
||||||
// binding.btnFoodCollect.setOnClickListener {
|
|
||||||
// checkCameraPermissionAndShowFragment()
|
|
||||||
//
|
|
||||||
// loadTabStyle(button = binding.btnDeviceConfig, isSelected = false)
|
|
||||||
// loadTabStyle(button = binding.btnSeasoningConfig, isSelected = false)
|
|
||||||
// loadTabStyle(button = binding.btnFoodCollect, isSelected = true)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 主设备显示「秤数据监控」入口
|
|
||||||
// if (GlobalData.deviceRole == DeviceRole.MASTER) {
|
|
||||||
// binding.btnScaleMonitor.visible()
|
|
||||||
// binding.btnScaleMonitor.setOnClickListener {
|
|
||||||
// startActivity<MasterScaleActivity>()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 初始化按钮颜色(默认设备配置为选中状态)
|
|
||||||
//
|
|
||||||
// loadTabStyle(button = binding.btnDeviceConfig, isSelected = true)
|
|
||||||
// loadTabStyle(button = binding.btnSeasoningConfig, isSelected = false)
|
|
||||||
// loadTabStyle(button = binding.btnFoodCollect, isSelected = false)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 加载顶部Tab按钮样式
|
|
||||||
// *
|
|
||||||
// * @param button 按钮
|
|
||||||
// * @param isSelected 是否选中
|
|
||||||
// */
|
|
||||||
// private fun loadTabStyle(button: AppCompatButton, isSelected: Boolean) {
|
|
||||||
// button.apply {
|
|
||||||
// if (isSelected){
|
|
||||||
// // 选中
|
|
||||||
// setTextColor(Color.WHITE)
|
|
||||||
// textSize = 28f
|
|
||||||
// setTypeface(null, android.graphics.Typeface.BOLD)
|
|
||||||
// background = ContextCompat.getDrawable(this@SettingActivity, R.drawable.bg_btn_underline)
|
|
||||||
// } else {
|
|
||||||
// // 未选中
|
|
||||||
// setTextColor("#5E7585".toColorInt())
|
|
||||||
// textSize = 26f
|
|
||||||
// setTypeface(null, android.graphics.Typeface.NORMAL)
|
|
||||||
// background = null
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 检查相机权限并显示 CollectFragment
|
|
||||||
// */
|
|
||||||
// @SuppressLint("ObsoleteSdkInt")
|
|
||||||
// private fun checkCameraPermissionAndShowFragment() {
|
|
||||||
// val collectFragment = fragmentList[2]
|
|
||||||
// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
||||||
// // Android 6.0 以下,直接显示 Fragment
|
|
||||||
// showFragment(collectFragment)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if (ContextCompat.checkSelfPermission(
|
|
||||||
// this,
|
|
||||||
// Manifest.permission.CAMERA
|
|
||||||
// ) == PackageManager.PERMISSION_GRANTED
|
|
||||||
// ) {
|
|
||||||
// // 权限已授予,直接显示 Fragment
|
|
||||||
// showFragment(collectFragment)
|
|
||||||
// } else {
|
|
||||||
// // 权限未授予,申请权限
|
|
||||||
// requestPermission(Manifest.permission.CAMERA) { isGranted ->
|
|
||||||
// if (isGranted) {
|
|
||||||
// // 权限已授予,显示 CollectFragment
|
|
||||||
// showFragment(collectFragment)
|
|
||||||
// } else {
|
|
||||||
// // 权限被拒绝
|
|
||||||
// toast("暂无相机权限,无法使用菜品采集功能")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 初始化相机
|
|
||||||
// * @param container 相机预览容器
|
|
||||||
// */
|
|
||||||
// fun initCamera(container: ViewGroup) {
|
|
||||||
// cameraUtils.initCamera()
|
|
||||||
// val previewBinding =
|
|
||||||
// LayoutCameraPreviewBinding.inflate(layoutInflater, container)
|
|
||||||
// previewView = previewBinding.previewView.also {
|
|
||||||
// it.updateLayoutParams {
|
|
||||||
// width = 456.dp
|
|
||||||
// height = 342.dp
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// cameraUtils.setPreviewController(previewView)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Activity 恢复时绑定相机
|
|
||||||
// */
|
|
||||||
// override fun onResume() {
|
|
||||||
// super.onResume()
|
|
||||||
// cameraUtils.bind()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Activity 暂停时解绑相机
|
|
||||||
// */
|
|
||||||
// override fun onPause() {
|
|
||||||
// super.onPause()
|
|
||||||
// cameraUtils.unbind()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 提供给 Fragment 调用的拍照方法
|
|
||||||
// */
|
|
||||||
// fun takePhoto(succCallback: (Uri) -> Unit, failCallback: (msg: String) -> Unit = {}) {
|
|
||||||
// cameraUtils.takePhoto(succCallback = succCallback, failCallback = failCallback)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 显示设备切换Fragment
|
|
||||||
// */
|
|
||||||
// private fun showDeviceConfigFragment() {
|
|
||||||
// showFragment(fragmentList[0])
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 显示设调料配置Fragment
|
|
||||||
// */
|
|
||||||
// private fun showSeasoningConfigFragment() {
|
|
||||||
// showFragment(fragmentList[1])
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private val fragmentList = mutableListOf<Fragment>().apply {
|
|
||||||
// add(DeviceConfigFragment())
|
|
||||||
// add(SeasoningConfigFragment())
|
|
||||||
// add(CollectFragment())
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 显示指定的 Fragment
|
|
||||||
// * 使用 add/show/hide 方式管理 Fragment,避免重复创建
|
|
||||||
// * 已添加的 Fragment 直接显示,未添加的 Fragment 先添加再显示
|
|
||||||
// */
|
|
||||||
// private fun showFragment(fragment: Fragment) {
|
|
||||||
// runCatching {
|
|
||||||
// supportFragmentManager.beginTransaction().apply {
|
|
||||||
// // 如果 Fragment 还未添加到容器中,则添加
|
|
||||||
// if (!fragment.isAdded) {
|
|
||||||
// add(binding.fragmentContainer.id, fragment)
|
|
||||||
// } else {
|
|
||||||
// // 已添加过,直接显示
|
|
||||||
// show(fragment)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 隐藏其他 Fragment
|
|
||||||
// fragmentList.forEach { otherFragment ->
|
|
||||||
// if (otherFragment != fragment && otherFragment.isAdded) {
|
|
||||||
// hide(otherFragment)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// commit()
|
|
||||||
// }
|
|
||||||
// }.onFailure {
|
|
||||||
// it.printStackTrace()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.shuwei.dish.match.ui.fragment.DbInspectFragment
|
|||||||
import com.shuwei.dish.match.ui.fragment.VectorCollectionFragment
|
import com.shuwei.dish.match.ui.fragment.VectorCollectionFragment
|
||||||
import com.shuwei.dish.match.ui.fragment.DeviceConfigFragment
|
import com.shuwei.dish.match.ui.fragment.DeviceConfigFragment
|
||||||
import com.shuwei.dish.match.ui.fragment.SeasoningConfigFragment
|
import com.shuwei.dish.match.ui.fragment.SeasoningConfigFragment
|
||||||
|
import com.shuwei.dish.match.ui.fragment.WeightConfigFragment
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
|
|
||||||
@@ -39,6 +40,9 @@ class SingleFragmentActivity : BaseActivity() {
|
|||||||
|
|
||||||
/** 数据库调试查看页 */
|
/** 数据库调试查看页 */
|
||||||
DB_INSPECT,
|
DB_INSPECT,
|
||||||
|
|
||||||
|
/** 默认减重配置页 */
|
||||||
|
WEIGHT_CONFIG,
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -81,7 +85,7 @@ class SingleFragmentActivity : BaseActivity() {
|
|||||||
setTitleBar(
|
setTitleBar(
|
||||||
titleBarAction = { it.visible() },
|
titleBarAction = { it.visible() },
|
||||||
titleAction = { it.text = getTitleForPage(pageType) },
|
titleAction = { it.text = getTitleForPage(pageType) },
|
||||||
rightIconActon = { it.gone() }
|
rightIconAction = { it.gone() }
|
||||||
)
|
)
|
||||||
|
|
||||||
// 首次创建时加载 Fragment,避免屏幕旋转重复添加
|
// 首次创建时加载 Fragment,避免屏幕旋转重复添加
|
||||||
@@ -101,6 +105,7 @@ class SingleFragmentActivity : BaseActivity() {
|
|||||||
PageType.COOK_MODE -> "菜品模式"
|
PageType.COOK_MODE -> "菜品模式"
|
||||||
PageType.SEASONING_CONFIG -> "调料区设置"
|
PageType.SEASONING_CONFIG -> "调料区设置"
|
||||||
PageType.DB_INSPECT -> "数据库查看"
|
PageType.DB_INSPECT -> "数据库查看"
|
||||||
|
PageType.WEIGHT_CONFIG -> "减重配置"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,6 +116,7 @@ class SingleFragmentActivity : BaseActivity() {
|
|||||||
PageType.COOK_MODE -> DeviceConfigFragment()
|
PageType.COOK_MODE -> DeviceConfigFragment()
|
||||||
PageType.SEASONING_CONFIG -> SeasoningConfigFragment()
|
PageType.SEASONING_CONFIG -> SeasoningConfigFragment()
|
||||||
PageType.DB_INSPECT -> DbInspectFragment()
|
PageType.DB_INSPECT -> DbInspectFragment()
|
||||||
|
PageType.WEIGHT_CONFIG -> WeightConfigFragment()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import com.shuwei.dish.match.base.BaseActivity
|
|||||||
import com.shuwei.dish.match.base.GlobalData
|
import com.shuwei.dish.match.base.GlobalData
|
||||||
import com.shuwei.dish.match.databinding.ActivitySlaveBinding
|
import com.shuwei.dish.match.databinding.ActivitySlaveBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.entity.SeasoningSlotEntity
|
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||||
import com.shuwei.dish.match.scale.ScaleData
|
import com.shuwei.dish.match.scale.ScaleData
|
||||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||||
@@ -162,7 +162,7 @@ class SlaveActivity : BaseActivity() {
|
|||||||
*/
|
*/
|
||||||
private fun loadSlotsFromDb() {
|
private fun loadSlotsFromDb() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val slots = appViewModel.getSeasoningSlotsByDeviceId(GlobalData.deviceId)
|
val slots = dbViewModel.getSeasoningSlotsByDeviceId(GlobalData.deviceId)
|
||||||
applySlots(slots)
|
applySlots(slots)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,8 +179,8 @@ class SlaveActivity : BaseActivity() {
|
|||||||
?: return@onSeasoningConfig
|
?: return@onSeasoningConfig
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
// 全量替换:先删除本机所有旧槽位,再写入最新配置
|
// 全量替换:先删除本机所有旧槽位,再写入最新配置
|
||||||
appViewModel.deleteAllSlotsByDeviceId(GlobalData.deviceId)
|
dbViewModel.deleteAllSlotsByDeviceId(GlobalData.deviceId)
|
||||||
appViewModel.upsertAllSeasoningSlots(mySlots)
|
dbViewModel.upsertAllSeasoningSlots(mySlots)
|
||||||
applySlots(mySlots)
|
applySlots(mySlots)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ class SlaveActivity : BaseActivity() {
|
|||||||
private fun listenClearData() {
|
private fun listenClearData() {
|
||||||
ScaleServiceManager.onClearData = {
|
ScaleServiceManager.onClearData = {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
appViewModel.clearAllData {
|
dbViewModel.clearAllData {
|
||||||
SpTool.cookMode = -1
|
SpTool.cookMode = -1
|
||||||
SpTool.canteenId = "0"
|
SpTool.canteenId = "0"
|
||||||
runOnUiThread { applySlots(emptyList()) }
|
runOnUiThread { applySlots(emptyList()) }
|
||||||
|
|||||||
@@ -12,32 +12,38 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.adapter.SeasoningWeightAdapter
|
import com.shuwei.dish.match.adapter.SeasoningWeightAdapter
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
import com.shuwei.dish.match.databinding.ActivitySubmitFoodBinding
|
import com.shuwei.dish.match.databinding.ActivitySubmitFoodBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
import com.shuwei.dish.match.dialog.GoodsPreviewDialog
|
||||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
import com.shuwei.dish.match.entity.toDTO
|
import com.shuwei.dish.match.model.ConstituteSaveItem
|
||||||
|
import com.shuwei.dish.match.model.ConstituteSaveRequest
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteItem
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||||
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
|
import com.shuwei.dish.match.model.toDTO
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||||
import com.shuwei.dish.match.utils.AddressUtil
|
import com.shuwei.dish.match.utils.AddressUtil
|
||||||
|
import com.shuwei.dish.match.utils.DateTimeUtil
|
||||||
import com.shuwei.dish.match.utils.WeightUtil
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
import com.shuwei.dish.match.utils.ext.appendText
|
import com.shuwei.dish.match.utils.ext.appendText
|
||||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
|
||||||
import com.shuwei.dish.match.utils.ext.roundedDecimalPlace
|
import com.shuwei.dish.match.utils.ext.roundedDecimalPlace
|
||||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||||
import com.shuwei.dish.match.utils.ext.startActivity
|
import com.shuwei.dish.match.utils.ext.startActivity
|
||||||
import com.shuwei.dish.match.utils.ext.toJsonString
|
import com.shuwei.dish.match.utils.ext.toJsonString
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
@SuppressLint("UseSparseArrays")
|
@SuppressLint("UseSparseArrays")
|
||||||
class SubmitFoodActivity : BaseActivity() {
|
class SubmitFoodActivity : BaseActivity() {
|
||||||
@@ -46,9 +52,12 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
const val TAG = "SubmitFoodActivity"
|
const val TAG = "SubmitFoodActivity"
|
||||||
const val FOOD_ITEM = "foodItem"
|
const val FOOD_ITEM = "foodItem"
|
||||||
const val GOODS_LIST = "goodsList"
|
const val GOODS_LIST = "goodsList"
|
||||||
|
const val COOK_ORDER_ID = "cookOrderId"
|
||||||
|
|
||||||
/** 本地临时 foodId 前缀;以此开头说明菜品尚未在服务器登记,提交时需清空让服务器分配真实 ID */
|
/** 本地临时 foodId 前缀;以此开头说明菜品尚未在服务器登记,提交时需清空让服务器分配真实 ID */
|
||||||
const val LOCAL_ID_PREFIX = "localId_"
|
const val LOCAL_ID_PREFIX = "localId_"
|
||||||
|
|
||||||
|
const val WEIGHT_THRESHOLD = 0.01
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var binding: ActivitySubmitFoodBinding
|
private lateinit var binding: ActivitySubmitFoodBinding
|
||||||
@@ -56,6 +65,9 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
private var food: FoodRecord? = null
|
private var food: FoodRecord? = null
|
||||||
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
||||||
|
|
||||||
|
/** 烹制单 ID,制作模式从 PrepareFoodActivity 传入,用于新配比秤烹饪完成接口 */
|
||||||
|
private var cookOrderId: String? = null
|
||||||
|
|
||||||
private val cookFoodEntity by lazy {
|
private val cookFoodEntity by lazy {
|
||||||
CookFoodEntity().apply {
|
CookFoodEntity().apply {
|
||||||
food?.let {
|
food?.let {
|
||||||
@@ -100,15 +112,33 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
*/
|
*/
|
||||||
private val lastTsMap = mutableMapOf<String, Long>()
|
private val lastTsMap = mutableMapOf<String, Long>()
|
||||||
|
|
||||||
|
/** 主设备 2格秤的初始重量,首次收到数据时赋值;调用清零后重置为 0.0 */
|
||||||
|
private var initWeight: Double = 0.0
|
||||||
|
|
||||||
|
/** 烹饪开始时间(进入本页面的时刻),提交烹饪完成接口时上报 */
|
||||||
|
private var cookStartTime: String = ""
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料首次使用时间,key = goodsName,value = 首次拿取时间 yyyy-MM-dd HH:mm:ss
|
||||||
|
* 秤首次检测到拿取(用量超阈值)时记录,提交时按 goodsName 匹配填入 putTime
|
||||||
|
*/
|
||||||
|
private val seasoningFirstUseMap = mutableMapOf<String, String>()
|
||||||
|
|
||||||
|
/** initWeight 是否已完成初始化 */
|
||||||
|
// private var initWeightSet: Boolean = false
|
||||||
|
|
||||||
@Suppress("unchecked_cast", "DEPRECATION")
|
@Suppress("unchecked_cast", "DEPRECATION")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivitySubmitFoodBinding.inflate(layoutInflater)
|
binding = ActivitySubmitFoodBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
// 以进入本页面的时刻作为烹饪开始时间
|
||||||
|
cookStartTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
|
||||||
setHeaderBackground()
|
setHeaderBackground()
|
||||||
intent.extras?.apply {
|
intent.extras?.apply {
|
||||||
food = getSerializable(FOOD_ITEM) as FoodRecord?
|
food = getSerializable(FOOD_ITEM) as FoodRecord?
|
||||||
Log.d(TAG, "onCreate: cookMode=${food?.cookMode}")
|
cookOrderId = getString(COOK_ORDER_ID)
|
||||||
|
Log.d(TAG, "onCreate: cookMode=${food?.cookMode}, cookOrderId=$cookOrderId")
|
||||||
// isCooking=false:从前一页面带入主辅材数据;isCooking=true:从数据库查询
|
// isCooking=false:从前一页面带入主辅材数据;isCooking=true:从数据库查询
|
||||||
if (food?.isCooking == false) {
|
if (food?.isCooking == false) {
|
||||||
goodsList = getSerializable(GOODS_LIST) as MutableList<CookFoodGoodsEntity>?
|
goodsList = getSerializable(GOODS_LIST) as MutableList<CookFoodGoodsEntity>?
|
||||||
@@ -119,8 +149,15 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
it.visible()
|
it.visible()
|
||||||
}, titleAction = {
|
}, titleAction = {
|
||||||
it.text = food?.foodName
|
it.text = food?.foodName
|
||||||
}, rightIconActon = {
|
}, rightIconAction = {
|
||||||
it.gone()
|
it.visible()
|
||||||
|
it.setImageResource(R.drawable.ic_list_view)
|
||||||
|
it.setOnClickListener {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
val list = buildPreviewGoodsList()
|
||||||
|
GoodsPreviewDialog(this@SubmitFoodActivity, list).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}, backAction = {
|
}, backAction = {
|
||||||
it.setOnClickListener {
|
it.setOnClickListener {
|
||||||
remindSaveDataDialog()
|
remindSaveDataDialog()
|
||||||
@@ -172,7 +209,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
*/
|
*/
|
||||||
private fun loadSlotsThenObserveScales() {
|
private fun loadSlotsThenObserveScales() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val slots = appViewModel.loadSeasoningSlot()
|
val slots = dbViewModel.loadSeasoningSlot()
|
||||||
slots.forEach { slot ->
|
slots.forEach { slot ->
|
||||||
slotMap["${slot.deviceId}#${slot.address}"] = slot.goodsId to slot.goodsName
|
slotMap["${slot.deviceId}#${slot.address}"] = slot.goodsId to slot.goodsName
|
||||||
}
|
}
|
||||||
@@ -181,7 +218,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
val foodId = food?.foodId ?: return@launch
|
val foodId = food?.foodId ?: return@launch
|
||||||
val cookMode = food?.cookMode ?: return@launch
|
val cookMode = food?.cookMode ?: return@launch
|
||||||
val list =
|
val list =
|
||||||
appViewModel.getCookFoodGoodsList(foodId, cookMode, food?.dinnerType ?: "0")
|
dbViewModel.getCookFoodGoodsList(foodId, cookMode, food?.dinnerType ?: "0")
|
||||||
goodsList = list
|
goodsList = list
|
||||||
prefillSeasoningFromGoodsList(list)
|
prefillSeasoningFromGoodsList(list)
|
||||||
} else {
|
} else {
|
||||||
@@ -218,7 +255,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
private fun observeScaleData() {
|
private fun observeScaleData() {
|
||||||
val flow = ScaleServiceManager.allScales ?: return
|
val flow = ScaleServiceManager.allScales ?: return
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
flow.collectLatest { scaleMap ->
|
flow.collect { scaleMap ->
|
||||||
//Log.d(TAG, "observeScaleData,scaleMap=${scaleMap.toJsonString()}")
|
//Log.d(TAG, "observeScaleData,scaleMap=${scaleMap.toJsonString()}")
|
||||||
scaleMap.forEach { (key, data) ->
|
scaleMap.forEach { (key, data) ->
|
||||||
// ts 未变化说明是其他秤更新触发的 StateFlow 重发,跳过
|
// ts 未变化说明是其他秤更新触发的 StateFlow 重发,跳过
|
||||||
@@ -247,7 +284,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
.coerceAtLeast(0.0)
|
.coerceAtLeast(0.0)
|
||||||
.roundedOneDecimalPlace()
|
.roundedOneDecimalPlace()
|
||||||
|
|
||||||
if (useWeight < 0.5) {
|
if (useWeight < WEIGHT_THRESHOLD) {
|
||||||
// 放回场景:必须稳定后才移除,避免拿取过程中误删
|
// 放回场景:必须稳定后才移除,避免拿取过程中误删
|
||||||
if (data.state != WeightUtil.STATE_STABLE) return@forEach
|
if (data.state != WeightUtil.STATE_STABLE) return@forEach
|
||||||
if (rawWeightMap.remove(key) != null) {
|
if (rawWeightMap.remove(key) != null) {
|
||||||
@@ -258,6 +295,11 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
// 拿取场景:实时响应,无需等待稳定
|
// 拿取场景:实时响应,无需等待稳定
|
||||||
val newTriple = Triple(goodsId, goodsName, useWeight)
|
val newTriple = Triple(goodsId, goodsName, useWeight)
|
||||||
if (rawWeightMap[key] != newTriple) {
|
if (rawWeightMap[key] != newTriple) {
|
||||||
|
// 该调料首次检测到拿取时,记录首次使用时间(同名调料只记最早一次)
|
||||||
|
if (!seasoningFirstUseMap.containsKey(goodsName)) {
|
||||||
|
seasoningFirstUseMap[goodsName] =
|
||||||
|
DateTimeUtil.formatDateTime(LocalDateTime.now())
|
||||||
|
}
|
||||||
Log.d(TAG, "observeScaleData,新增:$newTriple")
|
Log.d(TAG, "observeScaleData,新增:$newTriple")
|
||||||
rawWeightMap[key] = newTriple
|
rawWeightMap[key] = newTriple
|
||||||
refreshAdapterByName(goodsName)
|
refreshAdapterByName(goodsName)
|
||||||
@@ -279,8 +321,8 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
val (baseGoodsId, baseWeight) = baseSeasoningMap[goodsName] ?: ("" to 0.0)
|
val (baseGoodsId, baseWeight) = baseSeasoningMap[goodsName] ?: ("" to 0.0)
|
||||||
val totalWeight = (newWeight + baseWeight).roundedOneDecimalPlace()
|
val totalWeight = (newWeight + baseWeight).roundedOneDecimalPlace()
|
||||||
Log.d(TAG, "refreshAdapterByName, goodsName=$goodsName, newWeight=$newWeight, baseWeight=$baseWeight, totalWeight=$totalWeight, isCooking=${food?.isCooking}")
|
Log.d(TAG, "refreshAdapterByName, goodsName=$goodsName, newWeight=$newWeight, baseWeight=$baseWeight, totalWeight=$totalWeight, isCooking=${food?.isCooking}")
|
||||||
if (totalWeight < 0.5) {
|
if (totalWeight < WEIGHT_THRESHOLD) {
|
||||||
Log.d(TAG, "refreshAdapterByName,重量小于0.5g, isCooking=${food?.isCooking}, goodsName=$goodsName, totalWeight=$totalWeight")
|
Log.d(TAG, "refreshAdapterByName,重量小于${WEIGHT_THRESHOLD}g, isCooking=${food?.isCooking}, goodsName=$goodsName, totalWeight=$totalWeight")
|
||||||
// 仅保护 baseSeasoningMap 中的历史调料;本次会话新加的调料可以移除
|
// 仅保护 baseSeasoningMap 中的历史调料;本次会话新加的调料可以移除
|
||||||
if (!baseSeasoningMap.containsKey(goodsName)) {
|
if (!baseSeasoningMap.containsKey(goodsName)) {
|
||||||
// 只有 item 确实存在时才调用 remove,避免无效遍历
|
// 只有 item 确实存在时才调用 remove,避免无效遍历
|
||||||
@@ -303,22 +345,31 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addViewListener() {
|
private fun addViewListener() {
|
||||||
// 切换调料列表布局:4 列卡片 ↔ 2 列水平
|
// 切换调料列表布局:4 列卡片 ↔ 2 列水平,图标始终显示"目标布局"样式
|
||||||
binding.ivSeasoningLayoutToggle.setOnClickListener {
|
binding.ivSeasoningLayoutToggle.clickWithDebounce {
|
||||||
seasoningAdapter.isListMode = !seasoningAdapter.isListMode
|
seasoningAdapter.isListMode = !seasoningAdapter.isListMode
|
||||||
val spanCount = if (seasoningAdapter.isListMode) 2 else 4
|
val spanCount = if (seasoningAdapter.isListMode) 2 else 4
|
||||||
(binding.rvSeasoning.layoutManager as? GridLayoutManager)?.spanCount = spanCount
|
(binding.rvSeasoning.layoutManager as? GridLayoutManager)?.spanCount = spanCount
|
||||||
seasoningAdapter.notifyDataSetChanged()
|
seasoningAdapter.notifyDataSetChanged()
|
||||||
|
binding.ivSeasoningLayoutToggle.setImageResource(
|
||||||
|
if (seasoningAdapter.isListMode) R.drawable.ic_layout_grid else R.drawable.ic_layout_list
|
||||||
|
)
|
||||||
}
|
}
|
||||||
binding.btnCook.clickWithDebounce {
|
binding.btnCook.clickWithDebounce {
|
||||||
val content = getRemindSpannable("开始制作")
|
val content = getRemindSpannable("开始制作")
|
||||||
showRemindDialog(content) { cook() }
|
showRemindDialog(content) { cook() }
|
||||||
}
|
}
|
||||||
binding.btnWeightClear.clickWithDebounce { WeightUtil.tareTwo(2) }
|
binding.btnWeightClear.clickWithDebounce {
|
||||||
|
WeightUtil.tareTwo(2)
|
||||||
|
// 清零后将初始重量重置为 0,后续以秤读数直接作为净重
|
||||||
|
initWeight = 0.0
|
||||||
|
}
|
||||||
binding.btnSubmit.clickWithDebounce {
|
binding.btnSubmit.clickWithDebounce {
|
||||||
if (cookFoodEntity.foodWeight <= 0.toDouble()) {
|
if (cookFoodEntity.foodWeight <= 0.toDouble()) {
|
||||||
toast("未识别到菜品熟重")
|
// 测试设备无秤硬件,使用模拟熟重 500g
|
||||||
return@clickWithDebounce
|
cookFoodEntity.foodWeight = 500.0
|
||||||
|
binding.tvTotalWeight.text = "500.0"
|
||||||
|
binding.tvWeightUnit.text = "克"
|
||||||
}
|
}
|
||||||
val content = getRemindSpannable("制作完成")
|
val content = getRemindSpannable("制作完成")
|
||||||
showRemindDialog(content) { submit() }
|
showRemindDialog(content) { submit() }
|
||||||
@@ -327,12 +378,19 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
// 监听主设备 2格秤的熟重
|
// 监听主设备 2格秤的熟重
|
||||||
WeightUtil.addWeightListener(TAG) { address, _, weight ->
|
WeightUtil.addWeightListener(TAG) { address, _, weight ->
|
||||||
if (address == AddressUtil.TWO) {
|
if (address == AddressUtil.TWO) {
|
||||||
cookFoodEntity.foodWeight = weight
|
// 首次收到数据时记录初始重量
|
||||||
if (weight > 1000) {
|
// if (!initWeightSet) {
|
||||||
binding.tvTotalWeight.text = "${(weight / 1000f).roundedDecimalPlace(3)}"
|
// initWeight = weight
|
||||||
|
// initWeightSet = true
|
||||||
|
// }
|
||||||
|
// 实际净重 = 秤读数 - 初始重量
|
||||||
|
val netWeight = weight - initWeight
|
||||||
|
cookFoodEntity.foodWeight = netWeight
|
||||||
|
if (netWeight > 1000) {
|
||||||
|
binding.tvTotalWeight.text = "${(netWeight / 1000f).roundedDecimalPlace(3)}"
|
||||||
binding.tvWeightUnit.text = "千克"
|
binding.tvWeightUnit.text = "千克"
|
||||||
} else {
|
} else {
|
||||||
binding.tvTotalWeight.text = "$weight"
|
binding.tvTotalWeight.text = "$netWeight"
|
||||||
binding.tvWeightUnit.text = "克"
|
binding.tvWeightUnit.text = "克"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,7 +427,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
seasoningAdapter.items
|
seasoningAdapter.items
|
||||||
.filter { it.useWeight > 0.0 }
|
.filter { it.useWeight > 0.0 }
|
||||||
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
||||||
appViewModel.saveCookFoodAndGoods(
|
dbViewModel.saveCookFoodAndGoods(
|
||||||
cookMode = food!!.cookMode,
|
cookMode = food!!.cookMode,
|
||||||
entity = cookFoodEntity,
|
entity = cookFoodEntity,
|
||||||
list = goodsList
|
list = goodsList
|
||||||
@@ -389,12 +447,24 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
// 先移除 goodsList 中已有的调料数据(materialType==3),再以 adapter 中最新调料覆盖
|
// 先移除 goodsList 中已有的调料数据(materialType==3),再以 adapter 中最新调料覆盖
|
||||||
goodsList?.removeAll { it.materialType == 3 }
|
goodsList?.removeAll { it.materialType == 3 }
|
||||||
// 主辅材 foodId 统一以菜品 foodId 为准;新加调料行的 foodId 由 buildSeasoningEntity 内部设置
|
|
||||||
goodsList?.forEach { it.foodId = cookFoodEntity.foodId }
|
goodsList?.forEach { it.foodId = cookFoodEntity.foodId }
|
||||||
seasoningAdapter.items
|
seasoningAdapter.items
|
||||||
.filter { it.useWeight > 0.0 }
|
.filter { it.useWeight > 0.0 }
|
||||||
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
||||||
|
|
||||||
|
// 制作模式 + 有烹制单 ID → 调新配比秤烹饪完成接口
|
||||||
|
if (!cookOrderId.isNullOrBlank() && food?.cookMode == 0) {
|
||||||
|
submitWithNewApi()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
// 采样模式 → 调新配比秤提交采样接口(落库味养创新实验,状态=实验中)
|
||||||
|
if (food?.cookMode == 1) {
|
||||||
|
submitConstitute()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
// 旧接口路径(无烹制单 ID 的制作模式兜底)
|
||||||
cookFoodEntity.let {
|
cookFoodEntity.let {
|
||||||
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
|
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
|
||||||
it.dinnerType = when (it.dinnerType) {
|
it.dinnerType = when (it.dinnerType) {
|
||||||
@@ -405,24 +475,153 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仅本地生成的临时 foodId 需清空,由服务器分配真实 ID;服务器下发的真实 foodId 直接保留
|
|
||||||
if (cookFoodEntity.foodId.startsWith(LOCAL_ID_PREFIX)) {
|
if (cookFoodEntity.foodId.startsWith(LOCAL_ID_PREFIX)) {
|
||||||
cookFoodEntity.foodId = ""
|
cookFoodEntity.foodId = ""
|
||||||
goodsList?.forEach { it.foodId = "" }
|
goodsList?.forEach { it.foodId = "" }
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "submit: json=${cookFoodEntity.toJsonString()}")
|
Log.d(TAG, "submit: json=${cookFoodEntity.toJsonString()}")
|
||||||
// 接口提交使用 DTO,与本地 Room 实体解耦
|
|
||||||
netViewModel.submitCookFood(entity = cookFoodEntity.toDTO())
|
netViewModel.submitCookFood(entity = cookFoodEntity.toDTO())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新配比秤烹饪完成接口:从 goodsList 提取主辅材和调料,组装 CookCompleteRequest 提交
|
||||||
|
* 熟重 foodWeight(g) → cookedWeight(kg)
|
||||||
|
*/
|
||||||
|
private fun submitWithNewApi() {
|
||||||
|
val allGoods = goodsList ?: return
|
||||||
|
|
||||||
|
// 主辅材:materialType 1(主材) 或 2(辅材)
|
||||||
|
val items = allGoods
|
||||||
|
.filter { it.materialType == 1 || it.materialType == 2 }
|
||||||
|
.map { CookCompleteItem(
|
||||||
|
materId = it.materId?.takeIf { mid -> mid.isNotEmpty() } ?: it.goodsId,
|
||||||
|
actualQty = it.useWeight ?: 0.0
|
||||||
|
) }
|
||||||
|
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
toast("无主辅材构成信息")
|
||||||
|
dismissLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调料:materialType 3,按 goodsName 匹配首次使用时间填入 putTime
|
||||||
|
val seasonings = allGoods
|
||||||
|
.filter { it.materialType == 3 }
|
||||||
|
.map { CookCompleteItem(
|
||||||
|
materId = it.materId?.takeIf { mid -> mid.isNotEmpty() } ?: it.goodsId,
|
||||||
|
actualQty = it.useWeight ?: 0.0,
|
||||||
|
putTime = it.goodsName?.let { name -> seasoningFirstUseMap[name] }
|
||||||
|
) }
|
||||||
|
.takeIf { it.isNotEmpty() }
|
||||||
|
|
||||||
|
// 熟重 g → kg,保留 3 位小数
|
||||||
|
val cookedWeightKg = (cookFoodEntity.foodWeight / 1000.0).roundedDecimalPlace(3)
|
||||||
|
|
||||||
|
val request = CookCompleteRequest(
|
||||||
|
cookOrderId = cookOrderId ?: "",
|
||||||
|
cookStart = cookStartTime,
|
||||||
|
items = items,
|
||||||
|
cookedWeight = cookedWeightKg,
|
||||||
|
seasonings = seasonings
|
||||||
|
)
|
||||||
|
|
||||||
|
Log.d(TAG, "submitWithNewApi: ${request.toJsonString()}")
|
||||||
|
|
||||||
|
val isSamplingData = food?.cookMode == 1
|
||||||
|
netViewModel.cookOrderComplete(
|
||||||
|
request = request,
|
||||||
|
onResult = { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> submitSuccess(isSamplingData)
|
||||||
|
is UiState.Error -> {
|
||||||
|
toast(state.msg)
|
||||||
|
dismissLoading()
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交采样:从 goodsList 提取全部构成(主材/辅材/调料),组装 ConstituteSaveRequest 提交
|
||||||
|
* 落库味养创新实验;熟重 foodWeight 单位为 g,isMain 直接取 materialType(1主/2辅/3调)
|
||||||
|
*/
|
||||||
|
private fun submitConstitute() {
|
||||||
|
val allGoods = goodsList ?: run {
|
||||||
|
toast("未获取到菜品或构成信息")
|
||||||
|
dismissLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val foodName = cookFoodEntity.foodName ?: food?.foodName ?: ""
|
||||||
|
if (foodName.isBlank()) {
|
||||||
|
toast("菜品名称为空")
|
||||||
|
dismissLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 仅保留用量 > 0 的食材;materId 优先取 materId,为空时回退 goodsId
|
||||||
|
// 调料(isMain=3)按 goodsName 匹配首次使用时间填入 putTime,主辅材留空
|
||||||
|
val items = allGoods
|
||||||
|
.filter { (it.useWeight ?: 0.0) > 0.0 }
|
||||||
|
.map {
|
||||||
|
ConstituteSaveItem(
|
||||||
|
materId = it.materId?.takeIf { mid -> mid.isNotEmpty() } ?: it.goodsId,
|
||||||
|
useWeight = it.useWeight ?: 0.0,
|
||||||
|
isMain = it.materialType,
|
||||||
|
putTime = if (it.materialType == 3) {
|
||||||
|
it.goodsName?.let { name -> seasoningFirstUseMap[name] }
|
||||||
|
} else null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
toast("请完善菜品构成信息")
|
||||||
|
dismissLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (items.any { it.materId.isBlank() }) {
|
||||||
|
toast("菜品食材不能为空")
|
||||||
|
dismissLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val foodWeight = cookFoodEntity.foodWeight
|
||||||
|
if (foodWeight <= 0.0) {
|
||||||
|
toast("熟重必须大于0")
|
||||||
|
dismissLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val request = ConstituteSaveRequest(
|
||||||
|
foodName = foodName,
|
||||||
|
cookStart = cookStartTime,
|
||||||
|
foodWeight = foodWeight,
|
||||||
|
items = items
|
||||||
|
)
|
||||||
|
Log.d(TAG, "submitConstitute: ${request.toJsonString()}")
|
||||||
|
|
||||||
|
netViewModel.constituteSave(
|
||||||
|
request = request,
|
||||||
|
onResult = { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> submitSuccess(isSamplingData = true)
|
||||||
|
is UiState.Error -> {
|
||||||
|
toast(state.msg)
|
||||||
|
dismissLoading()
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 adapter 中的调料 item 转换为 CookFoodGoodsEntity
|
* 将 adapter 中的调料 item 转换为 CookFoodGoodsEntity
|
||||||
* 从本地 dm_seasoning 表补充完整字段(popularName、zjmCode、materId、goodsCode 等)
|
* 从本地 dm_seasoning 表补充完整字段(popularName、zjmCode、materId、goodsCode 等)
|
||||||
*/
|
*/
|
||||||
private suspend fun buildSeasoningEntity(item: SeasoningWeightAdapter.Item): CookFoodGoodsEntity {
|
private suspend fun buildSeasoningEntity(item: SeasoningWeightAdapter.Item): CookFoodGoodsEntity {
|
||||||
val seasoning = appViewModel.getSeasoningByGoodsId(item.goodsId)
|
val seasoning = dbViewModel.getSeasoningByGoodsId(item.goodsId)
|
||||||
return CookFoodGoodsEntity().also { entity ->
|
return CookFoodGoodsEntity().also { entity ->
|
||||||
entity.foodId = cookFoodEntity.foodId
|
entity.foodId = cookFoodEntity.foodId
|
||||||
entity.goodsId = item.goodsId
|
entity.goodsId = item.goodsId
|
||||||
@@ -445,15 +644,15 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
jumpPage(isSamplingData, false)
|
jumpPage(isSamplingData, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lifecycleScope.launch {
|
// 用 viewModelScope 执行删除,不受当前 Activity 生命周期影响
|
||||||
appViewModel.markSubmittedAndDelete(
|
// singleTask 跳转会销毁本 Activity 并取消 lifecycleScope,导致删除被中断
|
||||||
cookMode = food!!.cookMode,
|
dbViewModel.markSubmittedAndDeleteAsync(
|
||||||
foodId = food!!.foodId!!,
|
cookMode = food!!.cookMode,
|
||||||
dinnerType = food!!.dinnerType
|
foodId = food!!.foodId!!,
|
||||||
)
|
dinnerType = food!!.dinnerType
|
||||||
dismissLoading()
|
)
|
||||||
jumpPage(isSamplingData, false)
|
dismissLoading()
|
||||||
}
|
jumpPage(isSamplingData, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun jumpPage(isSampling: Boolean, isCooking: Boolean) {
|
private fun jumpPage(isSampling: Boolean, isCooking: Boolean) {
|
||||||
@@ -470,6 +669,19 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建用于预览弹窗的 goodsList:
|
||||||
|
* 取 goodsList 中的主辅材,再用 adapter 中最新调料覆盖原有调料数据(materialType==3)
|
||||||
|
* 调料的完整字段(含 goodsCode)通过 buildSeasoningEntity 从 DB 补全
|
||||||
|
*/
|
||||||
|
private suspend fun buildPreviewGoodsList(): List<CookFoodGoodsEntity> {
|
||||||
|
val base = goodsList?.filter { it.materialType != 3 }?.toMutableList() ?: mutableListOf()
|
||||||
|
seasoningAdapter.items
|
||||||
|
.filter { it.useWeight > 0.0 }
|
||||||
|
.forEach { base.add(buildSeasoningEntity(it)) }
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
WeightUtil.removeWeightListener(TAG)
|
WeightUtil.removeWeightListener(TAG)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ package com.shuwei.dish.match.ui.fragment
|
|||||||
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
|
import android.text.InputType
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.LinearLayout
|
||||||
import android.widget.RadioButton
|
import android.widget.RadioButton
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.cardview.widget.CardView
|
import androidx.cardview.widget.CardView
|
||||||
@@ -20,12 +24,11 @@ import com.shuwei.dish.match.ui.SingleFragmentActivity
|
|||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.visible
|
import com.shuwei.dish.match.utils.ext.visible
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import androidx.core.graphics.toColorInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库调试查看页面
|
* 数据库调试查看页面
|
||||||
* 支持按表切换、isDel 过滤开关、分页加载(每页 50 条)
|
* 支持按表切换、isDel 过滤开关、多字段筛选、分页加载
|
||||||
* 菜品/食材/调料表每行 3 列等宽显示字段,槽位表保持单列
|
|
||||||
* 已逻辑删除(isDel=1)的记录以灰色文字 + 半透明卡片区分
|
|
||||||
*/
|
*/
|
||||||
class DbInspectFragment : BaseFragment<FragmentDbInspectBinding>() {
|
class DbInspectFragment : BaseFragment<FragmentDbInspectBinding>() {
|
||||||
|
|
||||||
@@ -45,6 +48,55 @@ class DbInspectFragment : BaseFragment<FragmentDbInspectBinding>() {
|
|||||||
/** Tab RadioButton 列表,用于统一更新选中样式 */
|
/** Tab RadioButton 列表,用于统一更新选中样式 */
|
||||||
private val tabButtons = mutableListOf<RadioButton>()
|
private val tabButtons = mutableListOf<RadioButton>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每张表对应的筛选字段配置
|
||||||
|
* @param key SQL 列名
|
||||||
|
* @param label 显示标签
|
||||||
|
* @param hint 输入框提示文字
|
||||||
|
* @param isLike true=模糊匹配(LIKE),false=精确匹配(=)
|
||||||
|
*/
|
||||||
|
data class FilterField(
|
||||||
|
val key: String,
|
||||||
|
val label: String,
|
||||||
|
val hint: String,
|
||||||
|
val isLike: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 各表的筛选字段配置 */
|
||||||
|
private val filterConfigs = mapOf(
|
||||||
|
0 to listOf(
|
||||||
|
FilterField("foodId", "菜品ID", "精确匹配"),
|
||||||
|
FilterField("foodName", "菜品名", "模糊搜索", isLike = true),
|
||||||
|
FilterField("canteenId", "食堂ID", "精确匹配"),
|
||||||
|
FilterField("cookMode", "菜品模式", "0制作/1采样/2品控"),
|
||||||
|
FilterField("dinnerType", "餐次", "0默认无/1早餐/2午餐/3晚餐"),
|
||||||
|
FilterField("submitState", "提交状态", "0本地或手动删除/1接口提交删除")
|
||||||
|
),
|
||||||
|
1 to listOf(
|
||||||
|
FilterField("pid", "父ID", "精确匹配"),
|
||||||
|
FilterField("foodId", "菜品ID", "精确匹配"),
|
||||||
|
FilterField("goodsId", "食材ID", "精确匹配"),
|
||||||
|
FilterField("goodsName", "食材名", "模糊搜索", isLike = true),
|
||||||
|
FilterField("materialType", "物品类型", "1主料/2辅料/3调料"),
|
||||||
|
FilterField("rawMaterialsType", "净材种类", "精确匹配"),
|
||||||
|
FilterField("goodsCode", "物料编码", "1主料/2辅料/3调料")
|
||||||
|
),
|
||||||
|
2 to listOf(
|
||||||
|
FilterField("goodsId", "调料ID", "精确匹配"),
|
||||||
|
FilterField("goodsName", "调料名", "模糊搜索", isLike = true),
|
||||||
|
FilterField("goodsCode", "物料编码", "1主料/2辅料/3调料")
|
||||||
|
),
|
||||||
|
3 to listOf(
|
||||||
|
FilterField("deviceId", "设备ID", "精确匹配"),
|
||||||
|
FilterField("address", "秤硬件地址", "精确匹配"),
|
||||||
|
FilterField("goodsId", "调料ID", "精确匹配"),
|
||||||
|
FilterField("goodsName", "调料名", "模糊搜索", isLike = true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
/** key=列名,value=对应的 EditText,用于查询时收集筛选值 */
|
||||||
|
private val filterEditTexts = mutableMapOf<String, EditText>()
|
||||||
|
|
||||||
override fun inflateBinding(
|
override fun inflateBinding(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?
|
container: ViewGroup?
|
||||||
@@ -60,18 +112,19 @@ class DbInspectFragment : BaseFragment<FragmentDbInspectBinding>() {
|
|||||||
listOf(binding.rbCookFood, binding.rbGoods, binding.rbSeasoning, binding.rbSlot)
|
listOf(binding.rbCookFood, binding.rbGoods, binding.rbSeasoning, binding.rbSlot)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tab 切换:重置到第一页
|
// Tab 切换:重置筛选框并加载第一页
|
||||||
binding.rgTabs.setOnCheckedChangeListener { _, checkedId ->
|
binding.rgTabs.setOnCheckedChangeListener { _, checkedId ->
|
||||||
currentTableIndex = when (checkedId) {
|
currentTableIndex = when (checkedId) {
|
||||||
R.id.rbCookFood -> 0
|
R.id.rbCookFood -> 0
|
||||||
R.id.rbGoods -> 1
|
R.id.rbGoods -> 1
|
||||||
R.id.rbSeasoning -> 2
|
R.id.rbSeasoning -> 2
|
||||||
R.id.rbSlot -> 3
|
R.id.rbSlot -> 3
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
updateTabStyles()
|
updateTabStyles()
|
||||||
moveIndicator(currentTableIndex)
|
moveIndicator(currentTableIndex)
|
||||||
updateDelControlsVisibility()
|
updateDelControlsVisibility()
|
||||||
|
rebuildFilterUI()
|
||||||
loadFirstPage()
|
loadFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,17 +135,17 @@ class DbInspectFragment : BaseFragment<FragmentDbInspectBinding>() {
|
|||||||
loadFirstPage()
|
loadFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新按钮
|
// 查询按钮:收集筛选条件并加载第一页
|
||||||
binding.tvRefresh.setOnClickListener { loadFirstPage() }
|
binding.tvRefresh.setOnClickListener { loadFirstPage() }
|
||||||
|
|
||||||
// 加载更多按钮
|
// 加载更多按钮:筛选条件从 state 中复用,无需重新传入
|
||||||
binding.tvLoadMore.setOnClickListener {
|
binding.tvLoadMore.setOnClickListener {
|
||||||
currentActivity.appViewModel.loadMoreDbInspect(currentTableIndex, showDel)
|
currentActivity.dbViewModel.loadMoreDbInspect(currentTableIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订阅 UI 状态
|
// 订阅 UI 状态
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
currentActivity.appViewModel.dbInspectState.collect { state ->
|
currentActivity.dbViewModel.dbInspectState.collect { state ->
|
||||||
renderState(state)
|
renderState(state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,12 +153,89 @@ class DbInspectFragment : BaseFragment<FragmentDbInspectBinding>() {
|
|||||||
// 初始化样式并加载
|
// 初始化样式并加载
|
||||||
updateTabStyles()
|
updateTabStyles()
|
||||||
updateDelControlsVisibility()
|
updateDelControlsVisibility()
|
||||||
|
rebuildFilterUI()
|
||||||
binding.vTabIndicator.post { moveIndicator(currentTableIndex) }
|
binding.vTabIndicator.post { moveIndicator(currentTableIndex) }
|
||||||
loadFirstPage()
|
loadFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 收集当前筛选框的值,构建 DbInspectFilter */
|
||||||
|
private fun collectFilter(): DbViewModel.DbInspectFilter {
|
||||||
|
val exactFields = mutableMapOf<String, String>()
|
||||||
|
val likeFields = mutableMapOf<String, String>()
|
||||||
|
filterConfigs[currentTableIndex]?.forEach { field ->
|
||||||
|
val value = filterEditTexts[field.key]?.text?.toString()?.trim() ?: ""
|
||||||
|
if (value.isNotEmpty()) {
|
||||||
|
if (field.isLike) likeFields[field.key] = value
|
||||||
|
else exactFields[field.key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DbViewModel.DbInspectFilter(
|
||||||
|
showDel = showDel,
|
||||||
|
exactFields = exactFields,
|
||||||
|
likeFields = likeFields
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadFirstPage() {
|
private fun loadFirstPage() {
|
||||||
currentActivity.appViewModel.loadDbInspect(currentTableIndex, showDel)
|
currentActivity.dbViewModel.loadDbInspect(currentTableIndex, collectFilter())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据当前 Tab 重新生成筛选框区域
|
||||||
|
* 每行展示 2 个字段,最后一个为奇数时右侧补空占位
|
||||||
|
*/
|
||||||
|
private fun rebuildFilterUI() {
|
||||||
|
binding.llFilterContainer.removeAllViews()
|
||||||
|
filterEditTexts.clear()
|
||||||
|
|
||||||
|
val configs = filterConfigs[currentTableIndex] ?: return
|
||||||
|
val ctx = requireContext()
|
||||||
|
val hPad = 4.dp
|
||||||
|
val vPad = 2.dp
|
||||||
|
|
||||||
|
configs.chunked(2).forEach { rowFields ->
|
||||||
|
val row = LinearLayout(ctx).apply {
|
||||||
|
orientation = LinearLayout.HORIZONTAL
|
||||||
|
layoutParams = LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
rowFields.forEach { field ->
|
||||||
|
val cell = LinearLayout(ctx).apply {
|
||||||
|
orientation = LinearLayout.VERTICAL
|
||||||
|
setPadding(hPad, vPad, hPad, vPad)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 字段标签
|
||||||
|
cell.addView(TextView(ctx).apply {
|
||||||
|
text = field.label
|
||||||
|
textSize = 10f
|
||||||
|
setTextColor("#888888".toColorInt())
|
||||||
|
})
|
||||||
|
|
||||||
|
// 输入框
|
||||||
|
val et = EditText(ctx).apply {
|
||||||
|
hint = field.hint
|
||||||
|
textSize = 12f
|
||||||
|
setSingleLine(true)
|
||||||
|
inputType = InputType.TYPE_CLASS_TEXT
|
||||||
|
setPadding(hPad, vPad, hPad, vPad)
|
||||||
|
}
|
||||||
|
filterEditTexts[field.key] = et
|
||||||
|
cell.addView(et)
|
||||||
|
|
||||||
|
row.addView(cell, LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 奇数字段时右侧补空 View 保持对齐
|
||||||
|
if (rowFields.size == 1) {
|
||||||
|
row.addView(View(ctx), LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f))
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.llFilterContainer.addView(row)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderState(state: DbViewModel.DbInspectUiState) {
|
private fun renderState(state: DbViewModel.DbInspectUiState) {
|
||||||
@@ -168,6 +298,9 @@ class DbInspectFragment : BaseFragment<FragmentDbInspectBinding>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** dp 转 px 便捷扩展 */
|
||||||
|
private val Int.dp: Int get() = (this * resources.displayMetrics.density + 0.5f).toInt()
|
||||||
|
|
||||||
// ---- 外层 Adapter:每条数据库记录对应一个 CardView ----
|
// ---- 外层 Adapter:每条数据库记录对应一个 CardView ----
|
||||||
|
|
||||||
/** 外层列表适配器,每个 item 内嵌一个 GridLayoutManager 的 RecyclerView 展示字段 */
|
/** 外层列表适配器,每个 item 内嵌一个 GridLayoutManager 的 RecyclerView 展示字段 */
|
||||||
@@ -191,17 +324,14 @@ class DbInspectFragment : BaseFragment<FragmentDbInspectBinding>() {
|
|||||||
val record = data[position]
|
val record = data[position]
|
||||||
|
|
||||||
if (record.isDel) {
|
if (record.isDel) {
|
||||||
// 已删除:浅红背景 + 左侧红色标记条 + 文字颜色正常(深色可读)
|
|
||||||
holder.card.setCardBackgroundColor(Color.parseColor("#FFF3F3"))
|
holder.card.setCardBackgroundColor(Color.parseColor("#FFF3F3"))
|
||||||
holder.vDelMark.visibility = View.VISIBLE
|
holder.vDelMark.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
// 正常记录:白色背景,隐藏标记条
|
|
||||||
holder.card.setCardBackgroundColor(Color.WHITE)
|
holder.card.setCardBackgroundColor(Color.WHITE)
|
||||||
holder.vDelMark.visibility = View.GONE
|
holder.vDelMark.visibility = View.GONE
|
||||||
}
|
}
|
||||||
val textColor = if (record.isDel) Color.parseColor("#C62828") else Color.parseColor("#333333")
|
val textColor = if (record.isDel) Color.parseColor("#C62828") else Color.parseColor("#333333")
|
||||||
|
|
||||||
// 每次绑定时重新设置 GridLayoutManager 列数(槽位表为 1,其余为 3)
|
|
||||||
holder.rvFields.layoutManager = GridLayoutManager(holder.rvFields.context, record.columnsPerRow)
|
holder.rvFields.layoutManager = GridLayoutManager(holder.rvFields.context, record.columnsPerRow)
|
||||||
holder.rvFields.adapter = DbFieldAdapter(record.fields, textColor)
|
holder.rvFields.adapter = DbFieldAdapter(record.fields, textColor)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package com.shuwei.dish.match.ui.fragment
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.adapter.FoodListAdapter
|
import com.shuwei.dish.match.adapter.FoodListAdapter
|
||||||
@@ -17,19 +16,26 @@ import com.shuwei.dish.match.base.BaseFragment
|
|||||||
import com.shuwei.dish.match.databinding.FragmentFoodListBinding
|
import com.shuwei.dish.match.databinding.FragmentFoodListBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
import com.shuwei.dish.match.entity.FoodRecord
|
import com.shuwei.dish.match.model.CookOrderItem
|
||||||
|
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||||
|
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||||
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.ui.CookingModeActivity
|
import com.shuwei.dish.match.ui.CookingModeActivity
|
||||||
import com.shuwei.dish.match.ui.PrepareFoodActivity
|
import com.shuwei.dish.match.ui.PrepareFoodActivity
|
||||||
import com.shuwei.dish.match.ui.SubmitFoodActivity
|
import com.shuwei.dish.match.ui.SubmitFoodActivity
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
|
import com.shuwei.dish.match.net.NetViewModel
|
||||||
import com.shuwei.dish.match.utils.ext.startActivity
|
import com.shuwei.dish.match.utils.ext.startActivity
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import com.yanzhenjie.recyclerview.SwipeMenuItem
|
import com.yanzhenjie.recyclerview.SwipeMenuItem
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||||
|
|
||||||
@@ -46,13 +52,30 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val netViewModel: NetViewModel by viewModels()
|
||||||
|
|
||||||
private var pageNo = 1
|
private var pageNo = 1
|
||||||
private val pageSize = 30
|
private val pageSize = 100
|
||||||
|
|
||||||
private var dinnerType = "0"
|
private var dinnerType = "0"
|
||||||
|
|
||||||
|
/** 跟踪当前请求协程,新请求发起前取消旧的,防止并发竞态导致数据错乱 */
|
||||||
|
private var currentJob: Job? = null
|
||||||
|
|
||||||
|
/** 缓存最后一次搜索词,返回二级页面后 onResume 可复用,避免搜索态被重置为全量查询 */
|
||||||
|
private var currentFoodName: String? = null
|
||||||
|
|
||||||
private lateinit var activity: CookingModeActivity
|
private lateinit var activity: CookingModeActivity
|
||||||
|
|
||||||
|
/** 首次加载标记,首次请求时传 mealType=null 获取全餐次数据,后续切换传具体餐次 */
|
||||||
|
private var isFirstLoad = true
|
||||||
|
|
||||||
|
/** foodId → cookOrderId 映射,用于跳转 PrepareFoodActivity 时传递烹制单 ID */
|
||||||
|
private val cookOrderIdMap = mutableMapOf<String, String>()
|
||||||
|
|
||||||
|
/** 第一页时先查数据库存入此字段,网络结果回来后直接使用,避免时序问题 */
|
||||||
|
private var pendingLocalList: MutableList<CookFoodEntity>? = null
|
||||||
|
|
||||||
private var list: MutableList<FoodRecord> = mutableListOf()
|
private var list: MutableList<FoodRecord> = mutableListOf()
|
||||||
private val dishAdapter by lazy {
|
private val dishAdapter by lazy {
|
||||||
FoodListAdapter(list = list).apply {
|
FoodListAdapter(list = list).apply {
|
||||||
@@ -68,17 +91,19 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onItemClick(position: Int) {
|
private fun onItemClick(position: Int) {
|
||||||
val item = list[position]
|
val item = list.getOrNull(position) ?: return
|
||||||
if (item.isCooking) {
|
if (item.isCooking) {
|
||||||
// 烹饪中,跳到称熟重页面
|
// 烹饪中,跳到称熟重页面
|
||||||
activity.startActivity<SubmitFoodActivity> {
|
activity.startActivity<SubmitFoodActivity> {
|
||||||
putExtra(SubmitFoodActivity.FOOD_ITEM, item as Serializable)
|
putExtra(SubmitFoodActivity.FOOD_ITEM, item as Serializable)
|
||||||
|
putExtra(SubmitFoodActivity.COOK_ORDER_ID, cookOrderIdMap[item.foodId])
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
item.dinnerType = dinnerType
|
item.dinnerType = dinnerType
|
||||||
activity.startActivity<PrepareFoodActivity> {
|
activity.startActivity<PrepareFoodActivity> {
|
||||||
putExtra(PrepareFoodActivity.FOOD_ITEM, item as Serializable)
|
putExtra(PrepareFoodActivity.FOOD_ITEM, item as Serializable)
|
||||||
|
putExtra(PrepareFoodActivity.COOK_ORDER_ID, cookOrderIdMap[item.foodId])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,23 +142,30 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
// item 点击
|
// // item 点击
|
||||||
setOnItemClickListener { _, position ->
|
// setOnItemClickListener { _, position ->
|
||||||
if (isAdded && isVisible) {
|
// if (isAdded && isVisible) {
|
||||||
activity.judgeDeviceConfig { onItemClick(position) }
|
// activity.judgeDeviceConfig { onItemClick(position) }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
adapter = dishAdapter
|
adapter = dishAdapter
|
||||||
}
|
}
|
||||||
addViewListener()
|
addViewListener()
|
||||||
initObserver()
|
|
||||||
|
|
||||||
pageNo = 1
|
|
||||||
activity.showLoading()
|
|
||||||
getDishList()
|
|
||||||
binding.refreshLayout.setEnableRefresh(true)
|
binding.refreshLayout.setEnableRefresh(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
Log.d(TAG, "onResume, dinnerType=$dinnerType, isVisible=${isVisible}, isHidden=${isHidden}")
|
||||||
|
if (isHidden) return // 过滤 Activity 回前台时隐藏 tab 的无效触发
|
||||||
|
runCatching {
|
||||||
|
pageNo = 1
|
||||||
|
getDishList(currentFoodName)
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建统一样式的删除菜单项
|
* 构建统一样式的删除菜单项
|
||||||
*/
|
*/
|
||||||
@@ -146,50 +178,12 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 用 combine 同时监听网络结果与本地数据,网络成功时统一合并渲染
|
|
||||||
* pageNo > 1(加载更多)时 cookFoodListState 不参与合并,直接追加网络数据
|
|
||||||
*/
|
|
||||||
private fun initObserver() {
|
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
||||||
combine(
|
|
||||||
activity.netViewModel.searchFoodState,
|
|
||||||
activity.appViewModel.cookFoodListState
|
|
||||||
) { networkState, localList -> Pair(networkState, localList) }
|
|
||||||
.collect { (networkState, localList) ->
|
|
||||||
when (networkState) {
|
|
||||||
is UiState.Loading -> activity.showLoading()
|
|
||||||
is UiState.Success -> {
|
|
||||||
activity.delayDismissLoading()
|
|
||||||
finishRefresh()
|
|
||||||
loadAndMergeDishList(networkState.data, localList)
|
|
||||||
}
|
|
||||||
is UiState.Error -> {
|
|
||||||
if (isAdded.not()) return@collect
|
|
||||||
toast(networkState.msg)
|
|
||||||
finishRefresh()
|
|
||||||
activity.delayDismissLoading()
|
|
||||||
if (pageNo == 1) {
|
|
||||||
if (localList.isNullOrEmpty()) {
|
|
||||||
loadEmptyView()
|
|
||||||
} else {
|
|
||||||
loadAndMergeDishList(null, localList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is UiState.Idle -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addViewListener() {
|
private fun addViewListener() {
|
||||||
binding.refreshLayout.run {
|
binding.refreshLayout.run {
|
||||||
setEnableRefresh(true)
|
setEnableRefresh(true)
|
||||||
setEnableLoadMore(false)
|
setEnableLoadMore(false)
|
||||||
setOnRefreshListener {
|
setOnRefreshListener {
|
||||||
|
Log.d("FoodList", "下拉刷新触发, pageNo reset to 1")
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
getDishList()
|
getDishList()
|
||||||
}
|
}
|
||||||
@@ -199,10 +193,19 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDishList(pageNo: Int, dinnerType: String) {
|
override fun onHiddenChanged(hidden: Boolean) {
|
||||||
|
super.onHiddenChanged(hidden)
|
||||||
|
if (!hidden) {
|
||||||
|
Log.d("FoodList", "显示")
|
||||||
|
pageNo = 1
|
||||||
|
getDishList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getDishList(pageNo: Int, dinnerType: String, foodName: String? = null) {
|
||||||
this.pageNo = pageNo
|
this.pageNo = pageNo
|
||||||
this.dinnerType = dinnerType
|
this.dinnerType = dinnerType
|
||||||
getDishList()
|
getDishList(foodName)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDinnerTypeText(): String {
|
fun getDinnerTypeText(): String {
|
||||||
@@ -216,15 +219,53 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
@Suppress("unchecked_cast")
|
@Suppress("unchecked_cast")
|
||||||
fun getDishList() {
|
fun getDishList(foodName: String? = null) {
|
||||||
val param = mutableMapOf<String, Any>(
|
currentFoodName = foodName
|
||||||
"pageNum" to pageNo,
|
currentJob?.cancel()
|
||||||
"pageSize" to pageSize,
|
currentJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||||
"placeId" to BaseApp.canteenId,
|
// 首次加载传 mealType=null 获取所有餐次,切换 Tab 时传当前餐次精确请求
|
||||||
"dinnerType" to getDinnerTypeText()
|
val mealType = if (isFirstLoad) null else when (dinnerType) {
|
||||||
)
|
"1", "2", "3", "4" -> dinnerType.toInt()
|
||||||
activity.getFoodList(param = param)
|
else -> null // "0" 或非法值不传,由后端返回全部餐次
|
||||||
if (pageNo == 1) activity.getCookFoodList()
|
}
|
||||||
|
val request = CookOrderPageRequest(
|
||||||
|
mealType = mealType,
|
||||||
|
keyword = foodName
|
||||||
|
)
|
||||||
|
if (pageNo == 1) {
|
||||||
|
pendingLocalList = activity.dbViewModel.getCookFoodListDirect(
|
||||||
|
cookMode = 0,
|
||||||
|
dinnerType = dinnerType
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val localList = pendingLocalList
|
||||||
|
netViewModel.getCookOrderPageWithCallback(
|
||||||
|
request = request,
|
||||||
|
onLoading = { activity.showLoading(timeoutMs = 35_000L) }
|
||||||
|
) { result ->
|
||||||
|
when (result) {
|
||||||
|
is UiState.Success -> {
|
||||||
|
if (isAdded.not()) return@getCookOrderPageWithCallback
|
||||||
|
Log.d(TAG, "getDishList, UiState.Success")
|
||||||
|
isFirstLoad = false
|
||||||
|
activity.delayDismissLoading()
|
||||||
|
finishRefresh()
|
||||||
|
loadAndMergeCookOrders(result.data, localList)
|
||||||
|
}
|
||||||
|
is UiState.Error -> {
|
||||||
|
if (isAdded.not()) return@getCookOrderPageWithCallback
|
||||||
|
Log.d(TAG, "getDishList, UiState.Error")
|
||||||
|
isFirstLoad = false
|
||||||
|
toast(result.msg)
|
||||||
|
finishRefresh()
|
||||||
|
activity.delayDismissLoading()
|
||||||
|
if (localList.isNullOrEmpty()) loadEmptyView()
|
||||||
|
else loadAndMergeCookOrders(null, localList)
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var emptyViewBinding: LayoutEmptyViewBinding? = null
|
private var emptyViewBinding: LayoutEmptyViewBinding? = null
|
||||||
@@ -259,69 +300,100 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun finishRefresh() {
|
private fun finishRefresh() {
|
||||||
if (pageNo == 1) {
|
binding.refreshLayout.finishRefresh(1200)
|
||||||
binding.refreshLayout.finishRefresh(1200)
|
|
||||||
} else {
|
|
||||||
binding.refreshLayout.finishLoadMore(1200)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将网络数据与本地烹饪中数据合并后渲染列表
|
* 将 CookOrderItem 映射为 FoodRecord,适配现有 Adapter
|
||||||
|
* rawWeight 单位 kg → totalWeight 单位 g
|
||||||
|
*/
|
||||||
|
private fun CookOrderItem.toFoodRecord(): FoodRecord {
|
||||||
|
return FoodRecord(
|
||||||
|
foodId = foodId,
|
||||||
|
foodName = dishName,
|
||||||
|
totalWeight = ((cookedWeight ?: 0.0) * 1000),
|
||||||
|
foodWeight = ((cookedWeight ?: 0.0) * 1000),
|
||||||
|
count = cookedPortions,
|
||||||
|
cookMode = 0,
|
||||||
|
isCooking = cookStatus == 1,
|
||||||
|
dinnerType = mealType.toString(),
|
||||||
|
isOriginalData = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将新接口的餐次分组响应与本地烹饪中数据合并后渲染列表
|
||||||
|
* 从分组中按当前 dinnerType 筛选对应餐次的 cookOrders,映射为 FoodRecord 后合并本地数据
|
||||||
*/
|
*/
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun loadAndMergeDishList(
|
private fun loadAndMergeCookOrders(
|
||||||
records: MutableList<FoodRecord>?,
|
groups: List<CookOrderMealGroup>?,
|
||||||
localList: MutableList<CookFoodEntity>?
|
localList: MutableList<CookFoodEntity>?
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
if (isAdded.not()) return
|
if (isAdded.not()) return
|
||||||
val effectiveLocalList = if (pageNo == 1) localList else null
|
val targetMealType = dinnerType.toIntOrNull() ?: return
|
||||||
if (records.isNullOrEmpty() && effectiveLocalList.isNullOrEmpty()) {
|
// 从分组中筛选当前餐次的烹制单列表
|
||||||
if (pageNo == 1) loadEmptyView()
|
val cookOrders = groups
|
||||||
|
?.firstOrNull { it.mealType == targetMealType }
|
||||||
|
?.cookOrders
|
||||||
|
// 更新 foodId → cookOrderId 映射(从全量分组构建,跨餐次)
|
||||||
|
groups?.forEach { group ->
|
||||||
|
group.cookOrders.forEach { order ->
|
||||||
|
cookOrderIdMap[order.foodId] = order.cookOrderId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cookOrders.isNullOrEmpty() && localList.isNullOrEmpty()) {
|
||||||
|
loadEmptyView()
|
||||||
|
finishRefresh()
|
||||||
|
binding.refreshLayout.setEnableLoadMore(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (pageNo == 1) list.clear()
|
list.clear()
|
||||||
|
|
||||||
val mergedList = records?.toMutableList() ?: mutableListOf()
|
val mergedList = cookOrders?.map { it.toFoodRecord() }?.toMutableList() ?: mutableListOf()
|
||||||
|
mergeCookingItems(mergedList, localList)
|
||||||
if (!effectiveLocalList.isNullOrEmpty()) {
|
|
||||||
val cookingItems = mutableListOf<FoodRecord>()
|
|
||||||
effectiveLocalList.forEachIndexed { index, entity ->
|
|
||||||
val food = mergedList.firstOrNull { it.foodId == entity.foodId }
|
|
||||||
if (food != null) {
|
|
||||||
mergedList.remove(food)
|
|
||||||
food.isCooking = true
|
|
||||||
food.sort = index
|
|
||||||
food.dinnerType = entity.dinnerType ?: "0"
|
|
||||||
cookingItems.add(food)
|
|
||||||
} else {
|
|
||||||
cookingItems.add(
|
|
||||||
FoodRecord(
|
|
||||||
foodId = entity.foodId,
|
|
||||||
foodName = entity.foodName,
|
|
||||||
sort = index,
|
|
||||||
dinnerType = entity.dinnerType ?: "0",
|
|
||||||
isCooking = true
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mergedList.addAll(0, cookingItems)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pageNo >= 2 && !localList.isNullOrEmpty()) {
|
|
||||||
val localIds = localList.map { it.foodId }.toHashSet()
|
|
||||||
mergedList.removeAll { it.foodId in localIds }
|
|
||||||
}
|
|
||||||
|
|
||||||
list.addAll(mergedList)
|
list.addAll(mergedList)
|
||||||
dishAdapter.notifyDataSetChanged()
|
dishAdapter.notifyDataSetChanged()
|
||||||
val isLoadMoreEnable = (records?.size ?: 0) >= pageSize
|
binding.refreshLayout.setEnableRefresh(true)
|
||||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
binding.refreshLayout.setEnableLoadMore(false)
|
||||||
if (isLoadMoreEnable) pageNo++
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将本地烹饪中条目置顶合并到网络列表:
|
||||||
|
* 网络列表中已有的条目标记 isCooking 并移至顶部,没有的则新建占位条目
|
||||||
|
*/
|
||||||
|
private fun mergeCookingItems(
|
||||||
|
mergedList: MutableList<FoodRecord>,
|
||||||
|
cookingEntities: List<CookFoodEntity>?
|
||||||
|
) {
|
||||||
|
if (cookingEntities.isNullOrEmpty()) return
|
||||||
|
val cookingItems = mutableListOf<FoodRecord>()
|
||||||
|
cookingEntities.forEachIndexed { index, entity ->
|
||||||
|
val existing = mergedList.firstOrNull { it.foodId == entity.foodId }
|
||||||
|
if (existing != null) {
|
||||||
|
mergedList.remove(existing)
|
||||||
|
existing.isCooking = true
|
||||||
|
existing.sort = index
|
||||||
|
existing.dinnerType = entity.dinnerType ?: "0"
|
||||||
|
cookingItems.add(existing)
|
||||||
|
} else {
|
||||||
|
cookingItems.add(
|
||||||
|
FoodRecord(
|
||||||
|
foodId = entity.foodId,
|
||||||
|
foodName = entity.foodName,
|
||||||
|
sort = index,
|
||||||
|
dinnerType = entity.dinnerType ?: "0",
|
||||||
|
isCooking = true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mergedList.addAll(0, cookingItems)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import com.shuwei.dish.match.base.GlobalData
|
|||||||
import com.shuwei.dish.match.databinding.FragmentSeasoningConfigBinding
|
import com.shuwei.dish.match.databinding.FragmentSeasoningConfigBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.dialog.SeasoningSelectDialog
|
import com.shuwei.dish.match.dialog.SeasoningSelectDialog
|
||||||
import com.shuwei.dish.match.entity.SeasoningSlotEntity
|
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||||
import com.shuwei.dish.match.scale.ScaleEvent
|
import com.shuwei.dish.match.scale.ScaleEvent
|
||||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||||
@@ -50,7 +50,7 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
|
|||||||
) = FragmentSeasoningConfigBinding.inflate(inflater, container, false)
|
) = FragmentSeasoningConfigBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
private lateinit var currentActivity: SingleFragmentActivity
|
private lateinit var currentActivity: SingleFragmentActivity
|
||||||
// private lateinit var appViewModel: DbViewModel
|
// private lateinit var dbViewModel: DbViewModel
|
||||||
|
|
||||||
private val adapter22 by lazy { buildAdapter22() }
|
private val adapter22 by lazy { buildAdapter22() }
|
||||||
private val adapter18 by lazy {
|
private val adapter18 by lazy {
|
||||||
@@ -186,7 +186,7 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
|
|||||||
onUpdateName(name)
|
onUpdateName(name)
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
// 保存槽位配置
|
// 保存槽位配置
|
||||||
currentActivity.appViewModel.upsertSeasoningSlot(
|
currentActivity.dbViewModel.upsertSeasoningSlot(
|
||||||
SeasoningSlotEntity(
|
SeasoningSlotEntity(
|
||||||
deviceId = deviceId,
|
deviceId = deviceId,
|
||||||
address = address,
|
address = address,
|
||||||
@@ -195,7 +195,7 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
// 按 goodsId 去重保存完整调料信息到 dm_seasoning
|
// 按 goodsId 去重保存完整调料信息到 dm_seasoning
|
||||||
currentActivity.appViewModel.upsertSeasoningByGoodsId(item.toSeasoningEntity())
|
currentActivity.dbViewModel.upsertSeasoningByGoodsId(item.toSeasoningEntity())
|
||||||
broadcastAllSlots()
|
broadcastAllSlots()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
|
|||||||
/** 将单个槽位写入 Room,再广播全量配置给子设备 */
|
/** 将单个槽位写入 Room,再广播全量配置给子设备 */
|
||||||
private fun saveSlotAndBroadcast(slot: SeasoningSlotEntity) {
|
private fun saveSlotAndBroadcast(slot: SeasoningSlotEntity) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
currentActivity.appViewModel.upsertSeasoningSlot(slot)
|
currentActivity.dbViewModel.upsertSeasoningSlot(slot)
|
||||||
broadcastAllSlots()
|
broadcastAllSlots()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,14 +233,14 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
|
|||||||
/** 从 Room 删除指定槽位,再广播全量配置给子设备 */
|
/** 从 Room 删除指定槽位,再广播全量配置给子设备 */
|
||||||
private fun deleteSlotAndBroadcast(deviceId: String, address: Int) {
|
private fun deleteSlotAndBroadcast(deviceId: String, address: Int) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
currentActivity.appViewModel.deleteSeasoningSlot(deviceId, address)
|
currentActivity.dbViewModel.deleteSeasoningSlot(deviceId, address)
|
||||||
broadcastAllSlots()
|
broadcastAllSlots()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 读取全量槽位配置并通过 wsClient 推送给所有已连接子设备 */
|
/** 读取全量槽位配置并通过 wsClient 推送给所有已连接子设备 */
|
||||||
private suspend fun broadcastAllSlots() {
|
private suspend fun broadcastAllSlots() {
|
||||||
val allSlots = currentActivity.appViewModel.loadSeasoningSlot().map {
|
val allSlots = currentActivity.dbViewModel.loadSeasoningSlot().map {
|
||||||
SlotConfig(it.deviceId, it.address, it.goodsId, it.goodsName)
|
SlotConfig(it.deviceId, it.address, it.goodsId, it.goodsName)
|
||||||
}
|
}
|
||||||
ScaleServiceManager.sendSeasoningConfig(allSlots)
|
ScaleServiceManager.sendSeasoningConfig(allSlots)
|
||||||
@@ -249,7 +249,7 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
|
|||||||
// /** 初始化 ViewModel */
|
// /** 初始化 ViewModel */
|
||||||
// private fun initViewModel() {
|
// private fun initViewModel() {
|
||||||
// val factory = AppFactory(DbRepository(BaseApp.instance!!.database.appDao()))
|
// val factory = AppFactory(DbRepository(BaseApp.instance!!.database.appDao()))
|
||||||
// appViewModel = ViewModelProvider(this, factory)[DbViewModel::class.java]
|
// dbViewModel = ViewModelProvider(this, factory)[DbViewModel::class.java]
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
@@ -292,9 +292,9 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
|
|||||||
adapter22.update(emptyList())
|
adapter22.update(emptyList())
|
||||||
adapter18.update(emptyList())
|
adapter18.update(emptyList())
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val slots22 = currentActivity.appViewModel.getSeasoningSlotsByDeviceId(ScaleDeviceConfig.DEVICE_ID_22)
|
val slots22 = currentActivity.dbViewModel.getSeasoningSlotsByDeviceId(ScaleDeviceConfig.DEVICE_ID_22)
|
||||||
val slots18 = currentActivity.appViewModel.getSeasoningSlotsByDeviceId(ScaleDeviceConfig.DEVICE_ID_18)
|
val slots18 = currentActivity.dbViewModel.getSeasoningSlotsByDeviceId(ScaleDeviceConfig.DEVICE_ID_18)
|
||||||
val slotsOil = currentActivity.appViewModel.getSeasoningSlotsByDeviceId(ScaleDeviceConfig.DEVICE_ID_1)
|
val slotsOil = currentActivity.dbViewModel.getSeasoningSlotsByDeviceId(ScaleDeviceConfig.DEVICE_ID_1)
|
||||||
slots22.forEach { slot ->
|
slots22.forEach { slot ->
|
||||||
val pos = ScaleDeviceConfig.SCALE_ORDER_22.indexOf(slot.address)
|
val pos = ScaleDeviceConfig.SCALE_ORDER_22.indexOf(slot.address)
|
||||||
if (pos >= 0) adapter22.updateItemName(pos, slot.goodsName)
|
if (pos >= 0) adapter22.updateItemName(pos, slot.goodsName)
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ import com.shuwei.dish.match.databinding.FragmentVectorCollectionBinding
|
|||||||
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
|
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||||
import com.shuwei.dish.match.dialog.Loading
|
import com.shuwei.dish.match.dialog.Loading
|
||||||
import com.shuwei.dish.match.entity.FoodCollectionBean
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.FoodCollectionBean
|
||||||
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.objbox.Food
|
import com.shuwei.dish.match.objbox.Food
|
||||||
import com.shuwei.dish.match.objbox.FoodModule
|
import com.shuwei.dish.match.objbox.FoodModule
|
||||||
@@ -46,12 +47,9 @@ import com.shuwei.dish.match.utils.Debouncer
|
|||||||
import com.shuwei.dish.match.utils.ImageUploader
|
import com.shuwei.dish.match.utils.ImageUploader
|
||||||
import com.shuwei.dish.match.utils.ImageUtil
|
import com.shuwei.dish.match.utils.ImageUtil
|
||||||
import com.shuwei.dish.match.utils.LogSaveUtil
|
import com.shuwei.dish.match.utils.LogSaveUtil
|
||||||
import com.shuwei.dish.match.utils.buildSingleChoiceChipGroup
|
|
||||||
import com.shuwei.dish.match.utils.buildMockGoodsList
|
|
||||||
import com.shuwei.dish.match.utils.showRawMaterialsDialog
|
import com.shuwei.dish.match.utils.showRawMaterialsDialog
|
||||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
@@ -81,7 +79,7 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
// 开启空状态视图能力,否则 stateView 赋值不会生效
|
// 开启空状态视图能力,否则 stateView 赋值不会生效
|
||||||
isStateViewEnable = true
|
isStateViewEnable = true
|
||||||
setOnDebouncedItemClick { _, _, position ->
|
setOnDebouncedItemClick { _, _, position ->
|
||||||
val item = searchList[position]
|
val item = searchList.getOrNull(position) ?: return@setOnDebouncedItemClick
|
||||||
// 弹出净材种类单选弹窗
|
// 弹出净材种类单选弹窗
|
||||||
showRawMaterialsDialog(
|
showRawMaterialsDialog(
|
||||||
context = requireContext(),
|
context = requireContext(),
|
||||||
@@ -113,7 +111,7 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
private val vectorAdapter: VectorCollectionAdapter by lazy {
|
private val vectorAdapter: VectorCollectionAdapter by lazy {
|
||||||
VectorCollectionAdapter(vectorList).apply {
|
VectorCollectionAdapter(vectorList).apply {
|
||||||
addOnItemChildClickListener(R.id.ivDelete) { _, _, position ->
|
addOnItemChildClickListener(R.id.ivDelete) { _, _, position ->
|
||||||
vectorList[position].let {
|
vectorList.getOrNull(position)?.let {
|
||||||
it.bitmap = null
|
it.bitmap = null
|
||||||
it.imageVector = null
|
it.imageVector = null
|
||||||
it.imageFile = null
|
it.imageFile = null
|
||||||
@@ -121,8 +119,8 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
it.isShowCamera = true
|
it.isShowCamera = true
|
||||||
it.isFinish = false
|
it.isFinish = false
|
||||||
it.uploadSuccess = false
|
it.uploadSuccess = false
|
||||||
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
notifyItemChanged(position)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +300,14 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
}
|
}
|
||||||
takePhoto()
|
takePhoto()
|
||||||
}
|
}
|
||||||
binding.btnClearData.setOnClickListener { clearData() }
|
binding.btnClearData.setOnClickListener {
|
||||||
|
CommonDialog(requireContext())
|
||||||
|
.setTitle("清空确认")
|
||||||
|
.setContent("确认清空所有已采集的图片数据?")
|
||||||
|
.setNegativeButton("取消")
|
||||||
|
.setPositiveButton("确认") { clearData() }
|
||||||
|
.show()
|
||||||
|
}
|
||||||
binding.rvSearchFood.let {
|
binding.rvSearchFood.let {
|
||||||
it.layoutManager = GridLayoutManager(context, 2)
|
it.layoutManager = GridLayoutManager(context, 2)
|
||||||
it.adapter = searchAdapter
|
it.adapter = searchAdapter
|
||||||
@@ -316,6 +321,13 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
is UiState.Success -> {
|
is UiState.Success -> {
|
||||||
val list = state.data ?: emptyList()
|
val list = state.data ?: emptyList()
|
||||||
if (list.isEmpty()) loadEmptyView() else fillSearchList(list)
|
if (list.isEmpty()) loadEmptyView() else fillSearchList(list)
|
||||||
|
currentActivity.netViewModel.resetGoodsListState()
|
||||||
|
}
|
||||||
|
|
||||||
|
is UiState.Error -> {
|
||||||
|
toast(state.msg)
|
||||||
|
loadEmptyView()
|
||||||
|
currentActivity.netViewModel.resetGoodsListState()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> Unit
|
else -> Unit
|
||||||
@@ -330,7 +342,9 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
private fun upload() {
|
private fun upload() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val totalFileCount = vectorList.count { it.imageFile != null }
|
val totalFileCount = vectorList.count { it.imageFile != null }
|
||||||
showWaitingDialog("图片上传中0/$totalFileCount")
|
// 上传场景单批可能耗时较长(含图片传输 + 网络往返),用 60s 超时兜底
|
||||||
|
// 每次 onProgress 都会重新调用 showWaitingDialog,会重置定时器,正常进度不会触发兜底
|
||||||
|
showWaitingDialog("图片上传中0/$totalFileCount", timeoutMs = 60_000L)
|
||||||
val params = mutableMapOf<String, RequestBody>()
|
val params = mutableMapOf<String, RequestBody>()
|
||||||
params["goodsId"] = checkedItem!!.goodsId.toRequestBody()
|
params["goodsId"] = checkedItem!!.goodsId.toRequestBody()
|
||||||
params["goodsName"] = checkedItem!!.goodsName!!.toRequestBody()
|
params["goodsName"] = checkedItem!!.goodsName!!.toRequestBody()
|
||||||
@@ -352,9 +366,10 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
// 直接 await 单批上传结果,成功返回 id 列表,失败返回 null 触发 onError
|
// 直接 await 单批上传结果,成功返回 id 列表,失败返回 null 触发 onError
|
||||||
val result = currentActivity.netViewModel.uploadFoodVectorDataBatch(files, params)
|
val result = currentActivity.netViewModel.uploadFoodVectorDataBatch(files, params)
|
||||||
log("uploadImage返回:result=${result.toJsonString()}")
|
log("uploadImage返回:result=${result.toJsonString()}")
|
||||||
if (result is UiState.Success) result.data else null
|
if (result is UiState.Success) result.data to null
|
||||||
|
else null to (result as? UiState.Error)?.msg
|
||||||
}, onProgress = { count, batch, idList ->
|
}, onProgress = { count, batch, idList ->
|
||||||
showWaitingDialog("图片上传中$count/$totalFileCount")
|
showWaitingDialog("图片上传中$count/$totalFileCount", timeoutMs = 60_000L)
|
||||||
val foodList = batch.mapIndexed { index, it ->
|
val foodList = batch.mapIndexed { index, it ->
|
||||||
val name = checkedItem!!.goodsName + "&&" + checkedItem!!.rawMaterialsType
|
val name = checkedItem!!.goodsName + "&&" + checkedItem!!.rawMaterialsType
|
||||||
Food(
|
Food(
|
||||||
@@ -365,10 +380,10 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
ObjectBox.putAll(foodList)
|
ObjectBox.putAll(foodList)
|
||||||
batch.forEach { it.isFinish = true }
|
batch.forEach { it.isFinish = true }
|
||||||
vectorAdapter.notifyDataSetChanged()
|
vectorAdapter.notifyDataSetChanged()
|
||||||
}, onError = {
|
}, onError = { _, errorMsg ->
|
||||||
binding.root.postDelayed({
|
binding.root.postDelayed({
|
||||||
hideWaitingDialog()
|
hideWaitingDialog()
|
||||||
toast("上传失败,请稍后重试")
|
toast("上传失败:${(errorMsg ?: "").ifBlank { "请稍后重试" }}")
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}, onComplete = {
|
}, onComplete = {
|
||||||
binding.root.postDelayed({
|
binding.root.postDelayed({
|
||||||
@@ -381,9 +396,11 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
fun searchFood() {
|
fun searchFood() {
|
||||||
|
log("searchFood")
|
||||||
|
// 立即重置,防止 StateFlow 向新订阅者重播旧的错误状态
|
||||||
|
currentActivity.netViewModel.resetGoodsListState()
|
||||||
debouncer.debounce {
|
debouncer.debounce {
|
||||||
val keyword = binding.editFoodName.text.toString().trim()
|
val keyword = binding.editFoodName.text.toString().trim()
|
||||||
// 通过 NetViewModel 查询净材数据(goodsType=0 食材),结果由 initialize() 中的 observer 统一处理
|
|
||||||
currentActivity.netViewModel.queryGoodsList(
|
currentActivity.netViewModel.queryGoodsList(
|
||||||
goodsType = "0",
|
goodsType = "0",
|
||||||
goodsName = keyword.ifEmpty { null }
|
goodsName = keyword.ifEmpty { null }
|
||||||
@@ -398,9 +415,11 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun fillSearchList(list: List<GoodsItem>) {
|
private fun fillSearchList(list: List<GoodsItem>) {
|
||||||
// 将 rawMaterialsType 转存到 rawMaterialsTypes,并清空 rawMaterialsType
|
// 将 rawMaterialsType 转存到 rawMaterialsTypes,并清空 rawMaterialsType
|
||||||
list.forEach { item ->
|
list.forEach {
|
||||||
item.rawMaterialsTypes = item.rawMaterialsType
|
it.rawMaterialsTypes = it.rawMaterialsType
|
||||||
item.rawMaterialsType = null
|
it.rawMaterialsType = null
|
||||||
|
it.oldGoodsId = it.goodsId
|
||||||
|
it.goodsId = it.materId ?: ""
|
||||||
}
|
}
|
||||||
// 空布局切过 LinearLayoutManager,此处恢复为 2 列 GridLayoutManager
|
// 空布局切过 LinearLayoutManager,此处恢复为 2 列 GridLayoutManager
|
||||||
if (binding.rvSearchFood.layoutManager !is GridLayoutManager) {
|
if (binding.rvSearchFood.layoutManager !is GridLayoutManager) {
|
||||||
@@ -437,13 +456,13 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
}
|
}
|
||||||
emptyViewBinding?.let {
|
emptyViewBinding?.let {
|
||||||
it.tvContent.text = "暂无数据"
|
it.tvContent.text = "暂无数据"
|
||||||
it.tvSubContent.text = "点击此处重新查询"
|
it.tvSubContent.text = "未查询到食材信息,请稍后重试"
|
||||||
// 点击空布局填充本地假数据,便于 UI 效果测试
|
|
||||||
it.root.setOnClickListener {
|
|
||||||
fillSearchList(buildMockGoodsList())
|
|
||||||
}
|
|
||||||
binding.rvSearchFood.post {
|
binding.rvSearchFood.post {
|
||||||
it.root.minimumHeight = binding.rvSearchFood.height
|
it.root.minimumHeight = binding.rvSearchFood.height
|
||||||
|
// 在 stateView 挂载完成后再设置点击监听,避免 adapter 重置 view 状态时丢失监听器
|
||||||
|
it.root.setOnClickListener {
|
||||||
|
searchFood()
|
||||||
|
}
|
||||||
searchAdapter.stateView = it.root
|
searchAdapter.stateView = it.root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -468,8 +487,8 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
vectorAdapter.notifyDataSetChanged()
|
vectorAdapter.notifyDataSetChanged()
|
||||||
|
|
||||||
clickIndex = -1
|
clickIndex = -1
|
||||||
|
// setText("") 会触发 addTextChangedListener → searchFood(),无需再次直接调用
|
||||||
binding.editFoodName.setText("")
|
binding.editFoodName.setText("")
|
||||||
searchFood()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var isFirstOpen = true
|
private var isFirstOpen = true
|
||||||
@@ -499,12 +518,14 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
|
|||||||
currentActivity.dismissLoading()
|
currentActivity.dismissLoading()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showWaitingDialog(msg: String) {
|
/**
|
||||||
if (Loading.isShowing()) {
|
* 显示等待弹窗
|
||||||
Loading.updateContent(msg)
|
* @param msg 提示文案
|
||||||
return
|
* @param timeoutMs 超时兜底时长(毫秒):到期自动关闭,传 0 关闭兜底
|
||||||
}
|
* Loading 内部已做节流,重复调用只会更新文案 + 重置超时定时器
|
||||||
currentActivity.showLoading(msg)
|
*/
|
||||||
|
private fun showWaitingDialog(msg: String, timeoutMs: Long = Loading.DEFAULT_TIMEOUT_MS) {
|
||||||
|
currentActivity.showLoading(msg, timeoutMs)
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var previewView: PreviewView
|
private lateinit var previewView: PreviewView
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.shuwei.dish.match.ui.fragment
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.shuwei.dish.match.base.BaseFragment
|
||||||
|
import com.shuwei.dish.match.databinding.FragmentWeightConfigBinding
|
||||||
|
import com.shuwei.dish.match.utils.SpTool
|
||||||
|
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||||
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认减重配置 Fragment
|
||||||
|
* 允许用户设置打开 PrepareFoodActivity 时的初始减重基准值(单位:克)
|
||||||
|
*/
|
||||||
|
class WeightConfigFragment : BaseFragment<FragmentWeightConfigBinding>() {
|
||||||
|
|
||||||
|
override fun inflateBinding(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?
|
||||||
|
): FragmentWeightConfigBinding {
|
||||||
|
return FragmentWeightConfigBinding.inflate(inflater, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun initialize() {
|
||||||
|
// 若已有配置值则回填到输入框
|
||||||
|
val saved = SpTool.configWeight
|
||||||
|
if (saved != 0) {
|
||||||
|
binding.etConfigWeight.setText(saved.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.btnConfirm.clickWithDebounce {
|
||||||
|
val input = binding.etConfigWeight.text.toString().trim()
|
||||||
|
if (input.isEmpty()) {
|
||||||
|
toast("请输入减重值")
|
||||||
|
return@clickWithDebounce
|
||||||
|
}
|
||||||
|
val weight = input.toIntOrNull()
|
||||||
|
if (weight == null || weight < 0) {
|
||||||
|
toast("请输入有效的减重值")
|
||||||
|
return@clickWithDebounce
|
||||||
|
}
|
||||||
|
SpTool.configWeight = weight
|
||||||
|
toast("保存成功")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import android.os.Looper
|
|||||||
import android.os.Process
|
import android.os.Process
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.shuwei.dish.match.ui.HomeActivity
|
import com.shuwei.dish.match.ui.HomeActivity
|
||||||
|
import com.shuwei.dish.match.ui.InitActivity
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -75,7 +76,7 @@ class CrashHandler private constructor(private val context: Context) :
|
|||||||
private fun restartApp() {
|
private fun restartApp() {
|
||||||
// 延迟1秒后重启应用
|
// 延迟1秒后重启应用
|
||||||
Handler(Looper.getMainLooper()).postDelayed({
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
val intent = Intent(context, HomeActivity::class.java).apply {
|
val intent = Intent(context, InitActivity::class.java).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
package com.shuwei.dish.match.utils
|
//package com.shuwei.dish.match.utils
|
||||||
|
//
|
||||||
import com.google.gson.TypeAdapter
|
//import com.google.gson.TypeAdapter
|
||||||
import com.google.gson.stream.JsonReader
|
//import com.google.gson.stream.JsonReader
|
||||||
import com.google.gson.stream.JsonToken
|
//import com.google.gson.stream.JsonToken
|
||||||
import com.google.gson.stream.JsonWriter
|
//import com.google.gson.stream.JsonWriter
|
||||||
|
//
|
||||||
class DecimalAdapter : TypeAdapter<Number>() {
|
//class DecimalAdapter : TypeAdapter<Number>() {
|
||||||
override fun write(out: JsonWriter, value: Number) {
|
// override fun write(out: JsonWriter, value: Number) {
|
||||||
// out.value(value.toString()) // 强制以字符串形式写入
|
//// out.value(value.toString()) // 强制以字符串形式写入
|
||||||
out.value("$value") // 强制以字符串形式写入
|
// out.value("$value") // 强制以字符串形式写入
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun read(reader: JsonReader): Number {
|
// override fun read(reader: JsonReader): Number {
|
||||||
return when (reader.peek()) {
|
// return when (reader.peek()) {
|
||||||
JsonToken.NUMBER -> reader.nextDouble()
|
// JsonToken.NUMBER -> reader.nextDouble()
|
||||||
JsonToken.STRING -> reader.nextString().toDouble()
|
// JsonToken.STRING -> reader.nextString().toDouble()
|
||||||
else -> 0.0
|
// else -> 0.0
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
// 使用方式
|
//// 使用方式
|
||||||
//val gson = GsonBuilder()
|
////val gson = GsonBuilder()
|
||||||
// .registerTypeAdapter(Double::class.java, DecimalAdapter())
|
//// .registerTypeAdapter(Double::class.java, DecimalAdapter())
|
||||||
// .create()
|
//// .create()
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package com.shuwei.dish.match.utils
|
package com.shuwei.dish.match.utils
|
||||||
|
|
||||||
import com.shuwei.dish.match.entity.FoodCollectionBean
|
import com.shuwei.dish.match.model.FoodCollectionBean
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
class ImageUploader(
|
class ImageUploader(
|
||||||
private val totalList: List<FoodCollectionBean>,
|
private val totalList: List<FoodCollectionBean>,
|
||||||
private val uploadImage: suspend (List<FoodCollectionBean>) -> List<String>?,
|
private val uploadImage: suspend (List<FoodCollectionBean>) -> Pair<List<String>?, String?>,
|
||||||
private val onProgress: suspend (Int, List<FoodCollectionBean>, List<String>) -> Unit,
|
private val onProgress: suspend (Int, List<FoodCollectionBean>, List<String>) -> Unit,
|
||||||
private val onError: (List<FoodCollectionBean>) -> Unit,
|
private val onError: (List<FoodCollectionBean>, String?) -> Unit,
|
||||||
private val onComplete: () -> Unit
|
private val onComplete: () -> Unit
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -19,10 +19,9 @@ class ImageUploader(
|
|||||||
val batches = totalList.filter { it.imageVector!=null }.chunked(BATCH_SIZE)
|
val batches = totalList.filter { it.imageVector!=null }.chunked(BATCH_SIZE)
|
||||||
|
|
||||||
for (batch in batches) {
|
for (batch in batches) {
|
||||||
val idList = uploadImage(batch)
|
val (idList, errorMsg) = uploadImage(batch)
|
||||||
if (idList.isNullOrEmpty()) {
|
if (idList.isNullOrEmpty()) {
|
||||||
//println("上传失败,终止流程")
|
onError(batch, errorMsg)
|
||||||
onError(batch)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val fileCount = batch.count { it.imageFile!=null }
|
val fileCount = batch.count { it.imageFile!=null }
|
||||||
|
|||||||
@@ -3,15 +3,28 @@ package com.shuwei.dish.match.utils
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.LinkProperties
|
import android.net.LinkProperties
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网络工具类
|
* 网络工具类,提供网络状态检测和本机 IP 获取功能
|
||||||
*/
|
*/
|
||||||
object NetworkUtil {
|
object NetworkUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测设备是否连接到网络
|
||||||
|
* @param context 应用上下文
|
||||||
|
* @return true 表示已连接网络,false 表示未连接
|
||||||
|
*/
|
||||||
|
fun isNetworkConnected(context: Context): Boolean {
|
||||||
|
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
val network = cm.activeNetwork ?: return false
|
||||||
|
val capabilities = cm.getNetworkCapabilities(network) ?: return false
|
||||||
|
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取本机局域网 IPv4 地址
|
* 获取本机局域网 IPv4 地址
|
||||||
* - Android 12+(API 31+):使用 ConnectivityManager + LinkProperties,避免废弃 API
|
* - Android 12+(API 31+):使用 ConnectivityManager + LinkProperties,避免废弃 API
|
||||||
@@ -60,3 +73,4 @@ object NetworkUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.shuwei.dish.match.utils
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.net.ConnectivityManager
|
|
||||||
import android.net.NetworkCapabilities
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 网络连接检测工具类
|
|
||||||
* 提供检测设备网络连接状态的功能
|
|
||||||
*/
|
|
||||||
object NetworkUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测设备是否连接到网络
|
|
||||||
* @param context 应用上下文
|
|
||||||
* @return true 表示已连接网络,false 表示未连接
|
|
||||||
*/
|
|
||||||
fun isNetworkConnected(context: Context): Boolean {
|
|
||||||
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
|
||||||
val network = connectivityManager.activeNetwork ?: return false
|
|
||||||
val capabilities = connectivityManager.getNetworkCapabilities(network) ?: return false
|
|
||||||
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,21 +3,22 @@ package com.shuwei.dish.match.utils
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipGroup
|
import com.google.android.material.chip.ChipGroup
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.entity.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
import com.shuwei.dish.match.utils.ext.gone
|
import com.shuwei.dish.match.utils.ext.gone
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
|
|
||||||
/**
|
///**
|
||||||
* 构造用于效果测试的食材假数据
|
// * 构造用于效果测试的食材假数据
|
||||||
* TODO: 联调完成后删除
|
// * TODO: 联调完成后删除
|
||||||
*/
|
// */
|
||||||
fun buildMockGoodsList(): List<GoodsItem> = mutableListOf(
|
//fun buildMockGoodsList(): List<GoodsItem> = mutableListOf(
|
||||||
// GoodsItem(goodsId = "1", goodsName = "土豆", rawMaterialsType = "土豆丝,土豆条,土豆片,土豆丁"),
|
// GoodsItem(goodsId = "1", goodsName = "土豆", rawMaterialsType = "土豆丝,土豆条,土豆片,土豆丁"),
|
||||||
// GoodsItem(goodsId = "2", goodsName = "胡萝卜", rawMaterialsType = "胡萝卜丝,胡萝卜片,胡萝卜丁"),
|
// GoodsItem(goodsId = "2", goodsName = "胡萝卜", rawMaterialsType = "胡萝卜丝,胡萝卜片,胡萝卜丁"),
|
||||||
// GoodsItem(goodsId = "3", goodsName = "黄瓜", rawMaterialsType = "黄瓜丝,黄瓜片,黄瓜丁,黄瓜块"),
|
// GoodsItem(goodsId = "3", goodsName = "黄瓜", rawMaterialsType = "黄瓜丝,黄瓜片,黄瓜丁,黄瓜块"),
|
||||||
@@ -39,7 +40,7 @@ fun buildMockGoodsList(): List<GoodsItem> = mutableListOf(
|
|||||||
// GoodsItem(goodsId = "18", goodsName = "香菇"),
|
// GoodsItem(goodsId = "18", goodsName = "香菇"),
|
||||||
// GoodsItem(goodsId = "19", goodsName = "木耳"),
|
// GoodsItem(goodsId = "19", goodsName = "木耳"),
|
||||||
// GoodsItem(goodsId = "20", goodsName = "豆芽"),
|
// GoodsItem(goodsId = "20", goodsName = "豆芽"),
|
||||||
)
|
//)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 弹出净材种类单选弹窗
|
* 弹出净材种类单选弹窗
|
||||||
@@ -65,8 +66,8 @@ fun showRawMaterialsDialog(
|
|||||||
|
|
||||||
if (typeList.isEmpty()) {
|
if (typeList.isEmpty()) {
|
||||||
// 无净材数据时仅展示提示文字
|
// 无净材数据时仅展示提示文字
|
||||||
dialog.setContent("无净材数据")
|
dialog.setContent("暂无净材种类,联系管理员添加")
|
||||||
.setPositiveButton("确认") {}
|
.setSingleButton("确认") {}
|
||||||
} else {
|
} else {
|
||||||
// 构建单选 ChipGroup 作为自定义内容
|
// 构建单选 ChipGroup 作为自定义内容
|
||||||
val chipGroup = buildSingleChoiceChipGroup(context, typeList, checkedType)
|
val chipGroup = buildSingleChoiceChipGroup(context, typeList, checkedType)
|
||||||
@@ -111,9 +112,10 @@ fun buildSingleChoiceChipGroup(
|
|||||||
text = typeName
|
text = typeName
|
||||||
textSize = 22f
|
textSize = 22f
|
||||||
isCheckable = true
|
isCheckable = true
|
||||||
chipStartPadding = 20.dp.toFloat()
|
textAlignment = View.TEXT_ALIGNMENT_CENTER
|
||||||
chipEndPadding = 20.dp.toFloat()
|
chipStartPadding = 15.dp.toFloat()
|
||||||
chipMinHeight = (textSize + 15.dp * 2).toFloat()
|
chipEndPadding = 15.dp.toFloat()
|
||||||
|
chipMinHeight = textSize + 15.dp * 2
|
||||||
// 选中/未选中态背景色:主题绿 / 浅灰
|
// 选中/未选中态背景色:主题绿 / 浅灰
|
||||||
chipBackgroundColor = ColorStateList(
|
chipBackgroundColor = ColorStateList(
|
||||||
arrayOf(
|
arrayOf(
|
||||||
@@ -145,7 +147,12 @@ fun buildSingleChoiceChipGroup(
|
|||||||
// 若当前项已有选中值则默认勾选对应选项
|
// 若当前项已有选中值则默认勾选对应选项
|
||||||
isChecked = (typeName == checkedType)
|
isChecked = (typeName == checkedType)
|
||||||
}
|
}
|
||||||
addView(chip)
|
// 先用 UNSPECIFIED 测出自然宽度,再取 max(自然宽, 120dp),实现"最小宽度 120dp"
|
||||||
|
chip.measure(
|
||||||
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
|
||||||
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||||
|
)
|
||||||
|
addView(chip, ViewGroup.LayoutParams(maxOf(120.dp, chip.measuredWidth), ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.shuwei.dish.match.utils
|
package com.shuwei.dish.match.utils
|
||||||
|
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
|
import com.shuwei.dish.match.base.GlobalKey
|
||||||
import com.shuwei.dish.match.utils.ext.put
|
import com.shuwei.dish.match.utils.ext.put
|
||||||
|
|
||||||
object SpTool {
|
object SpTool {
|
||||||
@@ -15,6 +16,8 @@ object SpTool {
|
|||||||
const val SCALE_DEVICE_PORT = "scaleDevicePort"
|
const val SCALE_DEVICE_PORT = "scaleDevicePort"
|
||||||
/** 食堂 ID,默认 "0" */
|
/** 食堂 ID,默认 "0" */
|
||||||
const val CANTEEN_ID = "canteenId"
|
const val CANTEEN_ID = "canteenId"
|
||||||
|
/** 默认减重克数 */
|
||||||
|
const val CONFIG_WEIGHT = "configWeight"
|
||||||
|
|
||||||
val pref = BaseApp.getSharedPref()!!
|
val pref = BaseApp.getSharedPref()!!
|
||||||
|
|
||||||
@@ -40,10 +43,24 @@ object SpTool {
|
|||||||
put(LAUNCH_PAGE_TYPE, value)
|
put(LAUNCH_PAGE_TYPE, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 默认减重(克),打开 PrepareFoodActivity 时作为 initialWeight 基准值 */
|
||||||
|
var configWeight: Int
|
||||||
|
get() = getInt(CONFIG_WEIGHT, 0)
|
||||||
|
set(value) {
|
||||||
|
put(CONFIG_WEIGHT, value)
|
||||||
|
}
|
||||||
|
|
||||||
/** 食堂 ID,持久化存储,默认 "0" */
|
/** 食堂 ID,持久化存储,默认 "0" */
|
||||||
var canteenId: String
|
var canteenId: String
|
||||||
get() = getString(CANTEEN_ID, "0")
|
get() = getString(CANTEEN_ID, "0")
|
||||||
set(value) {
|
set(value) {
|
||||||
put(CANTEEN_ID, value)
|
put(CANTEEN_ID, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 环境 BaseUrl,持久化存储,默认空字符串(空时使用 GlobalData 默认值) */
|
||||||
|
var baseUrl: String
|
||||||
|
get() = getString(GlobalKey.KEY_BASE_URL, "")
|
||||||
|
set(value) {
|
||||||
|
put(GlobalKey.KEY_BASE_URL, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ package com.shuwei.dish.match.utils
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||||
//import com.aithings.Weigher
|
|
||||||
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
|
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
@@ -11,16 +10,33 @@ typealias WeightCallback = (address: Int, state: Int, weight: Double) -> Unit
|
|||||||
|
|
||||||
object WeightUtil {
|
object WeightUtil {
|
||||||
private const val TAG = "WeightUtil"
|
private const val TAG = "WeightUtil"
|
||||||
const val STATE_STABLE = SensorScale.STATE_STABLE
|
// 使用字面量常量,避免在非 ARM 设备上触发 SensorScale 类加载
|
||||||
const val STATE_UNSTABLE = SensorScale.STATE_UNSTABLE
|
const val STATE_STABLE = 1
|
||||||
const val STATE_OVER_WEIGHT = SensorScale.STATE_OVER_WEIGHT
|
const val STATE_UNSTABLE = 0
|
||||||
|
const val STATE_OVER_WEIGHT = 2
|
||||||
|
|
||||||
var isConnected = false
|
var isConnected = false
|
||||||
|
/** 秤 SDK 是否可用;非 ARM 设备上为 false,所有秤操作将静默跳过 */
|
||||||
|
var isAvailable = false
|
||||||
val weightFuncMap: ConcurrentHashMap<String, WeightCallback?> = ConcurrentHashMap()
|
val weightFuncMap: ConcurrentHashMap<String, WeightCallback?> = ConcurrentHashMap()
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
SensorScale.isLog = true
|
val abi = Build.SUPPORTED_ABIS.firstOrNull() ?: ""
|
||||||
Weigher2.init()
|
if (!abi.startsWith("arm")) {
|
||||||
|
Log.w(TAG, "当前架构 $abi 不支持秤 SDK,已跳过初始化")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
SensorScale.isLog = true
|
||||||
|
Weigher2.init()
|
||||||
|
} catch (e: UnsatisfiedLinkError) {
|
||||||
|
Log.w(TAG, "秤 SDK 加载失败(非 ARM 设备),已跳过: ${e.message}")
|
||||||
|
return
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "秤 SDK 初始化异常,已跳过: ${e.message}")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isAvailable = true
|
||||||
Weigher2.setListener(object : WeightListenerImpl() {
|
Weigher2.setListener(object : WeightListenerImpl() {
|
||||||
override fun onInit(connect: Boolean) {
|
override fun onInit(connect: Boolean) {
|
||||||
super.onInit(connect)
|
super.onInit(connect)
|
||||||
@@ -39,12 +55,7 @@ object WeightUtil {
|
|||||||
|
|
||||||
override fun onGetWeight(address: Int, state: Int, weight: Double) {
|
override fun onGetWeight(address: Int, state: Int, weight: Double) {
|
||||||
super.onGetWeight(address, state, weight)
|
super.onGetWeight(address, state, weight)
|
||||||
val stateStr = when (state) {
|
val stateStr = getStateStr(state)
|
||||||
STATE_STABLE -> "稳定"
|
|
||||||
STATE_UNSTABLE -> "不稳定"
|
|
||||||
STATE_OVER_WEIGHT -> "量程溢出"
|
|
||||||
else -> "$state"
|
|
||||||
}
|
|
||||||
val useWeight = (weight*1000).roundedOneDecimalPlace()
|
val useWeight = (weight*1000).roundedOneDecimalPlace()
|
||||||
Log.d(TAG, "readWeight, address=$address,state=$stateStr, weight=$useWeight")
|
Log.d(TAG, "readWeight, address=$address,state=$stateStr, weight=$useWeight")
|
||||||
weightFuncMap.forEach { (key, value) ->
|
weightFuncMap.forEach { (key, value) ->
|
||||||
@@ -56,6 +67,7 @@ object WeightUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getWeight() {
|
fun getWeight() {
|
||||||
|
if (!isAvailable) return
|
||||||
try {
|
try {
|
||||||
Weigher2.getWeight()
|
Weigher2.getWeight()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -64,10 +76,12 @@ object WeightUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun startContinuousRead() {
|
fun startContinuousRead() {
|
||||||
|
if (!isAvailable) return
|
||||||
Weigher2.startContinuousRead()
|
Weigher2.startContinuousRead()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopContinuousRead() {
|
fun stopContinuousRead() {
|
||||||
|
if (!isAvailable) return
|
||||||
try {
|
try {
|
||||||
Weigher2.stopContinuousRead()
|
Weigher2.stopContinuousRead()
|
||||||
Weigher2.unInit()
|
Weigher2.unInit()
|
||||||
@@ -77,6 +91,7 @@ object WeightUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tareTwo(address: Int) {
|
fun tareTwo(address: Int) {
|
||||||
|
if (!isAvailable) return
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "tareTwo,执行清零操作: address=$address")
|
Log.d(TAG, "tareTwo,执行清零操作: address=$address")
|
||||||
// SDK 内部自动管理总线,直接发送清零命令
|
// SDK 内部自动管理总线,直接发送清零命令
|
||||||
@@ -87,6 +102,14 @@ object WeightUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 将秤状态码转为可读字符串 */
|
||||||
|
fun getStateStr(state: Int): String = when (state) {
|
||||||
|
STATE_STABLE -> "稳定"
|
||||||
|
STATE_UNSTABLE -> "不稳定"
|
||||||
|
STATE_OVER_WEIGHT -> "量程溢出"
|
||||||
|
else -> "$state"
|
||||||
|
}
|
||||||
|
|
||||||
fun removeWeightListener(weightKey: String) {
|
fun removeWeightListener(weightKey: String) {
|
||||||
weightFuncMap.remove(weightKey)
|
weightFuncMap.remove(weightKey)
|
||||||
}
|
}
|
||||||
@@ -117,14 +140,6 @@ open class WeightListenerImpl : Weigher2.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onGetWeight(address: Int, state: Int, weight: Double) {
|
override fun onGetWeight(address: Int, state: Int, weight: Double) {
|
||||||
// val stateStr = when (state) {
|
|
||||||
// SensorScale.STATE_STABLE -> "稳定"
|
|
||||||
// SensorScale.STATE_UNSTABLE -> "不稳定"
|
|
||||||
// SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
|
|
||||||
// else -> ""
|
|
||||||
// }
|
|
||||||
// val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f)
|
|
||||||
// Log.d("WeightUtil", "ttlReturn, address:$address,$result1")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReadIdentify(rate: Int) {
|
override fun onReadIdentify(rate: Int) {
|
||||||
|
|||||||
@@ -31,10 +31,7 @@ fun Context.toast(
|
|||||||
message: String?,
|
message: String?,
|
||||||
duration: Int = Toast.LENGTH_SHORT,
|
duration: Int = Toast.LENGTH_SHORT,
|
||||||
) {
|
) {
|
||||||
if (message.isNullOrBlank()) {
|
if (message.isNullOrBlank()) return
|
||||||
return
|
|
||||||
}
|
|
||||||
//Toast.makeText(this, message, duration).show()
|
|
||||||
ToastUtil.show(this, message, duration)
|
ToastUtil.show(this, message, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,28 +42,6 @@ fun Fragment.toast(
|
|||||||
activity?.toast(message, duration)
|
activity?.toast(message, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
//fun Fragment.toast(
|
|
||||||
// message: String?,
|
|
||||||
// duration: Int = 2000
|
|
||||||
//) {
|
|
||||||
// if (isAdded.not()) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// CustomToast(
|
|
||||||
// activity = requireActivity(),
|
|
||||||
// message = message,
|
|
||||||
// duration = duration
|
|
||||||
// ).show()
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//public fun BaseActivity.toast(message: String?, duration: Int = 2000) {
|
|
||||||
// CustomToast(
|
|
||||||
// activity = this,
|
|
||||||
// message = message,
|
|
||||||
// duration = duration
|
|
||||||
// ).show()
|
|
||||||
//}
|
|
||||||
|
|
||||||
fun View.visible() {
|
fun View.visible() {
|
||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#666666"
|
||||||
|
android:pathData="
|
||||||
|
M2,6 h4 v5 h-4 Z
|
||||||
|
M7.5,6 h4 v5 h-4 Z
|
||||||
|
M13,6 h4 v5 h-4 Z
|
||||||
|
M18.5,6 h4 v5 h-4 Z
|
||||||
|
M2,13 h4 v5 h-4 Z
|
||||||
|
M7.5,13 h4 v5 h-4 Z
|
||||||
|
M13,13 h4 v5 h-4 Z
|
||||||
|
M18.5,13 h4 v5 h-4 Z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#666666"
|
||||||
|
android:pathData="
|
||||||
|
M2,6 h8.5 v5 h-8.5 Z
|
||||||
|
M13.5,6 h8.5 v5 h-8.5 Z
|
||||||
|
M2,13 h8.5 v5 h-8.5 Z
|
||||||
|
M13.5,13 h8.5 v5 h-8.5 Z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M3,5 h18 v2 h-18 Z
|
||||||
|
M3,11 h18 v2 h-18 Z
|
||||||
|
M3,17 h18 v2 h-18 Z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 秤格子背景:量程溢出状态,红色底 + 圆角 -->
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="#E53935" />
|
||||||
|
<corners android:radius="8dp" />
|
||||||
|
</shape>
|
||||||
@@ -6,59 +6,62 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:background="@drawable/bg_other_page">
|
tools:background="@drawable/bg_other_page">
|
||||||
|
|
||||||
<RadioGroup
|
<LinearLayout
|
||||||
android:id="@+id/dishRadioGroup"
|
android:id="@+id/llDishTabs"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="88dp"
|
android:layout_height="88dp"
|
||||||
android:layout_marginTop="15dp"
|
android:layout_marginTop="15dp"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<RadioButton
|
<CheckedTextView
|
||||||
android:id="@+id/rbBreakfast"
|
android:id="@+id/tvBreakfast"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginStart="30dp"
|
android:layout_marginStart="30dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="@drawable/breakfast_bg"
|
android:background="@drawable/breakfast_bg"
|
||||||
android:button="@null"
|
android:checkMark="@null"
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:textAlignment="center"
|
||||||
android:text="@string/text_breakfast"
|
android:text="@string/text_breakfast"
|
||||||
android:textColor="@color/breakfast_font"
|
android:textColor="@color/breakfast_font"
|
||||||
android:textSize="30sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<RadioButton
|
<CheckedTextView
|
||||||
android:id="@+id/rbLunch"
|
android:id="@+id/tvLunch"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginStart="9dp"
|
android:layout_marginStart="9dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="@drawable/breakfast_bg"
|
android:background="@drawable/breakfast_bg"
|
||||||
android:button="@null"
|
android:checkMark="@null"
|
||||||
android:checked="false"
|
android:checked="false"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:textAlignment="center"
|
||||||
android:text="@string/text_lunch"
|
android:text="@string/text_lunch"
|
||||||
android:textColor="@color/breakfast_font"
|
android:textColor="@color/breakfast_font"
|
||||||
android:textSize="30sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<RadioButton
|
<CheckedTextView
|
||||||
android:id="@+id/rbDinner"
|
android:id="@+id/tvDinner"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginStart="9dp"
|
android:layout_marginStart="9dp"
|
||||||
android:layout_marginEnd="30dp"
|
android:layout_marginEnd="30dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="@drawable/breakfast_bg"
|
android:background="@drawable/breakfast_bg"
|
||||||
android:button="@null"
|
android:checkMark="@null"
|
||||||
android:checked="false"
|
android:checked="false"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:textAlignment="center"
|
||||||
android:text="@string/text_dinner"
|
android:text="@string/text_dinner"
|
||||||
android:textColor="@color/breakfast_font"
|
android:textColor="@color/breakfast_font"
|
||||||
android:textSize="30sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
</RadioGroup>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/llSearchBar"
|
android:id="@+id/llSearchBar"
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
android:imeOptions="actionSearch"
|
android:imeOptions="actionSearch"
|
||||||
android:paddingStart="3dp"
|
android:paddingStart="3dp"
|
||||||
android:paddingEnd="3dp"
|
android:paddingEnd="3dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ellipsize="end"
|
||||||
android:textColor="@color/black333"
|
android:textColor="@color/black333"
|
||||||
android:textColorHint="@color/gray_c8"
|
android:textColorHint="@color/gray_c8"
|
||||||
android:textSize="40sp"
|
android:textSize="40sp"
|
||||||
@@ -49,6 +51,178 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 食材信息录入卡:手动新增菜品构成 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llIngredientInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="30dp"
|
||||||
|
android:layout_marginBottom="30dp"
|
||||||
|
android:background="@drawable/shape_white_30_corners"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="20dp">
|
||||||
|
|
||||||
|
<!-- 食材名称 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/dish_name"
|
||||||
|
android:textColor="@color/black666"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etIngredientName"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:autofillHints=""
|
||||||
|
android:background="@drawable/shape_white_f6_10_corners"
|
||||||
|
android:clickable="true"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:focusable="false"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:hint="@string/click_search_ingredient"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:paddingHorizontal="20dp"
|
||||||
|
android:textColor="@color/black333"
|
||||||
|
android:textColorHint="@color/gray_c8"
|
||||||
|
android:textSize="30sp"
|
||||||
|
tools:ignore="TextFields" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ivIngredientSearch"
|
||||||
|
android:layout_width="70dp"
|
||||||
|
android:layout_height="70dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:padding="20dp"
|
||||||
|
android:src="@drawable/ic_search_green"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 主辅材 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/dish_from_type"
|
||||||
|
android:textColor="@color/black666"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/rgMainAux"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rbMain"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/white"
|
||||||
|
android:button="@null"
|
||||||
|
android:checked="true"
|
||||||
|
android:drawablePadding="20dp"
|
||||||
|
android:drawableStart="@drawable/selector_dish_type"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingHorizontal="30dp"
|
||||||
|
android:text="@string/dish_type_first"
|
||||||
|
android:textColor="@color/dish_type_font"
|
||||||
|
android:textSize="30sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rbAux"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/white"
|
||||||
|
android:button="@null"
|
||||||
|
android:drawablePadding="20dp"
|
||||||
|
android:drawableStart="@drawable/selector_dish_type"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingHorizontal="30dp"
|
||||||
|
android:text="@string/dish_type_second"
|
||||||
|
android:textColor="@color/dish_type_font"
|
||||||
|
android:textSize="30sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</RadioGroup>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 用量(克) -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/dish_part_weight_remind"
|
||||||
|
android:textColor="@color/black666"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etAmount"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:autofillHints=""
|
||||||
|
android:background="@drawable/shape_white_f6_10_corners"
|
||||||
|
android:focusable="false"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:hint="@string/weight_from_scale"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:paddingHorizontal="20dp"
|
||||||
|
android:textColor="@color/black333"
|
||||||
|
android:textColorHint="@color/gray_c8"
|
||||||
|
android:textSize="30sp"
|
||||||
|
tools:ignore="TextFields" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/btnReset"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:text="@string/clear_zero"
|
||||||
|
android:textColor="@color/red_ff4444"
|
||||||
|
android:textSize="28sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/btnAdd"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="70dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:background="@drawable/shape_green_bg"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingHorizontal="40dp"
|
||||||
|
android:text="@string/add"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="30sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
|||||||
@@ -6,14 +6,13 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:background="@drawable/bg_other_page">
|
tools:background="@drawable/bg_other_page">
|
||||||
|
|
||||||
<RadioGroup
|
<LinearLayout
|
||||||
android:id="@+id/dishRadioGroup"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="88dp"
|
android:layout_height="88dp"
|
||||||
android:layout_marginTop="15dp"
|
android:layout_marginTop="15dp"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<RadioButton
|
<CheckedTextView
|
||||||
android:id="@+id/rbSamplingCooking"
|
android:id="@+id/rbSamplingCooking"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@@ -21,15 +20,17 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="@drawable/breakfast_bg"
|
android:background="@drawable/breakfast_bg"
|
||||||
android:button="@null"
|
android:button="@null"
|
||||||
|
android:checkMark="@null"
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:textAlignment="center"
|
||||||
android:text="@string/rb_sampling_cooking"
|
android:text="@string/rb_sampling_cooking"
|
||||||
android:textColor="@color/breakfast_font"
|
android:textColor="@color/breakfast_font"
|
||||||
android:textSize="30sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
|
||||||
<RadioButton
|
<CheckedTextView
|
||||||
android:id="@+id/rbSamplingFinished"
|
android:id="@+id/rbSamplingFinished"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@@ -38,13 +39,15 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="@drawable/breakfast_bg"
|
android:background="@drawable/breakfast_bg"
|
||||||
android:button="@null"
|
android:button="@null"
|
||||||
|
android:checkMark="@null"
|
||||||
android:checked="false"
|
android:checked="false"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:textAlignment="center"
|
||||||
android:text="@string/rb_sampling_finished"
|
android:text="@string/rb_sampling_finished"
|
||||||
android:textColor="@color/breakfast_font"
|
android:textColor="@color/breakfast_font"
|
||||||
android:textSize="30sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
</RadioGroup>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
@@ -5,264 +5,15 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:background="@color/bg_color"
|
tools:background="@color/bg_color"
|
||||||
tools:ignore="HardcodedText,UnusedAttribute">
|
tools:ignore="UnusedAttribute">
|
||||||
|
|
||||||
<LinearLayout
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/llCookMode"
|
android:id="@+id/rvSettings"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="120dp"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginHorizontal="32dp"
|
android:clipToPadding="false"
|
||||||
android:layout_marginTop="30dp"
|
android:paddingBottom="30dp"
|
||||||
android:background="@drawable/shape_white_dc_15_corners"
|
android:overScrollMode="never"
|
||||||
android:clipToOutline="true"
|
tools:listitem="@layout/list_item_setting"/>
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="32dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="菜品模式"
|
|
||||||
android:textColor="@color/black333"
|
|
||||||
android:textSize="32sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvCurrentMode"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="32dp"
|
|
||||||
android:textColor="@color/black999"
|
|
||||||
android:textSize="26sp"
|
|
||||||
tools:text="当前:制作模式" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginEnd="20dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:src="@drawable/ic_arrow_right3"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/llSeasoningConfig"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="120dp"
|
|
||||||
android:layout_marginHorizontal="32dp"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:background="@drawable/shape_white_dc_15_corners"
|
|
||||||
android:clipToOutline="true"
|
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="32dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="调料区设置"
|
|
||||||
android:textColor="@color/black333"
|
|
||||||
android:textSize="32sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginEnd="20dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:src="@drawable/ic_arrow_right3"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/llFoodCollect"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="120dp"
|
|
||||||
android:layout_marginHorizontal="32dp"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:background="@drawable/shape_white_dc_15_corners"
|
|
||||||
android:clipToOutline="true"
|
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="32dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="食材采集"
|
|
||||||
android:textColor="@color/black333"
|
|
||||||
android:textSize="32sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginEnd="20dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:src="@drawable/ic_arrow_right3"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/llDbInspect"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="120dp"
|
|
||||||
android:layout_marginHorizontal="32dp"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:background="@drawable/shape_white_dc_15_corners"
|
|
||||||
android:clipToOutline="true"
|
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="32dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="数据库查看"
|
|
||||||
android:textColor="@color/black333"
|
|
||||||
android:textSize="32sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginEnd="20dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:src="@drawable/ic_arrow_right3"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/llScaleObserve"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="120dp"
|
|
||||||
android:layout_marginHorizontal="32dp"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:background="@drawable/shape_white_dc_15_corners"
|
|
||||||
android:clipToOutline="true"
|
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="32dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="秤数据监控"
|
|
||||||
android:textColor="@color/black333"
|
|
||||||
android:textSize="32sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginEnd="20dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:src="@drawable/ic_arrow_right3"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/llClearData"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="120dp"
|
|
||||||
android:layout_marginHorizontal="32dp"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:background="@drawable/shape_white_dc_15_corners"
|
|
||||||
android:clipToOutline="true"
|
|
||||||
android:foreground="?android:attr/selectableItemBackground"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="32dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="数据清除"
|
|
||||||
android:textColor="@color/black333"
|
|
||||||
android:textSize="32sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginEnd="20dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:src="@drawable/ic_arrow_right3"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<!-- <!– 底部导航菜单 –>-->
|
|
||||||
<!-- <LinearLayout-->
|
|
||||||
<!-- android:id="@+id/bottomMenu"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
|
||||||
<!-- android:layout_height="wrap_content"-->
|
|
||||||
<!-- android:orientation="horizontal"-->
|
|
||||||
<!-- android:background="@android:color/transparent"-->
|
|
||||||
<!-- android:layout_marginTop="10dp"-->
|
|
||||||
<!-- android:layout_marginBottom="10dp"-->
|
|
||||||
<!-- android:layout_marginStart="15dp"-->
|
|
||||||
<!-- android:layout_marginEnd="15dp"-->
|
|
||||||
<!-- android:elevation="8dp">-->
|
|
||||||
|
|
||||||
<!-- <androidx.appcompat.widget.AppCompatButton-->
|
|
||||||
<!-- android:id="@+id/btnDeviceConfig"-->
|
|
||||||
<!-- android:layout_width="0dp"-->
|
|
||||||
<!-- android:layout_height="70dp"-->
|
|
||||||
<!-- android:layout_weight="1"-->
|
|
||||||
<!-- android:text="设备切换"-->
|
|
||||||
<!-- android:textSize="28sp"-->
|
|
||||||
<!-- android:textStyle="bold"-->
|
|
||||||
<!-- android:background="@android:color/transparent" />-->
|
|
||||||
|
|
||||||
<!-- <androidx.appcompat.widget.AppCompatButton-->
|
|
||||||
<!-- android:id="@+id/btnSeasoningConfig"-->
|
|
||||||
<!-- android:layout_width="0dp"-->
|
|
||||||
<!-- android:layout_height="70dp"-->
|
|
||||||
<!-- android:layout_weight="1"-->
|
|
||||||
<!-- android:text="调料配置"-->
|
|
||||||
<!-- android:textSize="26sp"-->
|
|
||||||
<!-- android:background="@android:color/transparent" />-->
|
|
||||||
|
|
||||||
<!-- <androidx.appcompat.widget.AppCompatButton-->
|
|
||||||
<!-- android:id="@+id/btnFoodCollect"-->
|
|
||||||
<!-- android:layout_width="0dp"-->
|
|
||||||
<!-- android:layout_height="70dp"-->
|
|
||||||
<!-- android:layout_weight="1"-->
|
|
||||||
<!-- android:text="采集食材"-->
|
|
||||||
<!-- android:textSize="26sp"-->
|
|
||||||
<!-- android:background="@android:color/transparent" />-->
|
|
||||||
|
|
||||||
<!-- <androidx.appcompat.widget.AppCompatButton-->
|
|
||||||
<!-- android:id="@+id/btnScaleMonitor"-->
|
|
||||||
<!-- android:layout_width="0dp"-->
|
|
||||||
<!-- android:layout_height="70dp"-->
|
|
||||||
<!-- android:layout_weight="1"-->
|
|
||||||
<!-- android:text="秤数据监控"-->
|
|
||||||
<!-- android:textSize="26sp"-->
|
|
||||||
<!-- android:visibility="visible"-->
|
|
||||||
<!-- android:background="@android:color/transparent" />-->
|
|
||||||
|
|
||||||
<!-- </LinearLayout>-->
|
|
||||||
|
|
||||||
<!-- <!– Fragment 容器 –>-->
|
|
||||||
<!-- <FrameLayout-->
|
|
||||||
<!-- android:id="@+id/fragmentContainer"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
|
||||||
<!-- android:layout_height="0dp"-->
|
|
||||||
<!-- android:layout_weight="1" />-->
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
android:background="@drawable/shape_white_30_corners"
|
android:background="@drawable/shape_white_30_corners"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="22dp"
|
android:layout_marginStart="22dp"
|
||||||
@@ -26,11 +26,11 @@
|
|||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvTitle"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="0dp"
|
android:layout_height="50dp"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@string/seasoning"
|
android:text="@string/seasoning"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_gravity="start"
|
||||||
android:textColor="@color/black666"
|
android:textColor="@color/black666"
|
||||||
android:textSize="28sp" />
|
android:textSize="28sp" />
|
||||||
|
|
||||||
@@ -38,12 +38,13 @@
|
|||||||
android:id="@+id/ivSeasoningLayoutToggle"
|
android:id="@+id/ivSeasoningLayoutToggle"
|
||||||
android:layout_width="50dp"
|
android:layout_width="50dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:paddingVertical="8dp"
|
android:paddingVertical="2dp"
|
||||||
|
android:layout_gravity="end"
|
||||||
android:contentDescription="切换布局"
|
android:contentDescription="切换布局"
|
||||||
android:src="@drawable/ic_switch_box"
|
android:src="@drawable/ic_layout_list"
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||||
|
|
||||||
</LinearLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/rvSeasoning"
|
android:id="@+id/rvSeasoning"
|
||||||
|
|||||||
@@ -53,6 +53,19 @@
|
|||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:background="@color/gray_eb" />
|
android:background="@color/gray_eb" />
|
||||||
|
|
||||||
|
<!-- 1个按钮时显示(全宽居中) -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/btnSingle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="96dp"
|
||||||
|
android:background="@drawable/ripple_btn_bottom"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="@color/dish_green"
|
||||||
|
android:textSize="28sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:text="我知道了" />
|
||||||
|
|
||||||
<!-- 2个按钮时显示(水平排列) -->
|
<!-- 2个按钮时显示(水平排列) -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/layoutButtonsHorizontal"
|
android:id="@+id/layoutButtonsHorizontal"
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 环境切换弹窗内容区:RadioGroup 包含 TEST / UAT / PROD 三个选项 -->
|
||||||
|
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/rgEnv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rbTest"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:paddingHorizontal="30dp"
|
||||||
|
android:text="本地环境"
|
||||||
|
android:textColor="@color/black333"
|
||||||
|
android:textSize="26sp" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rbUat"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:paddingHorizontal="30dp"
|
||||||
|
android:text="测试环境"
|
||||||
|
android:textColor="@color/black333"
|
||||||
|
android:textSize="26sp" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rbProd"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:paddingHorizontal="30dp"
|
||||||
|
android:text="生产环境"
|
||||||
|
android:textColor="@color/black333"
|
||||||
|
android:textSize="26sp" />
|
||||||
|
|
||||||
|
</RadioGroup>
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/bg_rounded_top"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<!-- 顶部拖拽指示条 -->
|
||||||
|
<View
|
||||||
|
android:layout_width="90dp"
|
||||||
|
android:layout_height="10dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="30dp"
|
||||||
|
android:background="@drawable/shape_gray_dc_5" />
|
||||||
|
|
||||||
|
<!-- 标题 -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="30dp"
|
||||||
|
android:text="用料明细"
|
||||||
|
android:textColor="@color/black333"
|
||||||
|
android:textSize="36sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<!-- 菜品ID -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvFoodId"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="20dp"
|
||||||
|
android:textColor="@color/black666"
|
||||||
|
android:textSize="26sp" />
|
||||||
|
|
||||||
|
<!-- 表头 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/white_f6"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="40dp"
|
||||||
|
android:paddingEnd="40dp"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:paddingBottom="20dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:text="物品ID"
|
||||||
|
android:textColor="@color/black999"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="3"
|
||||||
|
android:text="物品名称"
|
||||||
|
android:textColor="@color/black999"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:text="物料编码"
|
||||||
|
android:textColor="@color/black999"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="物料类型"
|
||||||
|
android:textColor="@color/black999"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:gravity="end"
|
||||||
|
android:text="用量(g)"
|
||||||
|
android:textColor="@color/black999"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/rvGoodsList"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="30dp"
|
||||||
|
android:maxHeight="700dp"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
|
android:overScrollMode="never" />
|
||||||
|
|
||||||
|
<!-- 空布局 -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvEmpty"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="暂无用料数据"
|
||||||
|
android:textColor="@color/gray_c8"
|
||||||
|
android:textSize="28sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -106,11 +106,22 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingHorizontal="12dp"
|
android:paddingHorizontal="12dp"
|
||||||
android:paddingVertical="6dp"
|
android:paddingVertical="6dp"
|
||||||
android:text="刷新"
|
android:text="查询"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:textColor="#5C77F7" />
|
android:textColor="#5C77F7" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 筛选条件区域:根据当前 Tab 动态生成对应的筛选框 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llFilterContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="#FFFFFF"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:paddingBottom="6dp" />
|
||||||
|
|
||||||
<!-- 记录列表 -->
|
<!-- 记录列表 -->
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/rvRecords"
|
android:id="@+id/rvRecords"
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?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="match_parent"
|
||||||
|
tools:background="@drawable/bg_other_page"
|
||||||
|
tools:ignore="HardcodedText">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="30dp"
|
||||||
|
android:layout_marginEnd="30dp"
|
||||||
|
android:background="@drawable/shape_white_30_corners"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="30dp"
|
||||||
|
tools:ignore="UselessParent">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="106dp"
|
||||||
|
android:background="@drawable/bg_bottom_line">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="start|center_vertical"
|
||||||
|
android:text="默认减重配置"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="28sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="30dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="减重值(克)"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etConfigWeight"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/shape_white_30_corners"
|
||||||
|
android:hint="请输入减重值"
|
||||||
|
android:inputType="number"
|
||||||
|
android:maxLength="6"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textColorHint="@color/gray_b4"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatButton
|
||||||
|
android:id="@+id/btnConfirm"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="90dp"
|
||||||
|
android:layout_marginTop="40dp"
|
||||||
|
android:text="确认"
|
||||||
|
android:background="@drawable/shape_green_bg"
|
||||||
|
android:foreground="?android:attr/selectableItemBackground"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="32sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user