From 23d211bfdb0681d8a5d035d8099d17364c5fb829 Mon Sep 17 00:00:00 2001 From: mazengfei <331023091@qq.com> Date: Mon, 13 Jul 2026 18:26:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(shelf):=20=E5=AE=9E=E7=8E=B0=E8=B4=9F?= =?UTF-8?q?=E6=BC=82=E7=A7=BB=E6=8A=91=E5=88=B6=E4=BB=A5=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E9=87=8D=E9=87=8F=E6=98=BE=E7=A4=BA=E5=87=86=E7=A1=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ShelfV3Activity中针对-5克以内的负读数做归零处理,避免误导显示 - 修改获取重量逻辑,保证显示重量与真实重量区分 - 在ShelfV3Adapter中对空秤零点附近的小负重量做归零处理 - 优化重量单位显示逻辑,根据负漂移抑制后的值显示克或千克 - 更新local.properties中SDK路径配置 --- .../java/com/sw/scalefusion/shelf/ShelfV3Activity.kt | 10 +++++++--- .../com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt | 6 ++++-- local.properties | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/sw/scalefusion/shelf/ShelfV3Activity.kt b/app/src/main/java/com/sw/scalefusion/shelf/ShelfV3Activity.kt index 7a56a25..5ff61a6 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/ShelfV3Activity.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/ShelfV3Activity.kt @@ -155,8 +155,10 @@ class ShelfV3Activity : BaseActivity() { binding.tvVegTypeName.text = model.vegTypeName val weightG = model.weight ?: 0.0 realWeight = (weightG * 1000.0).toInt() + // 负漂移抑制:-5克以内的负读数显示时归零(realWeight 保持真实值) + val displayWeight = if (realWeight in -5..0) 0 else realWeight binding.tvFoodWeight.text = if (weightG >= 1.0) "%.3f千克".format(weightG) - else "${realWeight}克" + else "${displayWeight}克" startTime = System.currentTimeMillis() } @@ -354,8 +356,10 @@ class ShelfV3Activity : BaseActivity() { val intervalTime = System.currentTimeMillis() - startTime val weight = event.weight log("格口${shelfModel?.slotNo}获取重量:${weight}克,间隔:${intervalTime}ms") - binding.tvFoodWeight.text = if (weight < 1000) "${weight}克" - else "%.3f千克".format(weight / 1000.0) + // 负漂移抑制:-5克以内的负读数显示时归零 + val displayWeight = if (weight in -5..0) 0 else weight + binding.tvFoodWeight.text = if (displayWeight < 1000) "${displayWeight}克" + else "%.3f千克".format(displayWeight / 1000.0) startTime = System.currentTimeMillis() window.decorView.postDelayed({ Loading.dismiss() }, 1000) } diff --git a/app/src/main/java/com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt b/app/src/main/java/com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt index 421c97a..2a036ab 100644 --- a/app/src/main/java/com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt +++ b/app/src/main/java/com/sw/scalefusion/shelf/adapter/ShelfV3Adapter.kt @@ -43,10 +43,12 @@ class ShelfV3Adapter(list: MutableList) : binding.tvShelfName.text = item.slotNo.padStart(2, '0') val weightG = item.weight ?: 0.0 + // 负漂移抑制:空秤零点可能出现 -5克以内的负读数,显示时归零 + val displayG = if (weightG in -0.005..0.0) 0.0 else weightG binding.tvFoodWeight.run { setTextColor(getColor(R.color.food_weight_orange)) - text = if (abs(weightG) >= 1.0) "%.3f千克".format(weightG) - else "${(weightG * 1000.0).toInt()}克" + text = if (abs(displayG) >= 1.0) "%.3f千克".format(displayG) + else "${(displayG * 1000.0).toInt()}克" } val isBlank = item.materName.isNullOrBlank() diff --git a/local.properties b/local.properties index ad55396..3d6d7d6 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Fri Jun 26 09:17:18 CST 2026 -sdk.dir=D\:\\Android\\sdk +#Thu Jul 02 16:04:28 CST 2026 +sdk.dir=C\:\\Users\\MZF\\AppData\\Local\\Android\\Sdk