diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 71c9ce5..9d39d29 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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") //经典加载 diff --git a/app/release/app-release.apk b/app/release/app-release.apk deleted file mode 100644 index 88b8238..0000000 Binary files a/app/release/app-release.apk and /dev/null differ diff --git a/app/release/baselineProfiles/0/app-release.dm b/app/release/baselineProfiles/0/app-release.dm index b6b41bc..3794e18 100644 Binary files a/app/release/baselineProfiles/0/app-release.dm and b/app/release/baselineProfiles/0/app-release.dm differ diff --git a/app/release/baselineProfiles/1/app-release.dm b/app/release/baselineProfiles/1/app-release.dm index 917e1a2..9fc4bf6 100644 Binary files a/app/release/baselineProfiles/1/app-release.dm and b/app/release/baselineProfiles/1/app-release.dm differ diff --git a/app/src/main/java/com/shuwei/dish/match/adapter/SeasoningCellTool.kt b/app/src/main/java/com/shuwei/dish/match/adapter/SeasoningCellTool.kt index ff91f92..f024d41 100644 --- a/app/src/main/java/com/shuwei/dish/match/adapter/SeasoningCellTool.kt +++ b/app/src/main/java/com/shuwei/dish/match/adapter/SeasoningCellTool.kt @@ -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() - 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? = 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?, - pageType: Int = 0 - ): MutableList { - val list = mutableListOf() - 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 - } - } - -} \ No newline at end of file +//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() +// 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? = 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?, +// pageType: Int = 0 +// ): MutableList { +// val list = mutableListOf() +// 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 +// } +// } +// +//} \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/dish/match/dialog/CustomToast.kt b/app/src/main/java/com/shuwei/dish/match/dialog/CustomToast.kt index a46a346..1fe6021 100644 --- a/app/src/main/java/com/shuwei/dish/match/dialog/CustomToast.kt +++ b/app/src/main/java/com/shuwei/dish/match/dialog/CustomToast.kt @@ -22,7 +22,7 @@ // // override fun onCreate(savedInstanceState: Bundle?) { // super.onCreate(savedInstanceState) -// setContentView(R.layout.custom_toast) +// setContentView(R.layout-sw800dp.custom_toast) // findViewById(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(R.id.tvMessage)?.text = message //// setCancelable(true) //// if (message.isNullOrBlank() || diff --git a/app/src/main/java/com/shuwei/dish/match/ui/DeviceSettingActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/DeviceSettingActivity.kt index cfde5a1..aefdb81 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/DeviceSettingActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/DeviceSettingActivity.kt @@ -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("品控模式", "菜品快速制作,记录熟重") - ) - } - - 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("品控模式", "菜品快速制作,记录熟重") +// ) +// } +// +// 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 { } - finish() - } - binding.rbModeSampling.setOnClickListener { - binding.rbModeCook.isChecked = false - binding.rbModeSampling.isChecked = true - loadCookSpan() - loadSamplingSpan(isClicked = true) - startActivity { } - 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(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("保存成功") - } - } - -} \ No newline at end of file +// } +// }) +// +// 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 { } +// finish() +// } +// binding.rbModeSampling.setOnClickListener { +// binding.rbModeCook.isChecked = false +// binding.rbModeSampling.isChecked = true +// loadCookSpan() +// loadSamplingSpan(isClicked = true) +// startActivity { } +// 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(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("保存成功") +// } +// } +// +//} \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/dish/match/ui/DishSamplingActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/DishSamplingActivity.kt index a3a78a4..fef7803 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/DishSamplingActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/DishSamplingActivity.kt @@ -239,8 +239,8 @@ class DishSamplingActivity : BaseActivity() { Log.d(TAG, "goToSubmit: goodsList:${list.toJsonString()}") // startActivity { startActivity { - 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 -> diff --git a/app/src/main/java/com/shuwei/dish/match/ui/PrepareCookActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/PrepareCookActivity.kt index 8b1e6c1..5f9e1db 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/PrepareCookActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/PrepareCookActivity.kt @@ -150,8 +150,8 @@ class PrepareCookActivity : BaseActivity() { Log.d(TAG, "goToSubmit: goodsList:${goodsList?.toJsonString()}") // startActivity { startActivity { - 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) } } diff --git a/app/src/main/java/com/shuwei/dish/match/ui/SamplingListActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/SamplingListActivity.kt index 5559171..7cee15c 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/SamplingListActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/SamplingListActivity.kt @@ -122,7 +122,7 @@ class SamplingListActivity : BaseActivity() { // context.startActivity { context.startActivity { 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) diff --git a/app/src/main/java/com/shuwei/dish/match/ui/SubmitDishActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/SubmitDishActivity.kt index b764e4c..2397bad 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/SubmitDishActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/SubmitDishActivity.kt @@ -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? = 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? - } - } - setTitleBar(titleBarAction = { - it.visible() - }, titleAction = { - it.text = food?.foodName - }, rightIconActon = { - it.gone() - it.setImageResource(R.drawable.ic_setting) - it.setOnClickListener { - //startActivity() - } - }) - 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? = 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 - private var isFirstSave = true - fun updateSeasoningList(list: MutableList) { - if (isFirstSave) { - val json = list.toJsonString() - val typeToken = object : TypeToken>() {} - seasoningList = json.toType(typeToken = typeToken) - isFirstSave = false - } - } - - private val seasoningArray by lazy { - SparseArray() - } - - - private val firstGoodsArray by lazy { - SparseArray() - } - - 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? = 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? +// } +// } +// setTitleBar(titleBarAction = { +// it.visible() +// }, titleAction = { +// it.text = food?.foodName +// }, rightIconActon = { +// it.gone() +// it.setImageResource(R.drawable.ic_setting) +// it.setOnClickListener { +// //startActivity() +// } +// }) +// 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? = 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 +// private var isFirstSave = true +// fun updateSeasoningList(list: MutableList) { +// if (isFirstSave) { +// val json = list.toJsonString() +// val typeToken = object : TypeToken>() {} +// seasoningList = json.toType(typeToken = typeToken) +// isFirstSave = false +// } +// } +// +// private val seasoningArray by lazy { +// SparseArray() +// } +// +// +// private val firstGoodsArray by lazy { +// SparseArray() +// } +// +// 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>() {} +//// 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>() {} // 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>() {} - 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>() {} - 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 { - putExtra(SelectDishActivity.IS_COOKING, isCooking) - } - return - } - startActivity { - 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) { - 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>() {} +// 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 { +// putExtra(SelectDishActivity.IS_COOKING, isCooking) +// } +// return +// } +// startActivity { +// 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) { +// SeasoningCellTool.loadData( +// activity = this, +// initList = list, +// recyclerView = binding.rvSeasoning, +// tvCell = binding.tvRightBottomCell +// ) +// } +//} +// +// diff --git a/app/src/main/java/com/shuwei/dish/match/ui/SubmitFoodActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/SubmitFoodActivity.kt index c77b241..b45ff88 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/SubmitFoodActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/SubmitFoodActivity.kt @@ -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 diff --git a/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt b/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt index cd92db9..12d63e9 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt @@ -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 { context.startActivity { putExtra( - SubmitDishActivity.FOOD_ITEM, + SubmitFoodActivity.FOOD_ITEM, item as Serializable ) } @@ -72,7 +71,7 @@ class DishListFragment : Fragment() { item.dinnerType = dinnerType context.startActivity { 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() { diff --git a/app/src/main/java/com/shuwei/dish/match/ui/fragment/SamplingListFragment.kt b/app/src/main/java/com/shuwei/dish/match/ui/fragment/SamplingListFragment.kt index 015da62..cae92ba 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/fragment/SamplingListFragment.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/fragment/SamplingListFragment.kt @@ -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) diff --git a/app/src/main/java/com/shuwei/dish/match/utils/DataUtil.kt b/app/src/main/java/com/shuwei/dish/match/utils/DataUtil.kt index 727d220..b87c1fd 100644 --- a/app/src/main/java/com/shuwei/dish/match/utils/DataUtil.kt +++ b/app/src/main/java/com/shuwei/dish/match/utils/DataUtil.kt @@ -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) } } diff --git a/app/src/main/res/drawable/bg_bottom_line.xml b/app/src/main/res/drawable/bg_bottom_line.xml new file mode 100644 index 0000000..1969cb6 --- /dev/null +++ b/app/src/main/res/drawable/bg_bottom_line.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_base.xml b/app/src/main/res/layout-sw800dp/activity_base.xml similarity index 100% rename from app/src/main/res/layout/activity_base.xml rename to app/src/main/res/layout-sw800dp/activity_base.xml diff --git a/app/src/main/res/layout/activity_device_config.xml b/app/src/main/res/layout-sw800dp/activity_device_config.xml similarity index 67% rename from app/src/main/res/layout/activity_device_config.xml rename to app/src/main/res/layout-sw800dp/activity_device_config.xml index 2efca5a..2ce4159 100644 --- a/app/src/main/res/layout/activity_device_config.xml +++ b/app/src/main/res/layout-sw800dp/activity_device_config.xml @@ -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"> + android:layout_marginStart="30dp" + android:layout_marginEnd="30dp" + android:background="@drawable/bg_bottom_line"> - + + + + + + - + + + + + + + + + + + + + + + - - - - + tools:background="@drawable/bg_other_page" + tools:ignore="HardcodedText"> - @@ -78,8 +78,7 @@ diff --git a/app/src/main/res/layout/custom_toast.xml b/app/src/main/res/layout-sw800dp/custom_toast.xml similarity index 100% rename from app/src/main/res/layout/custom_toast.xml rename to app/src/main/res/layout-sw800dp/custom_toast.xml diff --git a/app/src/main/res/layout/dialog_bottom_sheet.xml b/app/src/main/res/layout-sw800dp/dialog_bottom_sheet.xml similarity index 100% rename from app/src/main/res/layout/dialog_bottom_sheet.xml rename to app/src/main/res/layout-sw800dp/dialog_bottom_sheet.xml diff --git a/app/src/main/res/layout/dialog_bottom_sheet2.xml b/app/src/main/res/layout-sw800dp/dialog_bottom_sheet2.xml similarity index 100% rename from app/src/main/res/layout/dialog_bottom_sheet2.xml rename to app/src/main/res/layout-sw800dp/dialog_bottom_sheet2.xml diff --git a/app/src/main/res/layout/dialog_common.xml b/app/src/main/res/layout-sw800dp/dialog_common.xml similarity index 100% rename from app/src/main/res/layout/dialog_common.xml rename to app/src/main/res/layout-sw800dp/dialog_common.xml diff --git a/app/src/main/res/layout/dialog_loading.xml b/app/src/main/res/layout-sw800dp/dialog_loading.xml similarity index 100% rename from app/src/main/res/layout/dialog_loading.xml rename to app/src/main/res/layout-sw800dp/dialog_loading.xml diff --git a/app/src/main/res/layout/fragment_dish_list.xml b/app/src/main/res/layout-sw800dp/fragment_dish_list.xml similarity index 100% rename from app/src/main/res/layout/fragment_dish_list.xml rename to app/src/main/res/layout-sw800dp/fragment_dish_list.xml diff --git a/app/src/main/res/layout/fragment_dish_sampling.xml b/app/src/main/res/layout-sw800dp/fragment_dish_sampling.xml similarity index 100% rename from app/src/main/res/layout/fragment_dish_sampling.xml rename to app/src/main/res/layout-sw800dp/fragment_dish_sampling.xml diff --git a/app/src/main/res/layout/fragment_sampling_list.xml b/app/src/main/res/layout-sw800dp/fragment_sampling_list.xml similarity index 94% rename from app/src/main/res/layout/fragment_sampling_list.xml rename to app/src/main/res/layout-sw800dp/fragment_sampling_list.xml index 9dab987..7abd3e0 100644 --- a/app/src/main/res/layout/fragment_sampling_list.xml +++ b/app/src/main/res/layout-sw800dp/fragment_sampling_list.xml @@ -65,7 +65,7 @@ - + @@ -81,13 +81,13 @@ - + - + diff --git a/app/src/main/res/layout/layout_empty_view.xml b/app/src/main/res/layout-sw800dp/layout_empty_view.xml similarity index 100% rename from app/src/main/res/layout/layout_empty_view.xml rename to app/src/main/res/layout-sw800dp/layout_empty_view.xml diff --git a/app/src/main/res/layout/layout_food_remind.xml b/app/src/main/res/layout-sw800dp/layout_food_remind.xml similarity index 100% rename from app/src/main/res/layout/layout_food_remind.xml rename to app/src/main/res/layout-sw800dp/layout_food_remind.xml diff --git a/app/src/main/res/layout/layout_grid.xml b/app/src/main/res/layout-sw800dp/layout_grid.xml similarity index 99% rename from app/src/main/res/layout/layout_grid.xml rename to app/src/main/res/layout-sw800dp/layout_grid.xml index 8e78397..145f017 100644 --- a/app/src/main/res/layout/layout_grid.xml +++ b/app/src/main/res/layout-sw800dp/layout_grid.xml @@ -195,7 +195,7 @@ + + + tools:text="10" /> - - - \ No newline at end of file diff --git a/app/src/main/res/layout/list_item_cell.xml b/app/src/main/res/layout-sw800dp/list_item_cell.xml similarity index 100% rename from app/src/main/res/layout/list_item_cell.xml rename to app/src/main/res/layout-sw800dp/list_item_cell.xml diff --git a/app/src/main/res/layout/list_item_dish.xml b/app/src/main/res/layout-sw800dp/list_item_dish.xml similarity index 100% rename from app/src/main/res/layout/list_item_dish.xml rename to app/src/main/res/layout-sw800dp/list_item_dish.xml diff --git a/app/src/main/res/layout/list_item_dish_cook.xml b/app/src/main/res/layout-sw800dp/list_item_dish_cook.xml similarity index 100% rename from app/src/main/res/layout/list_item_dish_cook.xml rename to app/src/main/res/layout-sw800dp/list_item_dish_cook.xml diff --git a/app/src/main/res/layout/list_item_dish_record.xml b/app/src/main/res/layout-sw800dp/list_item_dish_record.xml similarity index 100% rename from app/src/main/res/layout/list_item_dish_record.xml rename to app/src/main/res/layout-sw800dp/list_item_dish_record.xml diff --git a/app/src/main/res/layout/list_item_home_mode.xml b/app/src/main/res/layout-sw800dp/list_item_home_mode.xml similarity index 100% rename from app/src/main/res/layout/list_item_home_mode.xml rename to app/src/main/res/layout-sw800dp/list_item_home_mode.xml diff --git a/app/src/main/res/layout/list_item_search_goods_info.xml b/app/src/main/res/layout-sw800dp/list_item_search_goods_info.xml similarity index 100% rename from app/src/main/res/layout/list_item_search_goods_info.xml rename to app/src/main/res/layout-sw800dp/list_item_search_goods_info.xml diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 8fdd780..4bfc287 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -12,5 +12,6 @@ ?attr/colorPrimaryVariant + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 58d32ad..95b4e50 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -12,6 +12,7 @@ ?attr/colorPrimaryVariant +