fix(cooking): 解决搜索框内容清除和称重逻辑问题
- 在 CookingModeActivity 中添加 clearSearchText 方法用于清除搜索框内容 - 在 FoodListFragment 中添加协程调度器导入并实现空搜索时自动清除功能 - 在 SubmitFoodActivity 中新增初始重量和初始化状态变量 - 修改称重清零逻辑,清零后重置初始重量为 0 - 实现净重计算逻辑,使用秤读数减去初始重量得到实际净重 - 更新重量显示逻辑,使用净重数值进行单位转换和显示
This commit is contained in:
@@ -197,4 +197,10 @@ class CookingModeActivity : BaseActivity() {
|
||||
isVisible = false
|
||||
}
|
||||
|
||||
fun clearSearchText() {
|
||||
isClearingByTabSwitch = true
|
||||
binding.etInputDish.text?.clear()
|
||||
isClearingByTabSwitch = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,6 +102,12 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
*/
|
||||
private val lastTsMap = mutableMapOf<String, Long>()
|
||||
|
||||
/** 主设备 2格秤的初始重量,首次收到数据时赋值;调用清零后重置为 0.0 */
|
||||
private var initWeight: Double = 0.0
|
||||
|
||||
/** initWeight 是否已完成初始化 */
|
||||
private var initWeightSet: Boolean = false
|
||||
|
||||
@Suppress("unchecked_cast", "DEPRECATION")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -316,7 +322,11 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
val content = getRemindSpannable("开始制作")
|
||||
showRemindDialog(content) { cook() }
|
||||
}
|
||||
binding.btnWeightClear.clickWithDebounce { WeightUtil.tareTwo(2) }
|
||||
binding.btnWeightClear.clickWithDebounce {
|
||||
WeightUtil.tareTwo(2)
|
||||
// 清零后将初始重量重置为 0,后续以秤读数直接作为净重
|
||||
initWeight = 0.0
|
||||
}
|
||||
binding.btnSubmit.clickWithDebounce {
|
||||
if (cookFoodEntity.foodWeight <= 0.toDouble()) {
|
||||
toast("未识别到菜品熟重")
|
||||
@@ -329,12 +339,19 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
// 监听主设备 2格秤的熟重
|
||||
WeightUtil.addWeightListener(TAG) { address, _, weight ->
|
||||
if (address == AddressUtil.TWO) {
|
||||
cookFoodEntity.foodWeight = weight
|
||||
if (weight > 1000) {
|
||||
binding.tvTotalWeight.text = "${(weight / 1000f).roundedDecimalPlace(3)}"
|
||||
// 首次收到数据时记录初始重量
|
||||
if (!initWeightSet) {
|
||||
initWeight = weight
|
||||
initWeightSet = true
|
||||
}
|
||||
// 实际净重 = 秤读数 - 初始重量
|
||||
val netWeight = weight - initWeight
|
||||
cookFoodEntity.foodWeight = netWeight
|
||||
if (netWeight > 1000) {
|
||||
binding.tvTotalWeight.text = "${(netWeight / 1000f).roundedDecimalPlace(3)}"
|
||||
binding.tvWeightUnit.text = "千克"
|
||||
} else {
|
||||
binding.tvTotalWeight.text = "$weight"
|
||||
binding.tvTotalWeight.text = "$netWeight"
|
||||
binding.tvWeightUnit.text = "克"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,10 @@ import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.yanzhenjie.recyclerview.SwipeMenuItem
|
||||
import androidx.fragment.app.viewModels
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import java.io.Serializable
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||
|
||||
@@ -192,6 +194,10 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||
)
|
||||
foodName?.let { param["foodName"] = it }
|
||||
if (pageNo == 1) {
|
||||
//解决回调页面刷新本地数据时,输入框内容还显示的问题
|
||||
if (foodName.isNullOrBlank()) {
|
||||
activity.clearSearchText()
|
||||
}
|
||||
pendingLocalList = activity.appViewModel.getCookFoodListDirect(
|
||||
cookMode = 0,
|
||||
dinnerType = dinnerType
|
||||
|
||||
Reference in New Issue
Block a user