This commit is contained in:
2026-02-06 17:31:52 +08:00
parent a4f3f9527c
commit 873ae95c0b
6 changed files with 58 additions and 45 deletions
@@ -7,6 +7,7 @@ import android.util.Log
import android.view.View
import androidx.activity.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.DishPartAdapter
@@ -23,6 +24,7 @@ import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.net.NetViewModel
import com.shuwei.dish.match.utils.AddressUtil
import com.shuwei.dish.match.utils.KeyboardUtil
import com.shuwei.dish.match.utils.SwipeCallback
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
import com.shuwei.dish.match.utils.ext.clickWithDebounce
@@ -167,6 +169,13 @@ class DishSamplingActivity : BaseActivity() {
layoutManager =
LinearLayoutManager(this@DishSamplingActivity, LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter
val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position ->
list.removeAt(position)
dishAdapter.notifyItemRemoved(position)
dishAdapter.notifyItemRangeChanged(position, list.size - position)
toast("已删除")
})
itemTouchHelper.attachToRecyclerView(this)
}
binding.etInputDishType.addOnActionSearchListener {
searchDishType()
@@ -285,6 +294,7 @@ class DishSamplingActivity : BaseActivity() {
relateionType = item.relateionType ?: 0
goodsOrRelationCode = item.goodsOrRelationCode
isNewDishType = true
// TODO: 待定
//allEdible = item.allEdible
}
@@ -88,7 +88,14 @@ class PrepareCookActivity : BaseActivity() {
}
binding.ivWeightAdd.setOnClickListener { addWeight() }
binding.tvAddFood.clickWithDebounce { addFood() }
binding.btnCook.clickWithDebounce { goToSubmit() }
binding.btnCook.clickWithDebounce {
val count = list.count { it.isSetFinished.not() }
if (count > 0) {
showRemindDialog()
return@clickWithDebounce
}
openSubmitPage()
}
binding.rgCook.setOnCheckedChangeListener { group, checkedId ->
if (clickIndex < 0 || clickIndex >= list.size) return@setOnCheckedChangeListener
val tempType =
@@ -146,19 +153,13 @@ class PrepareCookActivity : BaseActivity() {
}
}
private fun goToSubmit() {
val count = list.count { it.isSetFinished.not() }
if (count > 0) {
showRemindDialog()
return
}
private fun openSubmitPage() {
getGoodsList()
if (goodsList.isNullOrEmpty()) {
toast("菜品构成信息未设置")
toast("菜品构成信息")
return
}
Log.d(TAG, "goToSubmit: goodsList:${goodsList?.toJsonString()}")
startActivity<SubmitFoodActivity> {
putExtra(SubmitFoodActivity.GOODS_LIST, goodsList as Serializable)
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
@@ -169,19 +170,17 @@ class PrepareCookActivity : BaseActivity() {
if (goodsList == null) {
goodsList = mutableListOf()
}
list.forEach {
if (it.isSetFinished) {
goodsList?.add(CookFoodGoodsEntity().apply {
foodId = food!!.foodId
goodsId = it.goodsId
relateionType = it.relateionType
allEdible = it.allEdible
goodsName = it.goodsName
materialType = it.materialType
useWeight = it.useWeight ?: 0.toDouble()
goodsOrRelationCode = it.goodsOrRelationCode
})
}
list.filter { it.isSetFinished }.forEach {
goodsList?.add(CookFoodGoodsEntity().apply {
foodId = food!!.foodId
goodsId = it.goodsId
relateionType = it.relateionType
allEdible = it.allEdible
goodsName = it.goodsName
materialType = it.materialType
useWeight = it.useWeight ?: 0.toDouble()
goodsOrRelationCode = it.goodsOrRelationCode
})
}
}
@@ -193,7 +192,7 @@ class PrepareCookActivity : BaseActivity() {
rightText = "确认无误"
onLeftClick = { dismiss() }
onRightClick = {
goToSubmit()
openSubmitPage()
dismiss()
}
onDismiss = { hideStatusBar() }
@@ -271,13 +270,15 @@ class PrepareCookActivity : BaseActivity() {
var materialType: String
when (it.materialType) {
1 -> {
materialType = "主材"
materialType = "主材"
binding.rgCook.check(R.id.rbDishTypeFirst)
}
2 -> {
materialType = "辅材"
binding.rgCook.check(R.id.rbDishTypeSecond)
}
else -> {
materialType = ""
binding.rgCook.clearCheck()
@@ -87,9 +87,9 @@ class SamplingListActivity : BaseActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
//toast("isCooking=$isCooking")
refreshPage(isCooking)
// val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
// //toast("isCooking=$isCooking")
// refreshPage(isCooking)
}
@Deprecated("Deprecated in Java")
@@ -168,20 +168,20 @@ class SelectDishActivity : BaseActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
runCatching {
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
val lastDinnerType = intent?.getStringExtra(DINNER_TYPE) ?: "0"
if (lastDinnerType == "1" || lastDinnerType == "2" || lastDinnerType == "3") {
fragmentList[lastDinnerType.toInt() - 1].getDishList(1, lastDinnerType)
}
when (lastDinnerType) {
"1" -> binding.dishRadioGroup.check(R.id.rbBreakfast)
"2" -> binding.dishRadioGroup.check(R.id.rbLunch)
"3" -> binding.dishRadioGroup.check(R.id.rbDinner)
}
}.onFailure {
it.printStackTrace()
}
// runCatching {
// val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
// val lastDinnerType = intent?.getStringExtra(DINNER_TYPE) ?: "0"
// if (lastDinnerType == "1" || lastDinnerType == "2" || lastDinnerType == "3") {
// fragmentList[lastDinnerType.toInt() - 1].getDishList(1, lastDinnerType)
// }
// when (lastDinnerType) {
// "1" -> binding.dishRadioGroup.check(R.id.rbBreakfast)
// "2" -> binding.dishRadioGroup.check(R.id.rbLunch)
// "3" -> binding.dishRadioGroup.check(R.id.rbDinner)
// }
// }.onFailure {
// it.printStackTrace()
// }
}
@Deprecated("Deprecated in Java")
@@ -262,11 +262,12 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvDishPartList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:overScrollMode="never"
tools:itemCount="3"
tools:listitem="@layout/list_item_dish_cook" />
tools:listitem="@layout/list_item_dish_cook"
android:scrollbars="vertical"/>
</LinearLayout>
@@ -253,11 +253,12 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvDishPartList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:overScrollMode="never"
tools:itemCount="3"
tools:listitem="@layout/list_item_dish_cook" />
tools:listitem="@layout/list_item_dish_cook"
android:scrollbars="vertical" />
</LinearLayout>