Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
795deae228 | ||
|
|
873ae95c0b | ||
|
|
a4f3f9527c | ||
|
|
eaa1b1eb00 | ||
|
|
a4905e7226 |
Generated
+2
-2
@@ -4,10 +4,10 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-09-10T07:28:30.961571900Z">
|
||||
<DropdownSelection timestamp="2026-01-28T08:24:39.059017600Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="Default" identifier="serial=192.168.1.21:5555;connection=bc7af9a5" />
|
||||
<DeviceId pluginId="Default" identifier="serial=192.168.1.80:5555;connection=d6ad651e" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
|
||||
+5
-11
@@ -18,8 +18,9 @@ android {
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
ndk {
|
||||
//设置支持的SO库架构;x86_64 仅用于在 Windows 模拟器上调试(秤功能不可用)
|
||||
abiFilters.addAll(listOf("armeabi-v7a", "x86_64"))
|
||||
//设置支持的SO库架构
|
||||
abiFilters.addAll(listOf("armeabi-v7a"))
|
||||
//, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
|
||||
}
|
||||
|
||||
// 设置输出APK文件名格式
|
||||
@@ -41,13 +42,10 @@ android {
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
signingConfig = signingConfigs.getByName("debug_507")
|
||||
buildConfigField("Boolean", "IS_TEST_DEVICE", "false")
|
||||
}
|
||||
debug {
|
||||
//507扫码秤主板在android.buildTypes{}内增加
|
||||
signingConfig = signingConfigs.getByName("debug_507")
|
||||
// 调试构建视为测试设备,使用固定的 DEVICE_ID_1 代替真实 UDID
|
||||
buildConfigField("Boolean", "IS_TEST_DEVICE", "false")
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
@@ -59,11 +57,10 @@ android {
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
packagingOptions {
|
||||
pickFirst("lib/armeabi-v7a/libserial_port.so")
|
||||
pickFirst("lib/arm64-v8a/libserial_port.so")
|
||||
pickFirst("lib/arme64-v8a/libserial_port.so")
|
||||
}
|
||||
sourceSets {
|
||||
named("main") {
|
||||
@@ -90,12 +87,11 @@ dependencies {
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
implementation("com.squareup.okhttp3:okhttp:4.9.1")
|
||||
implementation("com.squareup.okhttp3:logging-interceptor:4.9.1")
|
||||
implementation("com.squareup.retrofit2:retrofit:2.9.0")
|
||||
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
// implementation("com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30")
|
||||
|
||||
implementation("io.github.cymchad:BaseRecyclerViewAdapterHelper4:4.1.2")
|
||||
|
||||
@@ -118,6 +114,4 @@ dependencies {
|
||||
//经典加载
|
||||
|
||||
//implementation("com.geyifeng.immersionbar:immersionbar:3.2.2")
|
||||
|
||||
implementation("com.google.android.flexbox:flexbox:3.0.0")
|
||||
}
|
||||
Binary file not shown.
@@ -8,11 +8,12 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemDishCookBinding
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||
import java.text.DecimalFormat
|
||||
|
||||
class DishPartAdapter(list: MutableList<GoodsItem>) :
|
||||
BaseQuickAdapter<GoodsItem, DishPartAdapter.VH>(list) {
|
||||
class DishPartAdapter(list: MutableList<CookFoodGoodsEntity>) :
|
||||
BaseQuickAdapter<CookFoodGoodsEntity, DishPartAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemDishCookBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
@@ -22,10 +23,11 @@ class DishPartAdapter(list: MutableList<GoodsItem>) :
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: GoodsItem?) {
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: CookFoodGoodsEntity?) {
|
||||
holder.binding.run {
|
||||
tvDishName.text = item!!.goodsName
|
||||
tvDishType.text = if (item.materialType == 1) "主辅材:主材" else if (item.materialType == 2) "主辅材:辅材" else ""
|
||||
//"${DecimalFormat("#").format(item.useWeight)}克"
|
||||
tvDishWeight.text =
|
||||
if (item.useWeight == null || item.useWeight == 0.toDouble()) "" else "${item.useWeight!!.roundedOneDecimalPlace()}克"
|
||||
tvDishWeight.setTextColor(
|
||||
@@ -36,15 +38,19 @@ class DishPartAdapter(list: MutableList<GoodsItem>) :
|
||||
)
|
||||
ivOperateIcon.setImageResource(
|
||||
if (item.isSamplingPage)
|
||||
//采集页面
|
||||
R.drawable.ic_delete
|
||||
else
|
||||
//制作页面
|
||||
if (item.isSetFinished) R.drawable.ic_dish_selected
|
||||
else R.drawable.ic_dish_unselected
|
||||
)
|
||||
root.setBackgroundResource(
|
||||
if (item.isClicked) R.drawable.shape_item_cook_dish
|
||||
else R.drawable.shape_white_fb_15_corners
|
||||
)
|
||||
root.run {
|
||||
setBackgroundResource(
|
||||
if (item.isItemClicked) R.drawable.shape_item_cook_dish
|
||||
else R.drawable.shape_white_fb_15_corners
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import androidx.core.content.ContextCompat
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.databinding.ListItemDishBinding
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
|
||||
@@ -6,7 +6,7 @@ import android.view.ViewGroup
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.databinding.ListItemDishRecordBinding
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
|
||||
class FoodRecordAdapter(list: MutableList<FoodRecord>) :
|
||||
BaseQuickAdapter<FoodRecord, FoodRecordAdapter.VH>(list) {
|
||||
|
||||
@@ -8,15 +8,15 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemSearchGoodsInfoBinding
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
|
||||
class GoodsInfoSearchAdapter(private var list: MutableList<GoodsItem>) :
|
||||
BaseQuickAdapter<GoodsItem, GoodsInfoSearchAdapter.VH>(list) {
|
||||
class GoodsInfoSearchAdapter(private var list: MutableList<CookFoodGoodsEntity>) :
|
||||
BaseQuickAdapter<CookFoodGoodsEntity, GoodsInfoSearchAdapter.VH>(list) {
|
||||
|
||||
override fun onBindViewHolder(
|
||||
holder: VH,
|
||||
position: Int,
|
||||
item: GoodsItem?
|
||||
item: CookFoodGoodsEntity?
|
||||
) {
|
||||
holder.binding.tvGoodsInfo.run {
|
||||
text = item?.goodsName
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemHomeModeBinding
|
||||
import com.shuwei.dish.match.model.HomeModeBean
|
||||
import com.shuwei.dish.match.entity.HomeModeBean
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@ import androidx.core.content.ContextCompat
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.databinding.ListItemDishBinding
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import java.text.DecimalFormat
|
||||
|
||||
@@ -28,9 +27,9 @@ class SamplingAdapter(list: MutableList<FoodRecord>) :
|
||||
holder.binding.run {
|
||||
val isCooking = item!!.isCooking
|
||||
clBlock.setBackgroundResource(R.drawable.shape_white_fb_15_corners)
|
||||
val totalWeight = item!!.totalWeight ?: 0.toDouble()
|
||||
val totalWeight = item.totalWeight ?: 0.toDouble()
|
||||
tvDishName.run {
|
||||
text = item!!.foodName
|
||||
text = (item.foodName?:"").ifBlank { "--" }
|
||||
setTextColor(
|
||||
ContextCompat.getColor(
|
||||
holder.itemView.context,
|
||||
@@ -41,11 +40,16 @@ class SamplingAdapter(list: MutableList<FoodRecord>) :
|
||||
tvDishCount.visible()
|
||||
if (isCooking) {
|
||||
tvDishCount.text = "制作统计:-kg"
|
||||
tvShowState.text = "烹饪中"
|
||||
tvShowState.text = "烹饪中"
|
||||
} else {
|
||||
val useWeight = if (totalWeight > 0.toDouble()) totalWeight else (item.foodWeight ?: 0.toDouble())
|
||||
tvDishCount.text = "累计统计:${df.format(useWeight / 1000.0F)}kg(${item.count}次)"
|
||||
tvShowState.text = "${df.format((item.foodWeight ?: 0.toDouble()) / 1000.0F)}kg"
|
||||
val realTotalWeight = if (totalWeight > 0.toDouble()) totalWeight else (item.foodWeight
|
||||
?: 0.toDouble())
|
||||
val showTotalWeight =
|
||||
if (realTotalWeight == 0.toDouble()) "-" else df.format(realTotalWeight / 1000.0F)
|
||||
tvDishCount.text = "累计统计:${showTotalWeight}kg(${item.count ?: "-"}次)"
|
||||
val foodWeight = item.foodWeight ?: 0.toDouble()
|
||||
val showFoodWeight = if (foodWeight == 0.toDouble()) "-" else df.format(foodWeight / 1000.0F)
|
||||
tvShowState.text = "${showFoodWeight}kg"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
//package com.shuwei.dish.match.adapter
|
||||
//
|
||||
//import android.content.Context
|
||||
//import android.view.LayoutInflater
|
||||
//import android.view.ViewGroup
|
||||
//import androidx.core.view.updateLayoutParams
|
||||
//import com.chad.library.adapter4.BaseQuickAdapter
|
||||
//import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
//import com.shuwei.dish.match.databinding.ListItemCellBinding
|
||||
//import com.shuwei.dish.match.model.GoodsItem
|
||||
//import com.shuwei.dish.match.utils.ext.dp
|
||||
//
|
||||
///**
|
||||
// * 调料格子列表适配器,使用 list_item_cell 布局展示调料名称与用量
|
||||
// */
|
||||
//class SeasoningAdapter(list: MutableList<GoodsItem>) :
|
||||
// BaseQuickAdapter<GoodsItem, SeasoningAdapter.VH>(list) {
|
||||
//
|
||||
// override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
// val binding = ListItemCellBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||
// return VH(binding)
|
||||
// }
|
||||
//
|
||||
// override fun onBindViewHolder(holder: VH, position: Int, item: GoodsItem?) {
|
||||
// item ?: return
|
||||
// holder.binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
// width = 226.dp
|
||||
// height = 120.dp
|
||||
// leftMargin = 7.dp
|
||||
// rightMargin = 8.dp
|
||||
// topMargin = 7.dp
|
||||
// bottomMargin = 8.dp
|
||||
// }
|
||||
// holder.binding.tvCell.text = TextCellAdapter.getTextSpan(item.toSeasoningEntity())
|
||||
// }
|
||||
//
|
||||
// inner class VH(val binding: ListItemCellBinding) : QuickViewHolder(binding.root)
|
||||
//}
|
||||
@@ -1,134 +0,0 @@
|
||||
//package com.shuwei.dish.match.adapter
|
||||
//
|
||||
//import android.annotation.SuppressLint
|
||||
//import android.widget.TextView
|
||||
//import androidx.recyclerview.widget.GridLayoutManager
|
||||
//import androidx.recyclerview.widget.RecyclerView
|
||||
//import com.shuwei.dish.match.base.BaseActivity
|
||||
//import com.shuwei.dish.match.dialog.BottomDialog2
|
||||
//import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
//import com.shuwei.dish.match.ui.DeviceSettingActivity
|
||||
//import com.shuwei.dish.match.ui.SubmitDishActivity
|
||||
//import com.shuwei.dish.match.utils.DataUtil
|
||||
//
|
||||
//object SeasoningCellTool {
|
||||
// private val TAG = "SeasoningCellTool"
|
||||
//
|
||||
// private val list = mutableListOf<SeasoningEntity>()
|
||||
// private lateinit var activity: BaseActivity
|
||||
// private var pageType: Int = 0
|
||||
//
|
||||
// @SuppressLint("StaticFieldLeak")
|
||||
// private lateinit var cellAdapter: TextCellAdapter
|
||||
//
|
||||
// @SuppressLint("NotifyDataSetChanged")
|
||||
// fun loadData(
|
||||
// activity: BaseActivity,
|
||||
// initList: MutableList<SeasoningEntity>? = null,
|
||||
// recyclerView: RecyclerView,
|
||||
// tvCell: TextView,
|
||||
// pageType: Int = 0
|
||||
// ) {
|
||||
// this.activity = activity
|
||||
// this.pageType = pageType
|
||||
// list.clear()
|
||||
// val tempList = buildData(initList, pageType)
|
||||
// list.addAll(tempList)
|
||||
// recyclerView.run {
|
||||
// if (adapter == null) {
|
||||
// layoutManager = GridLayoutManager(
|
||||
// activity,
|
||||
// 3,
|
||||
// GridLayoutManager.VERTICAL,
|
||||
// false
|
||||
// )
|
||||
// cellAdapter = TextCellAdapter(list).apply {
|
||||
// onCellClick = { position ->
|
||||
// val currentAddress = DataUtil.getWeighAddressArray().get(position)
|
||||
// BottomDialog2(
|
||||
// weighIndex = position,
|
||||
// weighAddress = currentAddress,
|
||||
// clickName = list[position].goodsName
|
||||
// ).show(activity) { item ->
|
||||
// list[position].let { current ->
|
||||
// syncItem(current, item)
|
||||
// //3-调料
|
||||
// current.materialType = 3
|
||||
// current.sort = position
|
||||
// }
|
||||
// notifyItemChanged(position)
|
||||
// if (position == 14) {
|
||||
// syncItem(list[10], list[14])
|
||||
// syncItem(list[11], list[14])
|
||||
// syncItem(list[13], list[14])
|
||||
// TextCellAdapter.loadCell(tvCell, list[14])
|
||||
// notifyItemChanged(10)
|
||||
// notifyItemChanged(11)
|
||||
// notifyItemChanged(13)
|
||||
// notifyItemChanged(14)
|
||||
// }
|
||||
// if (activity is DeviceSettingActivity) {
|
||||
// //activity.list = list
|
||||
// activity.saveSeasoning(list[position])
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// adapter = cellAdapter
|
||||
// } else {
|
||||
// cellAdapter.notifyDataSetChanged()
|
||||
// }
|
||||
// if (activity is SubmitDishActivity) {
|
||||
// activity.updateSeasoningList(list)
|
||||
// }
|
||||
// }
|
||||
// if (pageType == 1) {
|
||||
// tvCell.setOnClickListener {
|
||||
// cellAdapter.onCellClick?.invoke(14)
|
||||
// }
|
||||
// }
|
||||
// TextCellAdapter.loadCell(tvCell, list[list.size - 1])
|
||||
// }
|
||||
//
|
||||
// private fun buildData(
|
||||
// initList: MutableList<SeasoningEntity>?,
|
||||
// pageType: Int = 0
|
||||
// ): MutableList<SeasoningEntity> {
|
||||
// val list = mutableListOf<SeasoningEntity>()
|
||||
// repeat(15) {
|
||||
// list.add(SeasoningEntity().apply { this.pageType = pageType })
|
||||
// }
|
||||
// if (initList.isNullOrEmpty().not()) {
|
||||
// initList.forEach {
|
||||
// if (it.sort < list.size) {
|
||||
// list[it.sort] = it.apply { this.pageType = pageType }
|
||||
// }
|
||||
// }
|
||||
// var lastItem = initList.firstOrNull { it.sort == 14 }
|
||||
// lastItem = lastItem ?: list[list.size - 1]
|
||||
// list[10] = lastItem
|
||||
// list[11] = lastItem
|
||||
// list[13] = lastItem
|
||||
// }
|
||||
// return list
|
||||
// }
|
||||
//
|
||||
// private fun syncItem(item: SeasoningEntity, newItem: SeasoningEntity) {
|
||||
// item.run {
|
||||
// goodsId = newItem.goodsId
|
||||
// goodsName = newItem.goodsName
|
||||
// goodsOrRelationCode = newItem.goodsOrRelationCode
|
||||
// relateionType = newItem.relateionType
|
||||
// materialType = newItem.materialType
|
||||
// allEdible = newItem.allEdible
|
||||
// useWeight = newItem.useWeight
|
||||
// popularName = newItem.popularName
|
||||
// canteenId = newItem.canteenId
|
||||
// relateionType_dictText = newItem.relateionType_dictText
|
||||
//
|
||||
// foodId = newItem.foodId
|
||||
// sort = newItem.sort
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -8,15 +8,15 @@ import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemSearchGoodsInfoBinding
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
|
||||
class SeasoningSearchAdapter(private var list: MutableList<GoodsItem>) :
|
||||
BaseQuickAdapter<GoodsItem, SeasoningSearchAdapter.VH>(list) {
|
||||
class SeasoningSearchAdapter(private var list: MutableList<SeasoningEntity>) :
|
||||
BaseQuickAdapter<SeasoningEntity, SeasoningSearchAdapter.VH>(list) {
|
||||
|
||||
override fun onBindViewHolder(
|
||||
holder: VH,
|
||||
position: Int,
|
||||
item: GoodsItem?
|
||||
item: SeasoningEntity?
|
||||
) {
|
||||
holder.binding.tvGoodsInfo.run {
|
||||
text = item?.goodsName
|
||||
|
||||
@@ -1,137 +1,136 @@
|
||||
//package com.shuwei.dish.match.adapter
|
||||
//
|
||||
//import android.graphics.Typeface
|
||||
//import android.icu.text.DecimalFormat
|
||||
//import android.text.SpannableStringBuilder
|
||||
//import android.text.style.AbsoluteSizeSpan
|
||||
//import android.text.style.ForegroundColorSpan
|
||||
//import android.text.style.LineHeightSpan
|
||||
//import android.text.style.StyleSpan
|
||||
//import android.view.LayoutInflater
|
||||
//import android.view.ViewGroup
|
||||
//import android.widget.FrameLayout
|
||||
//import android.widget.TextView
|
||||
//import androidx.core.content.ContextCompat
|
||||
//import androidx.core.graphics.toColorInt
|
||||
//import androidx.recyclerview.widget.RecyclerView
|
||||
//import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
//import com.shuwei.dish.match.R
|
||||
//import com.shuwei.dish.match.databinding.ListItemCellBinding
|
||||
//import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
//import com.shuwei.dish.match.model.GoodsItem
|
||||
//import com.shuwei.dish.match.utils.ext.appendText
|
||||
//import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||
//import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||
//import com.shuwei.dish.match.utils.ext.dp
|
||||
//import com.shuwei.dish.match.utils.ext.invisible
|
||||
//import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||
//import com.shuwei.dish.match.utils.ext.visible
|
||||
//
|
||||
//class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
|
||||
// RecyclerView.Adapter<TextCellAdapter.VH>() {
|
||||
//
|
||||
// inner class VH(var binding: ListItemCellBinding) : QuickViewHolder(binding.root)
|
||||
//
|
||||
// override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
|
||||
// val inflater = LayoutInflater.from(parent.context)
|
||||
// val binding = ListItemCellBinding.inflate(inflater, parent, false)
|
||||
// return VH(binding)
|
||||
// }
|
||||
//
|
||||
// override fun onBindViewHolder(holder: VH, position: Int) {
|
||||
// val item = list[position]
|
||||
// holder.binding.run {
|
||||
// if (position == 10 || position == 11 || position == 13 || position == 14) {
|
||||
// root.invisible()
|
||||
package com.shuwei.dish.match.adapter
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.icu.text.DecimalFormat
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.style.AbsoluteSizeSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.LineHeightSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemCellBinding
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.utils.ext.appendText
|
||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
import com.shuwei.dish.match.utils.ext.invisible
|
||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
|
||||
class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
|
||||
RecyclerView.Adapter<TextCellAdapter.VH>() {
|
||||
|
||||
inner class VH(var binding: ListItemCellBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val binding = ListItemCellBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int) {
|
||||
val item = list[position]
|
||||
holder.binding.run {
|
||||
if (position == 10 || position == 11 || position == 13 || position == 14) {
|
||||
root.invisible()
|
||||
} else {
|
||||
root.visible()
|
||||
}
|
||||
loadCell(tvCell, item)
|
||||
//root.setBackgroundResource(R.color.dish_green)
|
||||
(root.layoutParams as RecyclerView.LayoutParams).let {
|
||||
// it.bottomMargin = 15.dp
|
||||
it.width = 226.dp
|
||||
it.height = 120.dp
|
||||
// it.rightMargin = 0
|
||||
// it.leftMargin = if (position % 3 == 0) 0 else 15.dp
|
||||
|
||||
it.leftMargin = 7.dp
|
||||
it.rightMargin = 8.dp
|
||||
it.topMargin = 7.dp
|
||||
it.bottomMargin = 8.dp
|
||||
}
|
||||
if (item.pageType == 1) {
|
||||
root.clickWithDebounce { onCellClick?.invoke(position) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = list.size
|
||||
|
||||
var onCellClick: ((positon: Int) -> Unit)? = null
|
||||
|
||||
companion object {
|
||||
fun loadLayout(frameLayout: FrameLayout, item: SeasoningEntity) {
|
||||
val child: TextView = frameLayout.getChildAt(0) as TextView
|
||||
child.text = getTextSpan(item)
|
||||
}
|
||||
fun loadCell(tvCell: TextView, item: SeasoningEntity) {
|
||||
tvCell.text = getTextSpan(item)
|
||||
}
|
||||
// fun loadCell2(tvCell: TextView, item: SeasoningEntity) {
|
||||
// if (item.goodsName.isNullOrBlank()) {
|
||||
// tvCell.run {
|
||||
// text = buildSpannableString {
|
||||
// appendText(
|
||||
// "未配置",
|
||||
// ForegroundColorSpan("#999999".toColorInt()),
|
||||
// StyleSpan(Typeface.BOLD),
|
||||
// AbsoluteSizeSpan(28, true),
|
||||
// LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
||||
// fm.descent += 10.dp // 增加行间距
|
||||
// }
|
||||
// )}
|
||||
// //setTextColor(ContextCompat.getColor(context, R.color.black999))
|
||||
// }
|
||||
// } else {
|
||||
// root.visible()
|
||||
// }
|
||||
// loadCell(tvCell, item)
|
||||
// //root.setBackgroundResource(R.color.dish_green)
|
||||
// (root.layoutParams as RecyclerView.LayoutParams).let {
|
||||
//// it.bottomMargin = 15.dp
|
||||
// it.width = 226.dp
|
||||
// it.height = 120.dp
|
||||
//// it.rightMargin = 0
|
||||
//// it.leftMargin = if (position % 3 == 0) 0 else 15.dp
|
||||
//
|
||||
// it.leftMargin = 7.dp
|
||||
// it.rightMargin = 8.dp
|
||||
// it.topMargin = 7.dp
|
||||
// it.bottomMargin = 8.dp
|
||||
// }
|
||||
// if (item.pageType == 1) {
|
||||
// root.clickWithDebounce { onCellClick?.invoke(position) }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun getItemCount() = list.size
|
||||
//
|
||||
// var onCellClick: ((positon: Int) -> Unit)? = null
|
||||
//
|
||||
// companion object {
|
||||
// fun loadLayout(frameLayout: FrameLayout, item: SeasoningEntity) {
|
||||
// val child: TextView = frameLayout.getChildAt(0) as TextView
|
||||
// child.text = getTextSpan(item)
|
||||
// }
|
||||
// fun loadCell(tvCell: TextView, item: SeasoningEntity) {
|
||||
// tvCell.text = getTextSpan(item)
|
||||
// }
|
||||
//// fun loadCell2(tvCell: TextView, item: SeasoningEntity) {
|
||||
//// if (item.goodsName.isNullOrBlank()) {
|
||||
//// tvCell.run {
|
||||
//// text = buildSpannableString {
|
||||
//// appendText(
|
||||
//// "未配置",
|
||||
//// ForegroundColorSpan("#999999".toColorInt()),
|
||||
//// StyleSpan(Typeface.BOLD),
|
||||
//// AbsoluteSizeSpan(28, true),
|
||||
//// LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
||||
//// fm.descent += 10.dp // 增加行间距
|
||||
//// }
|
||||
//// )}
|
||||
//// //setTextColor(ContextCompat.getColor(context, R.color.black999))
|
||||
//// if (item.pageType == 1) {
|
||||
//// tvCell.run {
|
||||
//// text = item.goodsName
|
||||
//// setTextColor(ContextCompat.getColor(context, R.color.black))
|
||||
//// }
|
||||
//// } else {
|
||||
// tvCell.text = getTextSpan(item)
|
||||
//// }
|
||||
//// } else {
|
||||
////// if (item.pageType == 1) {
|
||||
////// tvCell.run {
|
||||
////// text = item.goodsName
|
||||
////// setTextColor(ContextCompat.getColor(context, R.color.black))
|
||||
////// }
|
||||
////// } else {
|
||||
//// tvCell.text = getTextSpan(item)
|
||||
////// }
|
||||
//// }
|
||||
//// }
|
||||
//
|
||||
// fun getTextSpan(item: SeasoningEntity): SpannableStringBuilder {
|
||||
// val endIndex = if (item.sort == 9) 10 else 6
|
||||
// var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
|
||||
// if (name.length > endIndex) {
|
||||
// name = "${name.substring(0, endIndex)}…"
|
||||
// }
|
||||
// return buildSpannableString {
|
||||
// appendText(
|
||||
// name,
|
||||
// ForegroundColorSpan(if (item.goodsName.isNullOrBlank()) "#999999".toColorInt() else "#000000".toColorInt()),
|
||||
// StyleSpan(Typeface.BOLD),
|
||||
// AbsoluteSizeSpan(28, true),
|
||||
// LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
||||
// fm.descent += 10.dp // 增加行间距
|
||||
// }
|
||||
// )
|
||||
// append("\n")
|
||||
// val weight = item.useWeight ?: 0.toDouble()
|
||||
// val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
|
||||
// appendText(
|
||||
//// "${DecimalFormat("#").format(weight)}g",
|
||||
// "${weight.roundedOneDecimalPlace()}g",
|
||||
// ForegroundColorSpan(weightColor.toColorInt()),
|
||||
// AbsoluteSizeSpan(30, true)
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
fun getTextSpan(item: SeasoningEntity): SpannableStringBuilder {
|
||||
val endIndex = if (item.sort == 9) 10 else 6
|
||||
var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
|
||||
if (name.length > endIndex) {
|
||||
name = "${name.substring(0, endIndex)}…"
|
||||
}
|
||||
return buildSpannableString {
|
||||
appendText(
|
||||
name,
|
||||
ForegroundColorSpan(if (item.goodsName.isNullOrBlank()) "#999999".toColorInt() else "#000000".toColorInt()),
|
||||
StyleSpan(Typeface.BOLD),
|
||||
AbsoluteSizeSpan(28, true),
|
||||
LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
||||
fm.descent += 10.dp // 增加行间距
|
||||
}
|
||||
)
|
||||
append("\n")
|
||||
val weight = item.useWeight ?: 0.toDouble()
|
||||
val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
|
||||
appendText(
|
||||
// "${DecimalFormat("#").format(weight)}g",
|
||||
"${weight.roundedOneDecimalPlace()}g",
|
||||
ForegroundColorSpan(weightColor.toColorInt()),
|
||||
AbsoluteSizeSpan(30, true)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
@@ -17,30 +16,24 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ActivityBaseBinding
|
||||
import com.shuwei.dish.match.db.DbViewModel
|
||||
import com.shuwei.dish.match.dialog.Loading
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.net.NetViewModel
|
||||
import com.shuwei.dish.match.viewmodel.AppViewModel
|
||||
import com.shuwei.dish.match.ui.HomeActivity.Companion.TAG
|
||||
import com.shuwei.dish.match.ui.InitActivity
|
||||
import com.shuwei.dish.match.utils.ActivityManager
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.invisible
|
||||
import com.shuwei.dish.match.utils.ext.put
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.Locale
|
||||
import kotlin.getValue
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
open class BaseActivity : AppCompatActivity() {
|
||||
|
||||
val netViewModel: NetViewModel by viewModels()
|
||||
val dbViewModel: DbViewModel by viewModels()
|
||||
val appViewModel: AppViewModel by viewModels()
|
||||
|
||||
private lateinit var binding: ActivityBaseBinding
|
||||
private var launcher: ActivityResultLauncher<Intent>? = null
|
||||
private var launchCallback: ((Intent?) -> Unit)? = null
|
||||
@@ -101,7 +94,8 @@ open class BaseActivity : AppCompatActivity() {
|
||||
|
||||
fun statusBarDarkFont(enable: Boolean) {
|
||||
//window.decorView.systemUiVisibility = if (enable) View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR else 0
|
||||
val color = ContextCompat.getColor(this,
|
||||
val color = ContextCompat.getColor(
|
||||
this,
|
||||
if (enable) R.color.black else R.color.white
|
||||
)
|
||||
binding.tvLeftTime.setTextColor(color)
|
||||
@@ -178,9 +172,25 @@ open class BaseActivity : AppCompatActivity() {
|
||||
fun delayDismissLoading() {
|
||||
window.decorView.postDelayed({
|
||||
Loading.dismiss()
|
||||
},500)
|
||||
}, 500)
|
||||
}
|
||||
|
||||
|
||||
val netViewModel: NetViewModel by viewModels()
|
||||
fun queryGoodsList(
|
||||
param: MutableMap<String, Any>,
|
||||
onSuccess: (MutableList<CookFoodGoodsEntity>?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
netViewModel.queryGoodsList(param, onSuccess, onFailure)
|
||||
}
|
||||
|
||||
fun querySeasoningList(
|
||||
param: MutableMap<String, Any>,
|
||||
onSuccess: (MutableList<SeasoningEntity>?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
netViewModel.querySeasoningList(param, onSuccess, onFailure)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,11 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.db.DatabaseProvider
|
||||
import com.shuwei.dish.match.ui.InitActivity.Companion.TAG
|
||||
import com.shuwei.dish.match.utils.AppUtil
|
||||
import com.shuwei.dish.match.utils.BootReceiver
|
||||
|
||||
|
||||
@@ -17,7 +20,10 @@ class BaseApp : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
instance = this
|
||||
|
||||
val deviceId = AppUtil.getUDID(this)
|
||||
Log.d(TAG, "onCreate: deviceId=$deviceId")
|
||||
GlobalData.deviceId = deviceId
|
||||
// GlobalData.deviceId = "39a7abdd06b3c7ab"
|
||||
val filter = IntentFilter(Intent.ACTION_BOOT_COMPLETED)
|
||||
registerReceiver(BootReceiver(), filter)
|
||||
}
|
||||
@@ -26,9 +32,10 @@ class BaseApp : Application() {
|
||||
|
||||
// const val canteenId = "1678234139391512577"
|
||||
var canteenId = "0"
|
||||
var configUrl = ""
|
||||
// var configUrl = ""
|
||||
|
||||
var token: String? = null
|
||||
// var token: String? = null
|
||||
// var deviceId: String? = null
|
||||
var appVersion: String = "1"
|
||||
@Volatile
|
||||
private var sharedPref: SharedPreferences? = null
|
||||
|
||||
@@ -1,34 +1,14 @@
|
||||
package com.shuwei.dish.match.base
|
||||
|
||||
/**
|
||||
* 设备角色枚举
|
||||
* MASTER:主设备,负责汇聚所有设备的秤数据并展示大屏界面
|
||||
* SLAVE:子设备,负责推送本机秤数据给主设备
|
||||
*/
|
||||
enum class DeviceRole { MASTER, SLAVE }
|
||||
|
||||
object GlobalData {
|
||||
var appBaseUrl: String = TEST_BASE_URL
|
||||
|
||||
/**
|
||||
* 具体业务 BaseUrl
|
||||
*/
|
||||
const val TEST_BASE_URL = "http://192.168.1.201:14801"
|
||||
const val UAT_BASE_URL = "https://dev.yixiong-tech.com:8083"
|
||||
const val PROD_BASE_URL = "https://api.dm.yixiong-tech.com:8443"
|
||||
|
||||
//临时用于测试
|
||||
const val DEVICE_ID_2 = "8fc2ab34-2137-3112-acca-f884ea8736d4"
|
||||
var appBaseUrl: String = "https://dev.yixiong-tech.com:8081"
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
var deviceId: String = ""
|
||||
|
||||
/**
|
||||
* 当前设备角色,启动时从 SpTool 读取,默认为 SLAVE
|
||||
*/
|
||||
var deviceRole: DeviceRole = DeviceRole.SLAVE
|
||||
var appId = "Hkz1rBk6PZXbS8KwKr67K2eZtsz8bRoMHLg64bUdgCZj"
|
||||
var sdkKey = "AabXs3sHM8UhhE7oCGf4LVMLrdkGb1nJNksbjjTdVt7k"
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,5 +19,4 @@ object GlobalKey {
|
||||
const val KEY_TOKEN = "tokenKey"
|
||||
const val KEY_USER_INFO = "userInfoKey"
|
||||
const val KEY_USER_NAME = "userNameKey"
|
||||
const val KEY_BASE_URL = "baseUrl"
|
||||
}
|
||||
@@ -6,14 +6,10 @@ import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.shuwei.dish.match.db.dao.CookFoodDao
|
||||
import com.shuwei.dish.match.db.dao.CookFoodGoodsDao
|
||||
import com.shuwei.dish.match.db.dao.SeasoningDao
|
||||
import com.shuwei.dish.match.db.dao.SeasoningSlotDao
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||
import com.shuwei.dish.match.db.dao.AppDao
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
|
||||
|
||||
// 步骤1:更新版本号
|
||||
@@ -23,20 +19,16 @@ import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||
SeasoningEntity::class,
|
||||
CookFoodEntity::class,
|
||||
CookFoodGoodsEntity::class,
|
||||
SeasoningSlotEntity::class,
|
||||
],
|
||||
version = 13,
|
||||
version = 7,
|
||||
exportSchema = true
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
// abstract fun seasoningDao(): SeasoningDao
|
||||
// abstract fun cookFoodDao(): CookFoodDao
|
||||
// abstract fun cookFoodGoodsDao(): CookFoodGoodsDao
|
||||
|
||||
abstract fun cookFoodDao(): CookFoodDao
|
||||
|
||||
abstract fun cookFoodGoodsDao(): CookFoodGoodsDao
|
||||
|
||||
abstract fun seasoningDao(): SeasoningDao
|
||||
|
||||
abstract fun seasoningSlotDao(): SeasoningSlotDao
|
||||
abstract fun appDao(): AppDao
|
||||
|
||||
}
|
||||
|
||||
@@ -148,20 +140,6 @@ val MIGRATION_5_6 = MigrationImpl(5, 6) { db ->
|
||||
db.endTransaction()
|
||||
}
|
||||
|
||||
val MIGRATION_7_8 = MigrationImpl(7, 8) { db ->
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `dm_seasoning_slot` (
|
||||
`deviceId` TEXT NOT NULL,
|
||||
`address` INTEGER NOT NULL,
|
||||
`goodsId` TEXT NOT NULL,
|
||||
`goodsName` TEXT NOT NULL,
|
||||
PRIMARY KEY(`deviceId`, `address`)
|
||||
)
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
val MIGRATION_6_7 = MigrationImpl(6, 7) {db ->
|
||||
runCatching {
|
||||
|
||||
@@ -214,48 +192,6 @@ val MIGRATION_6_7 = MigrationImpl(6, 7) {db ->
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本8→9:为 dm_cook_food_goods 和 dm_seasoning 表新增 zjmCode、materId 字段
|
||||
*/
|
||||
val MIGRATION_8_9 = MigrationImpl(8, 9) { db ->
|
||||
db.execSQL("ALTER TABLE dm_cook_food_goods ADD COLUMN zjmCode TEXT DEFAULT ''")
|
||||
db.execSQL("ALTER TABLE dm_cook_food_goods ADD COLUMN materId TEXT DEFAULT ''")
|
||||
db.execSQL("ALTER TABLE dm_seasoning ADD COLUMN zjmCode TEXT DEFAULT ''")
|
||||
db.execSQL("ALTER TABLE dm_seasoning ADD COLUMN materId TEXT DEFAULT ''")
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本9→10:删除 dm_cook_food 表 foodId 唯一索引
|
||||
* 改为由应用层保证同一 foodId 且 isDel=0 只有一条记录,以支持逻辑删除
|
||||
*/
|
||||
val MIGRATION_9_10 = MigrationImpl(9, 10) { db ->
|
||||
db.execSQL("DROP INDEX IF EXISTS dm_cook_food_foodId_IDX")
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本10→11:为 dm_cook_food_goods 和 dm_seasoning 表新增 goodsCode(物料编码)字段
|
||||
*/
|
||||
val MIGRATION_10_11 = MigrationImpl(10, 11) { db ->
|
||||
db.execSQL("ALTER TABLE dm_cook_food_goods ADD COLUMN goodsCode TEXT DEFAULT ''")
|
||||
db.execSQL("ALTER TABLE dm_seasoning ADD COLUMN goodsCode TEXT DEFAULT ''")
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本11→12:为 dm_cook_food_goods 和 dm_seasoning 表新增 rawMaterialsType(净材种类)字段
|
||||
*/
|
||||
val MIGRATION_11_12 = MigrationImpl(11, 12) { db ->
|
||||
db.execSQL("ALTER TABLE dm_cook_food_goods ADD COLUMN rawMaterialsType TEXT DEFAULT NULL")
|
||||
db.execSQL("ALTER TABLE dm_seasoning ADD COLUMN rawMaterialsType TEXT DEFAULT NULL")
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本12→13:为 dm_cook_food 表新增 submitState(接口提交状态)字段
|
||||
* 0-未提交(本地草稿/手动删除),1-接口提交成功后删除
|
||||
*/
|
||||
val MIGRATION_12_13 = MigrationImpl(12, 13) { db ->
|
||||
db.execSQL("ALTER TABLE dm_cook_food ADD COLUMN submitState INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
|
||||
class DatabaseProvider(private val context: Context) {
|
||||
// 单例模式确保全局唯一实例
|
||||
val instance: AppDatabase by lazy {
|
||||
@@ -274,12 +210,6 @@ class DatabaseProvider(private val context: Context) {
|
||||
// .addMigrations(MIGRATION_4_5)
|
||||
// .addMigrations(MIGRATION_5_6)
|
||||
// .addMigrations(MIGRATION_6_7)
|
||||
.addMigrations(MIGRATION_7_8)
|
||||
.addMigrations(MIGRATION_8_9)
|
||||
.addMigrations(MIGRATION_9_10)
|
||||
.addMigrations(MIGRATION_10_11)
|
||||
.addMigrations(MIGRATION_11_12)
|
||||
.addMigrations(MIGRATION_12_13)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.shuwei.dish.match.db
|
||||
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.db.dao.AppDao
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
||||
class AppRepository(val appDao: AppDao) {
|
||||
|
||||
suspend fun insertCookFood(item: CookFoodEntity) = withContext(Dispatchers.IO) {
|
||||
appDao.insertCookFood(item)
|
||||
}
|
||||
|
||||
suspend fun updateCookFood(item: CookFoodEntity) = withContext(Dispatchers.IO) {
|
||||
appDao.updateCookFood(item)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodById(foodId: String, cookMode: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.getCookFoodById(BaseApp.canteenId, foodId, cookMode)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodList(cookMode: Int, dinnerType: String) = withContext(Dispatchers.IO) {
|
||||
appDao.getCookFoodList(BaseApp.canteenId, cookMode, dinnerType)
|
||||
}
|
||||
|
||||
suspend fun countCookFood(cookMode: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.countCookFood(BaseApp.canteenId, cookMode)
|
||||
}
|
||||
|
||||
suspend fun deleteCookFood(foodId: String, cookMode: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.deleteCookFood(BaseApp.canteenId, foodId, cookMode)
|
||||
}
|
||||
|
||||
suspend fun deleteCookFoodGoodsList(pid:Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
appDao.deleteCookFoodGoodsList(pid, foodId)
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
// suspend fun insertGoods(item: CookFoodGoodsEntity) = withContext(Dispatchers.IO) {
|
||||
// appDao.insertGoods(item)
|
||||
// }
|
||||
|
||||
suspend fun insertGoodsList(items: MutableList<CookFoodGoodsEntity>) =
|
||||
withContext(Dispatchers.IO) {
|
||||
appDao.insertGoodsList(items)
|
||||
}
|
||||
|
||||
// suspend fun updateGoods(item: CookFoodGoodsEntity) = withContext(Dispatchers.IO) {
|
||||
// appDao.updateGoods(item)
|
||||
// }
|
||||
|
||||
suspend fun getCookFoodGoodsList(pid:Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
appDao.getCookFoodGoodsList(pid, foodId)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodGoodsListByType(
|
||||
foodId: String,
|
||||
materialType: Int
|
||||
) = withContext(Dispatchers.IO) {
|
||||
appDao.getCookFoodGoodsListByType(foodId, materialType)
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
suspend fun getSeasoningById(id: Long) = withContext(Dispatchers.IO) {
|
||||
appDao.getSeasoningById(id)
|
||||
}
|
||||
|
||||
suspend fun getSeasoningBySort(sort:Int) = withContext(Dispatchers.IO) {
|
||||
appDao.getSeasoningBySort(sort)
|
||||
}
|
||||
|
||||
suspend fun getSeasoningByGoodsId(goodsId: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.getSeasoningByGoodsId(goodsId)
|
||||
}
|
||||
|
||||
suspend fun getAllStream() = withContext(Dispatchers.IO) {
|
||||
appDao.getAllStream()
|
||||
}
|
||||
|
||||
suspend fun search(query: String) = withContext(Dispatchers.IO) {
|
||||
appDao.search(query)
|
||||
}
|
||||
|
||||
suspend fun clearAllSeasoning() = withContext(Dispatchers.IO) {
|
||||
appDao.clearAllSeasoning()
|
||||
}
|
||||
|
||||
suspend fun deleteSeasoningBySort(sort: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.deleteSeasoningBySort(sort)
|
||||
}
|
||||
|
||||
suspend fun insertSeasoningList(items: MutableList<SeasoningEntity>) =
|
||||
withContext(Dispatchers.IO) {
|
||||
appDao.insertSeasoningList(items)
|
||||
}
|
||||
|
||||
suspend fun updateSeasoning(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
appDao.updateSeasoning(item)
|
||||
}
|
||||
|
||||
suspend fun insertSeasoning(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
appDao.insertSeasoning(item)
|
||||
}
|
||||
}
|
||||
//
|
||||
//class SeasoningRepository(val seasoningDao: SeasoningDao) {
|
||||
// val seasoningList: Flow<List<SeasoningEntity>> = seasoningDao.getAllStream()
|
||||
//
|
||||
// fun addSeasoning(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
// seasoningDao.insert(item)
|
||||
// }
|
||||
//
|
||||
// fun searchSeasoning(query: String) = withContext(Dispatchers.IO) {
|
||||
// seasoningDao.search(query)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//class CookFoodRepository(val cookFoodDao: CookFoodDao) {
|
||||
// fun getCookFood(foodId: String, cookMode:Int = 0) = withContext(Dispatchers.IO) {
|
||||
// cookFoodDao.getCookFoodById(foodId, cookMode)
|
||||
// }
|
||||
//
|
||||
// fun getCookFoodByList(cookMode:Int = 0) = withContext(Dispatchers.IO) {
|
||||
// cookFoodDao.getCookFoodList(cookMode)
|
||||
// }
|
||||
//
|
||||
// fun countCookFood(cookMode:Int = 0)= withContext(Dispatchers.IO) {
|
||||
// cookFoodDao.countCookFood(cookMode)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//class CookFoodGoodsRepository(val cookFoodGoodsDao: CookFoodGoodsDao) {
|
||||
// fun getFoodGoodsList(foodId: String) = withContext(Dispatchers.IO) {
|
||||
// cookFoodGoodsDao.getCookFoodGoodsList(foodId)
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -1,315 +0,0 @@
|
||||
package com.shuwei.dish.match.db
|
||||
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
||||
class DbRepository {
|
||||
|
||||
private val db = BaseApp.instance!!.database
|
||||
|
||||
suspend fun insertCookFood(item: CookFoodEntity) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().insertCookFood(item)
|
||||
}
|
||||
|
||||
suspend fun updateCookFood(item: CookFoodEntity) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().updateCookFood(item)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodById(foodId: String, cookMode: Int, dinnerType: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().getCookFoodById(BaseApp.canteenId, foodId, cookMode, dinnerType)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodList(cookMode: Int, dinnerType: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().getCookFoodList(BaseApp.canteenId, cookMode, dinnerType)
|
||||
}
|
||||
|
||||
suspend fun countCookFood(cookMode: Int) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().countCookFood(BaseApp.canteenId, cookMode)
|
||||
}
|
||||
|
||||
suspend fun deleteCookFood(foodId: String, cookMode: Int, dinnerType: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().deleteCookFood(BaseApp.canteenId, foodId, cookMode, dinnerType)
|
||||
}
|
||||
|
||||
/** 接口提交成功后逻辑删除菜品,同时把 submitState 置 1 */
|
||||
suspend fun markSubmittedAndDelete(foodId: String, cookMode: Int, dinnerType: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().markSubmittedAndDelete(BaseApp.canteenId, foodId, cookMode, dinnerType)
|
||||
}
|
||||
|
||||
suspend fun deleteCookFoodGoodsList(pid: Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().deleteCookFoodGoodsList(pid, foodId)
|
||||
}
|
||||
|
||||
/** 仅逻辑删除调料行(materialType = 3),主辅材不动 */
|
||||
suspend fun deleteSeasoningOnly(pid: Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().deleteSeasoningOnly(pid, foodId)
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
suspend fun insertGoodsList(items: MutableList<CookFoodGoodsEntity>) =
|
||||
withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().insertGoodsList(items)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodGoodsList(pid: Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().getCookFoodGoodsList(pid, foodId)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodGoodsListByType(
|
||||
foodId: String,
|
||||
materialType: Int
|
||||
) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().getCookFoodGoodsListByType(foodId, materialType)
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
suspend fun getSeasoningById(id: Long) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().getSeasoningById(id)
|
||||
}
|
||||
|
||||
suspend fun getSeasoningBySort(sort: Int) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().getSeasoningBySort(sort)
|
||||
}
|
||||
|
||||
suspend fun getSeasoningByGoodsId(goodsId: String) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().getSeasoningByGoodsId(goodsId)
|
||||
}
|
||||
|
||||
suspend fun getAllStream() = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().getAllStream()
|
||||
}
|
||||
|
||||
suspend fun search(query: String) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().search(query)
|
||||
}
|
||||
|
||||
suspend fun clearAllSeasoning() = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().clearAllSeasoning()
|
||||
}
|
||||
|
||||
suspend fun deleteSeasoningBySort(sort: Int) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().deleteSeasoningBySort(sort)
|
||||
}
|
||||
|
||||
suspend fun insertSeasoningList(items: MutableList<SeasoningEntity>) =
|
||||
withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().insertSeasoningList(items)
|
||||
}
|
||||
|
||||
suspend fun updateSeasoning(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().updateSeasoning(item)
|
||||
}
|
||||
|
||||
suspend fun insertSeasoning(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().insertSeasoning(item)
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 goodsId 查重后 upsert:存在则更新,不存在则插入
|
||||
* 确保同一个 goodsId 在 dm_seasoning 中只有一条记录
|
||||
*/
|
||||
suspend fun upsertSeasoningByGoodsId(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
val existing = db.seasoningDao().getSeasoningByGoodsId(item.goodsId)
|
||||
if (existing != null) {
|
||||
db.seasoningDao().updateSeasoning(item.also { it.id = existing.id })
|
||||
} else {
|
||||
item.id = 0
|
||||
db.seasoningDao().insertSeasoning(item)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定设备是否已配置调料槽位
|
||||
* @param deviceId 目标设备 ID
|
||||
* @return true 表示已有配置,false 表示未配置
|
||||
*/
|
||||
suspend fun hasSeasoningSlotConfig(deviceId: String) = withContext(Dispatchers.IO) {
|
||||
db.seasoningSlotDao().queryByDeviceId(deviceId).isNotEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有设备的调料槽位配置
|
||||
*/
|
||||
suspend fun getAllSeasoningSlots() = withContext(Dispatchers.IO) {
|
||||
db.seasoningSlotDao().queryAll()
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定设备的调料槽位配置
|
||||
* @param deviceId 目标设备 ID
|
||||
*/
|
||||
suspend fun getSeasoningSlotsByDeviceId(deviceId: String) = withContext(Dispatchers.IO) {
|
||||
db.seasoningSlotDao().queryByDeviceId(deviceId)
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入或更新单个调料槽位配置
|
||||
*/
|
||||
suspend fun upsertSeasoningSlot(slot: SeasoningSlotEntity) = withContext(Dispatchers.IO) {
|
||||
db.seasoningSlotDao().upsert(slot)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入或更新调料槽位配置
|
||||
*/
|
||||
suspend fun upsertAllSeasoningSlots(slots: List<SeasoningSlotEntity>) = withContext(Dispatchers.IO) {
|
||||
db.seasoningSlotDao().upsertAll(slots)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定设备的指定槽位配置
|
||||
* @param deviceId 目标设备 ID
|
||||
* @param address 秤硬件地址
|
||||
*/
|
||||
suspend fun deleteSeasoningSlot(deviceId: String, address: Int) = withContext(Dispatchers.IO) {
|
||||
db.seasoningSlotDao().deleteByDeviceIdAndAddress(deviceId, address)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定设备的全部槽位配置
|
||||
* @param deviceId 目标设备 ID
|
||||
*/
|
||||
suspend fun deleteAllSlotsByDeviceId(deviceId: String) = withContext(Dispatchers.IO) {
|
||||
db.seasoningSlotDao().deleteAllByDeviceId(deviceId)
|
||||
}
|
||||
|
||||
// ---- 调试用:查询各表全量数据(含已删除记录)----
|
||||
|
||||
/** 查询 dm_cook_food 全部记录 */
|
||||
suspend fun getAllCookFood() = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().getAllCookFood()
|
||||
}
|
||||
|
||||
/** 查询 dm_cook_food_goods 全部记录 */
|
||||
suspend fun getAllCookFoodGoods() = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().getAllCookFoodGoods()
|
||||
}
|
||||
|
||||
/** 查询 dm_seasoning 全部记录 */
|
||||
suspend fun getAllSeasoning() = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().getAllSeasoning()
|
||||
}
|
||||
|
||||
// ---- 调试用:分页查询(含 isDel 过滤)----
|
||||
|
||||
suspend fun getCookFoodPaged(showDel: Boolean, limit: Int, offset: Int) =
|
||||
withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().getCookFoodPaged(if (showDel) 1 else 0, limit, offset)
|
||||
}
|
||||
|
||||
suspend fun countCookFoodAll(showDel: Boolean) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodDao().countCookFoodAll(if (showDel) 1 else 0)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodGoodsPaged(showDel: Boolean, limit: Int, offset: Int) =
|
||||
withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().getCookFoodGoodsPaged(if (showDel) 1 else 0, limit, offset)
|
||||
}
|
||||
|
||||
suspend fun countCookFoodGoodsAll(showDel: Boolean) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().countCookFoodGoodsAll(if (showDel) 1 else 0)
|
||||
}
|
||||
|
||||
suspend fun getSeasoningPaged(showDel: Boolean, limit: Int, offset: Int) =
|
||||
withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().getSeasoningPaged(if (showDel) 1 else 0, limit, offset)
|
||||
}
|
||||
|
||||
suspend fun countSeasoningAll(showDel: Boolean) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().countSeasoningAll(if (showDel) 1 else 0)
|
||||
}
|
||||
|
||||
suspend fun getSlotPaged(limit: Int, offset: Int) = withContext(Dispatchers.IO) {
|
||||
db.seasoningSlotDao().getSlotPaged(limit, offset)
|
||||
}
|
||||
|
||||
suspend fun countSlotAll() = withContext(Dispatchers.IO) {
|
||||
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 张表的测试数据
|
||||
* 清除顺序:先删子表(食材),再删主表(菜品),最后删配置表(调料、槽位)
|
||||
*/
|
||||
suspend fun clearAllData() = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().deleteAll()
|
||||
db.cookFoodDao().deleteAll()
|
||||
db.seasoningDao().deleteAll()
|
||||
db.seasoningSlotDao().deleteAll()
|
||||
}
|
||||
}
|
||||
//
|
||||
//class SeasoningRepository(val seasoningDao: SeasoningDao) {
|
||||
// val seasoningList: Flow<List<SeasoningEntity>> = seasoningDao.getAllStream()
|
||||
//
|
||||
// fun addSeasoning(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
// seasoningDao.insert(item)
|
||||
// }
|
||||
//
|
||||
// fun searchSeasoning(query: String) = withContext(Dispatchers.IO) {
|
||||
// seasoningDao.search(query)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//class CookFoodRepository(val cookFoodDao: CookFoodDao) {
|
||||
// fun getCookFood(foodId: String, cookMode:Int = 0) = withContext(Dispatchers.IO) {
|
||||
// cookFoodDao.getCookFoodById(foodId, cookMode)
|
||||
// }
|
||||
//
|
||||
// fun getCookFoodByList(cookMode:Int = 0) = withContext(Dispatchers.IO) {
|
||||
// cookFoodDao.getCookFoodList(cookMode)
|
||||
// }
|
||||
//
|
||||
// fun countCookFood(cookMode:Int = 0)= withContext(Dispatchers.IO) {
|
||||
// cookFoodDao.countCookFood(cookMode)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//class CookFoodGoodsRepository(val cookFoodGoodsDao: CookFoodGoodsDao) {
|
||||
// fun getFoodGoodsList(foodId: String) = withContext(Dispatchers.IO) {
|
||||
// cookFoodGoodsDao.getCookFoodGoodsList(foodId)
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -1,623 +0,0 @@
|
||||
package com.shuwei.dish.match.db
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
import com.shuwei.dish.match.model.CollectedFoodItem
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
|
||||
class DbViewModel : ViewModel() {
|
||||
|
||||
private val rep = DbRepository()
|
||||
|
||||
fun updateCookFood(entity: CookFoodEntity) {
|
||||
viewModelScope.launch {
|
||||
rep.updateCookFood(entity)
|
||||
}
|
||||
}
|
||||
|
||||
private val _cookFoodDetailState = MutableStateFlow<CookFoodEntity?>(null)
|
||||
val cookFoodDetailState: StateFlow<CookFoodEntity?> = _cookFoodDetailState.asStateFlow()
|
||||
|
||||
fun getCookFoodById(foodId: String, cookMode: Int, dinnerType: String) {
|
||||
viewModelScope.launch {
|
||||
_cookFoodDetailState.value = rep.getCookFoodById(foodId, cookMode, dinnerType)
|
||||
}
|
||||
}
|
||||
|
||||
private val _cookFoodListState = MutableStateFlow<MutableList<CookFoodEntity>?>(null)
|
||||
val cookFoodListState: StateFlow<MutableList<CookFoodEntity>?> = _cookFoodListState.asStateFlow()
|
||||
fun resetCookFoodList() {
|
||||
_cookFoodListState.value = null
|
||||
}
|
||||
fun getCookFoodList(
|
||||
cookMode: Int,
|
||||
dinnerType: String = "0"
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
_cookFoodListState.value = rep.getCookFoodList(cookMode, dinnerType)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询本地烹饪中数据(回调版本),结果通过 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 {
|
||||
return rep.countCookFood(cookMode)
|
||||
}
|
||||
|
||||
// fun saveCookFood(cookMode: Int, entity: CookFoodEntity) {
|
||||
// viewModelScope.launch {
|
||||
// val data = rep.getCookFoodById(entity.foodId, cookMode)
|
||||
// if (data == null) {
|
||||
// rep.insertCookFood(entity)
|
||||
// return@launch
|
||||
// }
|
||||
// rep.updateCookFood(entity)
|
||||
// }
|
||||
// }
|
||||
|
||||
suspend fun saveCookFoodAndGoods(
|
||||
cookMode: Int,
|
||||
entity: CookFoodEntity,
|
||||
list: MutableList<CookFoodGoodsEntity>?
|
||||
) {
|
||||
val data = rep.getCookFoodById(entity.foodId, cookMode, entity.dinnerType ?: "0")
|
||||
if (data == null) {
|
||||
// 首次保存:主表 + 主辅材 + 调料 全量 insert
|
||||
rep.insertCookFood(entity)
|
||||
val newData = rep.getCookFoodById(entity.foodId, cookMode, entity.dinnerType ?: "0")
|
||||
// 回填 id,防止下次调用时 getCookFoodById 查不到而重复插入主辅材
|
||||
newData?.let { entity.id = it.id }
|
||||
list?.let {
|
||||
it.forEach { goods ->
|
||||
goods.id = 0
|
||||
goods.pid = newData?.id ?: 0
|
||||
}
|
||||
rep.insertGoodsList(it)
|
||||
}
|
||||
} else {
|
||||
// 已存在:主表与主辅材保持不变,仅重建调料部分,避免主表/主辅材累积逻辑删除脏数据
|
||||
rep.deleteSeasoningOnly(data.id, entity.foodId)
|
||||
val seasoningList = list?.filter { it.materialType == 3 }?.toMutableList()
|
||||
if (!seasoningList.isNullOrEmpty()) {
|
||||
seasoningList.forEach { goods ->
|
||||
goods.id = 0
|
||||
goods.pid = data.id
|
||||
goods.foodId = entity.foodId
|
||||
}
|
||||
rep.insertGoodsList(seasoningList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteCookFoodAndGoods(cookMode: Int, foodId: String, dinnerType: String) {
|
||||
val data = rep.getCookFoodById(foodId, cookMode, dinnerType)
|
||||
if (data != null) {
|
||||
rep.deleteCookFood(foodId = foodId, cookMode = cookMode, dinnerType = dinnerType)
|
||||
rep.deleteCookFoodGoodsList(pid = data.id, foodId = foodId)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口提交成功后删除本地菜品草稿(异步版本,绑定 viewModelScope)
|
||||
* 与 [markSubmittedAndDelete] 的区别:不是 suspend,内部用 viewModelScope 启动协程,
|
||||
* 不受调用方 Activity 生命周期影响,适合 singleTask 跳转前触发删除的场景
|
||||
*/
|
||||
fun markSubmittedAndDeleteAsync(cookMode: Int, foodId: String, dinnerType: String) {
|
||||
viewModelScope.launch {
|
||||
markSubmittedAndDelete(cookMode, foodId, dinnerType)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口提交成功后删除本地菜品草稿
|
||||
* 与 [deleteCookFoodAndGoods] 的区别:主表 submitState 会被置 1,便于审计区分手动删除与接口删除
|
||||
*/
|
||||
suspend fun markSubmittedAndDelete(cookMode: Int, foodId: String, dinnerType: String) {
|
||||
val data = rep.getCookFoodById(foodId, cookMode, dinnerType)
|
||||
if (data != null) {
|
||||
rep.markSubmittedAndDelete(foodId = foodId, cookMode = cookMode, dinnerType = dinnerType)
|
||||
rep.deleteCookFoodGoodsList(pid = data.id, foodId = foodId)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
suspend fun getCookFoodGoodsList(
|
||||
foodId: String,
|
||||
cookMode: Int,
|
||||
dinnerType: String
|
||||
): MutableList<CookFoodGoodsEntity> {
|
||||
val cookFood = rep.getCookFoodById(foodId, cookMode, dinnerType)
|
||||
return if (cookFood != null) rep.getCookFoodGoodsList(pid = cookFood.id, foodId = cookFood.foodId)
|
||||
else mutableListOf()
|
||||
}
|
||||
|
||||
// fun updateGoods(entity: CookFoodGoodsEntity) {
|
||||
// viewModelScope.launch {
|
||||
// rep.updateGoods(entity)
|
||||
// }
|
||||
// }
|
||||
|
||||
// fun saveCookFoodGoods(list: MutableList<CookFoodGoodsEntity>) {
|
||||
// viewModelScope.launch {
|
||||
// val foodId = list[0].foodId
|
||||
// val data: MutableList<CookFoodGoodsEntity>? =
|
||||
// rep.getCookFoodGoodsList(foodId!!)
|
||||
// if (data.isNullOrEmpty()) {
|
||||
// rep.insertGoodsList(list)
|
||||
// return@launch
|
||||
// }
|
||||
// val localDbSeasoningList = rep.getCookFoodGoodsListByType(foodId, 3)
|
||||
// localDbSeasoningList.forEach {
|
||||
// it.isDel = 1
|
||||
// //更新本地调料数据为已删除的状态
|
||||
// rep.updateGoods(it)
|
||||
// }
|
||||
// //筛选出调料数据保存,主辅材不会变更不需要再次处理
|
||||
// val saveSeasoningList = list.filter { it.materialType == 3 }
|
||||
// rep.insertGoodsList(saveSeasoningList.toMutableList())
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
// fun addSeasoning(list: MutableList<SeasoningEntity>, callback: () -> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// rep.deleteBatch()
|
||||
// rep.insertSeasoningList(items = list)
|
||||
// callback()
|
||||
// }
|
||||
// }
|
||||
|
||||
private val loadSeasoningMutex = Mutex()
|
||||
|
||||
/**
|
||||
* 本地调料列表状态流
|
||||
*/
|
||||
private val _seasoningState = MutableStateFlow<MutableList<SeasoningEntity>>(mutableListOf())
|
||||
val seasoningState: StateFlow<MutableList<SeasoningEntity>> = _seasoningState.asStateFlow()
|
||||
|
||||
fun loadSeasoning() {
|
||||
if (loadSeasoningMutex.isLocked) return
|
||||
viewModelScope.launch {
|
||||
loadSeasoningMutex.withLock {
|
||||
_seasoningState.value = rep.getAllStream()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有设备调料槽位配置的 UI 状态流
|
||||
*/
|
||||
private val _seasoningSlotState = MutableStateFlow<List<SeasoningSlotEntity>>(emptyList())
|
||||
val seasoningSlotState: StateFlow<List<SeasoningSlotEntity>> = _seasoningSlotState.asStateFlow()
|
||||
|
||||
/**
|
||||
* 查询所有调料槽位配置,更新 seasoningSlotState 并返回结果
|
||||
* 声明为 suspend,调用方可在同一协程中直接使用返回值,无需等待 StateFlow 更新
|
||||
*/
|
||||
suspend fun loadSeasoningSlot(): List<SeasoningSlotEntity> {
|
||||
val slots = rep.getAllSeasoningSlots()
|
||||
_seasoningSlotState.value = slots
|
||||
return slots
|
||||
}
|
||||
|
||||
fun deleteSeasoningBySort(sort: Int) {
|
||||
viewModelScope.launch {
|
||||
rep.deleteSeasoningBySort(sort)
|
||||
}
|
||||
}
|
||||
|
||||
private val _clearAllSeasoningState = MutableStateFlow(false)
|
||||
val clearAllSeasoningState: StateFlow<Boolean> = _clearAllSeasoningState.asStateFlow()
|
||||
|
||||
fun clearAllSeasoning() {
|
||||
viewModelScope.launch {
|
||||
rep.clearAllSeasoning()
|
||||
_clearAllSeasoningState.value = true
|
||||
}
|
||||
}
|
||||
|
||||
private val _hasSeasoningSlotConfigState = MutableStateFlow(false)
|
||||
val hasSeasoningSlotConfigState: StateFlow<Boolean> = _hasSeasoningSlotConfigState.asStateFlow()
|
||||
|
||||
/**
|
||||
* 查询指定设备是否已配置调料槽位
|
||||
* @param deviceId 目标设备 ID
|
||||
*/
|
||||
fun hasSeasoningSlotConfig(deviceId: String) {
|
||||
viewModelScope.launch {
|
||||
_hasSeasoningSlotConfigState.value = rep.hasSeasoningSlotConfig(deviceId)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定设备的调料槽位配置
|
||||
*/
|
||||
suspend fun getSeasoningSlotsByDeviceId(deviceId: String) =
|
||||
rep.getSeasoningSlotsByDeviceId(deviceId)
|
||||
|
||||
/**
|
||||
* 插入或更新单个调料槽位配置
|
||||
*/
|
||||
suspend fun upsertSeasoningSlot(slot: SeasoningSlotEntity) =
|
||||
rep.upsertSeasoningSlot(slot)
|
||||
|
||||
/**
|
||||
* 批量插入或更新调料槽位配置
|
||||
*/
|
||||
suspend fun upsertAllSeasoningSlots(slots: List<SeasoningSlotEntity>) =
|
||||
rep.upsertAllSeasoningSlots(slots)
|
||||
|
||||
/**
|
||||
* 删除指定设备的指定槽位配置
|
||||
* @param deviceId 目标设备 ID
|
||||
* @param address 秤硬件地址
|
||||
*/
|
||||
suspend fun deleteSeasoningSlot(deviceId: String, address: Int) =
|
||||
rep.deleteSeasoningSlot(deviceId, address)
|
||||
|
||||
/**
|
||||
* 删除指定设备的全部槽位配置(子设备接收全量广播时先清空再写入)
|
||||
* @param deviceId 目标设备 ID
|
||||
*/
|
||||
suspend fun deleteAllSlotsByDeviceId(deviceId: String) =
|
||||
rep.deleteAllSlotsByDeviceId(deviceId)
|
||||
|
||||
// ---- 数据库调试查看 ----
|
||||
|
||||
/**
|
||||
* 物理清空全部 4 张表的测试数据,完成后通过回调通知 UI
|
||||
* @param onDone 清除完成后在主线程执行的回调
|
||||
*/
|
||||
fun clearAllData(onDone: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
rep.clearAllData()
|
||||
onDone()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** 每页加载条数 */
|
||||
const val DB_INSPECT_PAGE_SIZE = 50
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条数据库记录的展示模型
|
||||
* @param isDel 是否已逻辑删除
|
||||
* @param fields 字段名-值对列表,按顺序排列
|
||||
* @param columnsPerRow 每行显示的列数,默认 3;槽位表传 1 保持单列
|
||||
*/
|
||||
data class DbRecord(
|
||||
val isDel: Boolean,
|
||||
val fields: List<Pair<String, String>>,
|
||||
val columnsPerRow: Int = 3
|
||||
)
|
||||
|
||||
/**
|
||||
* 数据库调试页面 UI 状态
|
||||
* @param items 当前已加载的记录列表
|
||||
* @param totalCount 当前过滤条件下的总记录数
|
||||
* @param hasMore 是否还有更多数据可加载
|
||||
* @param isLoading 是否正在加载(首次加载或加载更多)
|
||||
* @param filter 当前生效的筛选条件,供"加载更多"复用
|
||||
*/
|
||||
data class DbInspectUiState(
|
||||
val items: List<DbRecord> = emptyList(),
|
||||
val totalCount: Int = 0,
|
||||
val hasMore: 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())
|
||||
val dbInspectState: StateFlow<DbInspectUiState> = _dbInspectState.asStateFlow()
|
||||
|
||||
/**
|
||||
* 加载指定表的第一页数据(切换 Tab / 修改筛选条件时调用)
|
||||
* @param tableIndex 0=菜品 1=食材 2=调料 3=槽位
|
||||
* @param filter 筛选条件,包含 showDel 和各字段过滤值
|
||||
*/
|
||||
fun loadDbInspect(tableIndex: Int, filter: DbInspectFilter) {
|
||||
viewModelScope.launch {
|
||||
// 立即清空旧数据并显示加载状态,避免切换 Tab 时旧数据闪现
|
||||
_dbInspectState.value = DbInspectUiState(isLoading = true, filter = filter)
|
||||
val (items, total) = queryPage(tableIndex, filter, offset = 0)
|
||||
_dbInspectState.value = DbInspectUiState(
|
||||
items = items,
|
||||
totalCount = total,
|
||||
hasMore = items.size < total,
|
||||
isLoading = false,
|
||||
filter = filter
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加加载下一页数据(点击"加载更多"时调用)
|
||||
* 筛选条件从当前 state 中复用,无需重新传入
|
||||
* @param tableIndex 0=菜品 1=食材 2=调料 3=槽位
|
||||
*/
|
||||
fun loadMoreDbInspect(tableIndex: Int) {
|
||||
viewModelScope.launch {
|
||||
val current = _dbInspectState.value
|
||||
// 已在加载中或无更多数据时直接返回,防止重复请求
|
||||
if (!current.hasMore || current.isLoading) return@launch
|
||||
_dbInspectState.value = current.copy(isLoading = true)
|
||||
val (newItems, total) = queryPage(tableIndex, current.filter, offset = current.items.size)
|
||||
val merged = current.items + newItems
|
||||
_dbInspectState.value = DbInspectUiState(
|
||||
items = merged,
|
||||
totalCount = total,
|
||||
hasMore = merged.size < total,
|
||||
isLoading = false,
|
||||
filter = current.filter
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行分页查询,返回 DbRecord 列表和总记录数
|
||||
* 通过 buildQueries 将 filter 转换为动态 SQL
|
||||
*/
|
||||
private suspend fun queryPage(
|
||||
tableIndex: Int,
|
||||
filter: DbInspectFilter,
|
||||
offset: Int
|
||||
): Pair<List<DbRecord>, Int> {
|
||||
val limit = DB_INSPECT_PAGE_SIZE
|
||||
return when (tableIndex) {
|
||||
0 -> {
|
||||
val (pageQ, countQ) = buildQueries("dm_cook_food", "createTime DESC", true, filter, limit, offset)
|
||||
val total = rep.countCookFoodFiltered(countQ)
|
||||
val rows = rep.getCookFoodPagedFiltered(pageQ).map { e ->
|
||||
DbRecord(
|
||||
isDel = e.isDel == 1,
|
||||
fields = listOf(
|
||||
"id" to "${e.id}", "foodId" to "${e.foodId}", "foodName" to "${e.foodName}",
|
||||
"canteenId" to "${e.canteenId}", "foodWeight" to "${e.foodWeight}", "cookMode" to "${e.cookMode}",
|
||||
"dinnerType" to "${e.dinnerType}", "isDel" to "${e.isDel}", "submitState" to "${e.submitState}",
|
||||
"createTime" to "${e.createTime}"
|
||||
)
|
||||
)
|
||||
}
|
||||
rows to total
|
||||
}
|
||||
1 -> {
|
||||
val (pageQ, countQ) = buildQueries("dm_cook_food_goods", "createTime DESC", true, filter, limit, offset)
|
||||
val total = rep.countCookFoodGoodsFiltered(countQ)
|
||||
val rows = rep.getCookFoodGoodsPagedFiltered(pageQ).map { e ->
|
||||
DbRecord(
|
||||
isDel = e.isDel == 1,
|
||||
fields = listOf(
|
||||
"id" to "${e.id}", "pid" to "${e.pid}", "goodsId" to "${e.goodsId}",
|
||||
"goodsName" to "${e.goodsName}", "foodId" to "${e.foodId}", "materialType" to "${e.materialType}",
|
||||
"relateionType" to "${e.relateionType}", "allEdible" to "${e.allEdible}", "useWeight" to "${e.useWeight}",
|
||||
"sort" to "${e.sort}", "zjmCode" to "${e.zjmCode}", "materId" to "${e.materId}",
|
||||
"isDel" to "${e.isDel}", "createTime" to "${e.createTime}"
|
||||
)
|
||||
)
|
||||
}
|
||||
rows to total
|
||||
}
|
||||
2 -> {
|
||||
val (pageQ, countQ) = buildQueries("dm_seasoning", "sort ASC", true, filter, limit, offset)
|
||||
val total = rep.countSeasoningFiltered(countQ)
|
||||
val rows = rep.getSeasoningPagedFiltered(pageQ).map { e ->
|
||||
DbRecord(
|
||||
isDel = e.isDel == 1,
|
||||
fields = listOf(
|
||||
"id" to "${e.id}", "goodsId" to "${e.goodsId}", "goodsName" to "${e.goodsName}",
|
||||
"sort" to "${e.sort}", "materialType" to "${e.materialType}", "useWeight" to "${e.useWeight}",
|
||||
"zjmCode" to "${e.zjmCode}", "materId" to "${e.materId}", "isDel" to "${e.isDel}",
|
||||
"createTime" to "${e.createTime}"
|
||||
)
|
||||
)
|
||||
}
|
||||
rows to total
|
||||
}
|
||||
3 -> {
|
||||
val (pageQ, countQ) = buildQueries("dm_seasoning_slot", "deviceId ASC, address ASC", false, filter, limit, offset)
|
||||
val total = rep.countSlotFiltered(countQ)
|
||||
val rows = rep.getSlotPagedFiltered(pageQ).map { e ->
|
||||
DbRecord(
|
||||
isDel = false,
|
||||
fields = listOf(
|
||||
"deviceId" to e.deviceId, "address" to "${e.address}",
|
||||
"goodsId" to e.goodsId, "goodsName" to e.goodsName
|
||||
),
|
||||
columnsPerRow = 1
|
||||
)
|
||||
}
|
||||
rows to total
|
||||
}
|
||||
else -> emptyList<DbRecord>() to 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据筛选条件动态构建分页查询和计数查询的 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 {
|
||||
// list.forEach {
|
||||
// rep.updateSeasoning(it)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
fun saveSeasoning(entity: SeasoningEntity, block: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val list = rep.getSeasoningBySort(entity.sort)
|
||||
val size = list?.size?:0
|
||||
if (size == 1) {
|
||||
rep.updateSeasoning(entity.also { it.id = list!![0].id })
|
||||
block()
|
||||
return@launch
|
||||
}
|
||||
if (size > 1) {
|
||||
list?.forEach {
|
||||
rep.deleteSeasoningBySort(it.sort)
|
||||
}
|
||||
}
|
||||
entity.id = 0
|
||||
val id = rep.insertSeasoning(entity)
|
||||
entity.id = id
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 goodsId 查重后 upsert 调料数据,确保同一 goodsId 只有一条记录
|
||||
*/
|
||||
suspend fun upsertSeasoningByGoodsId(entity: SeasoningEntity) {
|
||||
rep.upsertSeasoningByGoodsId(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 goodsId 查询调料详情
|
||||
*/
|
||||
suspend fun getSeasoningByGoodsId(goodsId: String): SeasoningEntity? {
|
||||
return rep.getSeasoningByGoodsId(goodsId)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 已采集食材列表 UI 状态流
|
||||
* 元素为按名称分组后的(名称,数量)数据
|
||||
*/
|
||||
private val _collectedFoodListState = MutableStateFlow<List<CollectedFoodItem>>(emptyList())
|
||||
val collectedFoodListState: StateFlow<List<CollectedFoodItem>> = _collectedFoodListState.asStateFlow()
|
||||
|
||||
// /**
|
||||
// * 加载已采集食材列表,按名称分组统计数量
|
||||
// * 使用属性查询只读 name 字段,不加载 foodVector,节省内存
|
||||
// * @param nameFilter 名称过滤关键词,为空时加载全部
|
||||
// */
|
||||
// fun loadCollectedFoodList(nameFilter: String? = null) {
|
||||
// viewModelScope.launch {
|
||||
// val result = ObjectBox.queryFoodNameCounts(nameFilter)
|
||||
// _collectedFoodListState.value = result.map { (name, count) ->
|
||||
// CollectedFoodItem(foodName = name, collectCount = count)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 删除指定名称的所有采集记录,删除完成后刷新列表
|
||||
// * @param foodName 食材名称
|
||||
// * @param nameFilter 当前搜索关键词,用于删除后刷新列表
|
||||
// */
|
||||
// fun removeCollectedFood(foodName: String, nameFilter: String? = null) {
|
||||
// viewModelScope.launch {
|
||||
// ObjectBox.remove(foodName)
|
||||
// loadCollectedFoodList(nameFilter)
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 清除所有向量采集数据,完成后刷新列表
|
||||
// * @param onDone 清除完成后在主线程执行的回调
|
||||
// */
|
||||
// fun clearAllCollectedFood(onDone: (() -> Unit)? = null) {
|
||||
// viewModelScope.launch {
|
||||
// ObjectBox.removeAll()
|
||||
// loadCollectedFoodList()
|
||||
// onDone?.invoke()
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface AppDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertCookFood(item: CookFoodEntity): Long
|
||||
|
||||
@Update
|
||||
suspend fun updateCookFood(item: CookFoodEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
|
||||
suspend fun getCookFoodById(canteenId:String, foodId: String, cookMode: Int): CookFoodEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode AND dinnerType = :dinnerType ORDER BY createTime DESC")
|
||||
suspend fun getCookFoodList(canteenId:String, cookMode: Int, dinnerType:String): MutableList<CookFoodEntity>?
|
||||
|
||||
@Query("SELECT count(1) FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode")
|
||||
suspend fun countCookFood(canteenId:String, cookMode: Int): Int
|
||||
|
||||
@Query("DELETE FROM dm_cook_food WHERE canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
|
||||
suspend fun deleteCookFood(canteenId:String, foodId: String, cookMode: Int)
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertGoods(item: CookFoodGoodsEntity): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertGoodsList(items: MutableList<CookFoodGoodsEntity>): Array<Long>
|
||||
|
||||
@Update
|
||||
suspend fun updateGoods(item: CookFoodGoodsEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND pid = :pid AND foodId = :foodId")
|
||||
suspend fun getCookFoodGoodsList(pid:Long, foodId: String): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId AND materialType = :materialType")
|
||||
suspend fun getCookFoodGoodsListByType(
|
||||
foodId: String,
|
||||
materialType: Int
|
||||
): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
@Query("DELETE FROM dm_cook_food_goods WHERE pid = :pid AND foodId = :foodId")
|
||||
suspend fun deleteCookFoodGoodsList(pid:Long, foodId: String)
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND id = :id")
|
||||
suspend fun getSeasoningById(id: Long): SeasoningEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND sort = :sort")
|
||||
suspend fun getSeasoningBySort(sort: Int): MutableList<SeasoningEntity>?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId = :goodsId")
|
||||
suspend fun getSeasoningByGoodsId(goodsId: Int): SeasoningEntity?
|
||||
|
||||
// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC")
|
||||
// fun getAllStream(): Flow<MutableList<SeasoningEntity>>
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC")
|
||||
fun getAllStream(): MutableList<SeasoningEntity>
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsName LIKE '%' || :query || '%'")
|
||||
suspend fun search(query: String): MutableList<SeasoningEntity>
|
||||
|
||||
@Query("DELETE FROM dm_seasoning WHERE isDel = 0 AND sort = :sort")
|
||||
suspend fun deleteSeasoningBySort(sort:Int): Int
|
||||
|
||||
@Query("DELETE FROM dm_seasoning WHERE isDel = 0")
|
||||
suspend fun clearAllSeasoning(): Int
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSeasoningList(items: MutableList<SeasoningEntity>): Array<Long>
|
||||
|
||||
@Update
|
||||
suspend fun updateSeasoning(item: SeasoningEntity)
|
||||
|
||||
@Insert
|
||||
suspend fun insertSeasoning(item: SeasoningEntity): Long
|
||||
//--------------------------------------------------------------------------------------------
|
||||
}
|
||||
@@ -1,61 +1,20 @@
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.RawQuery
|
||||
import androidx.room.Update
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
|
||||
@Dao
|
||||
interface CookFoodDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertCookFood(item: CookFoodEntity): Long
|
||||
|
||||
@Update
|
||||
suspend fun updateCookFood(item: CookFoodEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode AND dinnerType = :dinnerType")
|
||||
suspend fun getCookFoodById(canteenId: String, foodId: String, cookMode: Int, dinnerType: String): CookFoodEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode AND dinnerType = :dinnerType ORDER BY createTime DESC")
|
||||
suspend fun getCookFoodList(canteenId: String, cookMode: Int, dinnerType: String): MutableList<CookFoodEntity>?
|
||||
|
||||
@Query("SELECT count(1) FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode")
|
||||
suspend fun countCookFood(canteenId: String, cookMode: Int): Int
|
||||
|
||||
// @Query("DELETE FROM dm_cook_food WHERE canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
|
||||
@Query("UPDATE dm_cook_food SET isDel = 1 WHERE isDel = 0 AND canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode AND dinnerType = :dinnerType")
|
||||
suspend fun deleteCookFood(canteenId: String, foodId: String, cookMode: Int, dinnerType: String)
|
||||
|
||||
/** 接口提交成功后逻辑删除菜品,同时把 submitState 置 1 以便在数据库审计中区分手动删除 */
|
||||
@Query("UPDATE dm_cook_food SET isDel = 1, submitState = 1 WHERE isDel = 0 AND canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode AND dinnerType = :dinnerType")
|
||||
suspend fun markSubmittedAndDelete(canteenId: String, foodId: String, cookMode: Int, dinnerType: String)
|
||||
|
||||
/** 查询全部菜品记录(含已删除),用于数据库调试查看 */
|
||||
@Query("SELECT * FROM dm_cook_food ORDER BY createTime DESC")
|
||||
suspend fun getAllCookFood(): MutableList<CookFoodEntity>
|
||||
|
||||
/** 分页查询菜品记录,showDel=true 时包含已删除记录 */
|
||||
@Query("SELECT * FROM dm_cook_food WHERE (:showDel = 1 OR isDel = 0) ORDER BY createTime DESC LIMIT :limit OFFSET :offset")
|
||||
suspend fun getCookFoodPaged(showDel: Int, limit: Int, offset: Int): List<CookFoodEntity>
|
||||
|
||||
/** 统计菜品记录总数,showDel=true 时包含已删除记录 */
|
||||
@Query("SELECT COUNT(*) FROM dm_cook_food WHERE (:showDel = 1 OR isDel = 0)")
|
||||
suspend fun countCookFoodAll(showDel: Int): Int
|
||||
|
||||
/** 物理清空全表,用于清除测试数据 */
|
||||
@Query("DELETE FROM dm_cook_food")
|
||||
suspend fun deleteAll()
|
||||
|
||||
/** 动态条件分页查询菜品记录,由 ViewModel 构建 SQL */
|
||||
@RawQuery
|
||||
suspend fun queryPagedFiltered(query: SupportSQLiteQuery): List<CookFoodEntity>
|
||||
|
||||
/** 动态条件统计菜品记录总数,由 ViewModel 构建 SQL */
|
||||
@RawQuery
|
||||
suspend fun countFiltered(query: SupportSQLiteQuery): Int
|
||||
}
|
||||
//package com.shuwei.dish.match.db.dao
|
||||
//
|
||||
//import androidx.room.Dao
|
||||
//import androidx.room.Query
|
||||
//import com.shuwei.dish.match.db.BaseDao
|
||||
//import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
//
|
||||
//@Dao
|
||||
//interface CookFoodDao : BaseDao<CookFoodEntity> {
|
||||
//
|
||||
// @Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND foodId = :foodId AND cookMode = :cookMode")
|
||||
// suspend fun getCookFoodById(foodId: String, cookMode:Int): CookFoodEntity?
|
||||
//
|
||||
// @Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND cookMode = :cookMode")
|
||||
// suspend fun getCookFoodList(cookMode:Int): MutableList<CookFoodEntity>?
|
||||
//
|
||||
// @Query("SELECT count(1) FROM dm_cook_food WHERE isDel = 0 AND cookMode = :cookMode")
|
||||
// suspend fun countCookFood(cookMode:Int): Int
|
||||
//
|
||||
//}
|
||||
@@ -1,61 +1,29 @@
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.RawQuery
|
||||
import androidx.room.Update
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
|
||||
@Dao
|
||||
interface CookFoodGoodsDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertGoods(item: CookFoodGoodsEntity): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertGoodsList(items: MutableList<CookFoodGoodsEntity>): Array<Long>
|
||||
|
||||
@Update
|
||||
suspend fun updateGoods(item: CookFoodGoodsEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND pid = :pid AND foodId = :foodId")
|
||||
suspend fun getCookFoodGoodsList(pid: Long, foodId: String): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId AND materialType = :materialType")
|
||||
suspend fun getCookFoodGoodsListByType(foodId: String, materialType: Int): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
// @Query("DELETE FROM dm_cook_food_goods WHERE pid = :pid AND foodId = :foodId")
|
||||
@Query("UPDATE dm_cook_food_goods SET isDel = 1 WHERE isDel = 0 AND pid = :pid AND foodId = :foodId")
|
||||
suspend fun deleteCookFoodGoodsList(pid: Long, foodId: String)
|
||||
|
||||
/** 仅逻辑删除调料行(materialType = 3),主辅材不动,用于 cook 时只重建调料部分 */
|
||||
@Query("UPDATE dm_cook_food_goods SET isDel = 1 WHERE isDel = 0 AND pid = :pid AND foodId = :foodId AND materialType = 3")
|
||||
suspend fun deleteSeasoningOnly(pid: Long, foodId: String)
|
||||
|
||||
/** 查询全部食材记录(含已删除),用于数据库调试查看 */
|
||||
@Query("SELECT * FROM dm_cook_food_goods ORDER BY createTime DESC")
|
||||
suspend fun getAllCookFoodGoods(): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
/** 分页查询食材记录,showDel=true 时包含已删除记录 */
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE (:showDel = 1 OR isDel = 0) ORDER BY createTime DESC LIMIT :limit OFFSET :offset")
|
||||
suspend fun getCookFoodGoodsPaged(showDel: Int, limit: Int, offset: Int): List<CookFoodGoodsEntity>
|
||||
|
||||
/** 统计食材记录总数,showDel=true 时包含已删除记录 */
|
||||
@Query("SELECT COUNT(*) FROM dm_cook_food_goods WHERE (:showDel = 1 OR isDel = 0)")
|
||||
suspend fun countCookFoodGoodsAll(showDel: Int): Int
|
||||
|
||||
/** 物理清空全表,用于清除测试数据 */
|
||||
@Query("DELETE FROM dm_cook_food_goods")
|
||||
suspend fun deleteAll()
|
||||
|
||||
/** 动态条件分页查询食材记录,由 ViewModel 构建 SQL */
|
||||
@RawQuery
|
||||
suspend fun queryPagedFiltered(query: SupportSQLiteQuery): List<CookFoodGoodsEntity>
|
||||
|
||||
/** 动态条件统计食材记录总数,由 ViewModel 构建 SQL */
|
||||
@RawQuery
|
||||
suspend fun countFiltered(query: SupportSQLiteQuery): Int
|
||||
}
|
||||
//package com.shuwei.dish.match.db.dao
|
||||
//
|
||||
//import androidx.room.Dao
|
||||
//import androidx.room.Query
|
||||
//import com.shuwei.dish.match.db.BaseDao
|
||||
//import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
//
|
||||
//@Dao
|
||||
//interface CookFoodGoodsDao : BaseDao<CookFoodGoodsEntity> {
|
||||
//
|
||||
// @Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId")
|
||||
// suspend fun getCookFoodGoodsList(foodId: String): MutableList<CookFoodGoodsEntity>
|
||||
//
|
||||
// @Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId AND materialType = :materialType")
|
||||
// suspend fun getCookFoodGoodsListByType(foodId: String, materialType:Int): MutableList<CookFoodGoodsEntity>
|
||||
//
|
||||
//// @Query(
|
||||
//// """
|
||||
//// UPDATE dm_cook_food_goods
|
||||
//// SET goodsName=:entity.goodsName, foodId=:entity.foodId, relateionType=:entity.relateionType, sort=:entity.sort
|
||||
//// allEdible=:entity.allEdible, useWeight=:entity.useWeight, isDel=:entity.isDel, createTime=:entity.createTime
|
||||
//// WHERE isDel = 0
|
||||
//// AND foodId=:entity.foodId
|
||||
//// AND goodsId=:goodsId
|
||||
//// """
|
||||
//// )
|
||||
//// fun updateByGoodsId(entity: CookFoodGoodsEntity)
|
||||
//
|
||||
//}
|
||||
@@ -1,70 +1,25 @@
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.RawQuery
|
||||
import androidx.room.Update
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
|
||||
@Dao
|
||||
interface SeasoningDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSeasoning(item: SeasoningEntity): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSeasoningList(items: MutableList<SeasoningEntity>): Array<Long>
|
||||
|
||||
@Update
|
||||
suspend fun updateSeasoning(item: SeasoningEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND id = :id")
|
||||
suspend fun getSeasoningById(id: Long): SeasoningEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND sort = :sort")
|
||||
suspend fun getSeasoningBySort(sort: Int): MutableList<SeasoningEntity>?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId = :goodsId")
|
||||
suspend fun getSeasoningByGoodsId(goodsId: String): SeasoningEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC")
|
||||
fun getAllStream(): MutableList<SeasoningEntity>
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsName LIKE '%' || :query || '%'")
|
||||
suspend fun search(query: String): MutableList<SeasoningEntity>
|
||||
|
||||
// @Query("DELETE FROM dm_seasoning WHERE isDel = 0 AND sort = :sort")
|
||||
@Query("UPDATE dm_seasoning SET isDel = 1 WHERE isDel = 0 AND sort = :sort")
|
||||
suspend fun deleteSeasoningBySort(sort: Int): Int
|
||||
|
||||
// @Query("DELETE FROM dm_seasoning WHERE isDel = 0")
|
||||
@Query("UPDATE dm_seasoning SET isDel = 1 WHERE isDel = 0")
|
||||
suspend fun clearAllSeasoning(): Int
|
||||
|
||||
/** 查询全部调料记录(含已删除),用于数据库调试查看 */
|
||||
@Query("SELECT * FROM dm_seasoning ORDER BY sort ASC")
|
||||
suspend fun getAllSeasoning(): MutableList<SeasoningEntity>
|
||||
|
||||
/** 分页查询调料记录,showDel=true 时包含已删除记录 */
|
||||
@Query("SELECT * FROM dm_seasoning WHERE (:showDel = 1 OR isDel = 0) ORDER BY sort ASC LIMIT :limit OFFSET :offset")
|
||||
suspend fun getSeasoningPaged(showDel: Int, limit: Int, offset: Int): List<SeasoningEntity>
|
||||
|
||||
/** 统计调料记录总数,showDel=true 时包含已删除记录 */
|
||||
@Query("SELECT COUNT(*) FROM dm_seasoning WHERE (:showDel = 1 OR isDel = 0)")
|
||||
suspend fun countSeasoningAll(showDel: Int): Int
|
||||
|
||||
/** 物理清空全表,用于清除测试数据(比 clearAllSeasoning 的逻辑删除更彻底) */
|
||||
@Query("DELETE FROM dm_seasoning")
|
||||
suspend fun deleteAll()
|
||||
|
||||
/** 动态条件分页查询调料记录,由 ViewModel 构建 SQL */
|
||||
@RawQuery
|
||||
suspend fun queryPagedFiltered(query: SupportSQLiteQuery): List<SeasoningEntity>
|
||||
|
||||
/** 动态条件统计调料记录总数,由 ViewModel 构建 SQL */
|
||||
@RawQuery
|
||||
suspend fun countFiltered(query: SupportSQLiteQuery): Int
|
||||
}
|
||||
//package com.shuwei.dish.match.db.dao
|
||||
//
|
||||
//import androidx.room.Dao
|
||||
//import androidx.room.Query
|
||||
//import com.shuwei.dish.match.db.BaseDao
|
||||
//import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
//import kotlinx.coroutines.flow.Flow
|
||||
//
|
||||
//@Dao
|
||||
//interface SeasoningDao : BaseDao<SeasoningEntity> {
|
||||
//
|
||||
//// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND id = :id")
|
||||
//// suspend fun getSeasoningById(id: Long): SeasoningEntity?
|
||||
////
|
||||
//// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 ORDER BY sort ASC")
|
||||
//// fun getAllStream(): Flow<MutableList<SeasoningEntity>>
|
||||
////
|
||||
//// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND name LIKE '%' || :query || '%'")
|
||||
//// suspend fun search(query: String): MutableList<SeasoningEntity>
|
||||
////
|
||||
//// @Query("DELETE FROM dm_seasoning WHERE rowid IN " +
|
||||
//// "(SELECT rowid FROM dm_seasoning LIMIT 1000)")
|
||||
//// suspend fun deleteBatch(): Int
|
||||
//
|
||||
//}
|
||||
@@ -1,77 +0,0 @@
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.RawQuery
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.shuwei.dish.match.db.entity.SeasoningSlotEntity
|
||||
|
||||
/**
|
||||
* 调料槽位配置 DAO
|
||||
* 以 (deviceId, address) 为主键做 upsert,保证同一槽位只保留最新配置
|
||||
*/
|
||||
@Dao
|
||||
interface SeasoningSlotDao {
|
||||
|
||||
/**
|
||||
* 插入或更新单个槽位配置(主键冲突时覆盖)
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsert(slot: SeasoningSlotEntity)
|
||||
|
||||
/**
|
||||
* 批量插入或更新槽位配置(主设备广播全量时使用)
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertAll(slots: List<SeasoningSlotEntity>)
|
||||
|
||||
/**
|
||||
* 查询指定设备的全部槽位配置
|
||||
* @param deviceId 目标设备 ID
|
||||
*/
|
||||
@Query("SELECT * FROM dm_seasoning_slot WHERE deviceId = :deviceId")
|
||||
suspend fun queryByDeviceId(deviceId: String): List<SeasoningSlotEntity>
|
||||
|
||||
/**
|
||||
* 查询所有设备的全部槽位配置(主设备广播时使用)
|
||||
*/
|
||||
@Query("SELECT * FROM dm_seasoning_slot")
|
||||
suspend fun queryAll(): List<SeasoningSlotEntity>
|
||||
|
||||
/** 分页查询槽位记录(槽位表无 isDel,showDel 参数忽略) */
|
||||
@Query("SELECT * FROM dm_seasoning_slot ORDER BY deviceId ASC, address ASC LIMIT :limit OFFSET :offset")
|
||||
suspend fun getSlotPaged(limit: Int, offset: Int): List<SeasoningSlotEntity>
|
||||
|
||||
/** 统计槽位记录总数 */
|
||||
@Query("SELECT COUNT(*) FROM dm_seasoning_slot")
|
||||
suspend fun countSlotAll(): Int
|
||||
|
||||
/**
|
||||
* 删除指定设备的指定槽位配置
|
||||
* @param deviceId 目标设备 ID
|
||||
* @param address 秤硬件地址
|
||||
*/
|
||||
@Query("DELETE FROM dm_seasoning_slot WHERE deviceId = :deviceId AND address = :address")
|
||||
suspend fun deleteByDeviceIdAndAddress(deviceId: String, address: Int)
|
||||
|
||||
/**
|
||||
* 删除指定设备的全部槽位配置(子设备接收全量广播时先清空再写入)
|
||||
* @param deviceId 目标设备 ID
|
||||
*/
|
||||
@Query("DELETE FROM dm_seasoning_slot WHERE deviceId = :deviceId")
|
||||
suspend fun deleteAllByDeviceId(deviceId: String)
|
||||
|
||||
/** 物理清空全表,用于清除测试数据 */
|
||||
@Query("DELETE FROM dm_seasoning_slot")
|
||||
suspend fun deleteAll()
|
||||
|
||||
/** 动态条件分页查询槽位记录,由 ViewModel 构建 SQL */
|
||||
@RawQuery
|
||||
suspend fun queryPagedFiltered(query: SupportSQLiteQuery): List<SeasoningSlotEntity>
|
||||
|
||||
/** 动态条件统计槽位记录总数,由 ViewModel 构建 SQL */
|
||||
@RawQuery
|
||||
suspend fun countFiltered(query: SupportSQLiteQuery): Int
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.shuwei.dish.match.db.entity
|
||||
|
||||
/** 默认调料配置 JSON 反序列化的包装类 */
|
||||
data class ResetReasoningRecord(
|
||||
val list: MutableList<SeasoningEntity> = mutableListOf()
|
||||
)
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.shuwei.dish.match.db.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
|
||||
/**
|
||||
* 调料槽位配置表,记录每个格子对应哪种调料
|
||||
* 主键为 (deviceId, address) 组合,唯一标识一个物理秤槽位
|
||||
*
|
||||
* @param deviceId 所属设备 ID,用于区分 22格/18格 设备
|
||||
* @param address 秤硬件地址,对应 ScaleDeviceConfig.SCALE_ORDER_22/18 中的值
|
||||
* @param goodsId 调料 ID
|
||||
* @param goodsName 调料名称,用于 adapter 展示
|
||||
*/
|
||||
@Entity(
|
||||
tableName = "dm_seasoning_slot",
|
||||
primaryKeys = ["deviceId", "address"]
|
||||
)
|
||||
data class SeasoningSlotEntity(
|
||||
val deviceId: String,
|
||||
val address: Int,
|
||||
val goodsId: String,
|
||||
val goodsName: String
|
||||
)
|
||||
@@ -1,193 +0,0 @@
|
||||
package com.shuwei.dish.match.dialog
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.core.view.isEmpty
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.GoodsInfoSearchAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.DialogBottomSheetBinding
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.net.RemoteRepository
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
|
||||
/**
|
||||
* @param goodsType 1-调料,0-食材
|
||||
*/
|
||||
class BottomDialog(
|
||||
private var goodsType: Int = 1,
|
||||
private var defGoodsName:String? = null
|
||||
) {
|
||||
companion object {
|
||||
const val TAG = "BottomDialog"
|
||||
}
|
||||
|
||||
private var list = mutableListOf<GoodsItem>()
|
||||
|
||||
private lateinit var binding: DialogBottomSheetBinding
|
||||
private lateinit var goodsInfoSearchAdapter: GoodsInfoSearchAdapter
|
||||
private var goodsName: String? = null
|
||||
|
||||
private var activity: BaseActivity? = null
|
||||
|
||||
fun show(activity: BaseActivity, callback: (item: GoodsItem) -> Unit) {
|
||||
this.activity = activity
|
||||
//直接使用BottomSheetDialog
|
||||
var dialog: BottomSheetDialog? = null
|
||||
val inflater = LayoutInflater.from(activity)
|
||||
binding = DialogBottomSheetBinding.inflate(inflater)
|
||||
|
||||
binding.tvSheetName.text = if (goodsType == 1) "调料检索" else "食材检索"
|
||||
binding.etSheetInput.hint = if (goodsType == 1) "输入调料名称" else "输入食材名称或速记码"
|
||||
goodsInfoSearchAdapter = GoodsInfoSearchAdapter(list).apply {
|
||||
setOnItemClickListener { _, _, position ->
|
||||
list[position].isClicked = true
|
||||
notifyItemChanged(position)
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
callback(list[position])
|
||||
dialog?.dismiss()
|
||||
}, 300)
|
||||
}
|
||||
}
|
||||
binding.recyclerView.run {
|
||||
layoutManager = GridLayoutManager(activity, 2, GridLayoutManager.VERTICAL, false)
|
||||
adapter = goodsInfoSearchAdapter
|
||||
addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrollStateChanged(rv: RecyclerView, newState: Int) {
|
||||
super.onScrollStateChanged(rv, newState);
|
||||
}
|
||||
|
||||
override fun onScrolled(rv: RecyclerView, dx: Int, dy: Int) {
|
||||
//解决RecyclerView和smartRefreshLayout滑动冲突问题
|
||||
super.onScrolled(rv, dx, dy)
|
||||
val topRowVerticalPosition = if (rv.isEmpty()) 0 else rv.getChildAt(0).top
|
||||
binding.refreshLayout.setNestedScrollingEnabled(topRowVerticalPosition >= 0)
|
||||
}
|
||||
})
|
||||
}
|
||||
dialog = BottomSheetDialog(activity, R.style.BottomSheet).apply {
|
||||
setContentView(binding.root)
|
||||
setCancelable(true)
|
||||
behavior.skipCollapsed = false // 跳过折叠状态
|
||||
// behavior.peekHeight = 880.dp
|
||||
// window?.setLayout(-1, 880.dp)
|
||||
show()
|
||||
setOnDismissListener {
|
||||
activity.hideStatusBar()
|
||||
}
|
||||
}
|
||||
binding.refreshLayout.setOnRefreshListener {
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
}
|
||||
|
||||
binding.refreshLayout.setOnLoadMoreListener {
|
||||
getGoodsList()
|
||||
}
|
||||
binding.etSheetInput.addTextChangedListener(
|
||||
onTextChanged = { text, start, before, count ->
|
||||
goodsName = text.toString()
|
||||
})
|
||||
binding.ivSearch.setOnClickListener { v ->
|
||||
searchGoods(v)
|
||||
}
|
||||
binding.root.setOnClickListener { v ->
|
||||
KeyboardUtil.hideKeyboard(v.context, v)
|
||||
}
|
||||
binding.etSheetInput.let { v ->
|
||||
v.addOnActionSearchListener {
|
||||
searchGoods(v)
|
||||
}
|
||||
}
|
||||
binding.refreshLayout.setEnableRefresh(false)
|
||||
binding.refreshLayout.setEnableLoadMore(false)
|
||||
|
||||
if (defGoodsName.isNullOrBlank().not()) {
|
||||
binding.etSheetInput.let {
|
||||
it.setText(defGoodsName)
|
||||
searchGoods(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchGoods(v: View) {
|
||||
if (goodsName.isNullOrBlank()) {
|
||||
activity?.toast("请${binding.etSheetInput.hint}")
|
||||
return
|
||||
}
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
KeyboardUtil.hideKeyboard(v.context, v)
|
||||
}
|
||||
|
||||
private var pageNo = 1
|
||||
private val pageSize = 120
|
||||
|
||||
/**
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun getGoodsList() {
|
||||
val param = mutableMapOf<String, Any>(
|
||||
"goodsType" to "$goodsType",
|
||||
"placeId" to BaseApp.canteenId,
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize
|
||||
)
|
||||
if (goodsName.isNullOrBlank().not()) {
|
||||
param["goodsName"] = goodsName!!
|
||||
}
|
||||
Log.d(TAG, "getGoodsList: param=$param")
|
||||
activity?.lifecycleScope?.launch {
|
||||
val state = RemoteRepository().queryGoodsList(param)
|
||||
when (state) {
|
||||
is UiState.Success -> {
|
||||
val records = state.data
|
||||
if (records.isNullOrEmpty()) {
|
||||
activity?.toast(if (goodsType == 1) "暂未搜索到调料信息" else "暂未搜索到食材信息")
|
||||
return@launch
|
||||
}
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(records)
|
||||
goodsInfoSearchAdapter.notifyDataSetChanged()
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh(1200)
|
||||
} else {
|
||||
binding.refreshLayout.finishLoadMore(1200)
|
||||
}
|
||||
val isLoadMoreEnable = records.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) {
|
||||
pageNo++
|
||||
}
|
||||
}
|
||||
is UiState.Error -> {
|
||||
activity?.toast(state.msg)
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh(1200)
|
||||
} else {
|
||||
binding.refreshLayout.finishLoadMore(1200)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
package com.shuwei.dish.match.dialog
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.Editable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.core.view.isEmpty
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.GoodsInfoSearchAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.DialogFoodSearchBinding
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
|
||||
/**
|
||||
* 食材搜索弹窗
|
||||
*/
|
||||
class FoodSearchDialog(
|
||||
private var defGoodsName: String? = null
|
||||
) {
|
||||
companion object {
|
||||
const val TAG = "BottomDialog"
|
||||
}
|
||||
|
||||
private var list = mutableListOf<CookFoodGoodsEntity>()
|
||||
|
||||
private lateinit var binding: DialogFoodSearchBinding
|
||||
private lateinit var searchAdapter: GoodsInfoSearchAdapter
|
||||
private var goodsName: String? = null
|
||||
|
||||
private var activity: BaseActivity? = null
|
||||
|
||||
fun show(activity: BaseActivity, callback: (item: CookFoodGoodsEntity) -> Unit) {
|
||||
this.activity = activity
|
||||
//直接使用BottomSheetDialog
|
||||
var dialog: BottomSheetDialog? = null
|
||||
val inflater = LayoutInflater.from(activity)
|
||||
binding = DialogFoodSearchBinding.inflate(inflater)
|
||||
dialog = BottomSheetDialog(activity, R.style.BottomSheet).apply {
|
||||
setContentView(binding.root)
|
||||
setCancelable(true)
|
||||
behavior.skipCollapsed = false // 跳过折叠状态
|
||||
// behavior.peekHeight = 880.dp
|
||||
// window?.setLayout(-1, 880.dp)
|
||||
show()
|
||||
setOnDismissListener {
|
||||
activity.hideStatusBar()
|
||||
}
|
||||
binding.etSheetInput.requestFocus()
|
||||
}
|
||||
binding.tvSheetName.text = "食材检索"
|
||||
binding.etSheetInput.run {
|
||||
hint = "输入食材名称或速记码"
|
||||
addTextChangedListener(afterTextChanged = { it: Editable? ->
|
||||
if (it.isNullOrBlank()) {
|
||||
list.clear()
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
}
|
||||
})
|
||||
}
|
||||
searchAdapter = GoodsInfoSearchAdapter(list).apply {
|
||||
setOnItemClickListener { _, _, position ->
|
||||
list[position].isClicked = true
|
||||
notifyItemChanged(position)
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
callback(list[position])
|
||||
dialog?.dismiss()
|
||||
}, 300)
|
||||
}
|
||||
}
|
||||
binding.recyclerView.run {
|
||||
layoutManager = GridLayoutManager(activity, 2, GridLayoutManager.VERTICAL, false)
|
||||
adapter = searchAdapter
|
||||
addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrollStateChanged(rv: RecyclerView, newState: Int) {
|
||||
super.onScrollStateChanged(rv, newState);
|
||||
}
|
||||
|
||||
override fun onScrolled(rv: RecyclerView, dx: Int, dy: Int) {
|
||||
//解决RecyclerView和smartRefreshLayout滑动冲突问题
|
||||
super.onScrolled(rv, dx, dy)
|
||||
val topRowVerticalPosition = if (rv.isEmpty()) 0 else rv.getChildAt(0).top
|
||||
binding.refreshLayout.setNestedScrollingEnabled(topRowVerticalPosition >= 0)
|
||||
}
|
||||
})
|
||||
}
|
||||
binding.refreshLayout.setOnRefreshListener {
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
}
|
||||
|
||||
binding.refreshLayout.setOnLoadMoreListener {
|
||||
getGoodsList()
|
||||
}
|
||||
binding.etSheetInput.addTextChangedListener(
|
||||
onTextChanged = { text, start, before, count ->
|
||||
goodsName = text.toString()
|
||||
})
|
||||
binding.ivSearch.setOnClickListener { v ->
|
||||
searchGoods(v)
|
||||
}
|
||||
binding.root.setOnClickListener { v ->
|
||||
KeyboardUtil.hideKeyboard(v.context, v)
|
||||
}
|
||||
binding.etSheetInput.let { v ->
|
||||
v.addOnActionSearchListener {
|
||||
searchGoods(v)
|
||||
}
|
||||
}
|
||||
binding.refreshLayout.setEnableRefresh(false)
|
||||
binding.refreshLayout.setEnableLoadMore(false)
|
||||
|
||||
if (defGoodsName.isNullOrBlank().not()) {
|
||||
binding.etSheetInput.let {
|
||||
it.setText(defGoodsName)
|
||||
searchGoods(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchGoods(v: View) {
|
||||
if (goodsName.isNullOrBlank()) {
|
||||
activity?.toast("请${binding.etSheetInput.hint}")
|
||||
return
|
||||
}
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
KeyboardUtil.hideKeyboard(v.context, v)
|
||||
}
|
||||
|
||||
private var pageNo = 1
|
||||
private val pageSize = 50
|
||||
|
||||
/**
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun getGoodsList() {
|
||||
// val pathSegmentList = UrlConfig.QUERY_GOODS_LIST.split(delimiters = arrayOf("/"), limit = 1)
|
||||
// val queryParams = mutableMapOf(
|
||||
// "goodsType" to "0",
|
||||
// "canteenId" to BaseApp.canteenId,
|
||||
// "pageNo" to "$pageNo",
|
||||
// "pageSize" to "$pageSize"
|
||||
// )
|
||||
// if (goodsName.isNullOrBlank().not()) {
|
||||
// queryParams.put("name", goodsName!!)
|
||||
// }
|
||||
// val sb = StringBuilder().apply {
|
||||
// append(UrlConfig.QUERY_GOODS_LIST)
|
||||
// append("?")
|
||||
// queryParams.forEach { (key, value) ->
|
||||
// append("$key=$value&")
|
||||
// }
|
||||
// }
|
||||
// sb.deleteCharAt(sb.length - 1)
|
||||
// Log.d(TAG, "getGoodsList: url = $sb")
|
||||
// HttpUtil.get(
|
||||
// url = sb.toString(),
|
||||
// doSuccess = {
|
||||
// val json = it.toJsonString()
|
||||
// Log.d(TAG, "getGoodsList: json=$json")
|
||||
// val recordBean: GoodsRecordBean? = json.toObject<GoodsRecordBean>()
|
||||
// if (recordBean == null || recordBean.records.isNullOrEmpty()) {
|
||||
// activity?.toast("暂未搜索到食材信息")
|
||||
// return@get
|
||||
// }
|
||||
// val records = recordBean.records
|
||||
// if (pageNo == 1) {
|
||||
// list.clear()
|
||||
// }
|
||||
// list.addAll(records!!)
|
||||
// searchAdapter.notifyDataSetChanged()
|
||||
// if (pageNo == 1) {
|
||||
// binding.refreshLayout.finishRefresh(1200)
|
||||
// } else {
|
||||
// binding.refreshLayout.finishLoadMore(1200)
|
||||
// }
|
||||
// val isLoadMoreEnable = records.size >= pageSize
|
||||
// binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
// if (isLoadMoreEnable) {
|
||||
// pageNo++
|
||||
// }
|
||||
// }, doFailure = { code, msg ->
|
||||
// activity?.toast(msg)
|
||||
// if (pageNo == 1) {
|
||||
// binding.refreshLayout.finishRefresh(1200)
|
||||
// } else {
|
||||
// binding.refreshLayout.finishLoadMore(1200)
|
||||
// }
|
||||
// })
|
||||
val param = mutableMapOf<String, Any>(
|
||||
"goodsType" to "0",
|
||||
"placeId" to BaseApp.canteenId,
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize
|
||||
)
|
||||
if (goodsName.isNullOrBlank().not()) {
|
||||
param.put("goodsName", goodsName!!)
|
||||
}
|
||||
activity?.queryGoodsList(param = param, onSuccess = {
|
||||
loadGoodsList(it)
|
||||
}, onFailure = { code, msg ->
|
||||
activity?.toast(msg)
|
||||
finishRefresh()
|
||||
})
|
||||
}
|
||||
|
||||
private fun finishRefresh() {
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh()
|
||||
} else {
|
||||
binding.refreshLayout.finishLoadMore()
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadGoodsList(records: MutableList<CookFoodGoodsEntity>?) {
|
||||
finishRefresh()
|
||||
if (records.isNullOrEmpty()) {
|
||||
activity?.toast("暂未搜索到食材信息")
|
||||
return
|
||||
}
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(records)
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) {
|
||||
pageNo++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+151
-58
@@ -4,14 +4,18 @@ import android.annotation.SuppressLint
|
||||
import android.graphics.Typeface
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.Editable
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.style.AbsoluteSizeSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.LineHeightSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.core.view.isEmpty
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
@@ -22,26 +26,21 @@ import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.SeasoningSearchAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.DialogBottomSheet2Binding
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.net.RemoteRepository
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.databinding.DialogSeasoningSearchBinding
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import com.shuwei.dish.match.utils.ext.appendText
|
||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
import com.shuwei.dish.match.utils.ext.roundedDecimalPlace
|
||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
|
||||
/**
|
||||
* @param goodsType 1-调料,0-食材
|
||||
* 调料搜索弹窗
|
||||
*/
|
||||
class BottomDialog2(
|
||||
class SeasoningSearchDialog(
|
||||
private var weighIndex: Int,
|
||||
private var weighAddress: Int,
|
||||
private var clickName: String? = null
|
||||
@@ -50,24 +49,30 @@ class BottomDialog2(
|
||||
const val TAG = "BottomDialog2"
|
||||
}
|
||||
|
||||
private val goodsType: Int = 1
|
||||
private var list = mutableListOf<GoodsItem>()
|
||||
private var list = mutableListOf<SeasoningEntity>()
|
||||
|
||||
private lateinit var binding: DialogBottomSheet2Binding
|
||||
private lateinit var binding: DialogSeasoningSearchBinding
|
||||
private lateinit var searchAdapter: SeasoningSearchAdapter
|
||||
private var goodsName: String? = null
|
||||
|
||||
private var activity: BaseActivity? = null
|
||||
|
||||
fun show(activity: BaseActivity, callback: (item: GoodsItem) -> Unit) {
|
||||
fun show(activity: BaseActivity, callback: (item: SeasoningEntity) -> Unit) {
|
||||
this.activity = activity
|
||||
//直接使用BottomSheetDialog
|
||||
var dialog: BottomSheetDialog? = null
|
||||
val inflater = LayoutInflater.from(activity)
|
||||
binding = DialogBottomSheet2Binding.inflate(inflater)
|
||||
binding = DialogSeasoningSearchBinding.inflate(inflater)
|
||||
|
||||
//binding.tvSheetName.text = if (goodsType == 1) "调料检索" else "食材检索"
|
||||
binding.etSheetInput.hint = if (goodsType == 1) "输入调料名称" else "输入食材名称或速记码"
|
||||
binding.etSheetInput.run {
|
||||
hint = "输入调料名称"
|
||||
addTextChangedListener(afterTextChanged = { it: Editable? ->
|
||||
if (it.isNullOrBlank()) {
|
||||
list.clear()
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
}
|
||||
})
|
||||
}
|
||||
searchAdapter = SeasoningSearchAdapter(list).apply {
|
||||
setOnItemClickListener { _, _, position ->
|
||||
list[position].isClicked = true
|
||||
@@ -98,12 +103,45 @@ class BottomDialog2(
|
||||
setContentView(binding.root)
|
||||
setCancelable(true)
|
||||
behavior.skipCollapsed = false // 跳过折叠状态
|
||||
// behavior.peekHeight = 880.dp
|
||||
// window?.setLayout(-1, 880.dp)
|
||||
//// behavior.peekHeight = 880.dp
|
||||
//// window?.setLayout(-1, 880.dp)
|
||||
// window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
|
||||
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
||||
//or WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
||||
//or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING // 禁用额外平移
|
||||
window?.setGravity(Gravity.BOTTOM)
|
||||
window?.setLayout(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
window?.setWindowAnimations(R.style.DialogSoftInputAnimation)
|
||||
window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
show()
|
||||
// val onGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener {
|
||||
// val r = Rect()
|
||||
// binding.root.getWindowVisibleDisplayFrame(r)
|
||||
// val screenHeight = binding.root.rootView.height
|
||||
// val keyboardHeight = screenHeight - r.bottom
|
||||
//
|
||||
// // 软键盘弹出(高度>200dp)
|
||||
// if (keyboardHeight > 200.dp) {
|
||||
// // 调整 Dialog 底部边距,避开软键盘
|
||||
// val layoutParams = binding.root.layoutParams as ViewGroup.MarginLayoutParams
|
||||
//// layoutParams.bottomMargin = keyboardHeight
|
||||
// layoutParams.bottomMargin = 200.dp
|
||||
// binding.root.layoutParams = layoutParams
|
||||
// } else {
|
||||
// // 软键盘收起,恢复边距
|
||||
// val layoutParams = binding.root.layoutParams as ViewGroup.MarginLayoutParams
|
||||
// layoutParams.bottomMargin = 0
|
||||
// binding.root.layoutParams = layoutParams
|
||||
// }
|
||||
// }
|
||||
setOnDismissListener {
|
||||
activity.hideStatusBar()
|
||||
// binding.root.viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener)
|
||||
}
|
||||
// binding.root.viewTreeObserver.addOnGlobalLayoutListener(onGlobalLayoutListener)
|
||||
}
|
||||
binding.refreshLayout.setOnRefreshListener {
|
||||
pageNo = 1
|
||||
@@ -129,6 +167,7 @@ class BottomDialog2(
|
||||
}
|
||||
}
|
||||
binding.refreshLayout.setEnableRefresh(false)
|
||||
binding.refreshLayout.setEnableLoadMore(false)
|
||||
binding.tvClear.setOnClickListener {
|
||||
Log.d(TAG, "show: weighAddress=$weighAddress")
|
||||
WeightUtil.tareTwo(weighAddress)
|
||||
@@ -137,7 +176,7 @@ class BottomDialog2(
|
||||
// WeightUtil.tareTwo(num+1)
|
||||
// }
|
||||
}
|
||||
WeightUtil.addWeightListener (
|
||||
WeightUtil.addWeightListener(
|
||||
weightKey = TAG,
|
||||
getWeight = { address, state, weight ->
|
||||
if (weighAddress == address) {
|
||||
@@ -166,57 +205,111 @@ class BottomDialog2(
|
||||
|
||||
private var currentWeight = 0.toDouble()
|
||||
private var pageNo = 1
|
||||
private val pageSize = 120
|
||||
private val pageSize = 50
|
||||
|
||||
/**
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun getGoodsList() {
|
||||
// val queryParams = mutableMapOf(
|
||||
// "goodsType" to "1",
|
||||
// "canteenId" to BaseApp.canteenId,
|
||||
// "pageNo" to "$pageNo",
|
||||
// "pageSize" to "$pageSize"
|
||||
// )
|
||||
// if (goodsName.isNullOrBlank().not()) {
|
||||
// queryParams.put("name", goodsName!!)
|
||||
// }
|
||||
// val sb = StringBuilder().apply {
|
||||
// append(UrlConfig.QUERY_GOODS_LIST)
|
||||
// append("?")
|
||||
// queryParams.forEach { (key, value) ->
|
||||
// append("$key=$value&")
|
||||
// }
|
||||
// }
|
||||
// sb.deleteCharAt(sb.length - 1)
|
||||
// Log.d(TAG, "getGoodsList: url = $sb")
|
||||
// HttpUtil.get(
|
||||
// url = sb.toString(),
|
||||
// doSuccess = {
|
||||
// val json = it.toJsonString()
|
||||
// Log.d(TAG, "getGoodsList: json=$json")
|
||||
// val recordBean: SeasoningRecordBean? = json.toObject<SeasoningRecordBean>()
|
||||
// if (recordBean == null || recordBean.records.isNullOrEmpty()) {
|
||||
// activity?.toast( "暂未搜索到调料信息")
|
||||
// return@get
|
||||
// }
|
||||
// val records = recordBean.records
|
||||
// if (pageNo == 1) {
|
||||
// list.clear()
|
||||
// }
|
||||
// list.addAll(records!!)
|
||||
// searchAdapter.notifyDataSetChanged()
|
||||
// if (pageNo == 1) {
|
||||
// binding.refreshLayout.finishRefresh(1200)
|
||||
// } else {
|
||||
// binding.refreshLayout.finishLoadMore(1200)
|
||||
// }
|
||||
// val isLoadMoreEnable = records.size >= pageSize
|
||||
// binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
// if (isLoadMoreEnable) {
|
||||
// pageNo++
|
||||
// }
|
||||
// }, doFailure = { code, msg ->
|
||||
// activity?.toast(msg)
|
||||
// if (pageNo == 1) {
|
||||
// binding.refreshLayout.finishRefresh(1200)
|
||||
// } else {
|
||||
// binding.refreshLayout.finishLoadMore(1200)
|
||||
// }
|
||||
// })
|
||||
|
||||
|
||||
val param = mutableMapOf<String, Any>(
|
||||
"goodsType" to "$goodsType",
|
||||
"goodsType" to "1",
|
||||
"placeId" to BaseApp.canteenId,
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize
|
||||
)
|
||||
if (goodsName.isNullOrBlank().not()) {
|
||||
param["goodsName"] = goodsName!!
|
||||
param.put("goodsName", goodsName!!)
|
||||
}
|
||||
Log.d(TAG, "getGoodsList: param=$param")
|
||||
activity?.lifecycleScope?.launch {
|
||||
val state = RemoteRepository().queryGoodsList(param)
|
||||
when (state) {
|
||||
is UiState.Success -> {
|
||||
val records = state.data
|
||||
if (records.isNullOrEmpty()) {
|
||||
activity?.toast(if (goodsType == 1) "暂未搜索到调料信息" else "暂未搜索到食材信息")
|
||||
return@launch
|
||||
}
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(records)
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh(1200)
|
||||
} else {
|
||||
binding.refreshLayout.finishLoadMore(1200)
|
||||
}
|
||||
val isLoadMoreEnable = records.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) {
|
||||
pageNo++
|
||||
}
|
||||
}
|
||||
is UiState.Error -> {
|
||||
activity?.toast(state.msg)
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh(1200)
|
||||
} else {
|
||||
binding.refreshLayout.finishLoadMore(1200)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
activity?.querySeasoningList(
|
||||
param = param,
|
||||
onSuccess = {
|
||||
loadGoodsList(it)
|
||||
},
|
||||
onFailure = { code, msg ->
|
||||
activity?.toast(msg)
|
||||
finishRefresh()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadGoodsList(records: MutableList<SeasoningEntity>?) {
|
||||
finishRefresh()
|
||||
if (records.isNullOrEmpty()) {
|
||||
activity?.toast("暂未搜索到调料信息")
|
||||
return
|
||||
}
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(records)
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) {
|
||||
pageNo++
|
||||
}
|
||||
}
|
||||
|
||||
private fun finishRefresh() {
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh()
|
||||
} else {
|
||||
binding.refreshLayout.finishLoadMore()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +317,7 @@ class BottomDialog2(
|
||||
var topWeight = "$weight"
|
||||
var bottomUnit = "克"
|
||||
if (weight >= 1000) {
|
||||
topWeight = "${(weight/1000).roundedDecimalPlace(3)}"
|
||||
topWeight = "${(weight / 1000).roundedDecimalPlace(3)}"
|
||||
bottomUnit = "千克"
|
||||
}
|
||||
return buildSpannableString {
|
||||
+3
-5
@@ -1,4 +1,4 @@
|
||||
package com.shuwei.dish.match.db.entity
|
||||
package com.shuwei.dish.match.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
@@ -18,13 +18,11 @@ data class CookFoodEntity(
|
||||
//0-制作模式,1-采样模式,2-品控模式
|
||||
var cookMode:Int = 0,
|
||||
var isDel: Int = 0,
|
||||
/** 接口提交状态:0-未提交(本地草稿或手动删除),1-接口提交成功后删除 */
|
||||
var submitState: Int = 0,
|
||||
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now()),
|
||||
var dinnerType: String? = "0",
|
||||
) : BaseEntity {
|
||||
// @Ignore
|
||||
// var stFoodInfoConstituteList: MutableList<CookFoodGoodsEntity>? = null
|
||||
@Ignore
|
||||
var stFoodInfoConstituteList: MutableList<CookFoodGoodsEntity>? = null
|
||||
@Ignore
|
||||
var matchingConstituteInfoList: MutableList<CookFoodGoodsEntity>? = null
|
||||
@Ignore
|
||||
+21
-30
@@ -1,9 +1,9 @@
|
||||
package com.shuwei.dish.match.db.entity
|
||||
package com.shuwei.dish.match.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.PrimaryKey
|
||||
import com.shuwei.dish.match.db.BaseEntity
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.utils.DateTimeUtil
|
||||
import java.io.Serializable
|
||||
import java.time.LocalDateTime
|
||||
@@ -63,36 +63,27 @@ class CookFoodGoodsEntity(
|
||||
|
||||
var relateionType_dictText: String? = "",
|
||||
|
||||
var zjmCode: String? = "",
|
||||
|
||||
var materId: String? = "",
|
||||
|
||||
/** 物料编码 */
|
||||
var goodsCode: String? = "",
|
||||
|
||||
/** 净材种类 */
|
||||
var rawMaterialsType: String? = null,
|
||||
|
||||
var isDel: Int = 0,
|
||||
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now())
|
||||
) : BaseEntity, Serializable {
|
||||
constructor() : this(goodsId = "") // 必需的空构造
|
||||
constructor() : this(goodsId = "") // 必需的空构造,
|
||||
|
||||
/**
|
||||
* 转换为 GoodsItem,用于 UI 层(DishPartAdapter、PrepareFoodActivity 等)
|
||||
*/
|
||||
fun toGoodsItem(): GoodsItem = GoodsItem(
|
||||
goodsId = goodsId,
|
||||
goodsName = goodsName,
|
||||
popularName = popularName,
|
||||
zjmCode = zjmCode,
|
||||
materId = materId,
|
||||
materCode = goodsCode,
|
||||
materialType = materialType,
|
||||
useWeight = useWeight,
|
||||
relateionType = relateionType,
|
||||
allEdible = allEdible,
|
||||
goodsOrRelationCode = goodsOrRelationCode,
|
||||
rawMaterialsType = rawMaterialsType
|
||||
)
|
||||
@Ignore
|
||||
var isSetFinished: Boolean = false
|
||||
|
||||
@Ignore
|
||||
var isItemClicked: Boolean = false
|
||||
|
||||
@Ignore
|
||||
var isSamplingPage: Boolean = false
|
||||
|
||||
@Ignore
|
||||
var isNewDishType: Boolean = false
|
||||
|
||||
@Ignore
|
||||
var isClicked: Boolean = false
|
||||
|
||||
//true-原始数据,false-非原始数据
|
||||
@Ignore
|
||||
var isOriginalData: Boolean = true
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.shuwei.dish.match.entity
|
||||
|
||||
data class HomeModeBean(
|
||||
|
||||
var modeName: String = "",
|
||||
var modeDesc: String = "",
|
||||
var modeIconId: Int = 0,
|
||||
var isLocked: Boolean = false,
|
||||
|
||||
var onClick: (() -> Unit)? = null
|
||||
)
|
||||
|
||||
data class FoodRecordBean(
|
||||
var records: MutableList<FoodRecord>? = null,
|
||||
var total: Int,
|
||||
var size: Int,
|
||||
var current: Int,
|
||||
var page: Int
|
||||
)
|
||||
|
||||
data class GoodsRecordBean(
|
||||
var records: MutableList<CookFoodGoodsEntity>? = null,
|
||||
var total: Int,
|
||||
var size: Int,
|
||||
var current: Int,
|
||||
var page: Int
|
||||
)
|
||||
|
||||
data class SeasoningRecordBean(
|
||||
var records: MutableList<SeasoningEntity>? = null,
|
||||
var total: Int,
|
||||
var size: Int,
|
||||
var current: Int,
|
||||
var page: Int
|
||||
)
|
||||
|
||||
data class ResetReasoningRecord(
|
||||
val list: MutableList<SeasoningEntity>
|
||||
)
|
||||
|
||||
//data class DishDetailEntity(
|
||||
// var foodId: String? = null,
|
||||
// var foodWeight: Double? = null,
|
||||
// var foodRealWeight: Double? = null,
|
||||
// var voList: List<DishPartEntity>? = null
|
||||
//)
|
||||
|
||||
//data class DishPartEntity(
|
||||
// var foodId: String? = null,
|
||||
// var foodName: String? = null,
|
||||
// var foodWeight: Int? = null,
|
||||
// var useWeight: Int? = null,
|
||||
// var useRealWeight: Int? = null,
|
||||
// var goodsId: Int? = null,
|
||||
// var goodsName: String? = null,
|
||||
// var materialType: Int? = null,
|
||||
// var isSetFinished: Boolean = false,
|
||||
// var isItemClicked: Boolean = false,
|
||||
// var isSamplingPage: Boolean = false
|
||||
//)
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.shuwei.dish.match.entity
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.shuwei.dish.match.db.BaseEntity
|
||||
|
||||
//@Entity(tableName = "dm_dish")
|
||||
//data class DishEntity (
|
||||
// /**
|
||||
// * 菜品id
|
||||
// */
|
||||
// @PrimaryKey var id: Long,
|
||||
// /**
|
||||
// * 菜品名称
|
||||
// */
|
||||
// var name: String? = "",
|
||||
// /**
|
||||
// * 菜品重量
|
||||
// */
|
||||
// var weight: Int? = 0,
|
||||
//
|
||||
// var sort: Int = 0,
|
||||
// @ColumnInfo(name = "create_time") val createTime: Long = System.currentTimeMillis()
|
||||
//): BaseEntity
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package com.shuwei.dish.match.model
|
||||
package com.shuwei.dish.match.entity
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
@@ -17,3 +17,4 @@ data class FoodRecord(
|
||||
var isOriginalData: Boolean = true,
|
||||
var sort: Int = 0
|
||||
) : Serializable
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//package com.shuwei.dish.match.entity
|
||||
//
|
||||
//import androidx.room.Ignore
|
||||
//import androidx.room.PrimaryKey
|
||||
//import com.shuwei.dish.match.db.BaseEntity
|
||||
//
|
||||
//data class GoodsInfoEntity(
|
||||
// @PrimaryKey(autoGenerate = true) var id: Long = 0,
|
||||
// var goodsId: Int,
|
||||
// var goodsName: String? = "",
|
||||
// var popularName: String? = "",
|
||||
// var canteenId: String? = "",
|
||||
// var goodsOrRelationCode: String? = "",
|
||||
// var relateionType: Int? = -1,
|
||||
// var relateionType_dictText: String? = "",
|
||||
//
|
||||
// var sort: Int = 0,
|
||||
//
|
||||
// var swMaterBaseMaterial: String? = "",
|
||||
// var preMaterClass: String? = "",
|
||||
// var preUseWeight: Int? = 0,
|
||||
// var preWeight: Int? = 0,
|
||||
// var oil: String? = "",
|
||||
// var sugar: String? = "",
|
||||
// /**
|
||||
// * isDel表示数据是否已删除,1-已删除,为无效数据,0-正常使用,有效数据
|
||||
// */
|
||||
// var isDel: Int = 0,
|
||||
// val createTime: Long = System.currentTimeMillis()
|
||||
//) : BaseEntity {
|
||||
// @Ignore
|
||||
// var pageType: Int = 0
|
||||
//
|
||||
// @Ignore
|
||||
// var isClicked: Boolean = false
|
||||
//
|
||||
// constructor() : this(id = -1, goodsId = -1) // 必需的空构造
|
||||
//}
|
||||
+6
-31
@@ -1,10 +1,9 @@
|
||||
package com.shuwei.dish.match.db.entity
|
||||
package com.shuwei.dish.match.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.PrimaryKey
|
||||
import com.shuwei.dish.match.db.BaseEntity
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.utils.DateTimeUtil
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@@ -56,16 +55,6 @@ data class SeasoningEntity(
|
||||
|
||||
var relateionType_dictText: String? = "",
|
||||
|
||||
var zjmCode: String? = "",
|
||||
|
||||
var materId: String? = "",
|
||||
|
||||
/** 物料编码 */
|
||||
var goodsCode: String? = "",
|
||||
|
||||
/** 净材种类 */
|
||||
var rawMaterialsType: String? = null,
|
||||
|
||||
var sort: Int = 9999,
|
||||
/**
|
||||
* isDel表示数据是否已删除,1-已删除,为无效数据,0-正常使用,有效数据
|
||||
@@ -73,25 +62,11 @@ data class SeasoningEntity(
|
||||
var isDel: Int = 0,
|
||||
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now())
|
||||
) : BaseEntity {
|
||||
/** UI 状态:格子类型,非数据库字段 */
|
||||
@Ignore var pageType: Int = 0
|
||||
/** UI 状态:是否选中,非数据库字段 */
|
||||
@Ignore var isClicked: Boolean = false
|
||||
@Ignore
|
||||
var pageType: Int = 0
|
||||
|
||||
@Ignore
|
||||
var isClicked: Boolean = false
|
||||
|
||||
constructor() : this(goodsId = "") // 必需的空构造
|
||||
|
||||
/** 转换为 GoodsItem,用于 UI 层展示 */
|
||||
fun toGoodsItem(): GoodsItem = GoodsItem(
|
||||
goodsId = goodsId,
|
||||
goodsName = goodsName,
|
||||
popularName = popularName,
|
||||
zjmCode = zjmCode,
|
||||
materId = materId,
|
||||
materialType = materialType,
|
||||
useWeight = useWeight,
|
||||
relateionType = relateionType,
|
||||
allEdible = allEdible,
|
||||
goodsOrRelationCode = goodsOrRelationCode,
|
||||
rawMaterialsType = rawMaterialsType
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//package com.shuwei.dish.match.http
|
||||
//
|
||||
//import android.annotation.SuppressLint
|
||||
//import android.util.Log
|
||||
//import okhttp3.Call
|
||||
//import okhttp3.Interceptor
|
||||
//import okhttp3.OkHttpClient
|
||||
//import okhttp3.Request
|
||||
//import okhttp3.Response
|
||||
//import java.util.concurrent.TimeUnit
|
||||
//
|
||||
//import javax.net.ssl.*
|
||||
//import java.security.SecureRandom
|
||||
//import java.security.cert.X509Certificate
|
||||
//
|
||||
//class HttpClient private constructor() {
|
||||
// private val client: OkHttpClient by lazy {
|
||||
// OkHttpClient.Builder()
|
||||
// .apply {
|
||||
// connectTimeout(15, TimeUnit.SECONDS)
|
||||
// readTimeout(30, TimeUnit.SECONDS)
|
||||
// writeTimeout(15, TimeUnit.SECONDS)
|
||||
// sslSocketFactory(createSSLSocketFactory(), TrustAllCerts())
|
||||
// hostnameVerifier { _, _ -> true }
|
||||
// //if (BuildConfig.Debug) {
|
||||
// addInterceptor(LoggingInterceptor())
|
||||
// // }
|
||||
// }
|
||||
// .build()
|
||||
// }
|
||||
//
|
||||
// companion object {
|
||||
// val instance by lazy { HttpClient() }
|
||||
// }
|
||||
//
|
||||
// fun newCall(request: Request): Call = client.newCall(request)
|
||||
//
|
||||
// inner class LoggingInterceptor : Interceptor {
|
||||
// override fun intercept(chain: Interceptor.Chain): Response {
|
||||
// val request = chain.request()
|
||||
// // 打印请求日志
|
||||
// Log.d("OkHttp", "--> ${request.method} ${request.url}")
|
||||
//
|
||||
// val response = chain.proceed(request)
|
||||
// // 打印响应日志
|
||||
// Log.d("OkHttp", "<-- ${response.code} ${response.request.url}")
|
||||
//
|
||||
// return response
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 信任所有证书的TrustManager实现
|
||||
// @SuppressLint("CustomX509TrustManager")
|
||||
// class TrustAllCerts : X509TrustManager {
|
||||
// @SuppressLint("TrustAllX509TrustManager")
|
||||
// override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {}
|
||||
// @SuppressLint("TrustAllX509TrustManager")
|
||||
// override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {}
|
||||
// override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()
|
||||
// }
|
||||
//
|
||||
// // 创建信任所有证书的SSLSocketFactory
|
||||
// fun createSSLSocketFactory(): SSLSocketFactory {
|
||||
// val sslContext = SSLContext.getInstance("TLS").apply {
|
||||
// init(null, arrayOf(TrustAllCerts()), SecureRandom())
|
||||
// }
|
||||
// return sslContext.socketFactory
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -0,0 +1,199 @@
|
||||
//package com.shuwei.dish.match.http
|
||||
//
|
||||
//import android.os.Handler
|
||||
//import android.os.Looper
|
||||
//import android.util.Log
|
||||
//import com.google.gson.reflect.TypeToken
|
||||
//import com.shuwei.dish.match.base.BaseApp
|
||||
//import com.shuwei.dish.match.base.BaseReq
|
||||
//import com.shuwei.dish.match.utils.SpTool
|
||||
//import com.shuwei.dish.match.utils.ext.toType
|
||||
//import okhttp3.Call
|
||||
//import okhttp3.Callback
|
||||
//import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
//import okhttp3.Request
|
||||
//import okhttp3.RequestBody.Companion.toRequestBody
|
||||
//import okhttp3.Response
|
||||
//import java.io.IOException
|
||||
//import java.util.concurrent.Executors
|
||||
//import java.util.concurrent.TimeUnit
|
||||
//
|
||||
//
|
||||
//object HttpUtil {
|
||||
//
|
||||
// var loopGetToken = true
|
||||
//
|
||||
// fun runMainThread(action: () -> Unit) {
|
||||
// Handler(Looper.getMainLooper()).post {
|
||||
// action()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // GET请求(HTTPS)
|
||||
// fun get(
|
||||
// url: String,
|
||||
// header: Map<String, String>?=null,
|
||||
// doSuccess: (data: Any) -> Unit,
|
||||
// doFailure: (code: Int?, msg: String?) -> Unit
|
||||
// ) {
|
||||
// val request = Request.Builder()
|
||||
// .url(if (url.isHttpApi()) url else UrlConfig.BASE_URL + url)
|
||||
// .apply {
|
||||
// if (header != null) {
|
||||
// header.forEach {
|
||||
// addHeader(it.key, it.value)
|
||||
// }
|
||||
// } else {
|
||||
// val token = getToken()
|
||||
// if (token.isNotBlank()) {
|
||||
// addHeader("X-Access-Token", token)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// .get()
|
||||
// .build()
|
||||
// HttpClient.instance.newCall(request).enqueue(CallbackImpl(doSuccess, doFailure))
|
||||
// }
|
||||
////
|
||||
//// fun get(
|
||||
//// isHttps: Boolean = false,
|
||||
//// host: String = "vip.shuziweidao.com",
|
||||
//// pathSegmentList: List<String>,
|
||||
//// queryParams: Map<String, String>,
|
||||
//// doSuccess: (data: Any) -> Unit,
|
||||
//// doFailure: (code: Int?, msg: String?) -> Unit
|
||||
//// ) {
|
||||
//// val token = getToken()
|
||||
//// val url = HttpUrl.Builder()
|
||||
//// .scheme(if (isHttps) "https" else "http")
|
||||
//// .host(host)
|
||||
//// .apply {
|
||||
//// pathSegmentList.forEach { addPathSegment(it) }
|
||||
//// queryParams.forEach { (key, value) -> addQueryParameter(key, value) }
|
||||
//// }
|
||||
//// .build()
|
||||
//// val request = Request.Builder()
|
||||
//// .url(url)
|
||||
//// .apply {
|
||||
//// if (token.isNotBlank()) {
|
||||
//// addHeader("Authorization", token)
|
||||
//// }
|
||||
//// }
|
||||
//// .get()
|
||||
//// .build()
|
||||
//// HttpClient.instance.newCall(request).enqueue(CallbackImpl(doSuccess, doFailure))
|
||||
//// }
|
||||
//
|
||||
// // POST表单(HTTPS)
|
||||
//// fun postForm(url: String, params: Map<String, String>, callback: Callback) {
|
||||
//// val formBody = FormBody.Builder().apply {
|
||||
//// params.forEach { (k, v) -> add(k, v) }
|
||||
//// }.build()
|
||||
////
|
||||
//// Request.Builder()
|
||||
//// .url(url)
|
||||
//// .post(formBody)
|
||||
//// .build().let { HttpClient.instance.newCall(it).enqueue(callback) }
|
||||
//// }
|
||||
//
|
||||
// // POST JSON(HTTPS)
|
||||
// fun postJson(
|
||||
// url: String,
|
||||
// json: String,
|
||||
// doSuccess: (data: Any) -> Unit,
|
||||
// doFailure: (code: Int?, msg: String?) -> Unit
|
||||
// ) {
|
||||
// val body = json
|
||||
// .toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
|
||||
// val token = getToken()
|
||||
// Request.Builder()
|
||||
// .url(if (url.isHttpApi()) url else UrlConfig.BASE_URL + url)
|
||||
// .apply {
|
||||
// if (token.isNotBlank()) {
|
||||
// addHeader("X-Access-Token", token)
|
||||
// }
|
||||
// }
|
||||
// .post(body)
|
||||
// .build()
|
||||
// .let { HttpClient.instance.newCall(it).enqueue(CallbackImpl(doSuccess, doFailure)) }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// val executor = Executors.newSingleThreadScheduledExecutor()
|
||||
// var getTokenIsRunning = false
|
||||
// private fun exeTokenThread() {
|
||||
// if (getTokenIsRunning.not()) {
|
||||
// executor.scheduleWithFixedDelay(
|
||||
// task, 0, 1, TimeUnit.MINUTES
|
||||
// )
|
||||
// getTokenIsRunning = true
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// val task = Runnable {
|
||||
// if (BaseApp.token.isNullOrBlank()) {
|
||||
// getAppToken()
|
||||
// } else {
|
||||
// executor.shutdown()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun getToken() = SpTool.getString(SpTool.TOKEN)
|
||||
////BaseApp.instance?.token ?:""
|
||||
////BaseApp.getSharedPref()?.getString("token", "") ?: ""
|
||||
//
|
||||
// fun getAppToken() {
|
||||
// val url = "${UrlConfig.GET_TOKEN}?qrcodeId=${SpTool.getString(SpTool.DEVICE_ID)}"
|
||||
//// Log.d(TAG, "getToken: url = $url")
|
||||
// get(url = url, doSuccess = {
|
||||
// SpTool.put(SpTool.TOKEN, it)
|
||||
// BaseApp.token = it.toString()
|
||||
// }) { code, msg ->
|
||||
// //toast(msg)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// class CallbackImpl(
|
||||
// private val doSuccess: (data: Any) -> Unit,
|
||||
// private val doFailure: (code: Int?, msg: String?) -> Unit
|
||||
// ) :
|
||||
// Callback {
|
||||
// override fun onFailure(call: Call, e: IOException) {
|
||||
// runMainThread {
|
||||
// e.printStackTrace()
|
||||
// doFailure(-1, "服务异常,${e.message}")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onResponse(call: Call, response: Response) {
|
||||
// val respData = response.body?.string()
|
||||
// runMainThread {
|
||||
// Log.d("HttpUtil", respData ?: "")
|
||||
// runCatching {
|
||||
// val typeToken = object : TypeToken<BaseReq<Any>>() {}
|
||||
// val baseReq = respData?.toType<BaseReq<Any>>(typeToken = typeToken)
|
||||
// if (baseReq == null) {
|
||||
// doFailure(-1, "查询数据失败")
|
||||
// return@runCatching
|
||||
// }
|
||||
// if (baseReq.code != 200) {
|
||||
// doFailure(baseReq.code, baseReq.message)
|
||||
// //baseReq.code == 500 ||
|
||||
// if (baseReq.code == 401 && loopGetToken) {
|
||||
// exeTokenThread()
|
||||
// }
|
||||
// return@runCatching
|
||||
// }
|
||||
// doSuccess(baseReq.result ?: "")
|
||||
// }.onFailure {
|
||||
// it.printStackTrace()
|
||||
// doFailure(-1, "解析异常")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//fun String.isHttpApi() = this.startsWith("http://") || this.startsWith("https://")
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.shuwei.dish.match.http
|
||||
|
||||
//import com.shuwei.dish.match.base.BaseApp
|
||||
|
||||
object UrlConfig {
|
||||
// private const val DEVICE_BASE_URL = "http://device.shuziweidao.com:8889"
|
||||
// /**
|
||||
// * device获取token
|
||||
// */
|
||||
// const val DEVICE_TOKEN = "${DEVICE_BASE_URL}/sys/getEquipmentToken"
|
||||
// /**
|
||||
// *获取配置信息
|
||||
// */
|
||||
// const val DEVICE_CONFIG = "${DEVICE_BASE_URL}/equipment/stEquipment/queryByEquipmentCode"
|
||||
|
||||
// const val BASE_URL = "http://vip.shuziweidao.com/shuwei-zhct"
|
||||
// const val DISH_DETAIL = "$BASE_URL/scales/goodsUseList?foodId={foodId}&foodWeight={foodWeight}"
|
||||
// const val DISH_LIST = "$BASE_URL/scales/getRestInfoFoods?eaId=99&type=0&foodName"
|
||||
|
||||
// const val BASE_URL = "http://192.168.1.207:9102"
|
||||
// const val BASE_URL = "https://yyjk.shuziweidao.com/gateway"
|
||||
const val BASE_URL = "https://yyjk.shuziweidao.com/gateway/"
|
||||
// const val DISH_LIST = "$BASE_URL/scales/getRestInfoFoods?eaId=99&type=0&foodName"
|
||||
|
||||
|
||||
// var DISH_DETAIL = "${BaseApp.configUrl}/food/stFoodInfoMatching/queryById"
|
||||
//
|
||||
// // "$BASE_URL/scales/generateToken?deviceId=1111111111111111111111111111"
|
||||
//
|
||||
// var GET_TOKEN = "${BaseApp.configUrl}/restaurant/equipment/stEquipment/getEquipmentToken"
|
||||
// var SUBMIT_DISH = "${BaseApp.configUrl}/food/stFoodInfoMatching/saveoredit"
|
||||
//
|
||||
// var QUERY_GOODS_LIST = "${BaseApp.configUrl}/food/stFoodInfoMatching/queryGoodsInfoList"
|
||||
// var QUERY_FOOD_LIST = "${BaseApp.configUrl}/food/stFoodInfoMatching/list"
|
||||
// var SAMPLING_LIST = "${BaseApp.configUrl}/food/stFoodInfoMatching/queryHistorical/goodsInfoList"
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.shuwei.dish.match.model
|
||||
|
||||
/**
|
||||
* 已采集食材列表项数据模型
|
||||
* @param foodName 食材名称
|
||||
* @param collectCount 已采集数量
|
||||
*/
|
||||
data class CollectedFoodItem(
|
||||
val foodName: String = "",
|
||||
val collectCount: Int = 0
|
||||
)
|
||||
@@ -1,43 +0,0 @@
|
||||
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
|
||||
|
||||
/**
|
||||
* 菜品详情接口传输对象(DTO),不依赖 Room
|
||||
* 对应接口:getConstituteByFoodId / saveConstitute
|
||||
*/
|
||||
data class CookFoodDTO(
|
||||
var foodId: String = "",
|
||||
var foodName: String? = null,
|
||||
var canteenId: String? = null,
|
||||
var foodWeight: Double = 0.0,
|
||||
// 0-制作模式,1-采样模式,2-品控模式
|
||||
var cookMode: Int = 0,
|
||||
var dinnerType: String? = "0",
|
||||
// 接口返回的食材构成列表
|
||||
var matchingConstituteInfoList: MutableList<CookFoodGoodsDTO>? = null,
|
||||
var foodConstituteList: MutableList<CookFoodGoodsDTO>? = null
|
||||
) : Serializable {
|
||||
|
||||
/**
|
||||
* 转换为 Room 实体,用于写入本地数据库
|
||||
* id/isDel/createTime 由 Room 自行管理,不从 DTO 携带
|
||||
*/
|
||||
fun toEntity(): CookFoodEntity = CookFoodEntity(
|
||||
foodId = foodId,
|
||||
foodName = foodName,
|
||||
canteenId = canteenId,
|
||||
foodWeight = foodWeight,
|
||||
cookMode = cookMode,
|
||||
dinnerType = dinnerType
|
||||
).also { entity ->
|
||||
entity.matchingConstituteInfoList = matchingConstituteInfoList
|
||||
?.map { it.toEntity() }
|
||||
?.toMutableList()
|
||||
entity.foodConstituteList = foodConstituteList
|
||||
?.map { it.toEntity() }
|
||||
?.toMutableList()
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
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
|
||||
|
||||
/**
|
||||
* 菜品构成(主辅料/调料)接口传输对象(DTO),不依赖 Room
|
||||
* 对应 CookFoodDTO 中 foodConstituteList、matchingConstituteInfoList 的元素
|
||||
*/
|
||||
data class CookFoodGoodsDTO(
|
||||
var goodsId: String = "",
|
||||
var goodsName: String? = null,
|
||||
var foodId: String? = "",
|
||||
var goodsOrRelationCode: String? = "",
|
||||
// 调料数据顺序
|
||||
var sort: Int = 0,
|
||||
// 食材原材料:1,预制品:2
|
||||
var relateionType: Int = 0,
|
||||
// 物品类型:1主料 2辅料 3调料
|
||||
var materialType: Int = 0,
|
||||
// 物品 是否全部可食:true-全部可食,false-部分可食
|
||||
var allEdible: Boolean = true,
|
||||
// 物品 用料重量
|
||||
var useWeight: Double? = 0.0,
|
||||
var popularName: String? = "",
|
||||
var canteenId: String? = "",
|
||||
var relateionType_dictText: String? = "",
|
||||
var zjmCode: String? = "",
|
||||
var materId: String? = "",
|
||||
// 物料编码
|
||||
var goodsCode: String? = "",
|
||||
// 净材种类
|
||||
var rawMaterialsType: String? = null
|
||||
) : Serializable {
|
||||
|
||||
/**
|
||||
* 转换为 GoodsItem,用于 UI 层
|
||||
*/
|
||||
fun toGoodsItem(): GoodsItem = GoodsItem(
|
||||
goodsId = goodsId,
|
||||
goodsName = goodsName,
|
||||
popularName = popularName,
|
||||
zjmCode = zjmCode,
|
||||
materId = materId,
|
||||
materCode = goodsCode,
|
||||
materialType = materialType,
|
||||
useWeight = useWeight,
|
||||
relateionType = relateionType,
|
||||
allEdible = allEdible,
|
||||
goodsOrRelationCode = goodsOrRelationCode,
|
||||
rawMaterialsType = rawMaterialsType
|
||||
)
|
||||
|
||||
/**
|
||||
* 转换为 Room 实体,用于写入本地数据库
|
||||
* id/pid/isDel/createTime 由 Room 自行管理,不从 DTO 携带
|
||||
*/
|
||||
fun toEntity(): CookFoodGoodsEntity = CookFoodGoodsEntity(
|
||||
goodsId = goodsId,
|
||||
goodsName = goodsName,
|
||||
foodId = foodId,
|
||||
goodsOrRelationCode = goodsOrRelationCode,
|
||||
sort = sort,
|
||||
relateionType = relateionType,
|
||||
materialType = materialType,
|
||||
allEdible = allEdible,
|
||||
useWeight = useWeight,
|
||||
popularName = popularName,
|
||||
canteenId = canteenId,
|
||||
relateionType_dictText = relateionType_dictText,
|
||||
zjmCode = zjmCode,
|
||||
materId = materId,
|
||||
goodsCode = goodsCode,
|
||||
rawMaterialsType = rawMaterialsType
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Room 实体 → DTO 反向映射,用于将本地数据转为接口提交格式
|
||||
* id/pid/isDel/createTime 为本地数据库字段,不参与提交
|
||||
*/
|
||||
fun CookFoodGoodsEntity.toDTO(): CookFoodGoodsDTO = CookFoodGoodsDTO(
|
||||
goodsId = goodsId,
|
||||
goodsName = goodsName,
|
||||
foodId = foodId,
|
||||
goodsOrRelationCode = goodsOrRelationCode,
|
||||
sort = sort,
|
||||
relateionType = relateionType,
|
||||
materialType = materialType,
|
||||
allEdible = allEdible,
|
||||
useWeight = useWeight,
|
||||
popularName = popularName,
|
||||
canteenId = canteenId,
|
||||
relateionType_dictText = relateionType_dictText,
|
||||
zjmCode = zjmCode,
|
||||
materId = materId,
|
||||
goodsCode = goodsCode,
|
||||
rawMaterialsType = rawMaterialsType
|
||||
)
|
||||
|
||||
/**
|
||||
* Room 实体 → DTO 反向映射,用于将本地数据转为接口提交格式
|
||||
* id/isDel/createTime 为本地数据库字段,不参与提交
|
||||
*/
|
||||
fun CookFoodEntity.toDTO(): CookFoodDTO = CookFoodDTO(
|
||||
foodId = foodId,
|
||||
foodName = foodName,
|
||||
canteenId = canteenId,
|
||||
foodWeight = foodWeight,
|
||||
cookMode = cookMode,
|
||||
dinnerType = dinnerType,
|
||||
matchingConstituteInfoList = matchingConstituteInfoList
|
||||
?.map { it.toDTO() }
|
||||
?.toMutableList(),
|
||||
foodConstituteList = foodConstituteList
|
||||
?.map { it.toDTO() }
|
||||
?.toMutableList()
|
||||
)
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.shuwei.dish.match.model
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import java.io.File
|
||||
|
||||
data class HomeModeBean(
|
||||
var modeName: String = "",
|
||||
var modeDesc: String = "",
|
||||
var modeIconId: Int = 0,
|
||||
var isLocked: Boolean = false,
|
||||
|
||||
var onClick: (() -> Unit)? = null
|
||||
)
|
||||
|
||||
data class FoodCollectionBean(
|
||||
var imageUri: Uri? = null,
|
||||
var bitmap: Bitmap? = null,
|
||||
var imageFile: File? = null,
|
||||
var imageVector: FloatArray? = null,
|
||||
var isShowCamera: Boolean = false,
|
||||
var isFinish:Boolean = false,
|
||||
var uploadSuccess:Boolean = false
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as FoodCollectionBean
|
||||
|
||||
if (isShowCamera != other.isShowCamera) return false
|
||||
if (isFinish != other.isFinish) return false
|
||||
if (uploadSuccess != other.uploadSuccess) return false
|
||||
if (imageUri != other.imageUri) return false
|
||||
if (bitmap != other.bitmap) return false
|
||||
if (imageFile != other.imageFile) return false
|
||||
if (!imageVector.contentEquals(other.imageVector)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = isShowCamera.hashCode()
|
||||
result = 31 * result + isFinish.hashCode()
|
||||
result = 31 * result + uploadSuccess.hashCode()
|
||||
result = 31 * result + (imageUri?.hashCode() ?: 0)
|
||||
result = 31 * result + (bitmap?.hashCode() ?: 0)
|
||||
result = 31 * result + (imageFile?.hashCode() ?: 0)
|
||||
result = 31 * result + (imageVector?.contentHashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
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
|
||||
|
||||
/**
|
||||
* 物品信息接口返回的数据类(DTO),不依赖 Room,同时承载 UI 状态字段
|
||||
* 对应接口:queryGoodsInfoList,食材(goodsType=0)和调料(goodsType=1)共用此结构
|
||||
*/
|
||||
data class GoodsItem(
|
||||
// 接口返回字段
|
||||
var goodsId: String = "",
|
||||
val goodsName: String? = null,
|
||||
val popularName: String? = null,
|
||||
val zjmCode: String? = null,
|
||||
var materId: String? = null,
|
||||
val materCode: String? = null,
|
||||
|
||||
// 从 CookFoodGoodsEntity 迁移的数据字段(DishPartAdapter 显示及转换用)
|
||||
var materialType: Int = 0,
|
||||
var useWeight: Double? = 0.0,
|
||||
var relateionType: Int = 0,
|
||||
var allEdible: Boolean = true,
|
||||
var goodsOrRelationCode: String? = "",
|
||||
|
||||
// 从 CookFoodGoodsEntity @Ignore 迁移的 UI 状态字段
|
||||
var isSetFinished: Boolean = false,
|
||||
// var isItemClicked: Boolean = false,
|
||||
var isSamplingPage: Boolean = false,
|
||||
var isNewDishType: Boolean = false,
|
||||
var isClicked: Boolean = false,
|
||||
// true-原始数据,false-非原始数据(识图新增)
|
||||
var isOriginalData: Boolean = true,
|
||||
// 识图匹配分数,-1 表示不显示
|
||||
var foodScore: Int = -1,
|
||||
// 净材种类(当前选中值)
|
||||
var rawMaterialsType: String? = null,
|
||||
// 净材种类候选列表(临时字段,逗号分隔,不持久化)
|
||||
var rawMaterialsTypes: String? = null,
|
||||
var oldGoodsId: String? = null
|
||||
) : Serializable {
|
||||
|
||||
/**
|
||||
* 物料编码,与查询接口返回的 materCode 同值,统一对外暴露为 goodsCode 供下游使用
|
||||
*/
|
||||
val goodsCode: String? get() = materCode
|
||||
|
||||
/**
|
||||
* 转换为 CookFoodGoodsEntity,用于写入数据库或传给 SubmitFoodActivity
|
||||
*/
|
||||
fun toCookFoodGoodsEntity(): CookFoodGoodsEntity = CookFoodGoodsEntity(
|
||||
goodsId = goodsId,
|
||||
goodsName = goodsName,
|
||||
popularName = popularName,
|
||||
zjmCode = zjmCode,
|
||||
materId = materId,
|
||||
goodsCode = goodsCode,
|
||||
materialType = materialType,
|
||||
useWeight = useWeight,
|
||||
relateionType = relateionType,
|
||||
allEdible = allEdible,
|
||||
goodsOrRelationCode = goodsOrRelationCode,
|
||||
rawMaterialsType = rawMaterialsType
|
||||
)
|
||||
|
||||
/**
|
||||
* 转换为 SeasoningEntity,用于保存调料完整信息到 dm_seasoning
|
||||
*/
|
||||
fun toSeasoningEntity(): SeasoningEntity = SeasoningEntity(
|
||||
goodsId = goodsId,
|
||||
goodsName = goodsName,
|
||||
popularName = popularName,
|
||||
zjmCode = zjmCode,
|
||||
materId = materId,
|
||||
goodsCode = goodsCode,
|
||||
materialType = materialType,
|
||||
relateionType = relateionType,
|
||||
allEdible = allEdible,
|
||||
goodsOrRelationCode = goodsOrRelationCode,
|
||||
rawMaterialsType = rawMaterialsType
|
||||
)
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.shuwei.dish.match.model
|
||||
|
||||
/**
|
||||
* 物品名称批量查询入参 DTO
|
||||
* 用于 queryGoodsInfoList 接口 goodsNames 字段的元素类型
|
||||
* @param goodsName 物品名称
|
||||
* @param rawMaterialsType 净材种类
|
||||
*/
|
||||
data class GoodsNameQueryDTO(
|
||||
val goodsName: String,
|
||||
val rawMaterialsType: String
|
||||
)
|
||||
@@ -1,40 +0,0 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.shuwei.dish.match.net
|
||||
|
||||
import com.shuwei.dish.match.utils.ext.toJsonString
|
||||
import com.shuwei.dish.match.utils.ext.toObject
|
||||
import com.shuwei.dish.match.utils.ext.toType
|
||||
import org.apache.http.conn.ConnectTimeoutException
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.net.SocketTimeoutException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
///**
|
||||
// * 通用网络请求封装,统一处理异常
|
||||
// * @param onRequest 实际的 Retrofit 接口请求
|
||||
// * @param onSuccess 成功回调
|
||||
// * @param onFailure 自定义错误回调(可选,不传则用默认提示)
|
||||
// */
|
||||
//suspend fun <T> apiRequest(
|
||||
// onRequest: suspend () -> T,
|
||||
// onSuccess: (T) -> Unit,
|
||||
// onFailure: ((ApiException) -> Unit)? = null
|
||||
//) {
|
||||
// try {
|
||||
// // 执行实际的网络请求
|
||||
// val result = onRequest()
|
||||
// onSuccess(result)
|
||||
// } catch (e: Exception) {
|
||||
// val apiException = getApiException(e)
|
||||
// // 优先执行自定义错误回调,没有则用默认提示
|
||||
// if (onFailure != null) {
|
||||
// onFailure(apiException)
|
||||
// } else {
|
||||
// // 默认的错误提示(可根据 ErrorType 定制)
|
||||
// val tip = apiException.errorMsg
|
||||
// // 切换到UI线程弹提示(用 MainScope 确保在主线程)
|
||||
// MainScope().launch {
|
||||
// BaseApp.instance?.toast(tip)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
/**
|
||||
* 通用网络请求封装,统一处理异常
|
||||
* @param onRequest 实际的 Retrofit 接口请求
|
||||
* @param onSuccess 成功回调
|
||||
* @param onFailure 自定义错误回调(可选,不传则用默认提示)
|
||||
*/
|
||||
suspend fun <T> request(
|
||||
onRequest: suspend () -> ApiResponse<T>,
|
||||
onSuccess: (T) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
var response: ApiResponse<T>?
|
||||
try {
|
||||
// 执行实际的网络请求
|
||||
response = onRequest()
|
||||
} catch (e: Exception) {
|
||||
val apiException = getApiException(e)
|
||||
onFailure("-1", apiException.errorMsg)
|
||||
return
|
||||
}
|
||||
if (response?.isSuccess() == true) {
|
||||
onSuccess(response.data as T)
|
||||
} else {
|
||||
onFailure(response?.code ?: "-1", response?.msg ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
data class CodeMsg(
|
||||
var code: String? = null,
|
||||
var msg: String? = null
|
||||
)
|
||||
|
||||
fun getApiException(e: Exception): ApiException {
|
||||
// 捕获各类网络异常并转换为自定义异常
|
||||
return when (e) {
|
||||
is HttpException -> httpException2ApiException(e)
|
||||
|
||||
is UnknownHostException -> ApiException(
|
||||
ErrorType.NETWORK_ERROR,
|
||||
errorMsg = "网络未连接,请检查网络"
|
||||
)
|
||||
|
||||
is SocketTimeoutException -> ApiException(
|
||||
ErrorType.TIMEOUT_ERROR,
|
||||
errorMsg = "请求超时,请稍后重试"
|
||||
)
|
||||
|
||||
is ConnectTimeoutException -> ApiException(
|
||||
ErrorType.TIMEOUT_ERROR,
|
||||
errorMsg = "连接超时,请检查网络"
|
||||
)
|
||||
|
||||
is IOException -> ApiException(
|
||||
ErrorType.NETWORK_ERROR,
|
||||
errorMsg = "网络异常:${e.message ?: "未知IO错误"}"
|
||||
)
|
||||
|
||||
is ApiException -> e
|
||||
else -> ApiException(
|
||||
ErrorType.UNKNOWN_ERROR,
|
||||
errorMsg = "未知错误:${e.message ?: "未知"}",
|
||||
throwable = e
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun httpException2ApiException(e: HttpException): ApiException {
|
||||
val body = e.response()?.errorBody()?.string()
|
||||
val codeMsg: CodeMsg? = body?.toObject<CodeMsg>()
|
||||
return ApiException(
|
||||
ErrorType.NETWORK_ERROR,
|
||||
errorMsg = codeMsg?.msg ?: ""
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package com.shuwei.dish.match.net
|
||||
|
||||
import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.model.CookFoodDTO
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Multipart
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Part
|
||||
import retrofit2.http.PartMap
|
||||
import retrofit2.http.Query
|
||||
import retrofit2.http.Url
|
||||
|
||||
@@ -24,7 +20,7 @@ interface ApiService {
|
||||
suspend fun getFoodDetail(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/getConstituteByFoodId",
|
||||
@Query("foodId") foodId: String
|
||||
): ApiResponse<CookFoodDTO?>
|
||||
): ApiResponse<CookFoodEntity?>
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,7 +29,7 @@ interface ApiService {
|
||||
@POST
|
||||
suspend fun submitCookFood(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/saveConstitute",
|
||||
@Body param: CookFoodDTO
|
||||
@Body param: CookFoodEntity
|
||||
): ApiResponse<Any?>
|
||||
|
||||
/**
|
||||
@@ -41,7 +37,7 @@ interface ApiService {
|
||||
*/
|
||||
@POST
|
||||
suspend fun searchFoodList(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryPageList",
|
||||
@Url url:String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryPageList",
|
||||
@Body param: MutableMap<String, Any>
|
||||
): ApiResponse<MutableList<FoodRecord>?>
|
||||
|
||||
@@ -50,27 +46,68 @@ interface ApiService {
|
||||
*/
|
||||
@POST
|
||||
suspend fun getSamplingList(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryHistoryGoodsInfoList",
|
||||
@Url url:String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryHistoryGoodsInfoList",
|
||||
@Body param: MutableMap<String, Any>
|
||||
): ApiResponse<MutableList<FoodRecord>?>
|
||||
|
||||
/**
|
||||
* 物品信息(食材 goodsType=0,调料 goodsType=1 共用此接口)
|
||||
* 物品信息
|
||||
*/
|
||||
@POST
|
||||
suspend fun queryGoodsList(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryGoodsInfoList",
|
||||
@Url url:String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryGoodsInfoList",
|
||||
@Body param: MutableMap<String, Any>
|
||||
): ApiResponse<MutableList<GoodsItem>?>
|
||||
): ApiResponse<MutableList<CookFoodGoodsEntity>?>
|
||||
|
||||
/**
|
||||
* 提交采集图片数据
|
||||
* 调料信息
|
||||
*/
|
||||
@Multipart
|
||||
@POST
|
||||
suspend fun uploadFoodVectorData(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/addWeighingCollectionData",
|
||||
@PartMap params: MutableMap<String, RequestBody>,
|
||||
@Part foodPics: List<MultipartBody.Part>
|
||||
): ApiResponse<List<String>?>
|
||||
suspend fun querySeasoningList(
|
||||
@Url url:String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryGoodsInfoList",
|
||||
@Body param: MutableMap<String, Any>
|
||||
): ApiResponse<MutableList<SeasoningEntity>?>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// *获取配置信息
|
||||
// */
|
||||
// @GET("/equipment/stEquipment/queryByEquipmentCode")
|
||||
// suspend fun getDeviceInfo(
|
||||
// @Query("equipmentCode") equipmentCode: String,
|
||||
// @Query("appVersion") appVersion: String = App.appVersion
|
||||
// ): ApiResponse<DeviceConfigInfo>
|
||||
//
|
||||
// @GET
|
||||
// suspend fun getAccessToken(
|
||||
// @Url url: String = UrlConfig.GET_ACCESS_TOKEN,
|
||||
// @Query("qrcodeId") qrcodeId: String
|
||||
// ): ApiResponse<String?>
|
||||
//
|
||||
// @GET
|
||||
// suspend fun getShelfList(
|
||||
// @Url url: String = UrlConfig.GET_SHELF_LIST,
|
||||
// @Query("deviceId") deviceId: String
|
||||
// ): ApiResponse<ShelfResult>
|
||||
//
|
||||
// @GET
|
||||
// suspend fun getGoodsList(
|
||||
// @Url url: String = UrlConfig.GET_GOODS_LIST,
|
||||
// @Query("canteenId") canteenId: String = "0",
|
||||
// @Query("goodsName") goodsName: String? = null,
|
||||
// @Query("pageNo") pageNo: Int = 1,
|
||||
// @Query("pageSize") pageSize: Int = 50
|
||||
// ): ApiResponse<MutableList<GoodsModel>?>
|
||||
//
|
||||
// @POST
|
||||
// suspend fun saveShelfGoodsList(
|
||||
// @Url url: String = UrlConfig.SAVE_SHELF_GOODS_LIST,
|
||||
// @Body body: ShelfBody
|
||||
// ): ApiResponse<Any?>
|
||||
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
package com.shuwei.dish.match.net
|
||||
|
||||
import java.io.IOException
|
||||
import java.net.ConnectException
|
||||
import java.net.SocketTimeoutException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
// 1. 网络异常类型枚举
|
||||
enum class ErrorType {
|
||||
NETWORK_ERROR, // 网络错误(无网)
|
||||
@@ -22,13 +17,3 @@ class ApiException(
|
||||
val errorMsg: String,
|
||||
val throwable: Throwable? = null
|
||||
) : Exception(errorMsg, throwable)
|
||||
|
||||
/** 将任意异常转换为 ApiException,供 safeApiCall 统一使用 */
|
||||
fun getApiException(e: Exception): ApiException = when (e) {
|
||||
is ApiException -> e
|
||||
is UnknownHostException -> ApiException(ErrorType.NETWORK_ERROR, errorMsg = "网络未连接,请检查网络")
|
||||
is SocketTimeoutException -> ApiException(ErrorType.TIMEOUT_ERROR, errorMsg = "请求超时,请稍后重试")
|
||||
is ConnectException -> ApiException(ErrorType.TIMEOUT_ERROR, errorMsg = "连接超时,请检查网络")
|
||||
is IOException -> ApiException(ErrorType.NETWORK_ERROR, errorMsg = "网络异常:${e.message ?: "未知IO错误"}")
|
||||
else -> ApiException(ErrorType.UNKNOWN_ERROR, errorMsg = "未知错误:${e.message ?: "未知"}", throwable = e)
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.shuwei.dish.match.net
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.util.Log
|
||||
import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.http.UrlConfig
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
@@ -16,7 +16,7 @@ import kotlin.apply
|
||||
import kotlin.jvm.java
|
||||
|
||||
val apiService: ApiService = Retrofit.Builder()
|
||||
.baseUrl(GlobalData.appBaseUrl)
|
||||
.baseUrl(UrlConfig.BASE_URL)
|
||||
// .baseUrl(UrlConfig.DEVICE_BASE_URL)
|
||||
.client(HttpManager.instance.client)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
|
||||
@@ -2,257 +2,110 @@ package com.shuwei.dish.match.net
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.model.CookFoodDTO
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.model.GoodsNameQueryDTO
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* 网络请求 ViewModel,所有网络操作通过 RemoteRepository 发起,不直接依赖 apiService
|
||||
* @param repository 网络数据仓库,默认使用单例实例
|
||||
*/
|
||||
class NetViewModel(
|
||||
private val repository: RemoteRepository = RemoteRepository()
|
||||
) : ViewModel() {
|
||||
class NetViewModel : ViewModel() {
|
||||
|
||||
/**
|
||||
* 提交制作菜品的 UI 状态流,UI 层通过 collect 监听
|
||||
*/
|
||||
private val _submitCookFoodState = MutableStateFlow<UiState<Any?>>(UiState.Idle)
|
||||
val submitCookFoodState: StateFlow<UiState<Any?>> = _submitCookFoodState.asStateFlow()
|
||||
|
||||
/**
|
||||
* 提交制作菜品
|
||||
*/
|
||||
fun submitCookFood(entity: CookFoodDTO) {
|
||||
viewModelScope.launch {
|
||||
_submitCookFoodState.value = UiState.Loading
|
||||
_submitCookFoodState.value = repository.submitCookFood(entity)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询菜品详情的 UI 状态流,UI 层通过 collect 监听
|
||||
*/
|
||||
private val _foodDetailState = MutableStateFlow<UiState<CookFoodDTO?>>(UiState.Idle)
|
||||
val foodDetailState: StateFlow<UiState<CookFoodDTO?>> = _foodDetailState.asStateFlow()
|
||||
|
||||
/**
|
||||
* 查询菜品详情
|
||||
*/
|
||||
fun getFoodDetail(foodId: String) {
|
||||
viewModelScope.launch {
|
||||
_foodDetailState.value = UiState.Loading
|
||||
_foodDetailState.value = repository.getFoodDetail(foodId)
|
||||
}
|
||||
}
|
||||
|
||||
fun resetFoodDetailState() {
|
||||
_foodDetailState.value = UiState.Idle
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索菜品列表的 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>) {
|
||||
viewModelScope.launch {
|
||||
// pageNum=1 时先 emit Idle 重置 replay 缓存,防止相同数据导致 SharedFlow 去重不触发
|
||||
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
|
||||
fun submitCookFood(
|
||||
entity: CookFoodEntity,
|
||||
onSuccess: (Any?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.searchFoodList(param))
|
||||
request(
|
||||
onRequest = {
|
||||
apiService.submitCookFood(param = entity)
|
||||
},
|
||||
onSuccess = onSuccess,
|
||||
onFailure = onFailure
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
private val _samplingListState = MutableStateFlow<UiState<MutableList<FoodRecord>?>>(UiState.Idle)
|
||||
val samplingListState: StateFlow<UiState<MutableList<FoodRecord>?>> = _samplingListState.asStateFlow()
|
||||
fun resetSamplingListState() {
|
||||
_samplingListState.value = UiState.Idle
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询采样数据列表
|
||||
*/
|
||||
fun getSamplingList(param: MutableMap<String, Any>) {
|
||||
viewModelScope.launch {
|
||||
_samplingListState.value = UiState.Loading
|
||||
_samplingListState.value = repository.getSamplingList(param)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询采样数据列表(回调版本),结果通过 onResult 直接回调,不经过 StateFlow
|
||||
* 适合不需要跨生命周期持续监听的一次性查询场景
|
||||
*/
|
||||
fun getSamplingListWithCallback(
|
||||
param: MutableMap<String, Any>,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<MutableList<FoodRecord>?>) -> Unit
|
||||
fun getFoodDetail(
|
||||
foodId: String,
|
||||
onSuccess: (CookFoodEntity?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.getSamplingList(param))
|
||||
request(
|
||||
onRequest = {
|
||||
apiService.getFoodDetail(foodId = foodId)
|
||||
},
|
||||
onSuccess = onSuccess,
|
||||
onFailure = onFailure
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询物品信息列表的 UI 状态流(食材/调料共用),UI 层通过 collect 监听
|
||||
*/
|
||||
private val _goodsListState = MutableStateFlow<UiState<MutableList<GoodsItem>?>>(UiState.Idle)
|
||||
val goodsListState: StateFlow<UiState<MutableList<GoodsItem>?>> = _goodsListState.asStateFlow()
|
||||
|
||||
/**
|
||||
* 食材搜索弹窗专用的 UI 状态流,与 goodsListState 隔离,避免弹窗请求影响其他页面
|
||||
*/
|
||||
private val _foodSearchGoodsListState = MutableStateFlow<UiState<MutableList<GoodsItem>?>>(UiState.Idle)
|
||||
val foodSearchGoodsListState: StateFlow<UiState<MutableList<GoodsItem>?>> = _foodSearchGoodsListState.asStateFlow()
|
||||
fun searchFoodList(
|
||||
param: MutableMap<String, Any>,
|
||||
onSuccess: (MutableList<FoodRecord>?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
request(
|
||||
onRequest = {
|
||||
apiService.searchFoodList(param = param)
|
||||
},
|
||||
onSuccess = onSuccess,
|
||||
onFailure = onFailure
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun resetGoodsListState() {
|
||||
_goodsListState.value = UiState.Idle
|
||||
fun getSamplingList(
|
||||
param: MutableMap<String, Any>,
|
||||
onSuccess: (MutableList<FoodRecord>?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
request(
|
||||
onRequest = {
|
||||
apiService.getSamplingList(param = param)
|
||||
},
|
||||
onSuccess = onSuccess,
|
||||
onFailure = onFailure
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询物品信息列表(食材 goodsType=0,调料 goodsType=1 共用)
|
||||
* @param goodsType 物品类型:0=食材,1=调料
|
||||
* @param placeId 场所 ID,默认取当前食堂 ID
|
||||
* @param pageNum 页码,默认第 1 页
|
||||
* @param pageSize 每页条数,默认 50
|
||||
* @param goodsName 按名称模糊搜索,为 null 时不传该字段
|
||||
* @param goodsNames 按名称+净材种类列表批量查询,为 null 时不传该字段
|
||||
*/
|
||||
fun queryGoodsList(
|
||||
goodsType: String,
|
||||
placeId: String = BaseApp.canteenId,
|
||||
pageNum: Int = 1,
|
||||
pageSize: Int = 50,
|
||||
goodsName: String? = null,
|
||||
goodsNames: List<GoodsNameQueryDTO>? = null
|
||||
param: MutableMap<String, Any>,
|
||||
onSuccess: (MutableList<CookFoodGoodsEntity>?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
val param = mutableMapOf<String, Any>(
|
||||
"goodsType" to goodsType,
|
||||
"placeId" to placeId,
|
||||
"pageNum" to pageNum,
|
||||
"pageSize" to pageSize
|
||||
)
|
||||
goodsName?.let { param["goodsName"] = it }
|
||||
goodsNames?.let { param["goodsNames"] = it }
|
||||
viewModelScope.launch {
|
||||
_goodsListState.value = UiState.Loading
|
||||
_goodsListState.value = repository.queryGoodsList(param)
|
||||
request(
|
||||
onRequest = {
|
||||
apiService.queryGoodsList(param = param)
|
||||
},
|
||||
onSuccess = onSuccess,
|
||||
onFailure = onFailure
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 食材搜索弹窗专用的查询方法,结果写入 foodSearchGoodsListState,不影响 goodsListState
|
||||
* @param goodsType 物品类型:0=食材,1=调料
|
||||
* @param placeId 场所 ID,默认取当前食堂 ID
|
||||
* @param pageNum 页码,默认第 1 页
|
||||
* @param pageSize 每页条数,默认 50
|
||||
* @param goodsName 按名称模糊搜索,为 null 时不传该字段
|
||||
* @param goodsNames 按名称+净材种类列表批量查询,为 null 时不传该字段
|
||||
*/
|
||||
fun queryFoodSearchGoodsList(
|
||||
goodsType: String,
|
||||
placeId: String = BaseApp.canteenId,
|
||||
pageNum: Int = 1,
|
||||
pageSize: Int = 50,
|
||||
goodsName: String? = null,
|
||||
goodsNames: List<GoodsNameQueryDTO>? = null
|
||||
fun querySeasoningList(
|
||||
param: MutableMap<String, Any>,
|
||||
onSuccess: (MutableList<SeasoningEntity>?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
val param = mutableMapOf<String, Any>(
|
||||
"goodsType" to goodsType,
|
||||
"placeId" to placeId,
|
||||
"pageNum" to pageNum,
|
||||
"pageSize" to pageSize
|
||||
)
|
||||
goodsName?.let { param["goodsName"] = it }
|
||||
goodsNames?.let { param["goodsNames"] = it }
|
||||
viewModelScope.launch {
|
||||
_foodSearchGoodsListState.value = UiState.Loading
|
||||
_foodSearchGoodsListState.value = repository.queryGoodsList(param)
|
||||
request(
|
||||
onRequest = {
|
||||
apiService.querySeasoningList(param = param)
|
||||
},
|
||||
onSuccess = onSuccess,
|
||||
onFailure = onFailure
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传采集菜品信息 UI 状态流,UI 层通过 collect 监听
|
||||
*/
|
||||
private val _uploadCollectState = MutableStateFlow<UiState<List<String>?>>(UiState.Idle)
|
||||
val uploadCollectState: StateFlow<UiState<List<String>?>> = _uploadCollectState.asStateFlow()
|
||||
|
||||
/**
|
||||
* 上传采集菜品信息(触发 StateFlow,适合单次上传场景)
|
||||
*/
|
||||
fun uploadFoodVectorData(
|
||||
fileList: List<File>,
|
||||
params: MutableMap<String, RequestBody>
|
||||
) {
|
||||
val fileParts = fileList.map { file ->
|
||||
file.asRequestBody("multipart/form-data".toMediaTypeOrNull())
|
||||
.let { MultipartBody.Part.createFormData("foodPics", file.name, it) }
|
||||
}
|
||||
viewModelScope.launch {
|
||||
_uploadCollectState.value = UiState.Loading
|
||||
_uploadCollectState.value = repository.uploadFoodVectorData(params, fileParts)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传采集菜品信息(直接返回结果,适合分批循环上传场景)
|
||||
* @param fileList 图片文件列表
|
||||
* @param params 附加参数
|
||||
* @return UiState 包装的结果
|
||||
*/
|
||||
suspend fun uploadFoodVectorDataBatch(
|
||||
fileList: List<File>,
|
||||
params: MutableMap<String, RequestBody>
|
||||
): UiState<List<String>?> {
|
||||
val fileParts = fileList.map { file ->
|
||||
//multipart/form-data image/jpeg
|
||||
file.asRequestBody("multipart/form-data".toMediaTypeOrNull())
|
||||
.let { MultipartBody.Part.createFormData("foodPics", file.name, it) }
|
||||
}
|
||||
return repository.uploadFoodVectorData(params, fileParts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.shuwei.dish.match.net
|
||||
|
||||
import com.shuwei.dish.match.model.CookFoodDTO
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
|
||||
/**
|
||||
* 网络数据仓库,封装所有 ApiService 调用
|
||||
* ViewModel 不直接接触 apiService,统一通过此类发起网络请求
|
||||
*/
|
||||
class RemoteRepository {
|
||||
|
||||
/** 统一封装 API 调用:处理响应映射和异常转换,返回 UiState */
|
||||
private suspend fun <T> safeApiCall(call: suspend () -> ApiResponse<T>): UiState<T?> {
|
||||
return try {
|
||||
val resp = call()
|
||||
if (resp.isSuccess()) UiState.Success(resp.data)
|
||||
else UiState.Error(resp.code, resp.msg ?: "")
|
||||
} catch (e: Exception) {
|
||||
UiState.Error("-1", getApiException(e).errorMsg)
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交制作菜品 */
|
||||
suspend fun submitCookFood(entity: CookFoodDTO): UiState<Any?> =
|
||||
safeApiCall { apiService.submitCookFood(param = entity) }
|
||||
|
||||
/** 查询菜品详情 */
|
||||
suspend fun getFoodDetail(foodId: String): UiState<CookFoodDTO?> =
|
||||
safeApiCall { apiService.getFoodDetail(foodId = foodId) }
|
||||
|
||||
/** 搜索菜品列表 */
|
||||
suspend fun searchFoodList(param: MutableMap<String, Any>): UiState<MutableList<FoodRecord>?> =
|
||||
safeApiCall { apiService.searchFoodList(param = param) }
|
||||
|
||||
/** 查询采样数据列表 */
|
||||
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 uploadFoodVectorData(
|
||||
params: MutableMap<String, RequestBody>,
|
||||
foodPics: List<MultipartBody.Part>
|
||||
): UiState<List<String>?> =
|
||||
safeApiCall { apiService.uploadFoodVectorData(params = params, foodPics = foodPics) }
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.shuwei.dish.match.net
|
||||
|
||||
/**
|
||||
* 统一 UI 状态模型,用于 ViewModel 向 UI 层传递请求状态
|
||||
* Idle — 初始状态,未发起请求
|
||||
* Loading — 请求进行中
|
||||
* Success — 请求成功,携带数据
|
||||
* Error — 请求失败,携带错误码和错误信息
|
||||
*/
|
||||
sealed class UiState<out T> {
|
||||
object Idle : UiState<Nothing>()
|
||||
object Loading : UiState<Nothing>()
|
||||
data class Success<T>(val data: T) : UiState<T>()
|
||||
data class Error(val code: String, val msg: String) : UiState<Nothing>()
|
||||
}
|
||||
@@ -12,11 +12,17 @@ import android.util.SparseArray
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.core.view.forEach
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.shuwei.dish.match.R
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.LayoutFoodRemindBinding
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.entity.ResetReasoningRecord
|
||||
import com.shuwei.dish.match.utils.AddressUtil
|
||||
import com.shuwei.dish.match.utils.JsonAssetsLoader
|
||||
import com.shuwei.dish.match.utils.MultiClickDetector
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.appendText
|
||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||
@@ -24,11 +30,12 @@ import com.shuwei.dish.match.utils.ext.dp
|
||||
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.viewmodel.AppViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import com.shuwei.dish.match.adapter.TextCellAdapter
|
||||
import com.shuwei.dish.match.databinding.ActivityDeviceConfigBinding
|
||||
import com.shuwei.dish.match.dialog.BottomDialog2
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.dialog.SeasoningSearchDialog
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
import com.shuwei.dish.match.utils.TextCellTool
|
||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
|
||||
@@ -36,7 +43,7 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
|
||||
const val TAG = "DeviceSettingActivity"
|
||||
const val TAG = "DeviceConfigActivity"
|
||||
|
||||
const val COOK_MODE = "cookMode"
|
||||
|
||||
@@ -54,9 +61,10 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
|
||||
private lateinit var binding: ActivityDeviceConfigBinding
|
||||
|
||||
private var cookMode: Int = 0
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
// private val weightArray = SparseIntArray()
|
||||
private var cookMode: Int = 0
|
||||
// private val weightArray = SparseIntArray()
|
||||
private val weightArray = SparseArray<Double>()
|
||||
private val addressArray = AddressUtil.getWeighAddressArray()
|
||||
|
||||
@@ -65,6 +73,7 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
binding = ActivityDeviceConfigBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
cookMode = intent.getIntExtra(COOK_MODE, 0)
|
||||
initViewModel()
|
||||
setHeaderBackground()
|
||||
setTitleBar(titleBarAction = {
|
||||
it.visible()
|
||||
@@ -72,6 +81,13 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
it.text = "设备配置"
|
||||
}, rightIconActon = {
|
||||
it.gone()
|
||||
// it.alpha = 0.0F
|
||||
// it.setImageResource(R.drawable.ic_setting)
|
||||
// it.setOnClickListener {_->
|
||||
// detector.setOnDelayedMultiClickListener(it) {
|
||||
// defaultDataSettingDialog()
|
||||
// }
|
||||
// }
|
||||
})
|
||||
|
||||
loadQualitySpan(isEnable = false)
|
||||
@@ -104,7 +120,9 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
binding.rbModeSampling.isChecked = false
|
||||
loadCookSpan(isClicked = true)
|
||||
loadSamplingSpan()
|
||||
startActivity<SelectDishActivity> { }
|
||||
startActivity<SelectDishActivity> {
|
||||
putExtra(SelectDishActivity.IS_CONFIG_PAGE, true)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
binding.rbModeSampling.setOnClickListener {
|
||||
@@ -113,7 +131,8 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
binding.rbModeSampling.isChecked = true
|
||||
loadCookSpan()
|
||||
loadSamplingSpan(isClicked = true)
|
||||
startActivity<SamplingListActivity> { }
|
||||
startActivity<SamplingListActivity> {
|
||||
putExtra(SamplingListActivity.IS_CONFIG_PAGE, true) }
|
||||
finish()
|
||||
}
|
||||
addWeighListener()
|
||||
@@ -125,84 +144,131 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
WeightUtil.addWeightListener(
|
||||
weightKey = TAG,
|
||||
getWeight = { address, state, weight ->
|
||||
Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight")
|
||||
weightArray.put(address, weight)
|
||||
val item = seasoningItems.firstOrNull { address == addressArray[it.sort] }
|
||||
item?.let {
|
||||
it.useWeight = weight
|
||||
updateGridData(it)
|
||||
// 根据是否量程溢出切换格子背景色
|
||||
val frameLayout = binding.include.root.findViewWithTag<FrameLayout>(it.sort.toString())
|
||||
frameLayout?.background = if (state == WeightUtil.STATE_OVER_WEIGHT) {
|
||||
ContextCompat.getDrawable(this, R.drawable.shape_red_10_corners)
|
||||
} else {
|
||||
ContextCompat.getDrawable(this, R.drawable.selector_text_cell)
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "addWeighListener: update-----------------------")
|
||||
})
|
||||
Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight")
|
||||
weightArray.put(address, weight)
|
||||
val item = seasoningItems.firstOrNull { address == addressArray[it.sort] }
|
||||
item?.let {
|
||||
it.useWeight = weight.toDouble()
|
||||
updateGridData(it)
|
||||
}
|
||||
Log.d(TAG, "addWeighListener: update-----------------------")
|
||||
})
|
||||
}
|
||||
|
||||
private var seasoningItems = mutableListOf<SeasoningEntity>()
|
||||
|
||||
private fun updateGridData(entity: SeasoningEntity) {
|
||||
val gridLayout = binding.include.root
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellTool.loadLayout(frameLayout, entity)
|
||||
}
|
||||
|
||||
private fun addGridItemListener() {
|
||||
binding.include.root.forEach { child ->
|
||||
child.clickWithDebounce {
|
||||
val sort = child.tag.toString().toInt()
|
||||
val entity = seasoningItems.firstOrNull { it.sort == sort }
|
||||
?: SeasoningEntity().also { it.sort = sort }
|
||||
val entity = seasoningItems.firstOrNull { it.sort == sort } ?: SeasoningEntity()
|
||||
clickGridItem(sort, entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadSeasoning() {
|
||||
Log.d(TAG, "loadSeasoning,start-----------------------")
|
||||
appViewModel.loadSeasoning { list ->
|
||||
Log.d(TAG, "loadSeasoning,list.size=${list.size}-----------------------")
|
||||
seasoningItems.clear()
|
||||
// 补全缺失的格子:对 0~11 中没有对应 sort 的位置,追加空实体
|
||||
val existingSorts = list.map { it.sort }.toSet()
|
||||
for (index in 0 until 12) {
|
||||
if (index !in existingSorts) {
|
||||
list.add(SeasoningEntity().also { it.sort = index })
|
||||
}
|
||||
val detector = MultiClickDetector(targetCount = 10, intervalMs = 800)
|
||||
|
||||
private fun defaultDataSettingDialog() {
|
||||
val remindBinding = LayoutFoodRemindBinding.inflate(layoutInflater)
|
||||
remindBinding.tvDialogTitle.text = "温馨提示"
|
||||
remindBinding.tvDialogContent.text =
|
||||
"您好,使用默认配置作为您的调料数据,则已有配置将被清除,确认吗?"
|
||||
CommonDialog(this).apply {
|
||||
messageView = remindBinding.root
|
||||
leftText = "取消"
|
||||
rightText = "确认"
|
||||
onLeftClick = { dismiss() }
|
||||
onRightClick = {
|
||||
dismiss()
|
||||
resetList()
|
||||
}
|
||||
seasoningItems.addAll(list)
|
||||
// 按 sort 字段找到对应 FrameLayout,填充数据
|
||||
list.forEach { entity ->
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = binding.include.root.findViewWithTag<FrameLayout>(tag)
|
||||
frameLayout?.let { TextCellTool.loadLayout(it, entity) }
|
||||
onDismiss = { hideStatusBar() }
|
||||
}.show()
|
||||
}
|
||||
|
||||
private fun resetList() {
|
||||
runCatching {
|
||||
val record = JsonAssetsLoader.parseJsonFromAssets<ResetReasoningRecord>(
|
||||
this,
|
||||
"default_seasoning_list.json"
|
||||
)
|
||||
// val weightArray = WeightUtil.weightArray
|
||||
appViewModel.clearAllSeasoning {
|
||||
record?.list?.forEach { entity ->
|
||||
entity.useWeight = weightArray[addressArray[entity.sort]].toDouble()
|
||||
appViewModel.saveSeasoning(entity) {
|
||||
updateGridData(entity)
|
||||
}
|
||||
}
|
||||
// loadSeasoning()
|
||||
}
|
||||
}.onFailure { it.printStackTrace() }
|
||||
}
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory =
|
||||
AppFactory(AppRepository(db.appDao()))
|
||||
appViewModel =
|
||||
ViewModelProvider(this, factory)[AppViewModel::class.java]
|
||||
}
|
||||
|
||||
private fun loadSeasoning() {
|
||||
appViewModel.loadSeasoning {
|
||||
seasoningItems.clear()
|
||||
seasoningItems.addAll(it)
|
||||
initConfigData()
|
||||
setGridData(seasoningItems)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initConfigData() {
|
||||
repeat(12) { num ->
|
||||
val firstOne = seasoningItems.firstOrNull { it.sort == num }
|
||||
if (firstOne == null) {
|
||||
seasoningItems.add(SeasoningEntity().also { it.sort = num })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setGridData(list: MutableList<SeasoningEntity>) {
|
||||
val gridLayout = binding.include.root
|
||||
list.forEach { entity ->
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateGridData(entity: SeasoningEntity) {
|
||||
val gridLayout = binding.include.root
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
|
||||
private fun clickGridItem(sort: Int, entity: SeasoningEntity) {
|
||||
val currentAddress = AddressUtil.getWeighAddressArray().get(sort)
|
||||
BottomDialog2(
|
||||
// val seasoningEntity = list.first{it.sort == sort}
|
||||
SeasoningSearchDialog(
|
||||
weighIndex = sort,
|
||||
weighAddress = currentAddress,
|
||||
clickName = entity.goodsName
|
||||
).show(this) { item ->
|
||||
syncItem(entity, item)
|
||||
//3-调料
|
||||
entity.materialType = 3
|
||||
entity.sort = sort
|
||||
saveSeasoning(entity) {
|
||||
val frameLayout = binding.include.root.findViewWithTag<FrameLayout>(sort.toString())
|
||||
frameLayout?.let { TextCellTool.loadLayout(it, entity) }
|
||||
val tag = sort.toString()
|
||||
val gridLayout = binding.include.root
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun syncItem(oldItem: SeasoningEntity, newItem: GoodsItem) {
|
||||
private fun syncItem(oldItem: SeasoningEntity, newItem: SeasoningEntity) {
|
||||
oldItem.run {
|
||||
goodsId = newItem.goodsId
|
||||
goodsName = newItem.goodsName
|
||||
@@ -212,6 +278,11 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
allEdible = newItem.allEdible
|
||||
useWeight = newItem.useWeight
|
||||
popularName = newItem.popularName
|
||||
canteenId = newItem.canteenId
|
||||
relateionType_dictText = newItem.relateionType_dictText
|
||||
|
||||
foodId = newItem.foodId
|
||||
sort = newItem.sort
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,20 +5,26 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.activity.viewModels
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.DishPartAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivityDishSamplingBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutFoodRemindBinding
|
||||
|
||||
import com.shuwei.dish.match.dialog.BottomDialog
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.dialog.FoodSearchDialog
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.net.NetViewModel
|
||||
import com.shuwei.dish.match.utils.AddressUtil
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.SwipeCallback
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||
@@ -27,6 +33,8 @@ import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.toJsonString
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import com.shuwei.dish.match.viewmodel.AppViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import java.io.Serializable
|
||||
|
||||
class DishSamplingActivity : BaseActivity() {
|
||||
@@ -54,6 +62,7 @@ class DishSamplingActivity : BaseActivity() {
|
||||
setTitleBar()
|
||||
setHeaderBackground()
|
||||
addViewClickListener()
|
||||
initViewModel()
|
||||
foodName = intent.getStringExtra(FOOD_NAME)
|
||||
binding.etInputDish.setText(foodName)
|
||||
|
||||
@@ -87,6 +96,16 @@ class DishSamplingActivity : BaseActivity() {
|
||||
})
|
||||
}
|
||||
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory =
|
||||
AppFactory(AppRepository(db.appDao()))
|
||||
appViewModel =
|
||||
ViewModelProvider(this, factory)[AppViewModel::class.java]
|
||||
}
|
||||
|
||||
fun getCookFoodList(action: (MutableList<CookFoodEntity>?) -> Unit) {
|
||||
appViewModel.getCookFoodList(cookMode = 1) { action(it) }
|
||||
}
|
||||
@@ -127,9 +146,9 @@ class DishSamplingActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
|
||||
val list: MutableList<GoodsItem> = mutableListOf()
|
||||
val list: MutableList<CookFoodGoodsEntity> = mutableListOf()
|
||||
|
||||
private var tempDishEntity: GoodsItem? = null
|
||||
private var tempDishEntity: CookFoodGoodsEntity? = null
|
||||
|
||||
private var dishMaterialType = 1
|
||||
|
||||
@@ -150,6 +169,13 @@ class DishSamplingActivity : BaseActivity() {
|
||||
layoutManager =
|
||||
LinearLayoutManager(this@DishSamplingActivity, LinearLayoutManager.VERTICAL, false)
|
||||
adapter = dishAdapter
|
||||
val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position ->
|
||||
list.removeAt(position)
|
||||
dishAdapter.notifyItemRemoved(position)
|
||||
dishAdapter.notifyItemRangeChanged(position, list.size - position)
|
||||
toast("已删除")
|
||||
})
|
||||
itemTouchHelper.attachToRecyclerView(this)
|
||||
}
|
||||
binding.etInputDishType.addOnActionSearchListener {
|
||||
searchDishType()
|
||||
@@ -221,7 +247,7 @@ class DishSamplingActivity : BaseActivity() {
|
||||
Log.d(TAG, "goToSubmit: goodsList:${list.toJsonString()}")
|
||||
// startActivity<SubmitDishActivity> {
|
||||
startActivity<SubmitFoodActivity> {
|
||||
putExtra(SubmitFoodActivity.GOODS_LIST, list.map { it.toCookFoodGoodsEntity() }.toMutableList() as java.io.Serializable)
|
||||
putExtra(SubmitFoodActivity.GOODS_LIST, list as java.io.Serializable)
|
||||
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
|
||||
}
|
||||
}
|
||||
@@ -251,7 +277,7 @@ class DishSamplingActivity : BaseActivity() {
|
||||
|
||||
private fun searchDishType() {
|
||||
val inputText = binding.etInputDishType.text.toString().trim()
|
||||
BottomDialog(goodsType = 0, defGoodsName = inputText).show(this@DishSamplingActivity) { item ->
|
||||
FoodSearchDialog(defGoodsName = inputText).show(this@DishSamplingActivity) { item ->
|
||||
val filterResult = list.firstOrNull { it.goodsName == item.goodsName }
|
||||
if (filterResult != null) {
|
||||
toast("不允许重复添加同一食材")
|
||||
@@ -261,7 +287,17 @@ class DishSamplingActivity : BaseActivity() {
|
||||
setText(item.goodsName)
|
||||
setSelection(length())
|
||||
}
|
||||
tempDishEntity = item
|
||||
tempDishEntity = CookFoodGoodsEntity().apply {
|
||||
goodsId = item.goodsId
|
||||
goodsName = item.goodsName
|
||||
|
||||
relateionType = item.relateionType ?: 0
|
||||
goodsOrRelationCode = item.goodsOrRelationCode
|
||||
|
||||
isNewDishType = true
|
||||
// TODO: 待定
|
||||
//allEdible = item.allEdible
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,7 @@ 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.LayoutEmptyViewBinding
|
||||
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
@@ -36,7 +34,7 @@ class FoodSearchActivity : BaseActivity() {
|
||||
|
||||
private var list: MutableList<FoodRecord> = mutableListOf()
|
||||
private var pageType = 0
|
||||
private var dinnerType = "0"
|
||||
private var dinnerType = "1"
|
||||
private val recordAdapter by lazy {
|
||||
FoodRecordAdapter(list).apply {
|
||||
isStateViewEnable = true
|
||||
@@ -64,7 +62,7 @@ class FoodSearchActivity : BaseActivity() {
|
||||
binding = ActivityFoodSearchBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
pageType = intent.getIntExtra(PAGE_TYPE, 0)
|
||||
dinnerType = intent.getStringExtra(DINNER_TYPE)?:"0"
|
||||
dinnerType = intent.getStringExtra(DINNER_TYPE) ?: "0"
|
||||
setHeaderBackground()
|
||||
foodName = intent.getStringExtra(FOOD_NAME)
|
||||
binding.etInputDish.setText(foodName)
|
||||
@@ -130,7 +128,7 @@ class FoodSearchActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private var pageNo = 1
|
||||
private var pageSize = 100
|
||||
private var pageSize = 10
|
||||
fun getDinnerTypeText(): String {
|
||||
return when (dinnerType) {
|
||||
"1" -> "早餐"
|
||||
@@ -139,58 +137,107 @@ class FoodSearchActivity : BaseActivity() {
|
||||
else -> "早餐"
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun queryListInfo(input: String) {
|
||||
showLoading()
|
||||
val param = mutableMapOf<String, Any>(
|
||||
// val map = mutableMapOf(
|
||||
// "foodName" to input.trim(),
|
||||
// "pageNo" to "$pageNo",
|
||||
// "pageSize" to "$pageSize",
|
||||
// "canteenId" to BaseApp.canteenId
|
||||
// "dinnerType" to getDinnerTypeText()
|
||||
// )
|
||||
// val sb = StringBuilder(UrlConfig.QUERY_FOOD_LIST).apply {
|
||||
// append("?")
|
||||
// map.forEach { (key, value) -> append("$key=$value&") }
|
||||
// }
|
||||
// sb.deleteCharAt(sb.length - 1)
|
||||
// HttpUtil.get(
|
||||
// url = sb.toString(),
|
||||
// doSuccess = {
|
||||
// delayDismissLoading()
|
||||
// finishRefresh()
|
||||
// binding.refreshLayout.run {
|
||||
// setEnableRefresh(true)
|
||||
// }
|
||||
// val json = it.toJsonString()
|
||||
// val recordBean: FoodRecordBean? = json.toObject<FoodRecordBean>()
|
||||
// if (recordBean == null || recordBean.records.isNullOrEmpty()) {
|
||||
//// toast("暂未搜索到相关菜品信息")
|
||||
// if (pageNo == 1) {
|
||||
// loadEmptyView()
|
||||
// }
|
||||
// return@get
|
||||
// }
|
||||
// val records = recordBean.records
|
||||
// if (pageNo == 1) {
|
||||
// list.clear()
|
||||
// }
|
||||
// list.addAll(records!!)
|
||||
// recordAdapter.notifyDataSetChanged()
|
||||
// val isLoadMoreEnable = records.size >= pageSize
|
||||
// binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
// if (isLoadMoreEnable) {
|
||||
// pageNo++
|
||||
// }
|
||||
// },
|
||||
// doFailure = { code, msg ->
|
||||
// binding.refreshLayout.run {
|
||||
// setEnableRefresh(true)
|
||||
// }
|
||||
// toast(msg)
|
||||
// delayDismissLoading()
|
||||
// finishRefresh()
|
||||
// if (pageNo == 1) {
|
||||
// loadEmptyView()
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
|
||||
val map = mutableMapOf<String, Any>(
|
||||
"foodName" to input.trim(),
|
||||
"pageNo" to pageNo,
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize,
|
||||
"canteenId" to BaseApp.canteenId
|
||||
"placeId" to BaseApp.canteenId,
|
||||
"dinnerType" to getDinnerTypeText()
|
||||
)
|
||||
if (dinnerType.toInt() > 0) {
|
||||
param["dinnerType"] = getDinnerTypeText()
|
||||
}
|
||||
netViewModel.searchFoodListWithCallback(
|
||||
param = param,
|
||||
onResult = { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> {
|
||||
delayDismissLoading()
|
||||
finishRefresh()
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
val records = state.data
|
||||
if (records.isNullOrEmpty()) {
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
return@searchFoodListWithCallback
|
||||
}
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(records)
|
||||
recordAdapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) {
|
||||
pageNo++
|
||||
}
|
||||
netViewModel.searchFoodList(
|
||||
param = map,
|
||||
onSuccess = {
|
||||
delayDismissLoading()
|
||||
finishRefresh()
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
if (it.isNullOrEmpty()) {
|
||||
// toast("暂未搜索到相关菜品信息")
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
is UiState.Error -> {
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
toast(state.msg)
|
||||
delayDismissLoading()
|
||||
finishRefresh()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
return@searchFoodList
|
||||
}
|
||||
}
|
||||
)
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(it)
|
||||
recordAdapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = it.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) {
|
||||
pageNo++
|
||||
}
|
||||
}, onFailure = { code, msg ->
|
||||
binding.refreshLayout.run {
|
||||
setEnableRefresh(true)
|
||||
}
|
||||
toast(msg)
|
||||
delayDismissLoading()
|
||||
finishRefresh()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun finishRefresh() {
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh(1200)
|
||||
@@ -200,12 +247,17 @@ class FoodSearchActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private var emptyViewBinding: LayoutEmptyViewBinding? = null
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadEmptyView() {
|
||||
list.clear()
|
||||
recordAdapter.notifyDataSetChanged()
|
||||
if (emptyViewBinding == null) {
|
||||
emptyViewBinding = LayoutEmptyViewBinding.inflate(LayoutInflater.from(this), binding.rvDishSearchList, false)
|
||||
emptyViewBinding = LayoutEmptyViewBinding.inflate(
|
||||
LayoutInflater.from(this),
|
||||
binding.rvDishSearchList,
|
||||
false
|
||||
)
|
||||
}
|
||||
emptyViewBinding!!.tvContent.text = "暂无数据"
|
||||
emptyViewBinding!!.tvSubContent.text = "可以尝试换个名称重新搜索"
|
||||
|
||||
@@ -2,18 +2,20 @@ package com.shuwei.dish.match.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.HomeModeAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivityHomeBinding
|
||||
|
||||
import com.shuwei.dish.match.model.HomeModeBean
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.entity.HomeModeBean
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.viewmodel.AppViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
|
||||
class HomeActivity : BaseActivity() {
|
||||
|
||||
@@ -29,6 +31,7 @@ class HomeActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
statusBarDarkFont(enable = true)
|
||||
initViewModel()
|
||||
// // 获取 ANDROID_ID
|
||||
// val deviceId =
|
||||
// Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
|
||||
@@ -38,7 +41,7 @@ class HomeActivity : BaseActivity() {
|
||||
binding = ActivityHomeBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setHeaderBackground(isHomePage = true)
|
||||
binding.radioGroup.setOnCheckedChangeListener { _, checkedId ->
|
||||
binding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
|
||||
if (checkedId == R.id.radioSw) {
|
||||
BaseApp.canteenId = "1678234139391512577"
|
||||
} else {
|
||||
@@ -129,6 +132,14 @@ class HomeActivity : BaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(AppRepository(db.appDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[AppViewModel::class.java]
|
||||
}
|
||||
|
||||
private fun goSampling() {
|
||||
appViewModel.loadSeasoning {
|
||||
if (it.isEmpty()) {
|
||||
|
||||
@@ -3,24 +3,25 @@ package com.shuwei.dish.match.ui
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.shuwei.dish.match.BuildConfig
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivityInitBinding
|
||||
import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.http.UrlConfig
|
||||
import com.shuwei.dish.match.utils.AppUtil
|
||||
import com.shuwei.dish.match.utils.QRCodeUtil
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.invisible
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
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.toObject
|
||||
import com.shuwei.dish.match.viewmodel.AppViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.toString
|
||||
|
||||
class InitActivity : BaseActivity() {
|
||||
companion object {
|
||||
@@ -28,6 +29,8 @@ class InitActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityInitBinding
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
@SuppressLint("HardwareIds")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -41,14 +44,11 @@ class InitActivity : BaseActivity() {
|
||||
BaseApp.appVersion = AppUtil.getAppVersionCode(this).toString()
|
||||
|
||||
// 获取 ANDROID_ID
|
||||
// var androidId =
|
||||
// Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
|
||||
// var androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
|
||||
// androidId = "39a7abdd06b3c7ab"
|
||||
val deviceId = if (BuildConfig.IS_TEST_DEVICE) GlobalData.DEVICE_ID_2 else AppUtil.getUDID(this)
|
||||
GlobalData.deviceId = deviceId
|
||||
SpTool.put(SpTool.DEVICE_ID, deviceId)
|
||||
// GlobalData.appBaseUrl = GlobalData.TEST_BASE_URL
|
||||
GlobalData.appBaseUrl = GlobalData.PROD_BASE_URL
|
||||
// BaseApp.deviceId = androidId
|
||||
// SpTool.put(SpTool.DEVICE_ID, androidId)
|
||||
// BaseApp.configUrl = UrlConfig.BASE_URL
|
||||
BaseApp.canteenId = "0"
|
||||
// // TODO: 以上保存deviceId用于临时使用,后续改为下面注释方式
|
||||
|
||||
@@ -71,15 +71,25 @@ class InitActivity : BaseActivity() {
|
||||
// return
|
||||
// }
|
||||
|
||||
binding.ivQrCode.invisible()
|
||||
binding.btnInit.invisible()
|
||||
// binding.ivQrCode.invisible()
|
||||
// binding.btnInit.invisible()
|
||||
|
||||
initViewModel()
|
||||
WeightUtil.init()
|
||||
WeightUtil.getWeight()
|
||||
WeightUtil.startContinuousRead()
|
||||
// HttpUtil.getAppToken()
|
||||
|
||||
// HttpUtil.loopGetToken = true
|
||||
countDown()
|
||||
}
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(AppRepository(db.appDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[AppViewModel::class.java]
|
||||
}
|
||||
|
||||
private fun startNextPage() {
|
||||
val launchPageType = SpTool.getInt(SpTool.LAUNCH_PAGE_TYPE, -1)
|
||||
when (launchPageType) {
|
||||
@@ -139,6 +149,72 @@ class InitActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
// private fun initConfig() {
|
||||
// binding.ivQrCode.setImageBitmap(
|
||||
// QRCodeUtil.generateQRCode(
|
||||
// content = BaseApp.deviceId ?: "",
|
||||
// size = 200.dp
|
||||
// )
|
||||
// )
|
||||
// binding.btnInit.setOnClickListener {
|
||||
//// HttpUtil.loopGetToken = false
|
||||
//// getDeviceConfig()
|
||||
// }
|
||||
// }
|
||||
|
||||
// private fun getDeviceConfig() {
|
||||
// val tokenUrl =
|
||||
// "${UrlConfig.DEVICE_TOKEN}?qrcodeId=${BaseApp.deviceId}&appVersion=${BaseApp.appVersion}"
|
||||
// HttpUtil.get(url = tokenUrl, doSuccess = { token ->
|
||||
// Log.d(TAG, "initConfig: $token")
|
||||
// getConfig(token.toString())
|
||||
// }, doFailure = { code, msg ->
|
||||
// Log.d(TAG, "initConfig: $code,$msg")
|
||||
// })
|
||||
// }
|
||||
|
||||
// private fun getConfig(token: String) {
|
||||
// val deviceConfigUrl =
|
||||
// "${UrlConfig.DEVICE_CONFIG}?equipmentCode=${BaseApp.deviceId}&&appVersion=${BaseApp.appVersion}"
|
||||
// HttpUtil.get(
|
||||
// url = deviceConfigUrl, header = mutableMapOf(
|
||||
// "X-Access-Token" to token
|
||||
// ), doSuccess = {
|
||||
// Log.d(TAG, "getDeviceConfig: $it")
|
||||
// val data = it.toJsonString()
|
||||
// val checkResult = checkConfigData(data)
|
||||
// if (checkResult.not()) {
|
||||
// toast("初始化设备失败,请稍后重试")
|
||||
// return@get
|
||||
// }
|
||||
// HttpUtil.loopGetToken = true
|
||||
// SpTool.put(SpTool.DEVICE_CONFIG_CACHE, data)
|
||||
// startActivity<HomeActivity>()
|
||||
//// finish()
|
||||
// }, doFailure = { code, msg ->
|
||||
// Log.d(TAG, "getDeviceConfig: $code,$msg")
|
||||
// toast("初始化设备失败,请稍后重试,code=${code},msg=${msg}")
|
||||
// })
|
||||
// }
|
||||
|
||||
data class DeviceConfigBean(
|
||||
var appPackageUrl: String? = null,
|
||||
var canteenId: String? = null
|
||||
)
|
||||
|
||||
// private fun checkConfigData(data: String): Boolean {
|
||||
// if (data.isBlank()) {
|
||||
// return false
|
||||
// }
|
||||
// val config = data.toObject<DeviceConfigBean?>()
|
||||
// if (config == null) {
|
||||
// return false
|
||||
// }
|
||||
// BaseApp.configUrl = config.appPackageUrl ?: ""
|
||||
// BaseApp.canteenId = config.canteenId ?: ""
|
||||
// return true
|
||||
// }
|
||||
|
||||
override fun onDestroy() {
|
||||
WeightUtil.stopContinuousRead()
|
||||
super.onDestroy()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.shuwei.dish.match.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.viewModels
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
@@ -12,17 +12,12 @@ import com.shuwei.dish.match.adapter.DishPartAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.databinding.ActivityPrepareCookBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutFoodRemindBinding
|
||||
import com.shuwei.dish.match.dialog.BottomDialog
|
||||
import com.shuwei.dish.match.dialog.FoodSearchDialog
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.model.CookFoodDTO
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import kotlinx.coroutines.launch
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.net.NetViewModel
|
||||
import com.shuwei.dish.match.utils.AddressUtil
|
||||
import com.shuwei.dish.match.utils.SwipeCallback
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
@@ -33,6 +28,7 @@ import com.shuwei.dish.match.utils.ext.toJsonString
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import java.io.Serializable
|
||||
import kotlin.getValue
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
class PrepareCookActivity : BaseActivity() {
|
||||
@@ -47,6 +43,8 @@ class PrepareCookActivity : BaseActivity() {
|
||||
private var food: FoodRecord? = null
|
||||
|
||||
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityPrepareCookBinding.inflate(layoutInflater)
|
||||
@@ -70,7 +68,9 @@ class PrepareCookActivity : BaseActivity() {
|
||||
food = intent.extras?.getSerializable(FOOD_ITEM) as FoodRecord?
|
||||
binding.tvDishName.text = food?.foodName ?: ""
|
||||
addViewClickListener()
|
||||
initObserver()
|
||||
|
||||
initRecyclerView()
|
||||
|
||||
getDishDetail()
|
||||
}
|
||||
|
||||
@@ -86,50 +86,18 @@ class PrepareCookActivity : BaseActivity() {
|
||||
binding.ivWeightClear.setOnClickListener {
|
||||
WeightUtil.tareTwo(AddressUtil.ONE)
|
||||
}
|
||||
binding.ivWeightAdd.setOnClickListener {
|
||||
if (clickIndex == -1) {
|
||||
toast("请选择菜品构成")
|
||||
return@setOnClickListener
|
||||
}
|
||||
val clickItem = list[clickIndex]
|
||||
clickItem.run {
|
||||
if (isNewDishType && materialType != 1 && materialType != 2) {
|
||||
toast("请选择主辅材类型")
|
||||
return@setOnClickListener
|
||||
}
|
||||
}
|
||||
val weight = binding.tvDishPartWeight.text.toString().toDoubleOrNull() ?:0.toDouble()
|
||||
if (weight <= 0.toDouble()) {
|
||||
toast("食材用量需要大于0")
|
||||
return@setOnClickListener
|
||||
}
|
||||
Log.d(TAG, "addViewClickListener->useRealWeight=$weight")
|
||||
clickItem.run {
|
||||
useWeight = weight.toDouble()
|
||||
isSetFinished = true
|
||||
dishPartAdapter.notifyItemChanged(clickIndex)
|
||||
}
|
||||
}
|
||||
binding.tvAddFood.clickWithDebounce {
|
||||
BottomDialog(goodsType = 0).show(this) { item ->
|
||||
val filterResult = list.firstOrNull { it.goodsId == item.goodsId }
|
||||
if (filterResult != null) {
|
||||
toast("不允许重复添加同一食材")
|
||||
return@show
|
||||
}
|
||||
list.add(GoodsItem(goodsId = item.goodsId, goodsName = item.goodsName, isNewDishType = true))
|
||||
onItemClick(list.size - 1)
|
||||
}
|
||||
}
|
||||
binding.ivWeightAdd.setOnClickListener { addWeight() }
|
||||
binding.tvAddFood.clickWithDebounce { addFood() }
|
||||
binding.btnCook.clickWithDebounce {
|
||||
val count = list.count { it.isSetFinished.not() }
|
||||
if (count > 0) {
|
||||
showRemindDialog()
|
||||
return@clickWithDebounce
|
||||
}
|
||||
goToSubmit()
|
||||
openSubmitPage()
|
||||
}
|
||||
binding.rgCook.setOnCheckedChangeListener { group, checkedId ->
|
||||
if (clickIndex < 0 || clickIndex >= list.size) return@setOnCheckedChangeListener
|
||||
val tempType =
|
||||
if (checkedId == R.id.rbDishTypeFirst) 1 else if (checkedId == R.id.rbDishTypeSecond) 2 else -1
|
||||
list[clickIndex].materialType = tempType
|
||||
@@ -140,14 +108,58 @@ class PrepareCookActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun goToSubmit() {
|
||||
private fun addWeight() {
|
||||
if (clickIndex == -1) {
|
||||
toast("请选择菜品构成")
|
||||
return
|
||||
}
|
||||
val clickItem = list[clickIndex]
|
||||
clickItem.run {
|
||||
if (isNewDishType && materialType != 1 && materialType != 2) {
|
||||
toast("请选择主辅材类型")
|
||||
return
|
||||
}
|
||||
}
|
||||
val weight = binding.tvDishPartWeight.text.toString().toDouble()
|
||||
if (weight <= 0.toDouble()) {
|
||||
toast("食材用量需要大于0")
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "addViewClickListener->useRealWeight=$weight")
|
||||
clickItem.run {
|
||||
useWeight = weight
|
||||
isOriginalData = false
|
||||
isSetFinished = true
|
||||
dishPartAdapter.notifyItemChanged(clickIndex)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addFood() {
|
||||
FoodSearchDialog().show(this) { item ->
|
||||
val filterResult = list.firstOrNull { it.goodsId == item.goodsId }
|
||||
if (filterResult != null) {
|
||||
toast("不允许重复添加同一食材")
|
||||
return@show
|
||||
}
|
||||
list.add(CookFoodGoodsEntity().apply {
|
||||
goodsId = item.goodsId
|
||||
goodsName = item.goodsName
|
||||
// materialType =
|
||||
isNewDishType = true
|
||||
isOriginalData = false
|
||||
})
|
||||
onItemClick(list.size - 1)
|
||||
binding.rvDishPartList.smoothScrollToPosition(list.size - 1)
|
||||
}
|
||||
}
|
||||
|
||||
private fun openSubmitPage() {
|
||||
getGoodsList()
|
||||
if (goodsList.isNullOrEmpty()) {
|
||||
toast("菜品构成信息未设置")
|
||||
toast("无菜品构成信息")
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "goToSubmit: goodsList:${goodsList?.toJsonString()}")
|
||||
// startActivity<SubmitDishActivity> {
|
||||
startActivity<SubmitFoodActivity> {
|
||||
putExtra(SubmitFoodActivity.GOODS_LIST, goodsList as Serializable)
|
||||
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
|
||||
@@ -158,12 +170,17 @@ class PrepareCookActivity : BaseActivity() {
|
||||
if (goodsList == null) {
|
||||
goodsList = mutableListOf()
|
||||
}
|
||||
list.forEach {
|
||||
if (it.isSetFinished) {
|
||||
goodsList?.add(it.toCookFoodGoodsEntity().also { entity ->
|
||||
entity.foodId = food!!.foodId
|
||||
})
|
||||
}
|
||||
list.filter { it.isSetFinished }.forEach {
|
||||
goodsList?.add(CookFoodGoodsEntity().apply {
|
||||
foodId = food!!.foodId
|
||||
goodsId = it.goodsId
|
||||
relateionType = it.relateionType
|
||||
allEdible = it.allEdible
|
||||
goodsName = it.goodsName
|
||||
materialType = it.materialType
|
||||
useWeight = it.useWeight ?: 0.toDouble()
|
||||
goodsOrRelationCode = it.goodsOrRelationCode
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +192,7 @@ class PrepareCookActivity : BaseActivity() {
|
||||
rightText = "确认无误"
|
||||
onLeftClick = { dismiss() }
|
||||
onRightClick = {
|
||||
goToSubmit()
|
||||
openSubmitPage()
|
||||
dismiss()
|
||||
}
|
||||
onDismiss = { hideStatusBar() }
|
||||
@@ -183,53 +200,57 @@ class PrepareCookActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
|
||||
private fun initObserver() {
|
||||
lifecycleScope.launch {
|
||||
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
netViewModel.foodDetailState.collect { state ->
|
||||
when (state) {
|
||||
is UiState.Loading -> showLoading()
|
||||
is UiState.Success -> {
|
||||
dismissLoading()
|
||||
netViewModel.resetFoodDetailState()
|
||||
val detail = state.data
|
||||
if (detail == null) {
|
||||
toast("查询菜品信息为空")
|
||||
return@collect
|
||||
}
|
||||
loadDishDetail(detail)
|
||||
}
|
||||
is UiState.Error -> {
|
||||
dismissLoading()
|
||||
toast(state.msg)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDishDetail() {
|
||||
netViewModel.getFoodDetail(food?.foodId ?: "")
|
||||
// //649
|
||||
// val url = "${UrlConfig.DISH_DETAIL}?foodId=${food?.foodId}"
|
||||
// HttpUtil.get(
|
||||
// url = url,
|
||||
// doSuccess = {
|
||||
// val json = it.toJsonString()
|
||||
// Log.d(TAG, "getDishDetail: json:$json")
|
||||
// val detail: CookFoodEntity? = json.toObject<CookFoodEntity>()
|
||||
// if (detail == null) {
|
||||
// toast("查询菜品信息为空")
|
||||
// return@get
|
||||
// }
|
||||
// loadDishDetail(detail)
|
||||
// }) { code, msg ->
|
||||
// toast(msg)
|
||||
// }
|
||||
|
||||
netViewModel.getFoodDetail(
|
||||
food?.foodId ?: "",
|
||||
onSuccess = { detail ->
|
||||
if (detail == null) {
|
||||
toast("查询菜品信息为空")
|
||||
return@getFoodDetail
|
||||
}
|
||||
loadDishDetail(detail)
|
||||
}, onFailure = { code, msg ->
|
||||
toast(msg)
|
||||
})
|
||||
}
|
||||
|
||||
private fun loadDishDetail(detail: CookFoodDTO) {
|
||||
|
||||
private fun loadDishDetail(detail: CookFoodEntity) {
|
||||
// val voList = detail.stFoodInfoConstituteList
|
||||
val voList = detail.foodConstituteList
|
||||
if (voList.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
//筛选出主材和辅材
|
||||
val tempDate = voList.filter { it.materialType == 1 || it.materialType == 2 }
|
||||
.map { it.toGoodsItem().also { item -> item.useWeight = 0.0 } }
|
||||
val tempData = voList.filter { it.materialType == 1 || it.materialType == 2 }
|
||||
.apply {
|
||||
forEach { it.useWeight = 0.toDouble() }
|
||||
}
|
||||
list.clear()
|
||||
list.addAll(tempDate)
|
||||
firstReqSize = list.size
|
||||
initRecyclerView()
|
||||
list.addAll(tempData)
|
||||
dishPartAdapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private var firstReqSize = 0
|
||||
private val list = mutableListOf<GoodsItem>()
|
||||
private val list = mutableListOf<CookFoodGoodsEntity>()
|
||||
private val dishPartAdapter by lazy {
|
||||
DishPartAdapter(list).apply {
|
||||
setOnItemClickListener { _, _, positon ->
|
||||
@@ -245,10 +266,28 @@ class PrepareCookActivity : BaseActivity() {
|
||||
text = it.goodsName
|
||||
setTypeface(typeface, Typeface.BOLD)
|
||||
}
|
||||
binding.tvDishType.text =
|
||||
if (it.materialType == 1) "主材" else if (it.materialType == 2) "辅材" else ""
|
||||
list.forEach { bean -> bean.isClicked = false }
|
||||
it.isClicked = true
|
||||
|
||||
var materialType: String
|
||||
when (it.materialType) {
|
||||
1 -> {
|
||||
materialType = "主材"
|
||||
binding.rgCook.check(R.id.rbDishTypeFirst)
|
||||
}
|
||||
|
||||
2 -> {
|
||||
materialType = "辅材"
|
||||
binding.rgCook.check(R.id.rbDishTypeSecond)
|
||||
}
|
||||
|
||||
else -> {
|
||||
materialType = ""
|
||||
binding.rgCook.clearCheck()
|
||||
}
|
||||
}
|
||||
binding.tvDishType.text = materialType
|
||||
|
||||
list.forEach { bean -> bean.isItemClicked = false }
|
||||
it.isItemClicked = true
|
||||
dishPartAdapter.notifyDataSetChanged()
|
||||
|
||||
if (it.isNewDishType) {
|
||||
@@ -279,6 +318,9 @@ class PrepareCookActivity : BaseActivity() {
|
||||
dishPartAdapter.notifyItemRemoved(position)
|
||||
dishPartAdapter.notifyItemRangeChanged(position, list.size - position)
|
||||
toast("已删除")
|
||||
if (list.isEmpty()) {
|
||||
binding.tvDishShowName.text = ""
|
||||
}
|
||||
})
|
||||
itemTouchHelper.attachToRecyclerView(this)
|
||||
}
|
||||
@@ -288,17 +330,23 @@ class PrepareCookActivity : BaseActivity() {
|
||||
@SuppressLint("GestureBackNavigation")
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onBackPressed() {
|
||||
if (list.size > firstReqSize) {
|
||||
//说明有新增的食材
|
||||
saveDataRemindDialog()
|
||||
return
|
||||
}
|
||||
val filterResult = list.firstOrNull { (it.useWeight ?: 0.toDouble()) > 0.toDouble() }
|
||||
if (filterResult != null) {
|
||||
//说明有称重的数据
|
||||
val count = list.count { !it.isOriginalData }
|
||||
if (count > 0) {
|
||||
//说明有新增或者设置重量
|
||||
saveDataRemindDialog()
|
||||
return
|
||||
}
|
||||
// if (list.size > firstReqSize) {
|
||||
// //说明有新增的食材
|
||||
// saveDataRemindDialog()
|
||||
// return
|
||||
// }
|
||||
// val filterResult = list.firstOrNull { (it.useWeight ?: 0.toDouble()) > 0.toDouble() }
|
||||
// if (filterResult != null) {
|
||||
// //说明有称重的数据
|
||||
// saveDataRemindDialog()
|
||||
// return
|
||||
// }
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@ package com.shuwei.dish.match.ui
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
@@ -14,17 +13,18 @@ import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivitySamplingBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.dialog.DialogTool
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.utils.DateTimeUtil
|
||||
import com.shuwei.dish.match.utils.SwipeCallback
|
||||
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.visible
|
||||
import com.shuwei.dish.match.viewmodel.AppViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import java.io.Serializable
|
||||
|
||||
class SamplingListActivity : BaseActivity() {
|
||||
@@ -34,6 +34,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
companion object {
|
||||
private const val TAG = "SamplingListActivity"
|
||||
const val IS_COOKING = "isCooking"
|
||||
const val IS_CONFIG_PAGE = "isConfigPage"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -42,6 +43,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
setContentView(binding.root)
|
||||
setTitleBar()
|
||||
setHeaderBackground()
|
||||
initViewModel()
|
||||
initRecyclerView()
|
||||
addViewListener()
|
||||
requestData(true)
|
||||
@@ -68,6 +70,14 @@ class SamplingListActivity : BaseActivity() {
|
||||
|
||||
}
|
||||
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(AppRepository(db.appDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[AppViewModel::class.java]
|
||||
}
|
||||
|
||||
fun getCookFoodList(action: (MutableList<CookFoodEntity>?) -> Unit) {
|
||||
appViewModel.getCookFoodList(cookMode = 1) { action(it) }
|
||||
}
|
||||
@@ -78,6 +88,10 @@ class SamplingListActivity : BaseActivity() {
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
val isConfigPage = intent?.getBooleanExtra(IS_CONFIG_PAGE, false) ?: false
|
||||
if (isConfigPage) {
|
||||
return
|
||||
}
|
||||
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
|
||||
//toast("isCooking=$isCooking")
|
||||
refreshPage(isCooking)
|
||||
@@ -103,14 +117,13 @@ class SamplingListActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun onItemClick(position:Int) {
|
||||
private fun onItemClick(position: Int) {
|
||||
val item = list[position]
|
||||
if (item.isCooking) {
|
||||
//烹饪中,跳到称熟重页面
|
||||
startActivity<SubmitFoodActivity> {
|
||||
putExtra(
|
||||
SubmitFoodActivity.FOOD_ITEM,
|
||||
item as Serializable
|
||||
SubmitFoodActivity.FOOD_ITEM, item as Serializable
|
||||
)
|
||||
}
|
||||
return
|
||||
@@ -148,7 +161,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun addViewListener() {
|
||||
binding.btnAddSampling.setOnClickListener {
|
||||
judgeDeviceConfig{
|
||||
judgeDeviceConfig {
|
||||
startActivity<DishSamplingActivity>()
|
||||
}
|
||||
}
|
||||
@@ -186,26 +199,50 @@ class SamplingListActivity : BaseActivity() {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun getSamplingList() {
|
||||
showLoading()
|
||||
val param = mutableMapOf<String, Any>(
|
||||
"pageNo" to pageNo,
|
||||
"pageSize" to pageSize,
|
||||
"canteenId" to BaseApp.canteenId
|
||||
)
|
||||
netViewModel.getSamplingListWithCallback(
|
||||
param = param,
|
||||
onResult = { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> loadDishList(state.data)
|
||||
is UiState.Error -> {
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
toast(state.msg)
|
||||
finishRefresh()
|
||||
delayDismissLoading()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
// val map = mapOf(
|
||||
//// "foodName" to input,
|
||||
// "pageNo" to "$pageNo",
|
||||
// "pageSize" to "$pageSize",
|
||||
// "canteenId" to BaseApp.canteenId
|
||||
// )
|
||||
// val sb = StringBuilder(UrlConfig.SAMPLING_LIST).apply {
|
||||
// append("?")
|
||||
// map.forEach { (key, value) -> append("$key=$value&") }
|
||||
// }
|
||||
// sb.deleteCharAt(sb.length - 1)
|
||||
// HttpUtil.get(
|
||||
// url = sb.toString(),
|
||||
// doSuccess = {
|
||||
// loadDishList(it)
|
||||
// }, doFailure = { code, msg ->
|
||||
// binding.refreshLayout.run {
|
||||
// setEnableRefresh(true)
|
||||
// }
|
||||
// toast(msg)
|
||||
// finishRefresh()
|
||||
// binding.refreshLayout.setEnableRefresh(true)
|
||||
// delayDismissLoading()
|
||||
// if (pageNo == 1) {
|
||||
// loadEmptyView()
|
||||
// }
|
||||
// })
|
||||
|
||||
netViewModel.getSamplingList(
|
||||
param = mutableMapOf(
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize,
|
||||
"placeId" to BaseApp.canteenId
|
||||
),
|
||||
onSuccess = {
|
||||
loadDishList(it)
|
||||
},
|
||||
onFailure = { code, msg ->
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
toast(msg)
|
||||
finishRefresh()
|
||||
delayDismissLoading()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -227,9 +264,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
dishAdapter.notifyDataSetChanged()
|
||||
if (emptyViewBinding == null) {
|
||||
emptyViewBinding = LayoutEmptyViewBinding.inflate(
|
||||
LayoutInflater.from(this),
|
||||
binding.rvSamplingList,
|
||||
false
|
||||
LayoutInflater.from(this), binding.rvSamplingList, false
|
||||
)
|
||||
}
|
||||
emptyViewBinding!!.tvContent.text = "暂无数据"
|
||||
@@ -280,8 +315,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
}
|
||||
val tempList = mutableListOf<FoodRecord>()
|
||||
|
||||
cookFoodEntities
|
||||
.sortedByDescending { DateTimeUtil.convert(dateStr = it.createTime) }
|
||||
cookFoodEntities.sortedByDescending { DateTimeUtil.convert(dateStr = it.createTime) }
|
||||
.forEach { entity ->
|
||||
tempList.add(FoodRecord().apply {
|
||||
foodId = entity.foodId
|
||||
@@ -315,6 +349,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
delayDismissLoading()
|
||||
finishRefresh()
|
||||
if (records.isNullOrEmpty()) {
|
||||
//toast("暂未搜索到相关菜品信息")
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
@@ -335,7 +370,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
|
||||
private var configFinished = false
|
||||
|
||||
fun judgeDeviceConfig(block:()-> Unit) {
|
||||
fun judgeDeviceConfig(block: () -> Unit) {
|
||||
if (configFinished) {
|
||||
block()
|
||||
return
|
||||
@@ -362,8 +397,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
startActivity<DeviceConfigActivity> {
|
||||
putExtra(DeviceConfigActivity.COOK_MODE, 2)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
private var isVisible = false
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package com.shuwei.dish.match.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.activity.viewModels
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivitySelectDishBinding
|
||||
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.dialog.DialogTool
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.entity.FoodRecordBean
|
||||
import com.shuwei.dish.match.net.NetViewModel
|
||||
import com.shuwei.dish.match.ui.fragment.DishListFragment
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
@@ -18,16 +22,22 @@ 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.visible
|
||||
import com.shuwei.dish.match.viewmodel.AppViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import kotlin.getValue
|
||||
|
||||
class SelectDishActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
const val IS_COOKING = "isCooking"
|
||||
const val DINNER_TYPE = "dinnerType"
|
||||
const val IS_CONFIG_PAGE = "isConfigPage"
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivitySelectDishBinding
|
||||
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
private var dinnerType: String = "1"
|
||||
|
||||
private val fragmentList = mutableListOf<DishListFragment>().apply {
|
||||
@@ -56,10 +66,17 @@ class SelectDishActivity : BaseActivity() {
|
||||
}, backAction = {
|
||||
it.gone()
|
||||
})
|
||||
initViewModel()
|
||||
addViewListener()
|
||||
loadFragment()
|
||||
}
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(AppRepository(db.appDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[AppViewModel::class.java]
|
||||
}
|
||||
|
||||
fun getCookFoodList(action: (MutableList<CookFoodEntity>?) -> Unit) {
|
||||
appViewModel.getCookFoodList(cookMode = 0, dinnerType = dinnerType) { action(it) }
|
||||
}
|
||||
@@ -153,6 +170,10 @@ class SelectDishActivity : BaseActivity() {
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
runCatching {
|
||||
val isConfigPage = intent?.getBooleanExtra(IS_CONFIG_PAGE, false) ?: false
|
||||
if (isConfigPage) {
|
||||
return
|
||||
}
|
||||
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
|
||||
val lastDinnerType = intent?.getStringExtra(DINNER_TYPE) ?: "0"
|
||||
if (lastDinnerType == "1" || lastDinnerType == "2" || lastDinnerType == "3") {
|
||||
@@ -187,4 +208,16 @@ class SelectDishActivity : BaseActivity() {
|
||||
isVisible = false
|
||||
}
|
||||
|
||||
public fun getFoodList(
|
||||
param: MutableMap<String, Any>,
|
||||
onSuccess: (MutableList<FoodRecord>?) -> Unit,
|
||||
onFailure: (String, String) -> Unit
|
||||
) {
|
||||
netViewModel.searchFoodList(
|
||||
param = param,
|
||||
onSuccess = onSuccess,
|
||||
onFailure = onFailure
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,26 +6,23 @@ import android.util.Log
|
||||
import android.util.SparseArray
|
||||
import android.util.SparseIntArray
|
||||
import android.widget.FrameLayout
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.util.forEach
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.TextCellAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivitySubmitFoodBinding
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
|
||||
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.shuwei.dish.match.model.toDTO
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.net.NetViewModel
|
||||
import com.shuwei.dish.match.utils.AddressUtil
|
||||
import com.shuwei.dish.match.utils.TextCellTool
|
||||
import kotlinx.coroutines.launch
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
@@ -35,12 +32,15 @@ import com.shuwei.dish.match.utils.ext.toJsonString
|
||||
import com.shuwei.dish.match.utils.ext.toType
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import com.shuwei.dish.match.viewmodel.AppViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import kotlin.getValue
|
||||
|
||||
@SuppressLint("UseSparseArrays")
|
||||
class SubmitFoodActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
const val TAG = "SubmitDishActivity"
|
||||
const val TAG = "SubmitFoodActivity"
|
||||
const val FOOD_ITEM = "foodItem"
|
||||
const val GOODS_LIST = "goodsList"
|
||||
}
|
||||
@@ -69,6 +69,7 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySubmitFoodBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
initViewModel()
|
||||
setHeaderBackground()
|
||||
intent.extras?.apply {
|
||||
food = getSerializable(FOOD_ITEM) as FoodRecord?
|
||||
@@ -94,11 +95,13 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
}
|
||||
})
|
||||
addViewListener()
|
||||
initObserver()
|
||||
}
|
||||
|
||||
private fun loadSeasoningFromLocal() {
|
||||
appViewModel.getCookFoodGoodsList(foodId = food!!.foodId!!, cookMode = food!!.cookMode, dinnerType = food!!.dinnerType) { it ->
|
||||
appViewModel.getCookFoodGoodsList(
|
||||
foodId = food!!.foodId!!,
|
||||
cookMode = food!!.cookMode
|
||||
) { it ->
|
||||
goodsList = mutableListOf()
|
||||
val goodsIdList = mutableListOf<String>()
|
||||
//设置主辅材数据
|
||||
@@ -175,33 +178,34 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
WeightUtil.addWeightListener(
|
||||
weightKey = TAG,
|
||||
getWeight = { address, state, weight ->
|
||||
if (address == AddressUtil.TWO) {
|
||||
cookFoodEntity.foodWeight = weight.toDouble()
|
||||
binding.tvTotalWeight.text = "${weight / 1000f}"
|
||||
}
|
||||
val firstWeight = firstGoodsArray.get(address, null)
|
||||
if (firstWeight == null) {
|
||||
//未设置数据
|
||||
if (state != WeightUtil.STATE_STABLE) {
|
||||
//首次记录数据需要稳定数据
|
||||
if (address == AddressUtil.TWO) {
|
||||
cookFoodEntity.foodWeight = weight.toDouble()
|
||||
binding.tvTotalWeight.text = "${weight / 1000f}"
|
||||
}
|
||||
val firstWeight = firstGoodsArray.get(address, null)
|
||||
if (firstWeight == null) {
|
||||
//未设置数据
|
||||
if (state != WeightUtil.STATE_STABLE) {
|
||||
//首次记录数据需要稳定数据
|
||||
return@addWeightListener
|
||||
}
|
||||
firstGoodsArray.put(address, weight)
|
||||
return@addWeightListener
|
||||
}
|
||||
firstGoodsArray.put(address, weight)
|
||||
return@addWeightListener
|
||||
}
|
||||
var realUseWeight = firstWeight - weight
|
||||
realUseWeight = if (realUseWeight > 0) realUseWeight else 0.0
|
||||
seasoningArray.put(address, realUseWeight.toDouble())
|
||||
var realUseWeight = firstWeight - weight
|
||||
realUseWeight = if (realUseWeight > 0) realUseWeight else 0.0
|
||||
seasoningArray.put(address, realUseWeight.toDouble())
|
||||
|
||||
// refreshSeasoningWeight()
|
||||
|
||||
val item = seasoningItems.firstOrNull { address == addressArray[it.sort]}
|
||||
item?.let {
|
||||
val lastWeight = seasoningArray.get(address) ?: 0.toDouble()
|
||||
it.useWeight = (lastWeight + getCookingSeasoning(address)).roundedOneDecimalPlace()
|
||||
updateGridData(it)
|
||||
}
|
||||
})
|
||||
val item = seasoningItems.firstOrNull { address == addressArray[it.sort] }
|
||||
item?.let {
|
||||
val lastWeight = seasoningArray.get(address) ?: 0.toDouble()
|
||||
it.useWeight =
|
||||
(lastWeight + getCookingSeasoning(address)).roundedOneDecimalPlace()
|
||||
updateGridData(it)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// private fun refreshSeasoningWeight() {
|
||||
@@ -217,17 +221,18 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
// setGridData(seasoningItems)
|
||||
// }
|
||||
|
||||
private fun updateGridData(entity:SeasoningEntity) {
|
||||
private fun updateGridData(entity: SeasoningEntity) {
|
||||
val gridLayout = binding.include.root
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellTool.loadLayout(frameLayout , entity)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
|
||||
private fun getCookingSeasoning(address: Int): Double {
|
||||
if (isCooking.not()) return 0.toDouble()
|
||||
if (seasoningItems.isEmpty()) return 0.toDouble()
|
||||
val weight = seasoningCookingItems?.get(weightRelateArray2.get(address))?.useWeight ?: 0.toDouble()
|
||||
val weight =
|
||||
seasoningCookingItems?.get(weightRelateArray2.get(address))?.useWeight ?: 0.toDouble()
|
||||
return weight
|
||||
}
|
||||
|
||||
@@ -260,12 +265,12 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
return
|
||||
}
|
||||
val realSeasoningData = seasoningItems
|
||||
//(binding.rvSeasoning.adapter as TextCellAdapter).list
|
||||
//(binding.rvSeasoning.adapter as TextCellAdapter).list
|
||||
if (realSeasoningData.isEmpty() && !isCooking) {
|
||||
toast("未获取到调料信息")
|
||||
return
|
||||
}
|
||||
if (realSeasoningData.isNotEmpty()&&realSeasoningData[0].goodsId.isBlank()) {
|
||||
if (realSeasoningData.isNotEmpty() && realSeasoningData[0].goodsId.isNullOrBlank()) {
|
||||
toast("还未设置调料信息,请去设置页面操作")
|
||||
return
|
||||
}
|
||||
@@ -316,7 +321,7 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
toast("未获取到调料信息")
|
||||
return
|
||||
}
|
||||
if (realSeasoningData.isNotEmpty()&&realSeasoningData[0].goodsId.isBlank()) {
|
||||
if (realSeasoningData.isNotEmpty() && realSeasoningData[0].goodsId.isNullOrBlank()) {
|
||||
toast("还未设置调料信息,请去设置页面操作")
|
||||
return
|
||||
}
|
||||
@@ -335,8 +340,9 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
cookFoodEntity.let {
|
||||
// it.stFoodInfoConstituteList = this@SubmitFoodActivity.goodsList
|
||||
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
|
||||
it.dinnerType = when(it.dinnerType) {
|
||||
it.dinnerType = when (it.dinnerType) {
|
||||
"1" -> "早餐"
|
||||
"2" -> "午餐"
|
||||
"3" -> "晚餐"
|
||||
@@ -350,20 +356,46 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
cookFoodEntity.foodId = ""
|
||||
goodsList?.forEach { it.foodId = "" }
|
||||
}
|
||||
netViewModel.submitCookFood(entity = cookFoodEntity.toDTO())
|
||||
val json = cookFoodEntity.toJsonString()
|
||||
Log.d(TAG, "submit: json=$json")
|
||||
// HttpUtil.postJson(
|
||||
// url = UrlConfig.SUBMIT_DISH,
|
||||
// json = json,
|
||||
// doSuccess = {
|
||||
// Log.d(TAG, "submit: postJson=$it")
|
||||
// submitSuccess(isSamplingData)
|
||||
// }, doFailure = { code, msg ->
|
||||
// Log.d(TAG, "submit: postJson:code=$code,msg=$msg")
|
||||
// toast(msg)
|
||||
// dismissLoading()
|
||||
// })
|
||||
|
||||
netViewModel.submitCookFood(
|
||||
entity = cookFoodEntity,
|
||||
onSuccess = {
|
||||
submitSuccess(isSamplingData)
|
||||
},
|
||||
onFailure = { code, msg ->
|
||||
toast(msg)
|
||||
dismissLoading()
|
||||
})
|
||||
}
|
||||
|
||||
private fun submitSuccess(isSamplingData: Boolean) {
|
||||
if (food?.foodId.isNullOrBlank().not()) {
|
||||
//接口提交成功后异步删除本地草稿
|
||||
dbViewModel.markSubmittedAndDeleteAsync(
|
||||
cookMode = food!!.cookMode,
|
||||
foodId = food!!.foodId!!,
|
||||
dinnerType = food!!.dinnerType ?: "0"
|
||||
)
|
||||
if (food?.foodId.isNullOrBlank()) {
|
||||
//本地无删除数据直接跳转页面
|
||||
dismissLoading()
|
||||
jumpPage(isSamplingData, false)
|
||||
return
|
||||
}
|
||||
//删除本地数据
|
||||
appViewModel.deleteCookFoodAndGoods(
|
||||
cookMode = food!!.cookMode,
|
||||
foodId = food!!.foodId!!
|
||||
) {
|
||||
dismissLoading()
|
||||
jumpPage(isSamplingData, false)
|
||||
}
|
||||
dismissLoading()
|
||||
jumpPage(isSamplingData, false)
|
||||
}
|
||||
|
||||
private fun jumpPage(isSampling: Boolean, isCooking: Boolean) {
|
||||
@@ -379,26 +411,14 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun initObserver() {
|
||||
lifecycleScope.launch {
|
||||
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
netViewModel.submitCookFoodState.collect { state ->
|
||||
when (state) {
|
||||
is UiState.Loading -> showLoading()
|
||||
is UiState.Success -> {
|
||||
Log.d(TAG, "submit: success")
|
||||
submitSuccess(food?.cookMode == 1)
|
||||
}
|
||||
is UiState.Error -> {
|
||||
Log.d(TAG, "submit: error code=${state.code}, msg=${state.msg}")
|
||||
toast(state.msg)
|
||||
dismissLoading()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory =
|
||||
AppFactory(AppRepository(db.appDao()))
|
||||
appViewModel =
|
||||
ViewModelProvider(this, factory)[AppViewModel::class.java]
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@@ -413,7 +433,7 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private var seasoningItems = mutableListOf<SeasoningEntity>()
|
||||
private var seasoningCookingItems: List<SeasoningEntity> ?= null
|
||||
private var seasoningCookingItems: List<SeasoningEntity>? = null
|
||||
private fun loadTextCell(list: MutableList<SeasoningEntity>) {
|
||||
seasoningItems.clear()
|
||||
seasoningItems.addAll(list)
|
||||
@@ -430,8 +450,8 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun initConfigData() {
|
||||
repeat(12) {num->
|
||||
val firstOne = seasoningItems.firstOrNull {it.sort == num}
|
||||
repeat(12) { num ->
|
||||
val firstOne = seasoningItems.firstOrNull { it.sort == num }
|
||||
if (firstOne == null) {
|
||||
seasoningItems.add(SeasoningEntity().also { it.sort = num })
|
||||
}
|
||||
@@ -443,7 +463,7 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
list.forEach { entity ->
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellTool.loadLayout(frameLayout, entity)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.base.BaseFragment
|
||||
import com.shuwei.dish.match.databinding.FragmentDishListBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
import com.shuwei.dish.match.ui.PrepareCookActivity
|
||||
import com.shuwei.dish.match.ui.SelectDishActivity
|
||||
import com.shuwei.dish.match.ui.SubmitFoodActivity
|
||||
@@ -86,13 +84,13 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?
|
||||
): FragmentDishListBinding {
|
||||
return FragmentDishListBinding.inflate(inflater, container, false)
|
||||
return FragmentDishListBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
activity = requireActivity() as SelectDishActivity
|
||||
dinnerType = arguments?.getString(DINNER_TYPE, "0")?:"0"
|
||||
dinnerType = arguments?.getString(DINNER_TYPE, "0") ?: "0"
|
||||
binding.rvDishList.run {
|
||||
layoutManager =
|
||||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
@@ -115,6 +113,7 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
pageNo = 1
|
||||
activity.showLoading()
|
||||
getDishList()
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
}
|
||||
|
||||
private fun addViewListener() {
|
||||
@@ -130,6 +129,7 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getDishList(pageNo: Int, dinnerType: String) {
|
||||
this.pageNo = pageNo
|
||||
this.dinnerType = dinnerType
|
||||
@@ -149,35 +149,71 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
@Suppress("unchecked_cast")
|
||||
fun getDishList() {
|
||||
activity.showLoading()
|
||||
val param = mutableMapOf<String, Any>(
|
||||
"dinnerType" to getDinnerTypeText(),
|
||||
"pageNo" to pageNo,
|
||||
"pageSize" to pageSize,
|
||||
"canteenId" to BaseApp.canteenId
|
||||
)
|
||||
activity.netViewModel.searchFoodListWithCallback(
|
||||
param = param,
|
||||
onResult = { state ->
|
||||
try {
|
||||
if (isAdded.not()) return@searchFoodListWithCallback
|
||||
when (state) {
|
||||
is UiState.Success -> loadDishList(state.data)
|
||||
is UiState.Error -> {
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
toast(state.msg)
|
||||
finishRefresh()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
activity.delayDismissLoading()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
activity.getFoodList(
|
||||
param = mutableMapOf(
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize,
|
||||
"placeId" to BaseApp.canteenId,
|
||||
"dinnerType" to getDinnerTypeText()
|
||||
),
|
||||
onSuccess = { records ->
|
||||
activity.delayDismissLoading()
|
||||
finishRefresh()
|
||||
loadDishList(records)
|
||||
},
|
||||
onFailure = { code, msg ->
|
||||
if (isAdded.not()) {
|
||||
return@getFoodList
|
||||
}
|
||||
toast(msg)
|
||||
finishRefresh()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
activity.delayDismissLoading()
|
||||
}
|
||||
)
|
||||
// val map = mapOf(
|
||||
//// "foodName" to input,
|
||||
// "dinnerType" to getDinnerTypeText(),
|
||||
// "pageNo" to "$pageNo",
|
||||
// "pageSize" to "$pageSize",
|
||||
// "canteenId" to BaseApp.canteenId
|
||||
// )
|
||||
// val sb = StringBuilder(UrlConfig.QUERY_FOOD_LIST).apply {
|
||||
// append("?")
|
||||
// map.forEach { (key, value) -> append("$key=$value&") }
|
||||
// }
|
||||
// sb.deleteCharAt(sb.length - 1)
|
||||
// HttpUtil.get(
|
||||
// url = sb.toString(),
|
||||
// doSuccess = { data ->
|
||||
// binding.refreshLayout.run {
|
||||
// setEnableRefresh(true)
|
||||
// }
|
||||
// activity.delayDismissLoading()
|
||||
// finishRefresh()
|
||||
// val json = data.toJsonString()
|
||||
// val recordBean: FoodRecordBean? = json.toObject<FoodRecordBean>()
|
||||
// loadDishList(recordBean)
|
||||
// }, doFailure = { code, msg ->
|
||||
// try {
|
||||
// if (isAdded.not()) {
|
||||
// return@get
|
||||
// }
|
||||
// binding.refreshLayout.run {
|
||||
// setEnableRefresh(true)
|
||||
// }
|
||||
// toast(msg)
|
||||
// finishRefresh()
|
||||
// if (pageNo == 1) {
|
||||
// loadEmptyView()
|
||||
// }
|
||||
// activity.delayDismissLoading()
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
private var emptyViewBinding: LayoutEmptyViewBinding? = null
|
||||
@@ -185,6 +221,8 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadEmptyView() {
|
||||
try {
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
binding.refreshLayout.setEnableLoadMore(false)
|
||||
list.clear()
|
||||
dishAdapter.notifyDataSetChanged()
|
||||
if (emptyViewBinding == null) {
|
||||
@@ -224,7 +262,7 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
if (food != null) {
|
||||
food.isCooking = true
|
||||
food.sort = index
|
||||
food.dinnerType = entity.dinnerType?:"0"
|
||||
food.dinnerType = entity.dinnerType ?: "0"
|
||||
tempList.add(food)
|
||||
} else {
|
||||
//当前查询到的list不包括本地数据id,可能数据在很多页以后了,暂时只能直接构造数据
|
||||
@@ -233,7 +271,7 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
foodId = entity.foodId,
|
||||
foodName = entity.foodName,
|
||||
sort = index,
|
||||
dinnerType = entity.dinnerType?:"0",
|
||||
dinnerType = entity.dinnerType ?: "0",
|
||||
isCooking = true
|
||||
)
|
||||
)
|
||||
@@ -248,11 +286,11 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadDishList(records: MutableList<FoodRecord>?) {
|
||||
try {
|
||||
if (isAdded.not()) return
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
activity.delayDismissLoading()
|
||||
finishRefresh()
|
||||
if (isAdded.not()) {
|
||||
return
|
||||
}
|
||||
if (records.isNullOrEmpty()) {
|
||||
//toast("暂未搜索到相关菜品信息")
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class DecimalAdapter : TypeAdapter<Number>() {
|
||||
override fun read(reader: JsonReader): Number {
|
||||
return when (reader.peek()) {
|
||||
JsonToken.NUMBER -> reader.nextDouble()
|
||||
JsonToken.STRING -> reader.nextString().toDoubleOrNull() ?: 0.0
|
||||
JsonToken.STRING -> reader.nextString().toDouble()
|
||||
else -> 0.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
package com.shuwei.dish.match.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.wabon.wbintelligenthardwaresdk.api.SensorScale;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 修复 SensorScale 地址编码 bug 的子类。
|
||||
*
|
||||
* 问题根因:SensorScale.zeroTwo / tareTwo 内部使用
|
||||
* String command = address + "630603";
|
||||
* 将 int 地址直接拼接为十进制字符串,再整体按十六进制解析成字节。
|
||||
* 对于地址 1-9,十进制 == 十六进制,偶然正确;
|
||||
* 对于地址 10+,十进制 "10" 被解析为 0x10(=16),命中错误的物理秤。
|
||||
*
|
||||
* 修复方式:重写这两个方法,将地址先格式化为两位十六进制字符串(如 10 → "0A"),
|
||||
* 再拼接命令码,通过反射调用父类私有方法 suspendSendThread 和 sumHex 发送。
|
||||
*/
|
||||
public class FixedSensorScale extends SensorScale {
|
||||
|
||||
private static final String TAG = "FixedSensorScale";
|
||||
|
||||
public FixedSensorScale(OnScaleResult result) {
|
||||
super(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写清零命令,修复地址编码:十进制地址 → 两位十六进制字符串。
|
||||
* 例:address=10 → "0A630603",发送字节 0x0A(正确),而非原来的 0x10(错误)。
|
||||
*
|
||||
* @param listener 操作成功回调
|
||||
* @param address 秤地址(来自 onGetWeight 回调的十进制值)
|
||||
*/
|
||||
@Override
|
||||
public void zeroTwo(OperateSuccessListener listener, int address) {
|
||||
sendFixedCommand(listener, address, "630603", "zeroTwo");
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写去皮命令,修复地址编码,逻辑同 zeroTwo。
|
||||
*
|
||||
* @param listener 操作成功回调
|
||||
* @param address 秤地址
|
||||
*/
|
||||
@Override
|
||||
public void tareTwo(OperateSuccessListener listener, int address) {
|
||||
sendFixedCommand(listener, address, "630601", "tareTwo");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用发送逻辑:将地址格式化为两位十六进制后拼接命令码,
|
||||
* 通过反射调用父类私有方法 sumHex 计算校验和,再调用 suspendSendThread 发送。
|
||||
*
|
||||
* @param listener 操作成功回调
|
||||
* @param address 秤地址(十进制)
|
||||
* @param commandCode 命令码(十六进制字符串,如 "630603")
|
||||
* @param methodName 调用方名称,仅用于日志
|
||||
*/
|
||||
private void sendFixedCommand(OperateSuccessListener listener, int address,
|
||||
String commandCode, String methodName) {
|
||||
try {
|
||||
// 将十进制地址转为两位十六进制字符串:10 → "0A",1 → "01"
|
||||
String hexAddress = String.format("%02X", address);
|
||||
String command = hexAddress + commandCode;
|
||||
Log.d(TAG, methodName + ", address=" + address
|
||||
+ ", hexAddress=" + hexAddress + ", command=" + command);
|
||||
|
||||
// 反射调用 sumHex(String) 计算校验和
|
||||
Method sumHexMethod = SensorScale.class.getDeclaredMethod("sumHex", String.class);
|
||||
sumHexMethod.setAccessible(true);
|
||||
String checksum = (String) sumHexMethod.invoke(this, command);
|
||||
|
||||
// 反射调用 suspendSendThread(String) 发送完整命令帧
|
||||
Method suspendMethod = SensorScale.class.getDeclaredMethod(
|
||||
"suspendSendThread", String.class);
|
||||
suspendMethod.setAccessible(true);
|
||||
suspendMethod.invoke(this, command + checksum);
|
||||
|
||||
// 保存回调(通过反射写入父类私有字段 mOperateSuccessListener)
|
||||
java.lang.reflect.Field listenerField = SensorScale.class
|
||||
.getDeclaredField("mOperateSuccessListener");
|
||||
listenerField.setAccessible(true);
|
||||
listenerField.set(this, listener);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, methodName + " 反射调用失败: address=" + address, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.shuwei.dish.match.utils
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.style.AbsoluteSizeSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.LineHeightSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.toColorInt
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.utils.ext.appendText
|
||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||
|
||||
object TextCellTool {
|
||||
|
||||
fun loadLayout(frameLayout: FrameLayout, item: SeasoningEntity) {
|
||||
val child: TextView = frameLayout.getChildAt(0) as TextView
|
||||
child.text = getTextSpan(item)
|
||||
}
|
||||
fun loadCell(tvCell: TextView, item: SeasoningEntity) {
|
||||
tvCell.text = getTextSpan(item)
|
||||
}
|
||||
|
||||
fun getTextSpan(item: SeasoningEntity): SpannableStringBuilder {
|
||||
val endIndex = if (item.sort == 9) 10 else 6
|
||||
var name = if (item.goodsName.isNullOrBlank()) "未配置" else item.goodsName!!
|
||||
if (name.length > endIndex) {
|
||||
name = "${name.take(endIndex)}…"
|
||||
}
|
||||
return buildSpannableString {
|
||||
appendText(
|
||||
name,
|
||||
ForegroundColorSpan(if (item.goodsName.isNullOrBlank()) "#999999".toColorInt() else "#000000".toColorInt()),
|
||||
StyleSpan(Typeface.BOLD),
|
||||
AbsoluteSizeSpan(28, true),
|
||||
LineHeightSpan { text, start, end, spanstartv, v, fm ->
|
||||
fm.descent += 10.dp // 增加行间距
|
||||
}
|
||||
)
|
||||
append("\n")
|
||||
val weight = item.useWeight ?: 0.toDouble()
|
||||
val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
|
||||
appendText(
|
||||
// "${DecimalFormat("#").format(weight)}g",
|
||||
"${weight.roundedOneDecimalPlace()}g",
|
||||
ForegroundColorSpan(weightColor.toColorInt()),
|
||||
AbsoluteSizeSpan(30, true)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,25 +23,14 @@ public class Weigher2 {
|
||||
public static final int ERR_003 = 1003;
|
||||
public static final int ERR_004 = 1004;
|
||||
public static final int ERR_PCB_NOT_SUPPORT = 2000;
|
||||
private static FixedSensorScale mSensorScale;
|
||||
private static String mDevicePort = "/dev/ttyS4";
|
||||
// private static String mDevicePort = "/dev/ttyS7";
|
||||
private static SensorScale mSensorScale;
|
||||
private static String mDevicePort = "/dev/ttyS4";
|
||||
private static boolean mConnect = false;
|
||||
private static Listener mListener;
|
||||
|
||||
/** 允许外部在 init() 前设置串口路径,用于不同硬件型号的子设备 */
|
||||
public static void setDevicePort(String port) {
|
||||
mDevicePort = port;
|
||||
Log.d(TAG, "串口已设置为: " + port);
|
||||
}
|
||||
|
||||
public static String getDevicePort() {
|
||||
return mDevicePort;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
String var0 = Build.MODEL;
|
||||
if ("pcb_941".equals(var0)) {
|
||||
String var0;
|
||||
if ((var0 = Build.MODEL) == "pcb_941") {
|
||||
Log.w(TAG, "pcb not support, " + var0);
|
||||
Listener var1;
|
||||
if ((var1 = mListener) != null) {
|
||||
@@ -51,9 +40,8 @@ public class Weigher2 {
|
||||
} else {
|
||||
System.init();
|
||||
initScale();
|
||||
if ("pcb_908".equals(var0)) {
|
||||
// mDevicePort = "/dev/ttyS4";
|
||||
mDevicePort = "/dev/ttyS7";
|
||||
if (var0 == "pcb_908") {
|
||||
mDevicePort = "/dev/ttyS4";
|
||||
}
|
||||
|
||||
mSensorScale.openScale(mDevicePort, 115200, (open) -> {
|
||||
@@ -76,8 +64,8 @@ public class Weigher2 {
|
||||
}
|
||||
|
||||
public static void config() {
|
||||
String var0 = Build.MODEL;
|
||||
if ("pcb_941".equals(var0)) {
|
||||
String var0;
|
||||
if ((var0 = Build.MODEL) == "pcb_941") {
|
||||
Log.w(TAG, "pcb not support, " + var0);
|
||||
Listener var2;
|
||||
if ((var2 = mListener) != null) {
|
||||
@@ -402,8 +390,7 @@ public class Weigher2 {
|
||||
}
|
||||
};
|
||||
//.<init>();
|
||||
// 使用修复版子类,解决地址 ≥ 10 时 zeroTwo/tareTwo 编码错误的问题
|
||||
mSensorScale = new FixedSensorScale(var0);
|
||||
mSensorScale = new SensorScale(var0);
|
||||
}
|
||||
|
||||
public static void setNoPull485Pin(boolean noPull) {
|
||||
@@ -419,7 +406,7 @@ public class Weigher2 {
|
||||
|
||||
void onSetIdentify();
|
||||
|
||||
// void onGetWeight(int var1, int var2, int var3);
|
||||
// void onGetWeight(int var1, int var2, int var3);
|
||||
void onGetWeight(int var1, int var2, double var3);
|
||||
|
||||
void onReadIdentify(int var1);
|
||||
|
||||
@@ -1,58 +1,33 @@
|
||||
package com.shuwei.dish.match.utils
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||
//import com.aithings.Weigher
|
||||
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
typealias WeightCallback = (address: Int, state: Int, weight: Double) -> Unit
|
||||
|
||||
object WeightUtil {
|
||||
private const val TAG = "WeightUtil"
|
||||
// 使用字面量常量,避免在非 ARM 设备上触发 SensorScale 类加载
|
||||
const val STATE_STABLE = 1
|
||||
const val STATE_UNSTABLE = 0
|
||||
const val STATE_OVER_WEIGHT = 2
|
||||
const val STATE_STABLE = SensorScale.STATE_STABLE
|
||||
const val STATE_UNSTABLE = SensorScale.STATE_UNSTABLE
|
||||
const val STATE_OVER_WEIGHT = SensorScale.STATE_OVER_WEIGHT
|
||||
|
||||
var isConnected = false
|
||||
/** 秤 SDK 是否可用;非 ARM 设备上为 false,所有秤操作将静默跳过 */
|
||||
var isAvailable = false
|
||||
val weightFuncMap: ConcurrentHashMap<String, WeightCallback?> = ConcurrentHashMap()
|
||||
var weightFuncMap: MutableMap<String, WeightCallback?>? =
|
||||
null
|
||||
|
||||
fun init() {
|
||||
val abi = Build.SUPPORTED_ABIS.firstOrNull() ?: ""
|
||||
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.init()
|
||||
Weigher2.setListener(object : WeightListenerImpl() {
|
||||
override fun onInit(connect: Boolean) {
|
||||
super.onInit(connect)
|
||||
isConnected = connect
|
||||
}
|
||||
|
||||
override fun onTare() {
|
||||
super.onTare()
|
||||
Log.d(TAG, "tareTwo,onTare 回调触发")
|
||||
}
|
||||
|
||||
override fun onZero() {
|
||||
super.onZero()
|
||||
Log.d(TAG, "tareTwo,onZero 回调触发")
|
||||
}
|
||||
|
||||
override fun onGetWeight(address: Int, state: Int, weight: Double) {
|
||||
super.onGetWeight(address, state, weight)
|
||||
val stateStr = when (state) {
|
||||
@@ -63,7 +38,7 @@ object WeightUtil {
|
||||
}
|
||||
val useWeight = (weight*1000).roundedOneDecimalPlace()
|
||||
Log.d(TAG, "readWeight, address=$address,state=$stateStr, weight=$useWeight")
|
||||
weightFuncMap.forEach { (key, value) ->
|
||||
weightFuncMap?.forEach { (key, value) ->
|
||||
value?.invoke(address, state, useWeight)
|
||||
}
|
||||
|
||||
@@ -80,12 +55,10 @@ object WeightUtil {
|
||||
}
|
||||
|
||||
fun startContinuousRead() {
|
||||
if (!isAvailable) return
|
||||
Weigher2.startContinuousRead()
|
||||
}
|
||||
|
||||
fun stopContinuousRead() {
|
||||
if (!isAvailable) return
|
||||
try {
|
||||
Weigher2.stopContinuousRead()
|
||||
Weigher2.unInit()
|
||||
@@ -96,25 +69,27 @@ object WeightUtil {
|
||||
|
||||
fun tareTwo(address: Int) {
|
||||
try {
|
||||
Log.d(TAG, "tareTwo,执行清零操作: address=$address")
|
||||
// SDK 内部自动管理总线,直接发送清零命令
|
||||
//Weigher2.tareTwo(address)
|
||||
Weigher2.zeroTwo(address)
|
||||
// Weigher2.tareTwo(address)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Log.e(TAG, "tareTwo,执行清零异常: address=$address, error=${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun removeWeightListener(weightKey: String) {
|
||||
weightFuncMap.remove(weightKey)
|
||||
private fun runOnUiThread(action: () -> Unit) {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
fun addWeightListener(
|
||||
weightKey: String,
|
||||
getWeight: WeightCallback = { _, _, _ -> }
|
||||
) {
|
||||
weightFuncMap[weightKey] = getWeight
|
||||
if (weightFuncMap == null) {
|
||||
weightFuncMap = mutableMapOf()
|
||||
}
|
||||
weightFuncMap?.put(weightKey, getWeight)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +99,7 @@ open class WeightListenerImpl : Weigher2.Listener {
|
||||
}
|
||||
|
||||
override fun onZero() {
|
||||
Log.d("WeightUtil", "tareTwo,zero ok")
|
||||
Log.d("WeightUtil", "zero ok")
|
||||
}
|
||||
|
||||
override fun onTare() {
|
||||
|
||||
@@ -2,15 +2,14 @@ package com.shuwei.dish.match.viewmodel
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.collections.forEach
|
||||
|
||||
class AppViewModel : ViewModel() {
|
||||
|
||||
private val rep = DbRepository()
|
||||
class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
|
||||
fun updateCookFood(entity: CookFoodEntity) {
|
||||
viewModelScope.launch {
|
||||
@@ -18,9 +17,9 @@ class AppViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getCookFoodById(foodId: String, cookMode: Int, dinnerType: String = "0", action: (CookFoodEntity?) -> Unit) {
|
||||
fun getCookFoodById(foodId: String, cookMode: Int, action: (CookFoodEntity?) -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val data = rep.getCookFoodById(foodId, cookMode, dinnerType)
|
||||
val data = rep.getCookFoodById(foodId, cookMode)
|
||||
action(data)
|
||||
}
|
||||
}
|
||||
@@ -43,6 +42,17 @@ class AppViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
// fun saveCookFood(cookMode: Int, entity: CookFoodEntity) {
|
||||
// viewModelScope.launch {
|
||||
// val data = rep.getCookFoodById(entity.foodId, cookMode)
|
||||
// if (data == null) {
|
||||
// rep.insertCookFood(entity)
|
||||
// return@launch
|
||||
// }
|
||||
// rep.updateCookFood(entity)
|
||||
// }
|
||||
// }
|
||||
|
||||
fun saveCookFoodAndGoods(
|
||||
cookMode: Int,
|
||||
entity: CookFoodEntity,
|
||||
@@ -50,17 +60,19 @@ class AppViewModel : ViewModel() {
|
||||
onFinish: () -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val data = rep.getCookFoodById(entity.foodId, cookMode, entity.dinnerType?:"")
|
||||
val data = rep.getCookFoodById(entity.foodId, cookMode)
|
||||
if (data != null) {
|
||||
rep.deleteCookFood(entity.foodId, cookMode, entity.dinnerType?:"")
|
||||
//存在数据删除
|
||||
rep.deleteCookFood(entity.foodId, cookMode)
|
||||
rep.deleteCookFoodGoodsList(data.id, entity.foodId)
|
||||
}
|
||||
//重新保存数据
|
||||
rep.insertCookFood(entity)
|
||||
val newData = rep.getCookFoodById(entity.foodId, cookMode, entity.dinnerType?:"")
|
||||
val newData = rep.getCookFoodById(entity.foodId, cookMode)
|
||||
list?.let { it ->
|
||||
it.forEach { goods ->
|
||||
goods.id = 0
|
||||
goods.pid = newData?.id ?: 0
|
||||
goods.pid = newData?.id?:0
|
||||
}
|
||||
rep.insertGoodsList(it)
|
||||
}
|
||||
@@ -71,27 +83,28 @@ class AppViewModel : ViewModel() {
|
||||
fun deleteCookFoodAndGoods(
|
||||
cookMode: Int,
|
||||
foodId: String,
|
||||
dinnerType: String = "0",
|
||||
onFinish: () -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val data = rep.getCookFoodById(foodId, cookMode, dinnerType)
|
||||
val data = rep.getCookFoodById(foodId, cookMode)
|
||||
if (data != null) {
|
||||
rep.deleteCookFood(foodId = foodId, cookMode = cookMode, dinnerType = dinnerType)
|
||||
rep.deleteCookFood(foodId = foodId, cookMode = cookMode)
|
||||
rep.deleteCookFoodGoodsList(pid = data.id, foodId = foodId)
|
||||
}
|
||||
onFinish()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
fun getCookFoodGoodsList(
|
||||
foodId: String,
|
||||
cookMode: Int,
|
||||
dinnerType: String = "0",
|
||||
action: (list: MutableList<CookFoodGoodsEntity>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val cookFood = rep.getCookFoodById(foodId, cookMode, dinnerType)
|
||||
val cookFood = rep.getCookFoodById(foodId, cookMode)
|
||||
cookFood?.let {
|
||||
val list = rep.getCookFoodGoodsList(pid = it.id, foodId = it.foodId)
|
||||
action(list)
|
||||
@@ -99,6 +112,43 @@ class AppViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
// fun updateGoods(entity: CookFoodGoodsEntity) {
|
||||
// viewModelScope.launch {
|
||||
// rep.updateGoods(entity)
|
||||
// }
|
||||
// }
|
||||
|
||||
// fun saveCookFoodGoods(list: MutableList<CookFoodGoodsEntity>) {
|
||||
// viewModelScope.launch {
|
||||
// val foodId = list[0].foodId
|
||||
// val data: MutableList<CookFoodGoodsEntity>? =
|
||||
// rep.getCookFoodGoodsList(foodId!!)
|
||||
// if (data.isNullOrEmpty()) {
|
||||
// rep.insertGoodsList(list)
|
||||
// return@launch
|
||||
// }
|
||||
// val localDbSeasoningList = rep.getCookFoodGoodsListByType(foodId, 3)
|
||||
// localDbSeasoningList.forEach {
|
||||
// it.isDel = 1
|
||||
// //更新本地调料数据为已删除的状态
|
||||
// rep.updateGoods(it)
|
||||
// }
|
||||
// //筛选出调料数据保存,主辅材不会变更不需要再次处理
|
||||
// val saveSeasoningList = list.filter { it.materialType == 3 }
|
||||
// rep.insertGoodsList(saveSeasoningList.toMutableList())
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
// fun addSeasoning(list: MutableList<SeasoningEntity>, callback: () -> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// rep.deleteBatch()
|
||||
// rep.insertSeasoningList(items = list)
|
||||
// callback()
|
||||
// }
|
||||
// }
|
||||
|
||||
private var isProcessing = false
|
||||
fun loadSeasoning(action: (MutableList<SeasoningEntity>) -> Unit) {
|
||||
viewModelScope.launch {
|
||||
@@ -116,17 +166,25 @@ class AppViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun clearAllSeasoning(action: () -> Unit) {
|
||||
fun clearAllSeasoning(action:()->Unit) {
|
||||
viewModelScope.launch {
|
||||
rep.clearAllSeasoning()
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
// fun updateAll(list: MutableList<SeasoningEntity>) {
|
||||
// viewModelScope.launch {
|
||||
// list.forEach {
|
||||
// rep.updateSeasoning(it)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
fun saveSeasoning(entity: SeasoningEntity, block: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val list = rep.getSeasoningBySort(entity.sort)
|
||||
val size = list?.size ?: 0
|
||||
val size = list?.size?:0
|
||||
if (size == 1) {
|
||||
rep.updateSeasoning(entity.also { it.id = list!![0].id })
|
||||
block()
|
||||
@@ -143,4 +201,6 @@ class AppViewModel : ViewModel() {
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
//import androidx.lifecycle.ViewModel
|
||||
//import androidx.lifecycle.viewModelScope
|
||||
//import com.shuwei.dish.match.db.CookFoodGoodsRepository
|
||||
//import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
//import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
//class CookFoodGoodsViewModel(private val rep: CookFoodGoodsRepository) : ViewModel() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//import androidx.lifecycle.ViewModel
|
||||
//import androidx.lifecycle.viewModelScope
|
||||
//import com.shuwei.dish.match.db.CookFoodRepository
|
||||
//import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
//import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
//class CookFoodViewModel(private val rep: CookFoodRepository) : ViewModel() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//import androidx.lifecycle.ViewModel
|
||||
//import androidx.lifecycle.viewModelScope
|
||||
//import com.shuwei.dish.match.db.SeasoningRepository
|
||||
//import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
//import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
//import kotlinx.coroutines.delay
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
//import androidx.lifecycle.ViewModel
|
||||
//import androidx.lifecycle.viewModelScope
|
||||
//import com.shuwei.dish.match.db.SeasoningRepository
|
||||
//import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
//import com.shuwei.dish.match.db.entity.SeasoningEntity
|
||||
//import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
//import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
//class SubmitDishViewModel(private val rep: SeasoningRepository) : ViewModel() {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.shuwei.dish.match.viewmodel.factory
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.viewmodel.AppViewModel
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class AppFactory(private val repo: AppRepository) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return AppViewModel(repo) as T
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//@Suppress("UNCHECKED_CAST")
|
||||
//class DeviceSettingFactory(private val repo: SeasoningRepository) : ViewModelProvider.Factory {
|
||||
// override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
// return DeviceSettingViewModel(repo) as T
|
||||
// }
|
||||
//}
|
||||
//
|
||||
////@Suppress("UNCHECKED_CAST")
|
||||
////class SubmitDishFactory(private val repo: SeasoningRepository) : ViewModelProvider.Factory {
|
||||
//// override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
//// return SubmitDishViewModel(repo) as T
|
||||
//// }
|
||||
////}
|
||||
//
|
||||
//@Suppress("UNCHECKED_CAST")
|
||||
//class CookFoodFactory(private val repo: CookFoodRepository) : ViewModelProvider.Factory {
|
||||
// override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
// return CookFoodViewModel(repo) as T
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//@Suppress("UNCHECKED_CAST")
|
||||
//class CookFoodGoodsFactory(private val repo: CookFoodGoodsRepository) : ViewModelProvider.Factory {
|
||||
// override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
// return CookFoodGoodsViewModel(repo) as T
|
||||
// }
|
||||
//}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#f0aaf0"/>
|
||||
<size android:width="2dp" android:height="100dp"/>
|
||||
</shape>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#FFEBEE" />
|
||||
<corners android:radius="10dp" />
|
||||
<stroke
|
||||
android:width="2dp"
|
||||
android:color="#FF5252" />
|
||||
</shape>
|
||||
@@ -126,13 +126,19 @@
|
||||
android:textColor="@color/gray_b4"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<!-- <View-->
|
||||
<!-- android:id="@+id/viewPoint"-->
|
||||
<!-- android:layout_width="5dp"-->
|
||||
<!-- android:layout_height="5dp"-->
|
||||
<!-- android:layout_gravity="center_vertical"-->
|
||||
<!-- android:background="@drawable/bg_circle_green"/>-->
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
android:id="@+id/include"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
layout="@layout/layout_grid" />
|
||||
layout="@layout/layout_grid"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -1,216 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:background="@drawable/bg_other_page">
|
||||
|
||||
<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">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="106dp"
|
||||
android:paddingStart="30dp"
|
||||
android:paddingEnd="30dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:text="菜品模式设置"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSetting"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:text="配置终端默认模式"
|
||||
android:textColor="@color/gray_b4"
|
||||
android:textSize="28sp" />
|
||||
</FrameLayout>
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/gray_eb" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/modeRadioGroup"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbModeCook"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="190dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/white"
|
||||
android:button="@null"
|
||||
android:drawableEnd="@drawable/mode_select"
|
||||
android:textSize="36sp"
|
||||
tools:text="制作模式" />
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/gray_eb" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbModeSampling"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="190dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/white"
|
||||
android:button="@null"
|
||||
android:drawableEnd="@drawable/mode_select"
|
||||
android:textSize="36sp"
|
||||
tools:text="采样模式" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/gray_eb" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbModeQuality"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="190dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:button="@null"
|
||||
android:drawableEnd="@drawable/ic_dish_disable"
|
||||
android:enabled="false"
|
||||
android:textColor="@color/gray_b4"
|
||||
android:textSize="36sp"
|
||||
tools:text="品控模式" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:text="@string/seasoning_setting"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:text="@string/seasoning_setting2"
|
||||
android:textColor="@color/gray_b4"
|
||||
android:textSize="28sp" />
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="20dp">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvSeasoning"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginStart="23dp"
|
||||
android:layout_marginEnd="22dp"
|
||||
android:overScrollMode="never"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:spanCount="3"
|
||||
tools:itemCount="15"
|
||||
tools:listitem="@layout/list_item_cell" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRightBottomCell"
|
||||
android:layout_width="467dp"
|
||||
android:layout_height="255dp"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@drawable/selector_text_cell"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="食盐" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:layout_marginStart="30dp"-->
|
||||
<!-- android:layout_marginTop="10dp"-->
|
||||
<!-- android:layout_marginEnd="30dp"-->
|
||||
<!-- android:layout_marginBottom="30dp"-->
|
||||
<!-- android:gravity="bottom"-->
|
||||
<!-- android:orientation="horizontal">-->
|
||||
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/btnCancel"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="90dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:background="@drawable/ripple_effect_light"-->
|
||||
<!-- android:gravity="center"-->
|
||||
<!-- android:text="取消"-->
|
||||
<!-- android:textColor="@color/dish_green"-->
|
||||
<!-- android:textSize="32sp"-->
|
||||
<!-- android:textStyle="bold"-->
|
||||
<!-- tools:ignore="HardcodedText" />-->
|
||||
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/btnConfirm"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="90dp"-->
|
||||
<!-- android:layout_marginStart="30dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:background="@drawable/ripple_effect_green"-->
|
||||
<!-- android:gravity="center"-->
|
||||
<!-- android:text="确定"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- android:textSize="32sp"-->
|
||||
<!-- android:textStyle="bold"-->
|
||||
<!-- tools:ignore="HardcodedText" />-->
|
||||
<!-- </LinearLayout>-->
|
||||
</LinearLayout>
|
||||
@@ -243,7 +243,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
@@ -262,15 +262,16 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvDishPartList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:overScrollMode="never"
|
||||
tools:itemCount="3"
|
||||
tools:listitem="@layout/list_item_dish_cook" />
|
||||
tools:listitem="@layout/list_item_dish_cook"
|
||||
android:scrollbars="vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnCook"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
@@ -280,9 +281,10 @@
|
||||
android:textColor="@color/white"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
android:background="@drawable/ripple_effect_green"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:clickable="true" />
|
||||
|
||||
<!-- android:background="@drawable/ripple_effect_green"-->
|
||||
<!-- android:background="@drawable/shape_green_bg"-->
|
||||
<!-- android:background="?attr/selectableItemBackground"-->
|
||||
<!-- android:clickable="true"-->
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold"
|
||||
tools:ignore="HardcodedText"
|
||||
android:visibility="visible"/>
|
||||
android:visibility="invisible"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
@@ -45,6 +45,7 @@
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:layout_marginBottom="50dp"
|
||||
tools:src="@mipmap/ic_logo1024"
|
||||
tools:ignore="ContentDescription" />
|
||||
tools:ignore="ContentDescription"
|
||||
android:visibility="invisible"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -204,7 +204,7 @@
|
||||
android:layout_marginTop="39dp"
|
||||
android:layout_marginBottom="39dp"
|
||||
android:text="@string/dish_weight_set_remind"
|
||||
android:textColor="@color/dish_green"
|
||||
android:textColor="@color/black999"
|
||||
android:textSize="26sp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -253,35 +253,26 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvDishPartList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:overScrollMode="never"
|
||||
tools:itemCount="3"
|
||||
tools:listitem="@layout/list_item_dish_cook" />
|
||||
tools:listitem="@layout/list_item_dish_cook"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- <com.google.android.material.button.MaterialButton-->
|
||||
<!-- android:id="@+id/btnCook"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="90dp"-->
|
||||
<!-- android:layout_margin="30dp"-->
|
||||
<!-- android:text="@string/goCooking"-->
|
||||
<!-- android:textSize="32sp"-->
|
||||
<!-- android:backgroundTint="@null"-->
|
||||
<!-- style="@style/CookButtonStyle"-->
|
||||
<!-- android:textStyle="bold"/>-->
|
||||
|
||||
<TextView
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnCook"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:layout_margin="30dp"
|
||||
android:background="@drawable/ripple_effect_green"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:gravity="center"
|
||||
android:text="@string/goCooking"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold" />
|
||||
<!-- android:background="@drawable/ripple_effect_green"-->
|
||||
|
||||
</LinearLayout>
|
||||
@@ -90,16 +90,17 @@
|
||||
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnAddSampling"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:layout_margin="30dp"
|
||||
android:background="@drawable/ripple_effect_green"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:gravity="center"
|
||||
android:text="@string/add_sampling"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold" />
|
||||
<!-- android:background="@drawable/ripple_effect_green"-->
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,173 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
tools:background="@drawable/bg_other_page">
|
||||
|
||||
<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">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:text="@string/seasoning"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="20dp">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvSeasoning"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginStart="23dp"
|
||||
android:layout_marginEnd="22dp"
|
||||
android:overScrollMode="never"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:spanCount="3"
|
||||
tools:itemCount="15"
|
||||
tools:listitem="@layout/list_item_cell" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRightBottomCell"
|
||||
android:layout_width="467dp"
|
||||
android:layout_height="255dp"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@drawable/shape_white_fb_15_corners2"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="食盐" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="30dp"
|
||||
android:paddingEnd="30dp">
|
||||
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:gravity="center"
|
||||
android:text="熟重"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btnWeightClear"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@drawable/shape_green_stroke"
|
||||
android:gravity="center"
|
||||
android:text="清零"
|
||||
android:textColor="@color/dish_green"
|
||||
android:textSize="28sp" />
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTotalWeight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:includeFontPadding="false"
|
||||
android:text="0.00"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="90sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvWeightUnit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:includeFontPadding="false"
|
||||
android:text="千克"
|
||||
android:textColor="@color/black999"
|
||||
android:textSize="32sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btnCook"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="制作"
|
||||
android:background="@drawable/ripple_effect_light"
|
||||
android:textColor="@color/dish_green"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold" />
|
||||
<!-- android:background="@drawable/shape_green_stroke"-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btnSubmit"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/ripple_effect_green"
|
||||
android:gravity="center"
|
||||
android:text="提交"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -20,28 +20,28 @@
|
||||
android:id="@+id/tvTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:text="@string/seasoning"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:text="@string/seasoning"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<include
|
||||
android:id="@+id/include"
|
||||
layout="@layout/layout_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
layout="@layout/layout_grid"/>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="30dp"
|
||||
@@ -106,38 +106,41 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnCook"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/shape_green_stroke"
|
||||
android:gravity="center"
|
||||
android:text="制作"
|
||||
android:background="@drawable/ripple_effect_light"
|
||||
android:textColor="@color/dish_green"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold" />
|
||||
<!-- android:background="@drawable/shape_green_stroke"-->
|
||||
<!-- android:background="@drawable/ripple_effect_light"-->
|
||||
|
||||
<TextView
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnSubmit"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/ripple_effect_green"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:gravity="center"
|
||||
android:text="提交"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold" />
|
||||
<!-- android:background="@drawable/ripple_effect_green"-->
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
+6
-3
@@ -5,6 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
tools:background="@color/white"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
@@ -67,6 +68,7 @@
|
||||
android:id="@+id/refreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
app:srlEnableOverScrollDrag="false">
|
||||
|
||||
<com.scwang.smart.refresh.header.ClassicsHeader
|
||||
@@ -76,12 +78,13 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="45dp"
|
||||
android:layout_marginTop="35dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginEnd="45dp"
|
||||
android:layout_marginBottom="150dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:nestedScrollingEnabled="true"
|
||||
android:minHeight="380dp"
|
||||
android:overScrollMode="never"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:spanCount="2"
|
||||
+8
-7
@@ -5,6 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
tools:background="@color/white"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
@@ -47,12 +48,10 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|end"
|
||||
android:text="清零"
|
||||
android:paddingStart="30dp"
|
||||
android:paddingEnd="30dp"
|
||||
android:paddingHorizontal="30dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingVertical="16dp"
|
||||
android:background="@drawable/ripple_effect_green"
|
||||
android:textColor="@color/white_f6"
|
||||
android:textSize="30sp"
|
||||
@@ -102,7 +101,7 @@
|
||||
android:id="@+id/refreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_marginTop="10dp"
|
||||
app:srlEnableOverScrollDrag="false">
|
||||
|
||||
<com.scwang.smart.refresh.header.ClassicsHeader
|
||||
@@ -112,10 +111,12 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="45dp"
|
||||
android:layout_marginEnd="45dp"
|
||||
android:layout_marginBottom="50dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:minHeight="380dp"
|
||||
android:nestedScrollingEnabled="true"
|
||||
android:overScrollMode="never"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
@@ -1,281 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:background="@drawable/bg_other_page">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llSearchBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_margin="30dp"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etInputDish"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginStart="28dp"
|
||||
android:layout_weight="1"
|
||||
android:autofillHints=""
|
||||
android:background="@color/white"
|
||||
android:gravity="center"
|
||||
android:hint="@string/dish_search_hint"
|
||||
android:inputType="text"
|
||||
android:imeOptions="actionSearch"
|
||||
android:paddingStart="3dp"
|
||||
android:paddingEnd="3dp"
|
||||
android:textColor="@color/black333"
|
||||
android:textColorHint="@color/gray_c8"
|
||||
android:textSize="40sp"
|
||||
tools:ignore="TextFields" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivDishSearch"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:src="@drawable/ic_search_gray"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="113dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dish_name"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvInputDishType"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="80dp"
|
||||
android:background="@color/white"
|
||||
android:gravity="center_vertical|end"
|
||||
android:hint="@string/dish_search_hint2"
|
||||
android:textColor="@color/black333"
|
||||
android:textColorHint="@color/gray_c8"
|
||||
android:textSize="28sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:drawablePadding="30dp"
|
||||
android:paddingEnd="30dp"
|
||||
android:paddingStart="30dp"
|
||||
app:drawableEndCompat="@drawable/ic_search_green" />
|
||||
|
||||
<!-- <ImageView-->
|
||||
<!-- android:id="@+id/ivDishTypeSearch"-->
|
||||
<!-- android:layout_width="62dp"-->
|
||||
<!-- android:layout_height="62dp"-->
|
||||
<!-- android:layout_marginStart="15dp"-->
|
||||
<!-- android:layout_marginEnd="15dp"-->
|
||||
<!-- android:paddingStart="15dp"-->
|
||||
<!-- android:paddingEnd="15dp"-->
|
||||
<!-- android:src="@drawable/ic_search_green"-->
|
||||
<!-- tools:ignore="ContentDescription" />-->
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/gray_eb" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="113dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:text="@string/dish_from_type"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/rgSampling"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:gravity="center_vertical|end"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbDishTypeFirst"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="30dp"
|
||||
android:background="@color/white"
|
||||
android:button="@null"
|
||||
android:drawableStart="@drawable/selector_dish_type"
|
||||
android:drawablePadding="30dp"
|
||||
android:gravity="center"
|
||||
android:paddingStart="30dp"
|
||||
android:paddingEnd="30dp"
|
||||
android:text="@string/dish_type_first"
|
||||
android:textColor="@color/dish_type_font"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbDishTypeSecond"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="30dp"
|
||||
android:background="@color/white"
|
||||
android:button="@null"
|
||||
android:checked="false"
|
||||
android:drawableStart="@drawable/selector_dish_type"
|
||||
android:drawablePadding="30dp"
|
||||
android:gravity="center"
|
||||
android:paddingStart="30dp"
|
||||
android:paddingEnd="30dp"
|
||||
android:text="@string/dish_type_second"
|
||||
android:textColor="@color/dish_type_font"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
</RadioGroup>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/gray_eb" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="170dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:text="@string/dish_part_weight_remind"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDishPartWeight"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_weight="1"
|
||||
android:autofillHints=""
|
||||
android:background="@drawable/shape_white_f6_10_corners"
|
||||
android:gravity="center"
|
||||
android:hint="-"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:text=""
|
||||
android:textColor="@color/dish_green"
|
||||
android:textColorHint="@color/gray_d6"
|
||||
android:textSize="60sp"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivWeightClear"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:src="@drawable/ic_weight_clear"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivWeightAdd"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:src="@drawable/ic_weight_add"
|
||||
tools:ignore="ContentDescription" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:text="@string/dish_composition"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvDishPartList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:overScrollMode="never"
|
||||
tools:itemCount="3"
|
||||
tools:listitem="@layout/list_item_dish_cook" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btnCook"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:layout_margin="30dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/goCooking"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
android:background="@drawable/ripple_effect_green"
|
||||
android:clickable="true" />
|
||||
|
||||
<!-- android:background="@drawable/shape_green_bg"-->
|
||||
<!-- android:background="?attr/selectableItemBackground"-->
|
||||
<!-- android:clickable="true"-->
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,105 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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"
|
||||
android:orientation="vertical"
|
||||
tools:background="@drawable/bg_other_page">
|
||||
|
||||
<!-- <RadioGroup-->
|
||||
<!-- android:id="@+id/dishRadioGroup"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="88dp"-->
|
||||
<!-- android:layout_marginTop="15dp"-->
|
||||
<!-- android:orientation="horizontal">-->
|
||||
|
||||
<!-- <RadioButton-->
|
||||
<!-- android:id="@+id/rbCooking"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:layout_marginStart="30dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:background="@drawable/breakfast_bg"-->
|
||||
<!-- android:button="@null"-->
|
||||
<!-- android:checked="true"-->
|
||||
<!-- android:gravity="center"-->
|
||||
<!-- android:text="@string/rb_sampling_cooking"-->
|
||||
<!-- android:textColor="@color/breakfast_font"-->
|
||||
<!-- android:textSize="30sp"-->
|
||||
<!-- android:textStyle="bold" />-->
|
||||
|
||||
|
||||
<!-- <RadioButton-->
|
||||
<!-- android:id="@+id/rbFinished"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:layout_marginStart="9dp"-->
|
||||
<!-- android:layout_marginEnd="30dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:background="@drawable/breakfast_bg"-->
|
||||
<!-- android:button="@null"-->
|
||||
<!-- android:checked="false"-->
|
||||
<!-- android:gravity="center"-->
|
||||
<!-- android:text="@string/rb_sampling_finished"-->
|
||||
<!-- android:textColor="@color/breakfast_font"-->
|
||||
<!-- android:textSize="30sp"-->
|
||||
<!-- android:textStyle="bold" />-->
|
||||
<!-- </RadioGroup>-->
|
||||
|
||||
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="0dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:orientation="vertical"-->
|
||||
<!-- android:layout_marginTop="30dp"-->
|
||||
<!-- android:layout_marginStart="30dp"-->
|
||||
<!-- android:layout_marginEnd="30dp"-->
|
||||
<!-- android:background="@drawable/shape_white_30_corners">-->
|
||||
|
||||
<!-- <TextView-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="@string/dish_list"-->
|
||||
<!-- android:textColor="@color/black666"-->
|
||||
<!-- android:textSize="28sp"-->
|
||||
<!-- android:visibility="gone"/>-->
|
||||
|
||||
<!-- <com.scwang.smart.refresh.layout-sw800dp.SmartRefreshLayout-->
|
||||
<!-- android:id="@+id/refreshLayout"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:layout_marginTop="8dp"-->
|
||||
<!-- android:layout_marginBottom="7dp">-->
|
||||
|
||||
<!-- <com.scwang.smart.refresh.header.ClassicsHeader-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content" />-->
|
||||
|
||||
<!-- <androidx.recyclerview.widget.RecyclerView-->
|
||||
<!-- android:id="@+id/rvSamplingList"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:overScrollMode="never"-->
|
||||
<!-- tools:listitem="@layout-sw800dp/list_item_dish" />-->
|
||||
|
||||
<!-- <com.scwang.smart.refresh.footer.ClassicsFooter-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content" />-->
|
||||
|
||||
<!-- </com.scwang.smart.refresh.layout-sw800dp.SmartRefreshLayout>-->
|
||||
<!-- </LinearLayout>-->
|
||||
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/btnAddSampling"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="90dp"-->
|
||||
<!-- android:layout_margin="30dp"-->
|
||||
<!-- android:background="@drawable/ripple_effect_green"-->
|
||||
<!-- android:gravity="center"-->
|
||||
<!-- android:text="@string/add_sampling"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- android:textSize="32sp"-->
|
||||
<!-- android:textStyle="bold" />-->
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,30 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
tools:background="@color/white">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDialogTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="60dp"
|
||||
android:text="@string/food_remind_01"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="36sp"
|
||||
android:layout_marginTop="60dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDialogContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/food_remind_02"
|
||||
android:textColor="@color/black999"
|
||||
android:layout_marginBottom="60dp"
|
||||
android:textSize="26sp" />
|
||||
</LinearLayout>
|
||||
@@ -8,6 +8,7 @@
|
||||
android:paddingTop="30dp"
|
||||
android:paddingEnd="22dp"
|
||||
android:paddingBottom="20dp"
|
||||
tools:background="@color/white"
|
||||
app:columnCount="3"
|
||||
app:orientation="vertical"
|
||||
app:rowCount="5"
|
||||
|
||||
@@ -41,5 +41,8 @@
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
</style>
|
||||
|
||||
<style name="DialogSoftInputAnimation">
|
||||
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
|
||||
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
|
||||
</style>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user