修改layout目录改为layout_sw800dp,优化调料显示UI,其它细节优化

This commit is contained in:
2025-09-03 17:40:28 +08:00
parent cde2dccd04
commit 03d3785e2b
46 changed files with 940 additions and 900 deletions
+30 -8
View File
@@ -1,3 +1,4 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
@@ -21,6 +22,8 @@ android {
abiFilters.addAll(listOf("armeabi", "armeabi-v7a"))
//, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
}
resConfigs("sw800dp")
}
signingConfigs {
create("debug_507") {
@@ -58,6 +61,25 @@ android {
pickFirst("lib/armeabi-v7a/libserial_port.so")
pickFirst("lib/arme64-v8a/libserial_port.so")
}
sourceSets {
named("main") {
res.setSrcDirs(
listOf(
"src/main/res",
"src/main/res/layout-sw800dp"
)
)
}
}
lint {
disable.add("MissingDefaultResource")
}
// productFlavors {
// create("sw800dp") {
// dimension = "screen"
//// resConfigs("en", "xxhdpi") // 可选额外配置
// }
// }
}
dependencies {
@@ -91,14 +113,14 @@ dependencies {
implementation("io.github.scwang90:refresh-header-classics:3.0.0-alpha")
//经典刷新头
implementation("io.github.scwang90:refresh-header-radar:3.0.0-alpha")
//雷达刷新头
implementation("io.github.scwang90:refresh-header-falsify:3.0.0-alpha")
//虚拟刷新头
implementation("io.github.scwang90:refresh-header-material:3.0.0-alpha")
//谷歌刷新头
implementation("io.github.scwang90:refresh-header-two-level:3.0.0-alpha")
//二级刷新头
implementation("io.github.scwang90:refresh-footer-ball:3.0.0-alpha")
// //雷达刷新头
// implementation("io.github.scwang90:refresh-header-falsify:3.0.0-alpha")
// //虚拟刷新头
// implementation("io.github.scwang90:refresh-header-material:3.0.0-alpha")
// //谷歌刷新头
// implementation("io.github.scwang90:refresh-header-two-level:3.0.0-alpha")
// //二级刷新头
// implementation("io.github.scwang90:refresh-footer-ball:3.0.0-alpha")
//球脉冲加载
implementation("io.github.scwang90:refresh-footer-classics:3.0.0-alpha")
//经典加载
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,134 +1,134 @@
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.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
}
}
}
//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.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
// }
// }
//
//}
@@ -22,7 +22,7 @@
//
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// setContentView(R.layout.custom_toast)
// setContentView(R.layout-sw800dp.custom_toast)
// findViewById<TextView>(R.id.tvMessage)?.text = message
// setCancelable(true)
// if (message.isNullOrBlank() ||
@@ -88,7 +88,7 @@
//// activity = activity,
//// themeResId = R.style.ToastDialogTheme,
//// ).apply {
//// setContentView(R.layout.custom_toast)
//// setContentView(R.layout-sw800dp.custom_toast)
//// findViewById<TextView>(R.id.tvMessage)?.text = message
//// setCancelable(true)
//// if (message.isNullOrBlank() ||
@@ -1,246 +1,246 @@
package com.shuwei.dish.match.ui
import android.graphics.Typeface
import android.os.Bundle
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 androidx.core.graphics.toColorInt
import androidx.lifecycle.ViewModelProvider
import com.shuwei.dish.match.adapter.SeasoningCellTool
import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.ActivityDeviceSettingBinding
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.DataUtil
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
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.R
class DeviceSettingActivity : BaseActivity() {
companion object {
const val TAG = "DeviceSettingActivity"
const val COOK_MODE = "cookMode"
val modeList = listOf<ModeBean>(
ModeBean("制作模式", "菜品快速制作,记录熟重"),
ModeBean("采样模式", "菜品快速制作,记录熟重"),
ModeBean("品控模式", "菜品快速制作,记录熟重")
)
}
data class ModeBean(
var modeName: String,
var modeDesc: String
)
private lateinit var binding: ActivityDeviceSettingBinding
private lateinit var appViewModel: AppViewModel
private var cookMode: Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityDeviceSettingBinding.inflate(layoutInflater)
setContentView(binding.root)
cookMode = intent.getIntExtra(COOK_MODE, 0)
initViewModel()
setHeaderBackground()
setTitleBar(titleBarAction = {
it.visible()
}, titleAction = {
it.text = "设备配置"
}, rightIconActon = {
it.visible()
it.alpha = 0.0F
it.setImageResource(R.drawable.ic_setting)
it.setOnClickListener {
// appViewModel.clearAllSeasoning{
// loadSeasoning()
//package com.shuwei.dish.match.ui
//
//import android.graphics.Typeface
//import android.os.Bundle
//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 androidx.core.graphics.toColorInt
//import androidx.lifecycle.ViewModelProvider
//import com.shuwei.dish.match.adapter.SeasoningCellTool
//import com.shuwei.dish.match.base.BaseActivity
//import com.shuwei.dish.match.base.BaseApp
//import com.shuwei.dish.match.databinding.ActivityDeviceSettingBinding
//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.DataUtil
//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
//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.R
//
//class DeviceSettingActivity : BaseActivity() {
//
// companion object {
//
// const val TAG = "DeviceSettingActivity"
//
// const val COOK_MODE = "cookMode"
//
// val modeList = listOf<ModeBean>(
// ModeBean("制作模式", "菜品快速制作,记录熟重"),
// ModeBean("采样模式", "菜品快速制作,记录熟重"),
// ModeBean("品控模式", "菜品快速制作,记录熟重")
// )
// }
//
// data class ModeBean(
// var modeName: String,
// var modeDesc: String
// )
//
// private lateinit var binding: ActivityDeviceSettingBinding
//
// private lateinit var appViewModel: AppViewModel
//
// private var cookMode: Int = 0
//
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// binding = ActivityDeviceSettingBinding.inflate(layoutInflater)
// setContentView(binding.root)
// cookMode = intent.getIntExtra(COOK_MODE, 0)
// initViewModel()
// setHeaderBackground()
// setTitleBar(titleBarAction = {
// it.visible()
// }, titleAction = {
// it.text = "设备配置"
// }, rightIconActon = {
// it.visible()
// it.alpha = 0.0F
// it.setImageResource(R.drawable.ic_setting)
// it.setOnClickListener {
//// appViewModel.clearAllSeasoning{
//// loadSeasoning()
//// }
// detector.setOnDelayedMultiClickListener(it) {
// defaultDataSettingDialog()
// }
detector.setOnDelayedMultiClickListener(it) {
defaultDataSettingDialog()
}
}
})
loadQualitySpan(isEnable = false)
when (cookMode) {
1 -> {
binding.rbModeCook.isChecked = true
binding.rbModeSampling.isChecked = false
loadCookSpan(isClicked = true)
loadSamplingSpan()
}
2 -> {
binding.rbModeCook.isChecked = false
binding.rbModeSampling.isChecked = true
loadCookSpan()
loadSamplingSpan(isClicked = true)
}
else -> 0
}
binding.rbModeCook.setOnClickListener {
binding.rbModeCook.isChecked = true
binding.rbModeSampling.isChecked = false
loadCookSpan(isClicked = true)
loadSamplingSpan()
startActivity<SelectDishActivity> { }
finish()
}
binding.rbModeSampling.setOnClickListener {
binding.rbModeCook.isChecked = false
binding.rbModeSampling.isChecked = true
loadCookSpan()
loadSamplingSpan(isClicked = true)
startActivity<SamplingListActivity> { }
finish()
}
}
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()
}
onDismiss = { hideStatusBar() }
}.show()
}
private fun resetList() {
runCatching {
val record = JsonAssetsLoader.parseJsonFromAssets<ResetReasoningRecord>(this,"default_seasoning_list.json")
val addressArray = DataUtil.getWeighAddressArray()
val weightArray = WeightUtil.weightArray
appViewModel.clearAllSeasoning {
record?.list?.forEach { entity ->
entity.useWeight = weightArray[addressArray[entity.sort]].toDouble()
appViewModel.saveSeasoning(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]
}
override fun onResume() {
super.onResume()
loadSeasoning()
}
private fun loadSeasoning() {
appViewModel.loadSeasoning { it ->
SeasoningCellTool.loadData(
activity = this,
initList = it,
recyclerView = binding.rvSeasoning,
tvCell = binding.tvRightBottomCell,
pageType = 1
)
}
}
private fun loadQualitySpan(isClicked: Boolean = false, isEnable: Boolean = true) {
binding.rbModeQuality.text =
getModeTextSpan(
topText = modeList[2].modeName,
bottomText = modeList[2].modeDesc,
topColor = if (isEnable) if (isClicked) "#00BC71" else "#000000" else "#B4B4B4",
bottomColor = if (isEnable) "#8B8B8B" else "#B4B4B4"
)
}
private fun loadSamplingSpan(isClicked: Boolean = false, isEnable: Boolean = true) {
binding.rbModeSampling.text =
getModeTextSpan(
topText = modeList[1].modeName,
bottomText = modeList[1].modeDesc,
topColor = if (isEnable) if (isClicked) "#00BC71" else "#000000" else "#B4B4B4",
bottomColor = if (isEnable) "#8B8B8B" else "#B4B4B4"
)
}
private fun loadCookSpan(isClicked: Boolean = false, isEnable: Boolean = true) {
binding.rbModeCook.text =
getModeTextSpan(
topText = modeList[0].modeName,
bottomText = modeList[0].modeDesc,
topColor = if (isEnable) if (isClicked) "#00BC71" else "#000000" else "#B4B4B4",
bottomColor = if (isEnable) "#8B8B8B" else "#B4B4B4"
)
}
private fun getModeTextSpan(
topText: String,
topColor: String,
bottomText: String,
bottomColor: String
): SpannableStringBuilder {
return buildSpannableString {
appendText(
topText,
ForegroundColorSpan(topColor.toColorInt()),
StyleSpan(Typeface.BOLD),
AbsoluteSizeSpan(36, true),
LineHeightSpan { text, start, end, spanstartv, v, fm ->
fm.descent += 10.dp // 增加行间距
}
)
append("\n")
appendText(
bottomText,
ForegroundColorSpan(bottomColor.toColorInt()),
AbsoluteSizeSpan(26, true)
)
}
}
fun saveSeasoning(entity: SeasoningEntity) {
appViewModel.saveSeasoning(entity) {
toast("保存成功")
}
}
}
// }
// })
//
// loadQualitySpan(isEnable = false)
// when (cookMode) {
// 1 -> {
// binding.rbModeCook.isChecked = true
// binding.rbModeSampling.isChecked = false
// loadCookSpan(isClicked = true)
// loadSamplingSpan()
// }
//
// 2 -> {
// binding.rbModeCook.isChecked = false
// binding.rbModeSampling.isChecked = true
// loadCookSpan()
// loadSamplingSpan(isClicked = true)
// }
//
// else -> 0
// }
//
// binding.rbModeCook.setOnClickListener {
// binding.rbModeCook.isChecked = true
// binding.rbModeSampling.isChecked = false
// loadCookSpan(isClicked = true)
// loadSamplingSpan()
// startActivity<SelectDishActivity> { }
// finish()
// }
// binding.rbModeSampling.setOnClickListener {
// binding.rbModeCook.isChecked = false
// binding.rbModeSampling.isChecked = true
// loadCookSpan()
// loadSamplingSpan(isClicked = true)
// startActivity<SamplingListActivity> { }
// finish()
// }
// }
//
// 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()
// }
// onDismiss = { hideStatusBar() }
// }.show()
// }
//
// private fun resetList() {
// runCatching {
// val record = JsonAssetsLoader.parseJsonFromAssets<ResetReasoningRecord>(this,"default_seasoning_list.json")
// val addressArray = DataUtil.getWeighAddressArray()
// val weightArray = WeightUtil.weightArray
// appViewModel.clearAllSeasoning {
// record?.list?.forEach { entity ->
// entity.useWeight = weightArray[addressArray[entity.sort]].toDouble()
// appViewModel.saveSeasoning(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]
// }
//
// override fun onResume() {
// super.onResume()
// loadSeasoning()
// }
//
// private fun loadSeasoning() {
// appViewModel.loadSeasoning { it ->
// SeasoningCellTool.loadData(
// activity = this,
// initList = it,
// recyclerView = binding.rvSeasoning,
// tvCell = binding.tvRightBottomCell,
// pageType = 1
// )
// }
// }
//
//
// private fun loadQualitySpan(isClicked: Boolean = false, isEnable: Boolean = true) {
// binding.rbModeQuality.text =
// getModeTextSpan(
// topText = modeList[2].modeName,
// bottomText = modeList[2].modeDesc,
// topColor = if (isEnable) if (isClicked) "#00BC71" else "#000000" else "#B4B4B4",
// bottomColor = if (isEnable) "#8B8B8B" else "#B4B4B4"
// )
// }
//
// private fun loadSamplingSpan(isClicked: Boolean = false, isEnable: Boolean = true) {
// binding.rbModeSampling.text =
// getModeTextSpan(
// topText = modeList[1].modeName,
// bottomText = modeList[1].modeDesc,
// topColor = if (isEnable) if (isClicked) "#00BC71" else "#000000" else "#B4B4B4",
// bottomColor = if (isEnable) "#8B8B8B" else "#B4B4B4"
// )
// }
//
// private fun loadCookSpan(isClicked: Boolean = false, isEnable: Boolean = true) {
// binding.rbModeCook.text =
// getModeTextSpan(
// topText = modeList[0].modeName,
// bottomText = modeList[0].modeDesc,
// topColor = if (isEnable) if (isClicked) "#00BC71" else "#000000" else "#B4B4B4",
// bottomColor = if (isEnable) "#8B8B8B" else "#B4B4B4"
// )
// }
//
// private fun getModeTextSpan(
// topText: String,
// topColor: String,
// bottomText: String,
// bottomColor: String
// ): SpannableStringBuilder {
//
//
// return buildSpannableString {
// appendText(
// topText,
// ForegroundColorSpan(topColor.toColorInt()),
// StyleSpan(Typeface.BOLD),
// AbsoluteSizeSpan(36, true),
// LineHeightSpan { text, start, end, spanstartv, v, fm ->
// fm.descent += 10.dp // 增加行间距
// }
// )
// append("\n")
// appendText(
// bottomText,
// ForegroundColorSpan(bottomColor.toColorInt()),
// AbsoluteSizeSpan(26, true)
// )
// }
// }
//
// fun saveSeasoning(entity: SeasoningEntity) {
// appViewModel.saveSeasoning(entity) {
// toast("保存成功")
// }
// }
//
//}
@@ -239,8 +239,8 @@ class DishSamplingActivity : BaseActivity() {
Log.d(TAG, "goToSubmit: goodsList:${list.toJsonString()}")
// startActivity<SubmitDishActivity> {
startActivity<SubmitFoodActivity> {
putExtra(SubmitDishActivity.GOODS_LIST, list as java.io.Serializable)
putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
putExtra(SubmitFoodActivity.GOODS_LIST, list as java.io.Serializable)
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
}
}
binding.etInputDish.let { v ->
@@ -150,8 +150,8 @@ class PrepareCookActivity : BaseActivity() {
Log.d(TAG, "goToSubmit: goodsList:${goodsList?.toJsonString()}")
// startActivity<SubmitDishActivity> {
startActivity<SubmitFoodActivity> {
putExtra(SubmitDishActivity.GOODS_LIST, goodsList as Serializable)
putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
putExtra(SubmitFoodActivity.GOODS_LIST, goodsList as Serializable)
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
}
}
@@ -122,7 +122,7 @@ class SamplingListActivity : BaseActivity() {
// context.startActivity<SubmitDishActivity> {
context.startActivity<SubmitFoodActivity> {
putExtra(
SubmitDishActivity.FOOD_ITEM,
SubmitFoodActivity.FOOD_ITEM,
item as Serializable
)
}
@@ -287,7 +287,7 @@ class SamplingListActivity : BaseActivity() {
emptyViewBinding!!.tvContent.text = "暂无数据"
emptyViewBinding!!.tvSubContent.text = "今日暂无采样数据,点击下方按钮新增采样"
dishAdapter.stateView = emptyViewBinding!!.root
//dishAdapter.setStateViewLayout(requireContext(), R.layout.layout_empty_view)
//dishAdapter.setStateViewLayout(requireContext(), R.layout-sw800dp.layout_empty_view)
binding.refreshLayout.run {
setEnableRefresh(binding.dishRadioGroup.checkedRadioButtonId == R.id.rbSamplingFinished)
@@ -1,429 +1,429 @@
package com.shuwei.dish.match.ui
import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.util.SparseArray
import android.util.SparseIntArray
import androidx.core.util.forEach
import androidx.lifecycle.ViewModelProvider
import com.aithings.Weigher
import com.google.gson.reflect.TypeToken
import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SeasoningCellTool
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.ActivitySubmitDishBinding
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.FoodRecord
import com.shuwei.dish.match.entity.SeasoningEntity
import com.shuwei.dish.match.http.HttpUtil
import com.shuwei.dish.match.http.UrlConfig
import com.shuwei.dish.match.utils.DataUtil
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.clickWithDebounce
import com.shuwei.dish.match.utils.ext.gone
import com.shuwei.dish.match.utils.ext.startActivity
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
@SuppressLint("UseSparseArrays")
class SubmitDishActivity : BaseActivity() {
companion object {
const val TAG = "SubmitDishActivity"
const val FOOD_ITEM = "foodItem"
const val GOODS_LIST = "goodsList"
}
private lateinit var binding: ActivitySubmitDishBinding
private var food: FoodRecord? = null
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
private var isCooking = false
private val cookFoodEntity by lazy {
CookFoodEntity().apply {
food?.let {
foodId = it.foodId ?: ""
foodName = it.foodName
cookMode = it.cookMode
dinnerType = it.dinnerType
}
canteenId = BaseApp.canteenId
}
}
@Suppress("unchecked_cast", "DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySubmitDishBinding.inflate(layoutInflater)
setContentView(binding.root)
initViewModel()
setHeaderBackground()
intent.extras?.apply {
food = getSerializable(FOOD_ITEM) as FoodRecord?
Log.d(TAG, "onCreate: cookMode=${food?.cookMode}")
isCooking = food?.isCooking ?: false
if (isCooking) {
//烹饪中,从本地查询数据
loadSeasoningFromLocal()
} else {
//非烹饪中,从菜品主辅材配置页面带入数据
goodsList = getSerializable(GOODS_LIST) as MutableList<CookFoodGoodsEntity>?
}
}
setTitleBar(titleBarAction = {
it.visible()
}, titleAction = {
it.text = food?.foodName
}, rightIconActon = {
it.gone()
it.setImageResource(R.drawable.ic_setting)
it.setOnClickListener {
//startActivity<DeviceSettingActivity>()
}
})
addViewListener()
}
private fun loadSeasoningFromLocal() {
appViewModel.getCookFoodGoodsList(foodId = food!!.foodId!!, cookMode = food!!.cookMode) { it ->
goodsList = mutableListOf()
//设置主辅材数据
goodsList?.addAll(it.filter { goods -> goods.materialType != 3 })
//获取调料数据并展示
val filterList: List<SeasoningEntity>? = it.filter { goods -> goods.materialType == 3 }
.map { entity ->
SeasoningEntity().also { se ->
se.goodsId = entity.goodsId
se.goodsName = entity.goodsName
se.goodsOrRelationCode = entity.goodsOrRelationCode
se.relateionType = entity.relateionType
se.materialType = entity.materialType
se.allEdible = entity.allEdible
se.useWeight = entity.useWeight
se.popularName = entity.popularName
se.canteenId = entity.canteenId
se.relateionType_dictText = entity.relateionType_dictText
se.foodId = entity.foodId
se.sort = entity.sort
se.pageType = 0
}
}
filterList?.toMutableList()?.let { cellData ->
loadTextCell(cellData)
}
}
}
private lateinit var seasoningList: List<SeasoningEntity>
private var isFirstSave = true
fun updateSeasoningList(list: MutableList<SeasoningEntity>) {
if (isFirstSave) {
val json = list.toJsonString()
val typeToken = object : TypeToken<List<SeasoningEntity>>() {}
seasoningList = json.toType(typeToken = typeToken)
isFirstSave = false
}
}
private val seasoningArray by lazy {
SparseArray<Double>()
}
private val firstGoodsArray by lazy {
SparseArray<Int>()
}
private fun addViewListener() {
addWeightListener()
binding.btnWeightClear.setOnClickListener { Weigher.tareTwo(1) }
binding.btnCook.clickWithDebounce {
cook()
}
binding.btnSubmit.clickWithDebounce {
if (cookFoodEntity.foodWeight <= 0.toDouble()) {
toast("未识别到菜品熟重")
return@clickWithDebounce
}
submit()
}
}
private fun addWeightListener() {
WeightUtil.addWeightListener(getWeight = { address, state, weight ->
if (address == 1) {
cookFoodEntity.foodWeight = weight.toDouble()
binding.tvTotalWeight.text = "${weight / 1000f}"
}
// if (state != SensorScale.STATE_STABLE) {
//package com.shuwei.dish.match.ui
//
//import android.annotation.SuppressLint
//import android.os.Bundle
//import android.util.Log
//import android.util.SparseArray
//import android.util.SparseIntArray
//import androidx.core.util.forEach
//import androidx.lifecycle.ViewModelProvider
//import com.aithings.Weigher
//import com.google.gson.reflect.TypeToken
//import com.shuwei.dish.match.R
//import com.shuwei.dish.match.adapter.SeasoningCellTool
//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.ActivitySubmitDishBinding
//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.FoodRecord
//import com.shuwei.dish.match.entity.SeasoningEntity
//import com.shuwei.dish.match.http.HttpUtil
//import com.shuwei.dish.match.http.UrlConfig
//import com.shuwei.dish.match.utils.DataUtil
//import com.shuwei.dish.match.utils.WeightUtil
//import com.shuwei.dish.match.utils.ext.clickWithDebounce
//import com.shuwei.dish.match.utils.ext.gone
//import com.shuwei.dish.match.utils.ext.startActivity
//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
//
//@SuppressLint("UseSparseArrays")
//class SubmitDishActivity : BaseActivity() {
//
// companion object {
// const val TAG = "SubmitDishActivity"
// const val FOOD_ITEM = "foodItem"
// const val GOODS_LIST = "goodsList"
// }
//
// private lateinit var binding: ActivitySubmitDishBinding
//
// private var food: FoodRecord? = null
// private var goodsList: MutableList<CookFoodGoodsEntity>? = null
//
// private var isCooking = false
//
// private val cookFoodEntity by lazy {
// CookFoodEntity().apply {
// food?.let {
// foodId = it.foodId ?: ""
// foodName = it.foodName
// cookMode = it.cookMode
// dinnerType = it.dinnerType
// }
// canteenId = BaseApp.canteenId
// }
// }
//
// @Suppress("unchecked_cast", "DEPRECATION")
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// binding = ActivitySubmitDishBinding.inflate(layoutInflater)
// setContentView(binding.root)
// initViewModel()
// setHeaderBackground()
// intent.extras?.apply {
// food = getSerializable(FOOD_ITEM) as FoodRecord?
// Log.d(TAG, "onCreate: cookMode=${food?.cookMode}")
// isCooking = food?.isCooking ?: false
// if (isCooking) {
// //烹饪中,从本地查询数据
// loadSeasoningFromLocal()
// } else {
// //非烹饪中,从菜品主辅材配置页面带入数据
// goodsList = getSerializable(GOODS_LIST) as MutableList<CookFoodGoodsEntity>?
// }
// }
// setTitleBar(titleBarAction = {
// it.visible()
// }, titleAction = {
// it.text = food?.foodName
// }, rightIconActon = {
// it.gone()
// it.setImageResource(R.drawable.ic_setting)
// it.setOnClickListener {
// //startActivity<DeviceSettingActivity>()
// }
// })
// addViewListener()
// }
//
// private fun loadSeasoningFromLocal() {
// appViewModel.getCookFoodGoodsList(foodId = food!!.foodId!!, cookMode = food!!.cookMode) { it ->
// goodsList = mutableListOf()
// //设置主辅材数据
// goodsList?.addAll(it.filter { goods -> goods.materialType != 3 })
//
// //获取调料数据并展示
// val filterList: List<SeasoningEntity>? = it.filter { goods -> goods.materialType == 3 }
// .map { entity ->
// SeasoningEntity().also { se ->
// se.goodsId = entity.goodsId
// se.goodsName = entity.goodsName
// se.goodsOrRelationCode = entity.goodsOrRelationCode
// se.relateionType = entity.relateionType
// se.materialType = entity.materialType
// se.allEdible = entity.allEdible
// se.useWeight = entity.useWeight
// se.popularName = entity.popularName
// se.canteenId = entity.canteenId
// se.relateionType_dictText = entity.relateionType_dictText
// se.foodId = entity.foodId
// se.sort = entity.sort
// se.pageType = 0
// }
// }
// filterList?.toMutableList()?.let { cellData ->
// loadTextCell(cellData)
// }
// }
// }
//
//
// private lateinit var seasoningList: List<SeasoningEntity>
// private var isFirstSave = true
// fun updateSeasoningList(list: MutableList<SeasoningEntity>) {
// if (isFirstSave) {
// val json = list.toJsonString()
// val typeToken = object : TypeToken<List<SeasoningEntity>>() {}
// seasoningList = json.toType(typeToken = typeToken)
// isFirstSave = false
// }
// }
//
// private val seasoningArray by lazy {
// SparseArray<Double>()
// }
//
//
// private val firstGoodsArray by lazy {
// SparseArray<Int>()
// }
//
// private fun addViewListener() {
// addWeightListener()
// binding.btnWeightClear.setOnClickListener { Weigher.tareTwo(1) }
//
// binding.btnCook.clickWithDebounce {
// cook()
// }
//
// binding.btnSubmit.clickWithDebounce {
// if (cookFoodEntity.foodWeight <= 0.toDouble()) {
// toast("未识别到菜品熟重")
// return@clickWithDebounce
// }
// submit()
// }
// }
//
// private fun addWeightListener() {
// WeightUtil.addWeightListener(getWeight = { address, state, weight ->
// if (address == 1) {
// cookFoodEntity.foodWeight = weight.toDouble()
// binding.tvTotalWeight.text = "${weight / 1000f}"
// }
//// if (state != SensorScale.STATE_STABLE) {
//// return@addWeightListener
//// }
// val firstWeight = firstGoodsArray.get(address, null)
//// if (firstWeight != weight) {
//// Log.d(
//// TAG,
//// "addViewListener: state=$state,address=$address,weight=$weight,firstWeight=$firstWeight"
//// )
//// }
// if (firstWeight == null) {
// //未设置数据
// firstGoodsArray.put(address, weight)
// return@addWeightListener
// }
val firstWeight = firstGoodsArray.get(address, null)
// if (firstWeight != weight) {
// Log.d(
// TAG,
// "addViewListener: state=$state,address=$address,weight=$weight,firstWeight=$firstWeight"
// )
// }
if (firstWeight == null) {
//未设置数据
firstGoodsArray.put(address, weight)
return@addWeightListener
}
// val cookingWeight =
// if (isCooking && seasoningList.isNullOrEmpty().not())
// seasoningList?.get(weightRelateArray2.get(address))?.weight ?: 0
// else 0
// var realUseWeight = firstWeight - weight + cookingWeight
var realUseWeight = firstWeight - weight
realUseWeight = if (realUseWeight > 0) realUseWeight else 0
// Log.d(
// TAG,
// "addViewListener: state=$state,address=$address,总共使用重量:$realUseWeight"
// )
seasoningArray.put(address, realUseWeight.toDouble())
refreshSeasoningWeight()
})
}
@SuppressLint("NotifyDataSetChanged")
private fun refreshSeasoningWeight() {
binding.rvSeasoning.adapter?.let { adapter ->
if (adapter is TextCellAdapter) {
adapter.list.let { items ->
weightRelateArray.forEach { key, value ->
items[key].useWeight =
(seasoningArray.get(value) ?: 0.toDouble()) + getCookingSeasoning(value)
}
}
adapter.notifyDataSetChanged()
TextCellAdapter.loadCell(binding.tvRightBottomCell, adapter.list[14])
}
}
}
private fun getCookingSeasoning(address: Int): Double {
if (isCooking.not()) return 0.toDouble()
if (seasoningList.isEmpty()) return 0.toDouble()
val weight = seasoningList[weightRelateArray2.get(address)].useWeight ?: 0.toDouble()
//Log.i(TAG, "getCookingSeasoning: weight[${address}]=$weight,seasoningList=${seasoningList.toJsonString()}")
return weight
}
private val weightRelateArray2 by lazy {
SparseIntArray().apply {
weightRelateArray.forEach { key, value ->
if (value == 3) {
put(3, 14)
} else {
put(value, key)
}
}
}
}
private val weightRelateArray by lazy {
DataUtil.getWeighAddressArray()
}
// private fun prepareData(acton: () -> Unit) {
//// val cookingWeight =
//// if (isCooking && seasoningList.isNullOrEmpty().not())
//// seasoningList?.get(weightRelateArray2.get(address))?.weight ?: 0
//// else 0
//// var realUseWeight = firstWeight - weight + cookingWeight
// var realUseWeight = firstWeight - weight
// realUseWeight = if (realUseWeight > 0) realUseWeight else 0
//// Log.d(
//// TAG,
//// "addViewListener: state=$state,address=$address,总共使用重量:$realUseWeight"
//// )
// seasoningArray.put(address, realUseWeight.toDouble())
//
// refreshSeasoningWeight()
// })
// }
//
// @SuppressLint("NotifyDataSetChanged")
// private fun refreshSeasoningWeight() {
// binding.rvSeasoning.adapter?.let { adapter ->
// if (adapter is TextCellAdapter) {
// adapter.list.let { items ->
// weightRelateArray.forEach { key, value ->
// items[key].useWeight =
// (seasoningArray.get(value) ?: 0.toDouble()) + getCookingSeasoning(value)
// }
// }
// adapter.notifyDataSetChanged()
// TextCellAdapter.loadCell(binding.tvRightBottomCell, adapter.list[14])
// }
// }
// }
//
// private fun getCookingSeasoning(address: Int): Double {
// if (isCooking.not()) return 0.toDouble()
// if (seasoningList.isEmpty()) return 0.toDouble()
// val weight = seasoningList[weightRelateArray2.get(address)].useWeight ?: 0.toDouble()
// //Log.i(TAG, "getCookingSeasoning: weight[${address}]=$weight,seasoningList=${seasoningList.toJsonString()}")
// return weight
// }
//
// private val weightRelateArray2 by lazy {
// SparseIntArray().apply {
// weightRelateArray.forEach { key, value ->
// if (value == 3) {
// put(3, 14)
// } else {
// put(value, key)
// }
// }
// }
// }
//
// private val weightRelateArray by lazy {
// DataUtil.getWeighAddressArray()
// }
//
//// private fun prepareData(acton: () -> Unit) {
////
//// //只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题
//// val seasoningJson = realSeasoningData.toJsonString()
//// val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {}
//// val tempSeasoningList = seasoningJson.toType(typeToken = typeToken)
//// goodsList?.addAll(tempSeasoningList)
//// acton()
////
//// }
//
// private fun cook() {
// if (food == null || goodsList.isNullOrEmpty()) {
// toast("未获取到菜品或构成信息")
// return
// }
// val realSeasoningData = (binding.rvSeasoning.adapter as TextCellAdapter).list
// if (realSeasoningData.isEmpty() && !isCooking) {
// toast("未获取到调料信息")
// return
// }
// if (realSeasoningData.isNotEmpty()&&realSeasoningData[0].goodsId.isNullOrBlank()) {
// toast("还未设置调料信息,请去设置页面操作")
// return
// }
// showLoading()
// //只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题
// val seasoningJson = realSeasoningData.toJsonString()
// val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {}
// val tempSeasoningList = seasoningJson.toType(typeToken = typeToken)
// goodsList?.addAll(tempSeasoningList)
// acton()
//
// cookFoodEntity.let {
// it.dinnerType = when (it.dinnerType) {
// "早餐" -> "1"
// "午餐" -> "2"
// "晚餐" -> "3"
// else -> it.dinnerType
// }
// }
// val isSamplingData = food!!.cookMode == 1
// if (isSamplingData) {
// //生成临时foodId,解决采样模式没有foodId,无法关联数据的问题
// val tempFoodId = cookFoodEntity.foodId.ifBlank { "${System.currentTimeMillis()}" }
// cookFoodEntity.foodId = tempFoodId
// }
// //全部设置同一foodId
// goodsList?.forEach {
// it.foodId = cookFoodEntity.foodId
// }
// //保存菜品-保存主辅料调料
// appViewModel.saveCookFoodAndGoods(
// cookMode = food!!.cookMode,
// entity = cookFoodEntity,
// list = goodsList,
// onFinish = {
// runOnUiThread {
// dismissLoading()
// jumpPage(isSamplingData, true)
// }
// })
// }
private fun cook() {
if (food == null || goodsList.isNullOrEmpty()) {
toast("未获取到菜品或构成信息")
return
}
val realSeasoningData = (binding.rvSeasoning.adapter as TextCellAdapter).list
if (realSeasoningData.isEmpty() && !isCooking) {
toast("未获取到调料信息")
return
}
if (realSeasoningData.isNotEmpty()&&realSeasoningData[0].goodsId.isNullOrBlank()) {
toast("还未设置调料信息,请去设置页面操作")
return
}
showLoading()
//只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题
val seasoningJson = realSeasoningData.toJsonString()
val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {}
val tempSeasoningList = seasoningJson.toType(typeToken = typeToken)
goodsList?.addAll(tempSeasoningList)
cookFoodEntity.let {
it.dinnerType = when (it.dinnerType) {
"早餐" -> "1"
"午餐" -> "2"
"晚餐" -> "3"
else -> it.dinnerType
}
}
val isSamplingData = food!!.cookMode == 1
if (isSamplingData) {
//生成临时foodId,解决采样模式没有foodId,无法关联数据的问题
val tempFoodId = cookFoodEntity.foodId.ifBlank { "${System.currentTimeMillis()}" }
cookFoodEntity.foodId = tempFoodId
}
//全部设置同一foodId
goodsList?.forEach {
it.foodId = cookFoodEntity.foodId
}
//保存菜品-保存主辅料调料
appViewModel.saveCookFoodAndGoods(
cookMode = food!!.cookMode,
entity = cookFoodEntity,
list = goodsList,
onFinish = {
runOnUiThread {
dismissLoading()
jumpPage(isSamplingData, true)
}
})
}
private fun submit() {
if (food == null || goodsList.isNullOrEmpty()) {
toast("未获取到菜品或构成信息")
return
}
val realSeasoningData = (binding.rvSeasoning.adapter as TextCellAdapter).list
if (realSeasoningData.isEmpty() && !isCooking) {
toast("未获取到调料信息")
return
}
if (realSeasoningData.isNotEmpty()&&realSeasoningData[0].goodsId.isNullOrBlank()) {
toast("还未设置调料信息,请去设置页面操作")
return
}
showLoading()
//只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题
val seasoningJson = realSeasoningData.toJsonString()
val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {}
val tempSeasoningList = seasoningJson.toType(typeToken = typeToken)
tempSeasoningList.forEach { entity ->
val realWeight = entity.useWeight ?: 0.toDouble()
val filterData = goodsList?.firstOrNull { it.goodsId == entity.goodsId }
//确保重量大于0,且无重复数据
if (realWeight > 0.toDouble() && filterData == null) {
goodsList?.add(entity)
}
}
cookFoodEntity.let {
it.stFoodInfoConstituteList = this@SubmitDishActivity.goodsList
it.dinnerType = when(it.dinnerType) {
"1" -> "早餐"
"2" -> "午餐"
"3" -> "晚餐"
else -> null
}
}
val isSamplingData = food!!.cookMode == 1
if (isSamplingData) {
//采样模式没有foodId
cookFoodEntity.foodId = ""
goodsList?.forEach { it.foodId = "" }
}
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()
})
}
private fun submitSuccess(isSamplingData: Boolean) {
if (food?.foodId.isNullOrBlank()) {
//本地无删除数据直接跳转页面
dismissLoading()
jumpPage(isSamplingData, false)
return
}
//删除本地数据
appViewModel.deleteCookFoodAndGoods(
cookMode = food!!.cookMode,
foodId = food!!.foodId!!
) {
dismissLoading()
jumpPage(isSamplingData, false)
}
}
private fun jumpPage(isSampling: Boolean, isCooking: Boolean) {
if (isSampling) {
startActivity<SamplingListActivity> {
putExtra(SelectDishActivity.IS_COOKING, isCooking)
}
return
}
startActivity<SelectDishActivity> {
putExtra(SelectDishActivity.IS_COOKING, isCooking)
putExtra(SelectDishActivity.DINNER_TYPE, food?.dinnerType)
}
}
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() {
super.onResume()
binding.tvRightBottomCell.visible()
if (isCooking.not()) {
//烹饪中使用本地数据,未烹饪则使用默认的调料配置数据
appViewModel.loadSeasoning {
Log.d(TAG, "onResume: loadSeasoning:${it.toJsonString()}")
loadTextCell(it)
}
}
}
private fun loadTextCell(list: MutableList<SeasoningEntity>) {
SeasoningCellTool.loadData(
activity = this,
initList = list,
recyclerView = binding.rvSeasoning,
tvCell = binding.tvRightBottomCell
)
}
}
//
// private fun submit() {
// if (food == null || goodsList.isNullOrEmpty()) {
// toast("未获取到菜品或构成信息")
// return
// }
// val realSeasoningData = (binding.rvSeasoning.adapter as TextCellAdapter).list
// if (realSeasoningData.isEmpty() && !isCooking) {
// toast("未获取到调料信息")
// return
// }
// if (realSeasoningData.isNotEmpty()&&realSeasoningData[0].goodsId.isNullOrBlank()) {
// toast("还未设置调料信息,请去设置页面操作")
// return
// }
// showLoading()
// //只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题
// val seasoningJson = realSeasoningData.toJsonString()
// val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {}
// val tempSeasoningList = seasoningJson.toType(typeToken = typeToken)
// tempSeasoningList.forEach { entity ->
// val realWeight = entity.useWeight ?: 0.toDouble()
// val filterData = goodsList?.firstOrNull { it.goodsId == entity.goodsId }
// //确保重量大于0,且无重复数据
// if (realWeight > 0.toDouble() && filterData == null) {
// goodsList?.add(entity)
// }
// }
//
// cookFoodEntity.let {
// it.stFoodInfoConstituteList = this@SubmitDishActivity.goodsList
// it.dinnerType = when(it.dinnerType) {
// "1" -> "早餐"
// "2" -> "午餐"
// "3" -> "晚餐"
// else -> null
// }
// }
//
// val isSamplingData = food!!.cookMode == 1
// if (isSamplingData) {
// //采样模式没有foodId
// cookFoodEntity.foodId = ""
// goodsList?.forEach { it.foodId = "" }
// }
// 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()
// })
// }
//
// private fun submitSuccess(isSamplingData: Boolean) {
// if (food?.foodId.isNullOrBlank()) {
// //本地无删除数据直接跳转页面
// dismissLoading()
// jumpPage(isSamplingData, false)
// return
// }
// //删除本地数据
// appViewModel.deleteCookFoodAndGoods(
// cookMode = food!!.cookMode,
// foodId = food!!.foodId!!
// ) {
// dismissLoading()
// jumpPage(isSamplingData, false)
// }
// }
//
// private fun jumpPage(isSampling: Boolean, isCooking: Boolean) {
// if (isSampling) {
// startActivity<SamplingListActivity> {
// putExtra(SelectDishActivity.IS_COOKING, isCooking)
// }
// return
// }
// startActivity<SelectDishActivity> {
// putExtra(SelectDishActivity.IS_COOKING, isCooking)
// putExtra(SelectDishActivity.DINNER_TYPE, food?.dinnerType)
// }
// }
//
// 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() {
// super.onResume()
// binding.tvRightBottomCell.visible()
// if (isCooking.not()) {
// //烹饪中使用本地数据,未烹饪则使用默认的调料配置数据
// appViewModel.loadSeasoning {
// Log.d(TAG, "onResume: loadSeasoning:${it.toJsonString()}")
// loadTextCell(it)
// }
// }
// }
//
// private fun loadTextCell(list: MutableList<SeasoningEntity>) {
// SeasoningCellTool.loadData(
// activity = this,
// initList = list,
// recyclerView = binding.rvSeasoning,
// tvCell = binding.tvRightBottomCell
// )
// }
//}
//
//
@@ -11,11 +11,9 @@ import androidx.lifecycle.ViewModelProvider
import com.aithings.Weigher
import com.google.gson.reflect.TypeToken
import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SeasoningCellTool
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.ActivitySubmitDishBinding
import com.shuwei.dish.match.databinding.ActivitySubmitFoodBinding
import com.shuwei.dish.match.db.AppRepository
@@ -20,7 +20,6 @@ import com.shuwei.dish.match.http.HttpUtil
import com.shuwei.dish.match.http.UrlConfig
import com.shuwei.dish.match.ui.PrepareCookActivity
import com.shuwei.dish.match.ui.SelectDishActivity
import com.shuwei.dish.match.ui.SubmitDishActivity
import com.shuwei.dish.match.ui.SubmitFoodActivity
import com.shuwei.dish.match.utils.SwipeCallback
import com.shuwei.dish.match.utils.ext.startActivity
@@ -63,7 +62,7 @@ class DishListFragment : Fragment() {
// context.startActivity<SubmitDishActivity> {
context.startActivity<SubmitFoodActivity> {
putExtra(
SubmitDishActivity.FOOD_ITEM,
SubmitFoodActivity.FOOD_ITEM,
item as Serializable
)
}
@@ -72,7 +71,7 @@ class DishListFragment : Fragment() {
item.dinnerType = dinnerType
context.startActivity<PrepareCookActivity> {
putExtra(
SubmitDishActivity.FOOD_ITEM,
SubmitFoodActivity.FOOD_ITEM,
item as Serializable
)
}
@@ -220,7 +219,7 @@ class DishListFragment : Fragment() {
emptyViewBinding!!.tvContent.text = "暂无数据"
emptyViewBinding!!.tvSubContent.text = "获取菜品数据失败,请检查网络设置或稍后重试"
dishAdapter.stateView = emptyViewBinding!!.root
//dishAdapter.setStateViewLayout(requireContext(), R.layout.layout_empty_view)
//dishAdapter.setStateViewLayout(requireContext(), R.layout-sw800dp.layout_empty_view)
}
private fun finishRefresh() {
@@ -204,7 +204,7 @@
// emptyViewBinding!!.tvContent.text = "暂无数据"
// emptyViewBinding!!.tvSubContent.text = "今日暂无采样数据,点击下方按钮新增采样"
// dishAdapter.stateView = emptyViewBinding!!.root
// //dishAdapter.setStateViewLayout(requireContext(), R.layout.layout_empty_view)
// //dishAdapter.setStateViewLayout(requireContext(), R.layout-sw800dp.layout_empty_view)
//
// binding.refreshLayout.run {
// setEnableRefresh(false)
@@ -15,8 +15,8 @@ object DataUtil {
put(6, 6)
put(7, 7)
put(8, 8)
put(9, 5)
put(10, 3)
put(9, 3)
put(10, 5)
put(11, 4)
}
}
@@ -0,0 +1,14 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:gravity="bottom">
<shape android:shape="rectangle">
<solid android:color="@color/gray_eb" />
<size android:height="1dp" />
</shape>
</item>
</layer-list>
@@ -5,11 +5,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:background="@drawable/bg_other_page">
tools:background="@drawable/bg_other_page"
tools:ignore="HardcodedText">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:background="@drawable/shape_white_30_corners"
@@ -18,8 +20,9 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="106dp"
android:paddingStart="30dp"
android:paddingEnd="30dp">
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:background="@drawable/bg_bottom_line">
<TextView
android:layout_width="wrap_content"
@@ -40,76 +43,80 @@
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" />
<!-- <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:layout_height="match_parent"
android:orientation="vertical">
<RadioButton
android:id="@+id/rbModeCook"
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:background="@color/white"
android:button="@null"
android:drawableEnd="@drawable/mode_select"
android:background="@drawable/bg_bottom_line"
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" />
<!-- <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_height="0dp"
android:layout_weight="1"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:background="@color/white"
android:button="@null"
android:drawableEnd="@drawable/mode_select"
android:background="@drawable/bg_bottom_line"
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/rbModeQuality"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
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>
<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:layout_marginBottom="60dp"
android:background="@drawable/shape_white_30_corners"
android:orientation="vertical"
android:layout_marginStart="30dp"
@@ -3,9 +3,10 @@
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:layout_height="match_parent"
android:orientation="vertical"
tools:background="@drawable/bg_other_page">
tools:background="@drawable/bg_other_page"
tools:ignore="HardcodedText">
<LinearLayout
android:layout_width="match_parent"
@@ -39,14 +40,13 @@
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginStart="30dp"
android:layout_marginTop="10dp"
android:layout_marginTop="30dp"
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">
@@ -78,8 +78,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
@@ -65,7 +65,7 @@
<!-- android:textSize="28sp"-->
<!-- android:visibility="gone"/>-->
<!-- <com.scwang.smart.refresh.layout.SmartRefreshLayout-->
<!-- <com.scwang.smart.refresh.layout-sw800dp.SmartRefreshLayout-->
<!-- android:id="@+id/refreshLayout"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
@@ -81,13 +81,13 @@
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:overScrollMode="never"-->
<!-- tools:listitem="@layout/list_item_dish" />-->
<!-- 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.SmartRefreshLayout>-->
<!-- </com.scwang.smart.refresh.layout-sw800dp.SmartRefreshLayout>-->
<!-- </LinearLayout>-->
<!-- <TextView-->
@@ -195,7 +195,7 @@
<TextView
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_height="255dp"
android:layout_marginStart="7dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="7dp"
@@ -209,9 +209,31 @@
android:textSize="28sp"
android:textStyle="bold"
app:layout_column="0"
app:layout_columnSpan="2"
app:layout_gravity="fill_horizontal"
app:layout_row="3"
app:layout_rowSpan="2"
tools:text="9" />
<TextView
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginStart="7dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="8dp"
android:background="@drawable/selector_text_cell"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:tag="10"
android:textColor="@color/black"
android:textSize="28sp"
android:textStyle="bold"
app:layout_column="2"
app:layout_columnWeight="1"
app:layout_row="3"
tools:text="9" />
tools:text="10" />
<TextView
android:layout_width="0dp"
@@ -228,31 +250,8 @@
android:textColor="@color/black"
android:textSize="28sp"
android:textStyle="bold"
app:layout_column="0"
app:layout_column="2"
app:layout_columnWeight="1"
app:layout_row="4"
tools:text="11" />
<TextView
android:layout_width="0dp"
android:layout_height="255dp"
android:layout_marginStart="7dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="8dp"
android:background="@drawable/selector_text_cell"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:tag="10"
android:textColor="@color/black"
android:textSize="28sp"
android:textStyle="bold"
app:layout_column="1"
app:layout_columnSpan="2"
app:layout_gravity="fill_horizontal"
app:layout_row="3"
app:layout_rowSpan="2"
tools:text="10" />
</androidx.gridlayout.widget.GridLayout>
+1
View File
@@ -12,5 +12,6 @@
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<!-- <item name="android:layout_width">828dp</item>-->
</style>
</resources>
+1
View File
@@ -12,6 +12,7 @@
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<!-- <item name="android:layout_width">828dp</item>-->
</style>
<style name="CookButtonStyle" parent="Widget.MaterialComponents.Button">