fix(activity): 修复 FoodRecognizeActivity 称重更新导致 useWeight 异常的问题
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -234,12 +234,8 @@ class FoodRecognizeActivity : BaseActivity() {
|
||||
}
|
||||
if (weight >= PrepareCookActivity.WEIGHT_RECOGNIZE_VALUE) {
|
||||
adapter.items.firstOrNull { it.isClicked }?.let { item ->
|
||||
if (weight > (item.useWeight ?: 0.0)) {
|
||||
// 重量增加:立即更新
|
||||
cancelPendingWeightUpdate()
|
||||
item.useWeight = currentWeight
|
||||
} else if (pendingWeight != weight) {
|
||||
// 重量减少且目标值变化:重置延迟任务,3 秒无新变化后更新
|
||||
if (pendingWeight != weight) {
|
||||
// 无论增减,均延迟更新,避免手拿物品时的瞬时增重干扰
|
||||
cancelPendingWeightUpdate()
|
||||
pendingWeight = weight
|
||||
pendingWeightRunnable = Runnable {
|
||||
@@ -266,10 +262,16 @@ class FoodRecognizeActivity : BaseActivity() {
|
||||
* 携带当前选中食材关闭页面
|
||||
*/
|
||||
private fun finishWithResult(isManualCancel: Boolean) {
|
||||
cancelPendingWeightUpdate()
|
||||
|
||||
val intent = Intent().apply {
|
||||
putExtra(IS_MANUAL_CANCEL, isManualCancel)
|
||||
if (isManualCancel.not()) {
|
||||
list.getOrNull(selectedPosition)?.let {
|
||||
// 兜底:若 useWeight 仍为空或0,使用当前实时重量
|
||||
if ((it.useWeight ?: 0.0) <= 0.0) {
|
||||
it.useWeight = currentWeight
|
||||
}
|
||||
putExtra(EXTRA_SELECTED_ITEM, it)
|
||||
}
|
||||
}
|
||||
@@ -281,6 +283,6 @@ class FoodRecognizeActivity : BaseActivity() {
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
cancelPendingWeightUpdate()
|
||||
// WeightUtil.removeWeightListener(TAG)
|
||||
WeightUtil.removeWeightListener(TAG)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user