2 Commits
Author SHA1 Message Date
lvmeng 9a0b066490 refactor(ui): 对页面名称进行统一重命名
- 将 SelectDishActivity 重命名为 CookingModeActivity
- 将 PrepareCookActivity 重命名为 PrepareFoodActivity
- 将 SamplingListActivity 重命名为 SamplingModeActivity
- 更新 AndroidManifest.xml 中的活动声明
- 修改 DishListFragment 中的相关引用
- 注释掉 DishSamplingActivity 的完整实现代码
- 更新 DeviceConfigFragment 中的活动跳转逻辑
- 优化 CookingModeActivity 的视图绑定方式
- 更新相关导入包路径和类引用
2026-04-28 18:13:50 +08:00
lvmengandClaude Sonnet 4.6 e8933fa578 fix(activity): 修复采样与菜品列表页异常场景的数据展示
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-28 17:46:19 +08:00
19 changed files with 638 additions and 622 deletions
+8 -8
View File
@@ -58,23 +58,23 @@
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".ui.SelectDishActivity" android:name=".ui.CookingModeActivity"
android:theme="@style/Theme.DishMatch.NoSplash" android:theme="@style/Theme.DishMatch.NoSplash"
android:launchMode="singleTask" android:launchMode="singleTask"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".ui.PrepareCookActivity" android:name=".ui.PrepareFoodActivity"
android:theme="@style/Theme.DishMatch.NoSplash" android:theme="@style/Theme.DishMatch.NoSplash"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<!-- <activity-->
<!-- android:name=".ui.DishSamplingActivity"-->
<!-- android:theme="@style/Theme.DishMatch.NoSplash"-->
<!-- android:screenOrientation="portrait"-->
<!-- tools:ignore="DiscouragedApi,LockedOrientationActivity" />-->
<activity <activity
android:name=".ui.DishSamplingActivity" android:name=".ui.SamplingModeActivity"
android:theme="@style/Theme.DishMatch.NoSplash"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.SamplingListActivity"
android:theme="@style/Theme.DishMatch.NoSplash" android:theme="@style/Theme.DishMatch.NoSplash"
android:launchMode="singleTask" android:launchMode="singleTask"
android:screenOrientation="portrait" android:screenOrientation="portrait"
@@ -7,8 +7,7 @@ import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp import com.shuwei.dish.match.databinding.ActivityCookingModeBinding
import com.shuwei.dish.match.databinding.ActivitySelectDishBinding
import com.shuwei.dish.match.dialog.CommonDialog import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.ui.fragment.DishListFragment import com.shuwei.dish.match.ui.fragment.DishListFragment
import com.shuwei.dish.match.utils.KeyboardUtil import com.shuwei.dish.match.utils.KeyboardUtil
@@ -18,7 +17,10 @@ import com.shuwei.dish.match.utils.ext.startActivity
import com.shuwei.dish.match.utils.ext.toast import com.shuwei.dish.match.utils.ext.toast
import com.shuwei.dish.match.utils.ext.visible import com.shuwei.dish.match.utils.ext.visible
class SelectDishActivity : BaseActivity() { /**
* 制作模式
*/
class CookingModeActivity : BaseActivity() {
companion object { companion object {
const val IS_COOKING = "isCooking" const val IS_COOKING = "isCooking"
@@ -26,7 +28,7 @@ class SelectDishActivity : BaseActivity() {
const val IS_CONFIG_PAGE = "isConfigPage" const val IS_CONFIG_PAGE = "isConfigPage"
} }
private lateinit var binding: ActivitySelectDishBinding private val binding by lazy { ActivityCookingModeBinding.inflate(layoutInflater) }
private var dinnerType: String = "1" private var dinnerType: String = "1"
@@ -38,7 +40,6 @@ class SelectDishActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivitySelectDishBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
setHeaderBackground() setHeaderBackground()
setTitleBar(titleBarAction = { setTitleBar(titleBarAction = {
@@ -1,291 +1,291 @@
package com.shuwei.dish.match.ui //package com.shuwei.dish.match.ui
//
import android.annotation.SuppressLint //import android.annotation.SuppressLint
import android.content.Intent //import android.content.Intent
import android.os.Bundle //import android.os.Bundle
import android.util.Log //import android.util.Log
import android.view.View //import android.view.View
import androidx.activity.addCallback //import androidx.activity.addCallback
import androidx.activity.viewModels //import androidx.activity.viewModels
import androidx.recyclerview.widget.ItemTouchHelper //import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager //import androidx.recyclerview.widget.LinearLayoutManager
import com.shuwei.dish.match.R //import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.DishPartAdapter //import com.shuwei.dish.match.adapter.DishPartAdapter
import com.shuwei.dish.match.base.BaseActivity //import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp //import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.ActivityDishSamplingBinding //import com.shuwei.dish.match.databinding.ActivityDishSamplingBinding
import com.shuwei.dish.match.dialog.FoodSearchDialog //import com.shuwei.dish.match.dialog.FoodSearchDialog
import com.shuwei.dish.match.dialog.CommonDialog //import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.entity.CookFoodEntity //import com.shuwei.dish.match.entity.CookFoodEntity
import com.shuwei.dish.match.entity.CookFoodGoodsEntity //import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.entity.FoodRecord //import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.net.NetViewModel //import com.shuwei.dish.match.net.NetViewModel
import com.shuwei.dish.match.utils.AddressUtil //import com.shuwei.dish.match.utils.AddressUtil
import com.shuwei.dish.match.utils.KeyboardUtil //import com.shuwei.dish.match.utils.KeyboardUtil
import com.shuwei.dish.match.utils.SwipeCallback //import com.shuwei.dish.match.utils.SwipeCallback
import com.shuwei.dish.match.utils.WeightUtil //import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener //import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
import com.shuwei.dish.match.utils.ext.clickWithDebounce //import com.shuwei.dish.match.utils.ext.clickWithDebounce
import com.shuwei.dish.match.utils.ext.gone //import com.shuwei.dish.match.utils.ext.gone
import com.shuwei.dish.match.utils.ext.startActivity //import com.shuwei.dish.match.utils.ext.startActivity
import com.shuwei.dish.match.utils.ext.toJsonString //import com.shuwei.dish.match.utils.ext.toJsonString
import com.shuwei.dish.match.utils.ext.toast //import com.shuwei.dish.match.utils.ext.toast
import com.shuwei.dish.match.utils.ext.visible //import com.shuwei.dish.match.utils.ext.visible
import java.io.Serializable //import java.io.Serializable
//
class DishSamplingActivity : BaseActivity() { //class DishSamplingActivity : BaseActivity() {
//
private lateinit var binding: ActivityDishSamplingBinding // private lateinit var binding: ActivityDishSamplingBinding
//
var foodName: String? = null // var foodName: String? = null
//
private var foodId: String? = null // private var foodId: String? = null
//
companion object { // companion object {
private const val TAG = "DishSamplingActivity" // private const val TAG = "DishSamplingActivity"
public const val FOOD_NAME = "foodName" // public const val FOOD_NAME = "foodName"
public const val PAGE_FROM = "pageFrom" // public const val PAGE_FROM = "pageFrom"
public const val HOME = "home" // public const val HOME = "home"
} // }
//
private var pageFrom: String? = null // private var pageFrom: String? = null
//
override fun onCreate(savedInstanceState: Bundle?) { // override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) // super.onCreate(savedInstanceState)
binding = ActivityDishSamplingBinding.inflate(layoutInflater) // binding = ActivityDishSamplingBinding.inflate(layoutInflater)
setContentView(binding.root) // setContentView(binding.root)
pageFrom = intent.getStringExtra(PAGE_FROM) // pageFrom = intent.getStringExtra(PAGE_FROM)
setTitleBar() // setTitleBar()
setHeaderBackground() // setHeaderBackground()
addViewClickListener() // addViewClickListener()
foodName = intent.getStringExtra(FOOD_NAME) // foodName = intent.getStringExtra(FOOD_NAME)
binding.etInputDish.setText(foodName) // binding.etInputDish.setText(foodName)
//
WeightUtil.addWeightListener( // WeightUtil.addWeightListener(
weightKey = TAG, // weightKey = TAG,
getWeight = { address, state, weight -> // getWeight = { address, state, weight ->
//Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight") // //Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
if (address == AddressUtil.ONE) { // if (address == AddressUtil.ONE) {
tempDishEntity?.useWeight = weight.toDouble() // tempDishEntity?.useWeight = weight.toDouble()
binding.tvDishPartWeight.text = "${weight}" // binding.tvDishPartWeight.text = "${weight}"
} // }
}) // })
addBackKeyListener() // addBackKeyListener()
} // }
//
private fun setTitleBar() { // private fun setTitleBar() {
setTitleBar(titleBarAction = { // setTitleBar(titleBarAction = {
it.visible() // it.visible()
}, titleAction = { // }, titleAction = {
it.text = "菜品采集" // it.text = "菜品采集"
}, rightIconActon = { // }, rightIconActon = {
it.gone() // it.gone()
it.setImageResource(R.drawable.ic_setting) // it.setImageResource(R.drawable.ic_setting)
it.setOnClickListener { // it.setOnClickListener {
//startActivity<DeviceSettingActivity>() // //startActivity<DeviceSettingActivity>()
} // }
}, backAction = { // }, backAction = {
it.visible() // it.visible()
it.setOnClickListener { // it.setOnClickListener {
onBackPressedDispatcher.onBackPressed() // onBackPressedDispatcher.onBackPressed()
} // }
}) // })
} // }
//
//
//
fun getCookFoodList() { // fun getCookFoodList() {
appViewModel.getCookFoodList(cookMode = 1) // appViewModel.getCookFoodList(cookMode = 1)
} // }
//
/** // /**
* 监听返回键 // * 监听返回键
*/ // */
fun addBackKeyListener() { // fun addBackKeyListener() {
onBackPressedDispatcher.addCallback(this) { // onBackPressedDispatcher.addCallback(this) {
if (list.isEmpty().not()) { // if (list.isEmpty().not()) {
//说明有新增的食材 // //说明有新增的食材
saveDataRemindDialog() // saveDataRemindDialog()
return@addCallback // return@addCallback
} // }
if (pageFrom == HOME) { // if (pageFrom == HOME) {
startActivity<SamplingListActivity>() // startActivity<SamplingListActivity>()
} // }
onBackPressedDispatcher.onBackPressed() // onBackPressedDispatcher.onBackPressed()
} // }
} // }
//
private fun saveDataRemindDialog() { // private fun saveDataRemindDialog() {
CommonDialog(this) // CommonDialog(this)
.setTitle("返回提示") // .setTitle("返回提示")
.setContent("您好,当前页面存在未保存的数据,\n确认返回吗?") // .setContent("您好,当前页面存在未保存的数据,\n确认返回吗?")
.setNegativeButton("取消") // .setNegativeButton("取消")
.setPositiveButton("确认") { // .setPositiveButton("确认") {
if (pageFrom == HOME) { // if (pageFrom == HOME) {
startActivity<SamplingListActivity>() // startActivity<SamplingListActivity>()
} // }
finish() // finish()
} // }
.setOnDismissCallback { hideStatusBar() } // .setOnDismissCallback { hideStatusBar() }
.show() // .show()
} // }
//
//
val list: MutableList<CookFoodGoodsEntity> = mutableListOf() // val list: MutableList<CookFoodGoodsEntity> = mutableListOf()
//
private var tempDishEntity: CookFoodGoodsEntity? = null // private var tempDishEntity: CookFoodGoodsEntity? = null
//
private var dishMaterialType = 1 // private var dishMaterialType = 1
//
private val dishAdapter by lazy { // private val dishAdapter by lazy {
DishPartAdapter(list).apply { // DishPartAdapter(list).apply {
addOnItemChildClickListener(R.id.ivOperateIcon) { _, _, position -> // addOnItemChildClickListener(R.id.ivOperateIcon) { _, _, position ->
//删除操作 // //删除操作
list.removeAt(position) // list.removeAt(position)
notifyItemRemoved(position) // notifyItemRemoved(position)
notifyItemRangeChanged(position, list.size - position) // notifyItemRangeChanged(position, list.size - position)
} // }
} // }
} // }
//
@SuppressLint("NotifyDataSetChanged") // @SuppressLint("NotifyDataSetChanged")
private fun addViewClickListener() { // private fun addViewClickListener() {
binding.rvDishPartList.run { // binding.rvDishPartList.run {
layoutManager = // layoutManager =
LinearLayoutManager(this@DishSamplingActivity, LinearLayoutManager.VERTICAL, false) // LinearLayoutManager(this@DishSamplingActivity, LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter // adapter = dishAdapter
val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position -> // val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position ->
list.removeAt(position) // list.removeAt(position)
dishAdapter.notifyItemRemoved(position) // dishAdapter.notifyItemRemoved(position)
dishAdapter.notifyItemRangeChanged(position, list.size - position) // dishAdapter.notifyItemRangeChanged(position, list.size - position)
toast("已删除") // toast("已删除")
}) // })
itemTouchHelper.attachToRecyclerView(this) // itemTouchHelper.attachToRecyclerView(this)
} // }
binding.etInputDishType.addOnActionSearchListener { // binding.etInputDishType.addOnActionSearchListener {
searchDishType() // searchDishType()
} // }
binding.ivDishTypeSearch.setOnClickListener { // binding.ivDishTypeSearch.setOnClickListener {
searchDishType() // searchDishType()
} // }
//
binding.ivWeightClear.setOnClickListener { // binding.ivWeightClear.setOnClickListener {
WeightUtil.tareTwo(AddressUtil.ONE) // WeightUtil.tareTwo(AddressUtil.ONE)
} // }
binding.ivWeightAdd.setOnClickListener { // binding.ivWeightAdd.setOnClickListener {
if (tempDishEntity == null) { // if (tempDishEntity == null) {
toast("请输入食材名称") // toast("请输入食材名称")
return@setOnClickListener // return@setOnClickListener
} // }
if (binding.rgSampling.checkedRadioButtonId == -1) { // if (binding.rgSampling.checkedRadioButtonId == -1) {
toast("请选择主辅材类型") // toast("请选择主辅材类型")
return@setOnClickListener // return@setOnClickListener
} // }
val realWeight = tempDishEntity!!.useWeight ?: 0.0 // val realWeight = tempDishEntity!!.useWeight ?: 0.0
if (realWeight <= 0.toDouble()) { // if (realWeight <= 0.toDouble()) {
toast("食材用量需要大于0") // toast("食材用量需要大于0")
return@setOnClickListener // return@setOnClickListener
} // }
if (tempDishEntity?.goodsName != binding.etInputDishType.text.toString().trim()) { // if (tempDishEntity?.goodsName != binding.etInputDishType.text.toString().trim()) {
toast("所选择的食材名称与输入框内容不一致") // toast("所选择的食材名称与输入框内容不一致")
return@setOnClickListener // return@setOnClickListener
} // }
tempDishEntity!!.apply { // tempDishEntity!!.apply {
isSamplingPage = true // isSamplingPage = true
materialType = dishMaterialType // materialType = dishMaterialType
} // }
val result = list.firstOrNull { it.goodsId == tempDishEntity!!.goodsId } // val result = list.firstOrNull { it.goodsId == tempDishEntity!!.goodsId }
if (result != null) { // if (result != null) {
toast("${result.goodsName}食材已添加,请勿重复操作") // toast("${result.goodsName}食材已添加,请勿重复操作")
return@setOnClickListener // return@setOnClickListener
} // }
list.add(tempDishEntity!!) // list.add(tempDishEntity!!)
dishAdapter.notifyDataSetChanged() // dishAdapter.notifyDataSetChanged()
tempDishEntity = null // tempDishEntity = null
binding.etInputDishType.setText("") // binding.etInputDishType.setText("")
binding.rgSampling.clearCheck() // binding.rgSampling.clearCheck()
} // }
binding.rgSampling.setOnCheckedChangeListener { group, checkedId -> // binding.rgSampling.setOnCheckedChangeListener { group, checkedId ->
dishMaterialType = if (checkedId == R.id.rbDishTypeFirst) 1 else 2 // dishMaterialType = if (checkedId == R.id.rbDishTypeFirst) 1 else 2
} // }
binding.ivDishSearch.setOnClickListener { v -> // binding.ivDishSearch.setOnClickListener { v ->
jumpSearch(v) // jumpSearch(v)
} // }
binding.btnCook.clickWithDebounce { // binding.btnCook.clickWithDebounce {
val showFoodName = binding.etInputDish.text.toString().trim() // val showFoodName = binding.etInputDish.text.toString().trim()
if (showFoodName.isBlank()) { // if (showFoodName.isBlank()) {
toast("菜品名称为空") // toast("菜品名称为空")
return@clickWithDebounce // return@clickWithDebounce
} // }
if (list.isEmpty()) { // if (list.isEmpty()) {
toast("菜品构成信息未设置") // toast("菜品构成信息未设置")
return@clickWithDebounce // return@clickWithDebounce
} // }
val food = FoodRecord() // val food = FoodRecord()
binding.etInputDish.let { // binding.etInputDish.let {
if (it.tag != null && it.tag.toString() == it.text.toString()) { // if (it.tag != null && it.tag.toString() == it.text.toString()) {
food.foodId = foodId // food.foodId = foodId
} // }
} // }
food.foodName = showFoodName // food.foodName = showFoodName
food.cookMode = 1 // food.cookMode = 1
Log.d(TAG, "goToSubmit: goodsList:${list.toJsonString()}") // Log.d(TAG, "goToSubmit: goodsList:${list.toJsonString()}")
// startActivity<SubmitDishActivity> { //// startActivity<SubmitDishActivity> {
startActivity<SubmitFoodActivity> { // startActivity<SubmitFoodActivity> {
putExtra(SubmitFoodActivity.GOODS_LIST, list as java.io.Serializable) // putExtra(SubmitFoodActivity.GOODS_LIST, list as java.io.Serializable)
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable) // putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
} // }
} // }
binding.etInputDish.let { v -> // binding.etInputDish.let { v ->
v.addOnActionSearchListener { // v.addOnActionSearchListener {
jumpSearch(v) // jumpSearch(v)
} // }
} // }
} // }
//
private fun jumpSearch(v: View) { // private fun jumpSearch(v: View) {
val intent = Intent(this, FoodSearchActivity::class.java).apply { // val intent = Intent(this, FoodSearchActivity::class.java).apply {
putExtra(FoodSearchActivity.FOOD_NAME, binding.etInputDish.text.toString().trim()) // putExtra(FoodSearchActivity.FOOD_NAME, binding.etInputDish.text.toString().trim())
} // }
startActivity(intent) { // startActivity(intent) {
foodId = it?.getStringExtra(FoodSearchActivity.FOOD_ID) // foodId = it?.getStringExtra(FoodSearchActivity.FOOD_ID)
foodName = it?.getStringExtra(FoodSearchActivity.FOOD_NAME) // foodName = it?.getStringExtra(FoodSearchActivity.FOOD_NAME)
binding.etInputDish.run { // binding.etInputDish.run {
setText(foodName) // setText(foodName)
tag = foodName // tag = foodName
setSelection(text.length) // setSelection(text.length)
} // }
} // }
KeyboardUtil.hideKeyboard(v) // KeyboardUtil.hideKeyboard(v)
} // }
//
private fun searchDishType() { // private fun searchDishType() {
val inputText = binding.etInputDishType.text.toString().trim() // val inputText = binding.etInputDishType.text.toString().trim()
FoodSearchDialog( // FoodSearchDialog(
activity = this@DishSamplingActivity, // activity = this@DishSamplingActivity,
defGoodsName = inputText // defGoodsName = inputText
) { item -> // ) { item ->
val filterResult = list.firstOrNull { it.goodsName == item.goodsName } // val filterResult = list.firstOrNull { it.goodsName == item.goodsName }
if (filterResult != null) { // if (filterResult != null) {
toast("不允许重复添加同一食材") // toast("不允许重复添加同一食材")
return@FoodSearchDialog // return@FoodSearchDialog
} // }
binding.etInputDishType.run { // binding.etInputDishType.run {
setText(item.goodsName) // setText(item.goodsName)
setSelection(length()) // setSelection(length())
} // }
tempDishEntity = CookFoodGoodsEntity().apply { // tempDishEntity = CookFoodGoodsEntity().apply {
goodsId = item.goodsId // goodsId = item.goodsId
goodsName = item.goodsName // goodsName = item.goodsName
//
relateionType = item.relateionType ?: 0 // relateionType = item.relateionType ?: 0
goodsOrRelationCode = item.goodsOrRelationCode // goodsOrRelationCode = item.goodsOrRelationCode
//
isNewDishType = true // isNewDishType = true
// TODO: 待定 // // TODO: 待定
//allEdible = item.allEdible // //allEdible = item.allEdible
} // }
}.show() // }.show()
} // }
//
} //}
@@ -25,6 +25,9 @@ import com.shuwei.dish.match.utils.ext.visible
import java.io.Serializable import java.io.Serializable
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
/**
* 菜品搜索页面
*/
class FoodSearchActivity : BaseActivity() { class FoodSearchActivity : BaseActivity() {
companion object { companion object {
@@ -46,8 +49,8 @@ class FoodSearchActivity : BaseActivity() {
setOnItemClickListener { adapter, view, position -> setOnItemClickListener { adapter, view, position ->
if (pageType == 1) { if (pageType == 1) {
val jumpItem = list[position].also { it.dinnerType = dinnerType } val jumpItem = list[position].also { it.dinnerType = dinnerType }
startActivity<PrepareCookActivity> { startActivity<PrepareFoodActivity> {
putExtra(PrepareCookActivity.FOOD_ITEM, jumpItem as Serializable) putExtra(PrepareFoodActivity.FOOD_ITEM, jumpItem as Serializable)
} }
return@setOnItemClickListener return@setOnItemClickListener
} }
@@ -16,6 +16,9 @@ import com.shuwei.dish.match.utils.ext.startActivity
import com.shuwei.dish.match.utils.ext.toast import com.shuwei.dish.match.utils.ext.toast
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
/**
* 主页,包括三种模式:制作模式、采样模式、品控模式
*/
class HomeActivity : BaseActivity() { class HomeActivity : BaseActivity() {
companion object { companion object {
@@ -105,7 +108,7 @@ class HomeActivity : BaseActivity() {
modeIconId = R.drawable.ic_mode_cook, modeIconId = R.drawable.ic_mode_cook,
onClick = { onClick = {
SpTool.cookMode = 0 SpTool.cookMode = 0
startActivity<SelectDishActivity>() startActivity<CookingModeActivity>()
finish() finish()
}) })
) )
@@ -138,20 +141,20 @@ class HomeActivity : BaseActivity() {
val slots = appViewModel.loadSeasoningSlot() val slots = appViewModel.loadSeasoningSlot()
if (slots.isEmpty()) { if (slots.isEmpty()) {
// 无调料信息,打开采样历史列表页面,点击设置配置调料信息 // 无调料信息,打开采样历史列表页面,点击设置配置调料信息
startActivity<SamplingListActivity>() startActivity<SamplingModeActivity>()
finish() finish()
return@launch return@launch
} }
val count = appViewModel.countCookFood(cookMode = 1) val count = appViewModel.countCookFood(cookMode = 1)
if (count > 0) { if (count > 0) {
// 有烹饪中数据,打开采样历史列表页面 // 有烹饪中数据,打开采样历史列表页面
startActivity<SamplingListActivity>() startActivity<SamplingModeActivity>()
finish() finish()
return@launch return@launch
} }
// 无烹饪数据,打开新增采样页面 // 无烹饪数据,打开新增采样页面
startActivity<PrepareCookActivity> { startActivity<PrepareFoodActivity> {
putExtra(PrepareCookActivity.PAGE_FROM, PrepareCookActivity.HOME) putExtra(PrepareFoodActivity.PAGE_FROM, PrepareFoodActivity.HOME)
} }
finish() finish()
} }
@@ -72,7 +72,7 @@ class InitActivity : BaseActivity() {
// 主设备:走原有路由逻辑 // 主设备:走原有路由逻辑
when (SpTool.cookMode) { when (SpTool.cookMode) {
0 -> { 0 -> {
startActivity<SelectDishActivity>() startActivity<CookingModeActivity>()
} }
1 -> { 1 -> {
@@ -91,18 +91,18 @@ class InitActivity : BaseActivity() {
val slots = appViewModel.loadSeasoningSlot() val slots = appViewModel.loadSeasoningSlot()
if (slots.isEmpty()) { if (slots.isEmpty()) {
// 无调料信息,打开采样历史列表页面,点击设置配置调料信息 // 无调料信息,打开采样历史列表页面,点击设置配置调料信息
startActivity<SamplingListActivity>() startActivity<SamplingModeActivity>()
return@launch return@launch
} }
val count = appViewModel.countCookFood(cookMode = 1) val count = appViewModel.countCookFood(cookMode = 1)
if (count > 0) { if (count > 0) {
// 有烹饪中数据,打开采样历史列表页面 // 有烹饪中数据,打开采样历史列表页面
startActivity<SamplingListActivity>() startActivity<SamplingModeActivity>()
return@launch return@launch
} }
// 无烹饪数据,打开新增采样页面 // 无烹饪数据,打开新增采样页面
startActivity<PrepareCookActivity> { startActivity<PrepareFoodActivity> {
putExtra(PrepareCookActivity.PAGE_FROM, PrepareCookActivity.HOME) putExtra(PrepareFoodActivity.PAGE_FROM, PrepareFoodActivity.HOME)
} }
} }
} }
@@ -16,7 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.DishPartAdapter import com.shuwei.dish.match.adapter.DishPartAdapter
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.databinding.ActivityPrepareCookBinding import com.shuwei.dish.match.databinding.ActivityPrepareFoodBinding
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
import com.shuwei.dish.match.dialog.CommonDialog import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.entity.CookFoodEntity import com.shuwei.dish.match.entity.CookFoodEntity
@@ -39,15 +39,15 @@ import com.shuwei.dish.match.utils.ext.toJsonString
import com.shuwei.dish.match.utils.ext.toast import com.shuwei.dish.match.utils.ext.toast
import com.shuwei.dish.match.utils.ext.visible import com.shuwei.dish.match.utils.ext.visible
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.Serializable import java.io.Serializable
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import kotlin.getValue
import kotlin.math.abs import kotlin.math.abs
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
class PrepareCookActivity : BaseActivity() { class PrepareFoodActivity : BaseActivity() {
companion object { companion object {
const val TAG = "CookActivity" const val TAG = "CookActivity"
@@ -59,7 +59,7 @@ class PrepareCookActivity : BaseActivity() {
const val WEIGHT_RECOGNIZE_VALUE = 10 const val WEIGHT_RECOGNIZE_VALUE = 10
} }
private lateinit var binding: ActivityPrepareCookBinding private val binding by lazy { ActivityPrepareFoodBinding.inflate(layoutInflater) }
private val cameraUtils: CameraUtils by lazy { CameraUtils(this) } private val cameraUtils: CameraUtils by lazy { CameraUtils(this) }
@@ -76,7 +76,6 @@ class PrepareCookActivity : BaseActivity() {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityPrepareCookBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
setHeaderBackground() setHeaderBackground()
pageFrom = intent.getStringExtra(PAGE_FROM) pageFrom = intent.getStringExtra(PAGE_FROM)
@@ -383,7 +382,7 @@ class PrepareCookActivity : BaseActivity() {
private fun initRecyclerView() { private fun initRecyclerView() {
binding.rvDishPartList.run { binding.rvDishPartList.run {
layoutManager = layoutManager =
LinearLayoutManager(this@PrepareCookActivity, LinearLayoutManager.VERTICAL, false) LinearLayoutManager(this@PrepareFoodActivity, LinearLayoutManager.VERTICAL, false)
adapter = dishPartAdapter adapter = dishPartAdapter
val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishPartAdapter) { position -> val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishPartAdapter) { position ->
if (list[position].isNewDishType.not()) { if (list[position].isNewDishType.not()) {
@@ -435,7 +434,7 @@ class PrepareCookActivity : BaseActivity() {
return@addCallback return@addCallback
} }
if (pageFrom == HOME) { if (pageFrom == HOME) {
startActivity<SamplingListActivity>() startActivity<SamplingModeActivity>()
} }
} else { } else {
// 制作模式:有未保存数据时提示 // 制作模式:有未保存数据时提示
@@ -459,7 +458,7 @@ class PrepareCookActivity : BaseActivity() {
.setNegativeButton("取消") .setNegativeButton("取消")
.setPositiveButton("确认") { .setPositiveButton("确认") {
if (SpTool.cookMode == 1 && pageFrom == HOME) { if (SpTool.cookMode == 1 && pageFrom == HOME) {
startActivity<SamplingListActivity>() startActivity<SamplingModeActivity>()
} }
finish() finish()
} }
@@ -475,7 +474,7 @@ class PrepareCookActivity : BaseActivity() {
lastPhotoUri = uri lastPhotoUri = uri
lifecycleScope.launch { lifecycleScope.launch {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val bitmap = ImageUtil.uriToBitmap(this@PrepareCookActivity, uri) val bitmap = ImageUtil.uriToBitmap(this@PrepareFoodActivity, uri)
if (bitmap == null) { if (bitmap == null) {
dismissLoading() dismissLoading()
Log.d(TAG, "takePhoto bitmap is null") Log.d(TAG, "takePhoto bitmap is null")
@@ -14,10 +14,9 @@ import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SamplingAdapter import com.shuwei.dish.match.adapter.SamplingAdapter
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.ActivitySamplingBinding import com.shuwei.dish.match.databinding.ActivitySamplingModeBinding
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
import com.shuwei.dish.match.dialog.CommonDialog import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.entity.CookFoodEntity
import com.shuwei.dish.match.entity.FoodRecord import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.utils.DateTimeUtil import com.shuwei.dish.match.utils.DateTimeUtil
import com.shuwei.dish.match.utils.SwipeCallback import com.shuwei.dish.match.utils.SwipeCallback
@@ -28,10 +27,12 @@ import com.shuwei.dish.match.utils.ext.visible
import java.io.Serializable import java.io.Serializable
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import com.shuwei.dish.match.net.UiState import com.shuwei.dish.match.net.UiState
/**
* 采样模式
*/
class SamplingModeActivity : BaseActivity() {
class SamplingListActivity : BaseActivity() { private val binding by lazy { ActivitySamplingModeBinding.inflate(layoutInflater) }
private lateinit var binding: ActivitySamplingBinding
companion object { companion object {
private const val TAG = "SamplingListActivity" private const val TAG = "SamplingListActivity"
@@ -41,7 +42,6 @@ class SamplingListActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivitySamplingBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
setTitleBar() setTitleBar()
setHeaderBackground() setHeaderBackground()
@@ -59,6 +59,7 @@ class SamplingListActivity : BaseActivity() {
lifecycleScope.launch { lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) { repeatOnLifecycle(Lifecycle.State.STARTED) {
appViewModel.cookFoodListState.collect { cookFoodEntities -> appViewModel.cookFoodListState.collect { cookFoodEntities ->
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingCooking) return@collect
delayDismissLoading() delayDismissLoading()
if (cookFoodEntities.isNullOrEmpty()) { if (cookFoodEntities.isNullOrEmpty()) {
loadEmptyView() loadEmptyView()
@@ -89,8 +90,18 @@ class SamplingListActivity : BaseActivity() {
netViewModel.samplingListState.collect { state -> netViewModel.samplingListState.collect { state ->
when (state) { when (state) {
is UiState.Loading -> showLoading() is UiState.Loading -> showLoading()
is UiState.Success -> loadDishList(state.data) is UiState.Success -> {
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingFinished) {
delayDismissLoading()
return@collect
}
loadDishList(state.data)
}
is UiState.Error -> { is UiState.Error -> {
if (binding.dishRadioGroup.checkedRadioButtonId != R.id.rbSamplingFinished) {
delayDismissLoading()
return@collect
}
binding.refreshLayout.setEnableRefresh(true) binding.refreshLayout.setEnableRefresh(true)
toast(state.msg) toast(state.msg)
finishRefresh() finishRefresh()
@@ -170,8 +181,8 @@ class SamplingListActivity : BaseActivity() {
} }
return return
} }
startActivity<PrepareCookActivity> { startActivity<PrepareFoodActivity> {
putExtra(PrepareCookActivity.FOOD_NAME, item.foodName) putExtra(PrepareFoodActivity.FOOD_NAME, item.foodName)
} }
} }
@@ -179,7 +190,7 @@ class SamplingListActivity : BaseActivity() {
private fun initRecyclerView() { private fun initRecyclerView() {
binding.rvSamplingList.run { binding.rvSamplingList.run {
layoutManager = layoutManager =
LinearLayoutManager(this@SamplingListActivity, LinearLayoutManager.VERTICAL, false) LinearLayoutManager(this@SamplingModeActivity, LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter adapter = dishAdapter
val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position -> val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position ->
if (list[position].isCooking.not()) { if (list[position].isCooking.not()) {
@@ -204,7 +215,7 @@ class SamplingListActivity : BaseActivity() {
private fun addViewListener() { private fun addViewListener() {
binding.btnAddSampling.setOnClickListener { binding.btnAddSampling.setOnClickListener {
judgeDeviceConfig { judgeDeviceConfig {
startActivity<PrepareCookActivity>() startActivity<PrepareFoodActivity>()
} }
} }
binding.refreshLayout.setOnRefreshListener { binding.refreshLayout.setOnRefreshListener {
@@ -5,8 +5,7 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp import com.shuwei.dish.match.ui.fragment.VectorCollectionFragment
import com.shuwei.dish.match.ui.fragment.CollectFragment
import com.shuwei.dish.match.ui.fragment.DeviceConfigFragment import com.shuwei.dish.match.ui.fragment.DeviceConfigFragment
import com.shuwei.dish.match.ui.fragment.SeasoningConfigFragment import com.shuwei.dish.match.ui.fragment.SeasoningConfigFragment
import com.shuwei.dish.match.utils.ext.gone import com.shuwei.dish.match.utils.ext.gone
@@ -103,7 +102,7 @@ class SingleFragmentActivity : BaseActivity() {
* 根据页面类型创建对应 Fragment 实例 * 根据页面类型创建对应 Fragment 实例
*/ */
private fun createFragment(pageType: PageType): Fragment = when (pageType) { private fun createFragment(pageType: PageType): Fragment = when (pageType) {
PageType.FOOD_COLLECT -> CollectFragment() PageType.FOOD_COLLECT -> VectorCollectionFragment()
PageType.COOK_MODE -> DeviceConfigFragment() PageType.COOK_MODE -> DeviceConfigFragment()
PageType.SEASONING_CONFIG -> SeasoningConfigFragment() PageType.SEASONING_CONFIG -> SeasoningConfigFragment()
} }
@@ -12,8 +12,6 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import com.google.gson.reflect.TypeToken
import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SeasoningWeightAdapter import com.shuwei.dish.match.adapter.SeasoningWeightAdapter
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp import com.shuwei.dish.match.base.BaseApp
@@ -22,7 +20,6 @@ import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.entity.CookFoodEntity import com.shuwei.dish.match.entity.CookFoodEntity
import com.shuwei.dish.match.entity.CookFoodGoodsEntity import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.entity.FoodRecord import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.net.NetViewModel
import com.shuwei.dish.match.net.UiState import com.shuwei.dish.match.net.UiState
import com.shuwei.dish.match.scale.ScaleDeviceConfig import com.shuwei.dish.match.scale.ScaleDeviceConfig
import com.shuwei.dish.match.scale.ScaleServiceManager import com.shuwei.dish.match.scale.ScaleServiceManager
@@ -36,13 +33,10 @@ import com.shuwei.dish.match.utils.ext.roundedDecimalPlace
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
import com.shuwei.dish.match.utils.ext.startActivity import com.shuwei.dish.match.utils.ext.startActivity
import com.shuwei.dish.match.utils.ext.toJsonString import com.shuwei.dish.match.utils.ext.toJsonString
import com.shuwei.dish.match.utils.ext.toType
import com.shuwei.dish.match.utils.ext.toast import com.shuwei.dish.match.utils.ext.toast
import com.shuwei.dish.match.utils.ext.visible import com.shuwei.dish.match.utils.ext.visible
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@SuppressLint("UseSparseArrays") @SuppressLint("UseSparseArrays")
class SubmitFoodActivity : BaseActivity() { class SubmitFoodActivity : BaseActivity() {
@@ -401,14 +395,14 @@ class SubmitFoodActivity : BaseActivity() {
private fun jumpPage(isSampling: Boolean, isCooking: Boolean) { private fun jumpPage(isSampling: Boolean, isCooking: Boolean) {
if (isSampling) { if (isSampling) {
startActivity<SamplingListActivity> { startActivity<SamplingModeActivity> {
putExtra(SelectDishActivity.IS_COOKING, isCooking) putExtra(CookingModeActivity.IS_COOKING, isCooking)
} }
return return
} }
startActivity<SelectDishActivity> { startActivity<CookingModeActivity> {
putExtra(SelectDishActivity.IS_COOKING, isCooking) putExtra(CookingModeActivity.IS_COOKING, isCooking)
putExtra(SelectDishActivity.DINNER_TYPE, food?.dinnerType) putExtra(CookingModeActivity.DINNER_TYPE, food?.dinnerType)
} }
} }
@@ -11,8 +11,8 @@ import android.view.ViewGroup
import androidx.core.graphics.toColorInt import androidx.core.graphics.toColorInt
import com.shuwei.dish.match.base.BaseFragment import com.shuwei.dish.match.base.BaseFragment
import com.shuwei.dish.match.databinding.FragmentDeviceConfigBinding import com.shuwei.dish.match.databinding.FragmentDeviceConfigBinding
import com.shuwei.dish.match.ui.SamplingListActivity import com.shuwei.dish.match.ui.SamplingModeActivity
import com.shuwei.dish.match.ui.SelectDishActivity import com.shuwei.dish.match.ui.CookingModeActivity
import com.shuwei.dish.match.utils.SpTool import com.shuwei.dish.match.utils.SpTool
import com.shuwei.dish.match.utils.ext.appendText import com.shuwei.dish.match.utils.ext.appendText
import com.shuwei.dish.match.utils.ext.buildSpannableString import com.shuwei.dish.match.utils.ext.buildSpannableString
@@ -94,8 +94,8 @@ class DeviceConfigFragment : BaseFragment<FragmentDeviceConfigBinding>() {
binding.rbModeSampling.isChecked = false binding.rbModeSampling.isChecked = false
loadCookSpan(isClicked = true) loadCookSpan(isClicked = true)
loadSamplingSpan() loadSamplingSpan()
activity?.startActivity<SelectDishActivity> { activity?.startActivity<CookingModeActivity> {
putExtra(SelectDishActivity.IS_CONFIG_PAGE, true) putExtra(CookingModeActivity.IS_CONFIG_PAGE, true)
} }
activity?.finish() activity?.finish()
} }
@@ -105,8 +105,8 @@ class DeviceConfigFragment : BaseFragment<FragmentDeviceConfigBinding>() {
binding.rbModeSampling.isChecked = true binding.rbModeSampling.isChecked = true
loadCookSpan() loadCookSpan()
loadSamplingSpan(isClicked = true) loadSamplingSpan(isClicked = true)
activity?.startActivity<SamplingListActivity> { activity?.startActivity<SamplingModeActivity> {
putExtra(SamplingListActivity.IS_CONFIG_PAGE, true) putExtra(SamplingModeActivity.IS_CONFIG_PAGE, true)
} }
activity?.finish() activity?.finish()
} }
@@ -3,7 +3,6 @@ package com.shuwei.dish.match.ui.fragment
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
@@ -19,8 +18,8 @@ import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
import com.shuwei.dish.match.entity.CookFoodEntity import com.shuwei.dish.match.entity.CookFoodEntity
import com.shuwei.dish.match.entity.FoodRecord import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.net.UiState import com.shuwei.dish.match.net.UiState
import com.shuwei.dish.match.ui.PrepareCookActivity import com.shuwei.dish.match.ui.PrepareFoodActivity
import com.shuwei.dish.match.ui.SelectDishActivity import com.shuwei.dish.match.ui.CookingModeActivity
import com.shuwei.dish.match.ui.SubmitFoodActivity import com.shuwei.dish.match.ui.SubmitFoodActivity
import com.shuwei.dish.match.utils.SwipeCallback import com.shuwei.dish.match.utils.SwipeCallback
import com.shuwei.dish.match.utils.ext.startActivity import com.shuwei.dish.match.utils.ext.startActivity
@@ -49,7 +48,7 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
private var dinnerType = "0" private var dinnerType = "0"
private lateinit var activity: SelectDishActivity private lateinit var activity: CookingModeActivity
private var list: MutableList<FoodRecord> = mutableListOf() private var list: MutableList<FoodRecord> = mutableListOf()
private val dishAdapter by lazy { private val dishAdapter by lazy {
@@ -79,7 +78,7 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
return return
} }
item.dinnerType = dinnerType item.dinnerType = dinnerType
activity.startActivity<PrepareCookActivity> { activity.startActivity<PrepareFoodActivity> {
putExtra( putExtra(
SubmitFoodActivity.FOOD_ITEM, SubmitFoodActivity.FOOD_ITEM,
item as Serializable item as Serializable
@@ -95,7 +94,7 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
} }
override fun initialize() { override fun initialize() {
activity = requireActivity() as SelectDishActivity activity = requireActivity() as CookingModeActivity
dinnerType = arguments?.getString(DINNER_TYPE, "0") ?: "0" dinnerType = arguments?.getString(DINNER_TYPE, "0") ?: "0"
binding.rvDishList.run { binding.rvDishList.run {
layoutManager = layoutManager =
@@ -146,8 +145,15 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
if (isAdded.not()) return@collect if (isAdded.not()) return@collect
toast(networkState.msg) toast(networkState.msg)
finishRefresh() finishRefresh()
if (pageNo == 1) loadEmptyView()
activity.delayDismissLoading() activity.delayDismissLoading()
if (pageNo == 1) {
// 网络异常或接口不通时,降级使用本地数据;本地也为空才显示空视图
if (localList.isNullOrEmpty()) {
loadEmptyView()
} else {
loadAndMergeDishList(null, localList)
}
}
} }
is UiState.Idle -> {} is UiState.Idle -> {}
} }
@@ -19,7 +19,7 @@ import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.VectorCollectionAdapter import com.shuwei.dish.match.adapter.VectorCollectionAdapter
import com.shuwei.dish.match.adapter.FoodSearchAdapter import com.shuwei.dish.match.adapter.FoodSearchAdapter
import com.shuwei.dish.match.base.BaseFragment import com.shuwei.dish.match.base.BaseFragment
import com.shuwei.dish.match.databinding.FragmentCollectBinding import com.shuwei.dish.match.databinding.FragmentVectorCollectionBinding
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
import com.shuwei.dish.match.dialog.Loading import com.shuwei.dish.match.dialog.Loading
import com.shuwei.dish.match.entity.CookFoodGoodsEntity import com.shuwei.dish.match.entity.CookFoodGoodsEntity
@@ -37,7 +37,7 @@ import com.shuwei.dish.match.utils.ext.dp
import com.shuwei.dish.match.utils.ext.toast import com.shuwei.dish.match.utils.ext.toast
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
class CollectFragment : BaseFragment<FragmentCollectBinding>() { class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>() {
companion object { companion object {
private const val TAG = "CollectFragment" private const val TAG = "CollectFragment"
@@ -105,8 +105,8 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>() {
override fun inflateBinding( override fun inflateBinding(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup? container: ViewGroup?
): FragmentCollectBinding { ): FragmentVectorCollectionBinding {
return FragmentCollectBinding.inflate(inflater, container, false) return FragmentVectorCollectionBinding.inflate(inflater, container, false)
} }
//typealias CameraCallback = (Uri) -> Unit //typealias CameraCallback = (Uri) -> Unit
+254 -254
View File
@@ -7,287 +7,287 @@
android:orientation="vertical" android:orientation="vertical"
tools:background="@drawable/bg_other_page"> tools:background="@drawable/bg_other_page">
<LinearLayout <!-- <LinearLayout-->
android:id="@+id/llSearchBar" <!-- android:id="@+id/llSearchBar"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="100dp" <!-- android:layout_height="100dp"-->
android:layout_margin="30dp" <!-- android:layout_margin="30dp"-->
android:background="@drawable/shape_white_30_corners" <!-- android:background="@drawable/shape_white_30_corners"-->
android:gravity="center_vertical" <!-- android:gravity="center_vertical"-->
android:orientation="horizontal"> <!-- android:orientation="horizontal">-->
<EditText <!-- <EditText-->
android:id="@+id/etInputDish" <!-- android:id="@+id/etInputDish"-->
android:layout_width="0dp" <!-- android:layout_width="0dp"-->
android:layout_height="80dp" <!-- android:layout_height="80dp"-->
android:layout_marginStart="28dp" <!-- android:layout_marginStart="28dp"-->
android:layout_weight="1" <!-- android:layout_weight="1"-->
android:autofillHints="" <!-- android:autofillHints=""-->
android:background="@color/white" <!-- android:background="@color/white"-->
android:gravity="center" <!-- android:gravity="center"-->
android:hint="@string/dish_search_hint" <!-- android:hint="@string/dish_search_hint"-->
android:inputType="text" <!-- android:inputType="text"-->
android:imeOptions="actionSearch" <!-- android:imeOptions="actionSearch"-->
android:paddingStart="3dp" <!-- android:paddingStart="3dp"-->
android:paddingEnd="3dp" <!-- android:paddingEnd="3dp"-->
android:textColor="@color/black333" <!-- android:textColor="@color/black333"-->
android:textColorHint="@color/gray_c8" <!-- android:textColorHint="@color/gray_c8"-->
android:textSize="40sp" <!-- android:textSize="40sp"-->
tools:ignore="TextFields" /> <!-- tools:ignore="TextFields" />-->
<ImageView <!-- <ImageView-->
android:id="@+id/ivDishSearch" <!-- android:id="@+id/ivDishSearch"-->
android:layout_width="60dp" <!-- android:layout_width="60dp"-->
android:layout_height="60dp" <!-- android:layout_height="60dp"-->
android:layout_marginStart="20dp" <!-- android:layout_marginStart="20dp"-->
android:layout_marginEnd="20dp" <!-- android:layout_marginEnd="20dp"-->
android:paddingStart="10dp" <!-- android:paddingStart="10dp"-->
android:paddingEnd="10dp" <!-- android:paddingEnd="10dp"-->
android:src="@drawable/ic_search_gray" <!-- android:src="@drawable/ic_search_gray"-->
tools:ignore="ContentDescription" /> <!-- tools:ignore="ContentDescription" />-->
</LinearLayout> <!-- </LinearLayout>-->
<LinearLayout <!-- <LinearLayout-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="wrap_content" <!-- android:layout_height="wrap_content"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
android:layout_marginBottom="30dp" <!-- android:layout_marginBottom="30dp"-->
android:background="@drawable/shape_white_30_corners" <!-- android:background="@drawable/shape_white_30_corners"-->
android:gravity="center_vertical" <!-- android:gravity="center_vertical"-->
android:orientation="vertical"> <!-- android:orientation="vertical">-->
<LinearLayout <!-- <LinearLayout-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="113dp" <!-- android:layout_height="113dp"-->
android:gravity="center_vertical" <!-- android:gravity="center_vertical"-->
android:orientation="horizontal"> <!-- android:orientation="horizontal">-->
<TextView <!-- <TextView-->
android:layout_width="0dp" <!-- android:layout_width="0dp"-->
android:layout_height="wrap_content" <!-- android:layout_height="wrap_content"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
android:layout_weight="1" <!-- android:layout_weight="1"-->
android:text="@string/dish_name" <!-- android:text="@string/dish_name"-->
android:textColor="@color/black666" <!-- android:textColor="@color/black666"-->
android:textSize="28sp" /> <!-- android:textSize="28sp" />-->
<EditText <!-- <EditText-->
android:id="@+id/etInputDishType" <!-- android:id="@+id/etInputDishType"-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_height="80dp" <!-- android:layout_height="80dp"-->
android:background="@color/white" <!-- android:background="@color/white"-->
android:gravity="center_vertical" <!-- android:gravity="center_vertical"-->
android:hint="@string/dish_search_hint2" <!-- android:hint="@string/dish_search_hint2"-->
android:textColor="@color/black333" <!-- android:textColor="@color/black333"-->
android:textColorHint="@color/gray_c8" <!-- android:textColorHint="@color/gray_c8"-->
android:imeOptions="actionSearch" <!-- android:imeOptions="actionSearch"-->
android:inputType="text" <!-- android:inputType="text"-->
android:textSize="28sp" <!-- android:textSize="28sp"-->
android:maxLines="1" <!-- android:maxLines="1"-->
android:paddingEnd="6dp" <!-- android:paddingEnd="6dp"-->
android:paddingStart="6dp" <!-- android:paddingStart="6dp"-->
android:ellipsize="end"/> <!-- android:ellipsize="end"/>-->
<ImageView <!-- <ImageView-->
android:id="@+id/ivDishTypeSearch" <!-- android:id="@+id/ivDishTypeSearch"-->
android:layout_width="80dp" <!-- android:layout_width="80dp"-->
android:layout_height="80dp" <!-- android:layout_height="80dp"-->
android:padding="24dp" <!-- android:padding="24dp"-->
android:layout_marginEnd="6dp" <!-- android:layout_marginEnd="6dp"-->
android:src="@drawable/ic_search_green" <!-- android:src="@drawable/ic_search_green"-->
tools:ignore="ContentDescription" /> <!-- tools:ignore="ContentDescription" />-->
<!-- <ImageView--> <!-- &lt;!&ndash; <ImageView&ndash;&gt;-->
<!-- android:id="@+id/ivDishTypeSearch"--> <!-- &lt;!&ndash; android:id="@+id/ivDishTypeSearch"&ndash;&gt;-->
<!-- android:layout_width="62dp"--> <!-- &lt;!&ndash; android:layout_width="62dp"&ndash;&gt;-->
<!-- android:layout_height="62dp"--> <!-- &lt;!&ndash; android:layout_height="62dp"&ndash;&gt;-->
<!-- android:layout_marginStart="15dp"--> <!-- &lt;!&ndash; android:layout_marginStart="15dp"&ndash;&gt;-->
<!-- android:layout_marginEnd="15dp"--> <!-- &lt;!&ndash; android:layout_marginEnd="15dp"&ndash;&gt;-->
<!-- android:paddingStart="15dp"--> <!-- &lt;!&ndash; android:paddingStart="15dp"&ndash;&gt;-->
<!-- android:paddingEnd="15dp"--> <!-- &lt;!&ndash; android:paddingEnd="15dp"&ndash;&gt;-->
<!-- android:src="@drawable/ic_search_green"--> <!-- &lt;!&ndash; android:src="@drawable/ic_search_green"&ndash;&gt;-->
<!-- tools:ignore="ContentDescription" />--> <!-- &lt;!&ndash; tools:ignore="ContentDescription" />&ndash;&gt;-->
</LinearLayout> <!-- </LinearLayout>-->
<com.google.android.material.divider.MaterialDivider <!-- <com.google.android.material.divider.MaterialDivider-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="1dp" <!-- android:layout_height="1dp"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
app:dividerColor="@color/gray_eb" /> <!-- app:dividerColor="@color/gray_eb" />-->
<LinearLayout <!-- <LinearLayout-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="113dp" <!-- android:layout_height="113dp"-->
android:gravity="center_vertical" <!-- android:gravity="center_vertical"-->
android:orientation="horizontal"> <!-- android:orientation="horizontal">-->
<TextView <!-- <TextView-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_height="wrap_content" <!-- android:layout_height="wrap_content"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
android:text="@string/dish_from_type" <!-- android:text="@string/dish_from_type"-->
android:textColor="@color/black666" <!-- android:textColor="@color/black666"-->
android:textSize="28sp" /> <!-- android:textSize="28sp" />-->
<RadioGroup <!-- <RadioGroup-->
android:id="@+id/rgSampling" <!-- android:id="@+id/rgSampling"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="80dp" <!-- android:layout_height="80dp"-->
android:gravity="center_vertical|end" <!-- android:gravity="center_vertical|end"-->
android:orientation="horizontal"> <!-- android:orientation="horizontal">-->
<RadioButton <!-- <RadioButton-->
android:id="@+id/rbDishTypeFirst" <!-- android:id="@+id/rbDishTypeFirst"-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_height="match_parent" <!-- android:layout_height="match_parent"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:background="@color/white" <!-- android:background="@color/white"-->
android:button="@null" <!-- android:button="@null"-->
android:drawableStart="@drawable/selector_dish_type" <!-- android:drawableStart="@drawable/selector_dish_type"-->
android:drawablePadding="30dp" <!-- android:drawablePadding="30dp"-->
android:gravity="center" <!-- android:gravity="center"-->
android:paddingStart="30dp" <!-- android:paddingStart="30dp"-->
android:paddingEnd="30dp" <!-- android:paddingEnd="30dp"-->
android:text="@string/dish_type_first" <!-- android:text="@string/dish_type_first"-->
android:textColor="@color/dish_type_font" <!-- android:textColor="@color/dish_type_font"-->
android:textSize="30sp" <!-- android:textSize="30sp"-->
android:textStyle="bold" /> <!-- android:textStyle="bold" />-->
<RadioButton <!-- <RadioButton-->
android:id="@+id/rbDishTypeSecond" <!-- android:id="@+id/rbDishTypeSecond"-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_height="match_parent" <!-- android:layout_height="match_parent"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:background="@color/white" <!-- android:background="@color/white"-->
android:button="@null" <!-- android:button="@null"-->
android:checked="false" <!-- android:checked="false"-->
android:drawableStart="@drawable/selector_dish_type" <!-- android:drawableStart="@drawable/selector_dish_type"-->
android:drawablePadding="30dp" <!-- android:drawablePadding="30dp"-->
android:gravity="center" <!-- android:gravity="center"-->
android:paddingStart="30dp" <!-- android:paddingStart="30dp"-->
android:paddingEnd="30dp" <!-- android:paddingEnd="30dp"-->
android:text="@string/dish_type_second" <!-- android:text="@string/dish_type_second"-->
android:textColor="@color/dish_type_font" <!-- android:textColor="@color/dish_type_font"-->
android:textSize="30sp" <!-- android:textSize="30sp"-->
android:textStyle="bold" /> <!-- android:textStyle="bold" />-->
</RadioGroup> <!-- </RadioGroup>-->
</LinearLayout> <!-- </LinearLayout>-->
<com.google.android.material.divider.MaterialDivider <!-- <com.google.android.material.divider.MaterialDivider-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="1dp" <!-- android:layout_height="1dp"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
app:dividerColor="@color/gray_eb" /> <!-- app:dividerColor="@color/gray_eb" />-->
<LinearLayout <!-- <LinearLayout-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="170dp" <!-- android:layout_height="170dp"-->
android:gravity="center_vertical" <!-- android:gravity="center_vertical"-->
android:orientation="horizontal"> <!-- android:orientation="horizontal">-->
<TextView <!-- <TextView-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_height="wrap_content" <!-- android:layout_height="wrap_content"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
android:text="@string/dish_part_weight_remind" <!-- android:text="@string/dish_part_weight_remind"-->
android:textColor="@color/black666" <!-- android:textColor="@color/black666"-->
android:textSize="28sp" /> <!-- android:textSize="28sp" />-->
<TextView <!-- <TextView-->
android:id="@+id/tvDishPartWeight" <!-- android:id="@+id/tvDishPartWeight"-->
android:layout_width="0dp" <!-- android:layout_width="0dp"-->
android:layout_height="100dp" <!-- android:layout_height="100dp"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_weight="1" <!-- android:layout_weight="1"-->
android:autofillHints="" <!-- android:autofillHints=""-->
android:background="@drawable/shape_white_f6_10_corners" <!-- android:background="@drawable/shape_white_f6_10_corners"-->
android:gravity="center" <!-- android:gravity="center"-->
android:hint="-" <!-- android:hint="-"-->
android:maxLines="1" <!-- android:maxLines="1"-->
android:paddingStart="20dp" <!-- android:paddingStart="20dp"-->
android:paddingEnd="20dp" <!-- android:paddingEnd="20dp"-->
android:text="" <!-- android:text=""-->
android:textColor="@color/dish_green" <!-- android:textColor="@color/dish_green"-->
android:textColorHint="@color/gray_d6" <!-- android:textColorHint="@color/gray_d6"-->
android:textSize="60sp" <!-- android:textSize="60sp"-->
tools:ignore="HardcodedText" /> <!-- tools:ignore="HardcodedText" />-->
<ImageView <!-- <ImageView-->
android:id="@+id/ivWeightClear" <!-- android:id="@+id/ivWeightClear"-->
android:layout_width="90dp" <!-- android:layout_width="90dp"-->
android:layout_height="90dp" <!-- android:layout_height="90dp"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:src="@drawable/ic_weight_clear" <!-- android:src="@drawable/ic_weight_clear"-->
tools:ignore="ContentDescription" /> <!-- tools:ignore="ContentDescription" />-->
<ImageView <!-- <ImageView-->
android:id="@+id/ivWeightAdd" <!-- android:id="@+id/ivWeightAdd"-->
android:layout_width="90dp" <!-- android:layout_width="90dp"-->
android:layout_height="90dp" <!-- android:layout_height="90dp"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
android:src="@drawable/ic_weight_add" <!-- android:src="@drawable/ic_weight_add"-->
tools:ignore="ContentDescription" /> <!-- tools:ignore="ContentDescription" />-->
</LinearLayout> <!-- </LinearLayout>-->
</LinearLayout> <!-- </LinearLayout>-->
<LinearLayout <!-- <LinearLayout-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="0dp" <!-- android:layout_height="0dp"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginTop="0dp" <!-- android:layout_marginTop="0dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
android:layout_weight="1" <!-- android:layout_weight="1"-->
android:background="@drawable/shape_white_30_corners" <!-- android:background="@drawable/shape_white_30_corners"-->
android:orientation="vertical"> <!-- android:orientation="vertical">-->
<TextView <!-- <TextView-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_height="wrap_content" <!-- android:layout_height="wrap_content"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginTop="40dp" <!-- android:layout_marginTop="40dp"-->
android:layout_marginBottom="40dp" <!-- android:layout_marginBottom="40dp"-->
android:text="@string/dish_composition" <!-- android:text="@string/dish_composition"-->
android:textColor="@color/black666" <!-- android:textColor="@color/black666"-->
android:textSize="28sp" /> <!-- android:textSize="28sp" />-->
<androidx.recyclerview.widget.RecyclerView <!-- <androidx.recyclerview.widget.RecyclerView-->
android:id="@+id/rvDishPartList" <!-- android:id="@+id/rvDishPartList"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="match_parent" <!-- android:layout_height="match_parent"-->
android:layout_marginBottom="20dp" <!-- android:layout_marginBottom="20dp"-->
android:overScrollMode="never" <!-- android:overScrollMode="never"-->
tools:itemCount="3" <!-- tools:itemCount="3"-->
tools:listitem="@layout/list_item_dish_cook" <!-- tools:listitem="@layout/list_item_dish_cook"-->
android:scrollbars="vertical"/> <!-- android:scrollbars="vertical"/>-->
</LinearLayout> <!-- </LinearLayout>-->
<TextView <!-- <TextView-->
android:id="@+id/btnCook" <!-- android:id="@+id/btnCook"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="90dp" <!-- android:layout_height="90dp"-->
android:layout_margin="30dp" <!-- android:layout_margin="30dp"-->
android:gravity="center" <!-- android:gravity="center"-->
android:text="@string/goCooking" <!-- android:text="@string/goCooking"-->
android:textColor="@color/white" <!-- android:textColor="@color/white"-->
android:textSize="32sp" <!-- android:textSize="32sp"-->
android:textStyle="bold" <!-- android:textStyle="bold"-->
android:background="@drawable/shape_green_bg"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true" />
<!-- android:background="@drawable/ripple_effect_green"-->
<!-- android:background="@drawable/shape_green_bg"--> <!-- android:background="@drawable/shape_green_bg"-->
<!-- android:background="?attr/selectableItemBackground"--> <!-- android:foreground="?android:attr/selectableItemBackground"-->
<!-- android:clickable="true"--> <!-- android:clickable="true" />-->
<!--&lt;!&ndash; android:background="@drawable/ripple_effect_green"&ndash;&gt;-->
<!--&lt;!&ndash; android:background="@drawable/shape_green_bg"&ndash;&gt;-->
<!--&lt;!&ndash; android:background="?attr/selectableItemBackground"&ndash;&gt;-->
<!--&lt;!&ndash; android:clickable="true"&ndash;&gt;-->
</LinearLayout> </LinearLayout>
@@ -55,7 +55,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:layout_width="120dp" android:layout_width="wrap_content"
android:layout_height="80dp" android:layout_height="80dp"
android:layout_gravity="start" android:layout_gravity="start"
android:layout_marginStart="30dp" android:layout_marginStart="30dp"