From 5ac35a9cab1e44f952d1b120893c9ee20aa56636 Mon Sep 17 00:00:00 2001 From: lvmeng <848755140@qq.com> Date: Wed, 15 Apr 2026 09:52:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor(activity):=20=E5=B0=86=20ScaleServiceM?= =?UTF-8?q?anager.stop()=20=E8=BF=81=E7=A7=BB=E8=87=B3=20InitActivity.onDe?= =?UTF-8?q?stroy=EF=BC=8C=E4=BC=98=E5=8C=9618=E6=A0=BC=E5=AD=90=E5=B8=83?= =?UTF-8?q?=E5=B1=80=E9=97=B4=E8=B7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/shuwei/dish/match/base/BaseApp.kt | 5 ----- .../java/com/shuwei/dish/match/ui/InitActivity.kt | 2 ++ .../com/shuwei/dish/match/ui/MasterScaleActivity.kt | 13 +++++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/shuwei/dish/match/base/BaseApp.kt b/app/src/main/java/com/shuwei/dish/match/base/BaseApp.kt index c47be71..4cfeed1 100644 --- a/app/src/main/java/com/shuwei/dish/match/base/BaseApp.kt +++ b/app/src/main/java/com/shuwei/dish/match/base/BaseApp.kt @@ -48,11 +48,6 @@ class BaseApp : Application() { ObjectBox.init(this) } - override fun onTerminate() { - ScaleServiceManager.stop() - super.onTerminate() - } - companion object { // const val canteenId = "1678234139391512577" diff --git a/app/src/main/java/com/shuwei/dish/match/ui/InitActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/InitActivity.kt index 2bb41a3..b6b4258 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/InitActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/InitActivity.kt @@ -18,6 +18,7 @@ import com.shuwei.dish.match.base.GlobalData import com.shuwei.dish.match.databinding.ActivityInitBinding import com.shuwei.dish.match.db.AppRepository import com.shuwei.dish.match.objbox.FoodModule +import com.shuwei.dish.match.scale.ScaleServiceManager import com.shuwei.dish.match.utils.AppUtil import com.shuwei.dish.match.utils.NetworkUtils import com.shuwei.dish.match.utils.SpTool @@ -122,6 +123,7 @@ class InitActivity : BaseActivity() { override fun onDestroy() { WeightUtil.stopContinuousRead() + ScaleServiceManager.stop() super.onDestroy() } diff --git a/app/src/main/java/com/shuwei/dish/match/ui/MasterScaleActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/MasterScaleActivity.kt index 1b78046..aebff72 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/MasterScaleActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/MasterScaleActivity.kt @@ -8,6 +8,7 @@ import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView +import androidx.core.view.updateLayoutParams import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -192,7 +193,7 @@ class MasterScaleActivity : BaseActivity() { repeat(2) { rowIdx -> val cell = makeScaleCellFixed(sorted.getOrNull(index++), largeCellSize, largeCellSize, margin) // 两列中间水平间距翻倍(第1列右边距、第2列左边距),列内两格子中间垂直间距翻倍,外侧保持不变 - (cell.layoutParams as? LinearLayout.LayoutParams)?.apply { + cell.updateLayoutParams { bottomMargin = if (rowIdx == 0) margin * 2 else margin topMargin = if (rowIdx == 1) margin * 2 else margin rightMargin = if (colIdx == 0) margin * 2 else margin @@ -258,6 +259,8 @@ class MasterScaleActivity : BaseActivity() { */ private fun buildLayout18(container: LinearLayout, scales: List) { val cellSize = container.context.cellSize(6) + // 第2、3行列间距 10dp(margin=5dp),单独计算格子尺寸 + val cellSize23 = (resources.displayMetrics.widthPixels - 32.dp - 6 * 10.dp) / 6 // 按指定顺序重排(address 从1开始,转为0-based index取值) val scaleByAddress = scales.associateBy { it.address } val sorted = SCALE_ORDER_18.map { scaleByAddress[it] } @@ -265,11 +268,13 @@ class MasterScaleActivity : BaseActivity() { var index = 0 // 第1行:增大 margin 使格子看起来更小 val row1 = makeRowLayout(container) - repeat(6) { row1.addView(makeScaleCell(sorted.getOrNull(index++), cellSize, inHorizontalRow = true, margin = 8.dp)) } + repeat(6) { row1.addView(makeScaleCell(sorted.getOrNull(index++), cellSize, inHorizontalRow = true, margin = 12.dp)) } container.addView(row1) - repeat(2) { + repeat(2) { rowIdx -> val row = makeRowLayout(container) - repeat(6) { row.addView(makeScaleCell(sorted.getOrNull(index++), cellSize, inHorizontalRow = true)) } + // 第2行(rowIdx=0)底部加 6dp,使第2、3行间距与第1、2行一致(均为10dp) + if (rowIdx == 0) row.updateLayoutParams { bottomMargin = 6.dp } + repeat(6) { row.addView(makeScaleCell(sorted.getOrNull(index++), cellSize23, inHorizontalRow = true, margin = 5.dp)) } container.addView(row) } }