refactor(activity): 将 ScaleServiceManager.stop() 迁移至 InitActivity.onDestroy,优化18格子布局间距
This commit is contained in:
@@ -48,11 +48,6 @@ class BaseApp : Application() {
|
||||
ObjectBox.init(this)
|
||||
}
|
||||
|
||||
override fun onTerminate() {
|
||||
ScaleServiceManager.stop()
|
||||
super.onTerminate()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
// const val canteenId = "1678234139391512577"
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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<LinearLayout.LayoutParams> {
|
||||
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<ScaleData>) {
|
||||
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<LinearLayout.LayoutParams> { bottomMargin = 6.dp }
|
||||
repeat(6) { row.addView(makeScaleCell(sorted.getOrNull(index++), cellSize23, inHorizontalRow = true, margin = 5.dp)) }
|
||||
container.addView(row)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user