feat(fragment): 新增默认减重配置功能
- SpTool 新增 configWeight 属性,持久化存储默认减重克数 - 新增 WeightConfigFragment 及对应布局,支持数字输入和回填 - SingleFragmentActivity 注册 WEIGHT_CONFIG 页面类型 - SettingActivity 在食材采集下方新增减重配置入口 - PrepareFoodActivity 打开时从 SpTool.configWeight 初始化 initialWeight Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,8 @@ data class SettingItem(
|
||||
SEASONING_CONFIG,
|
||||
/** 食材采集 */
|
||||
FOOD_COLLECT,
|
||||
/** 减重配置 */
|
||||
WEIGHT_CONFIG,
|
||||
/** 数据库查看(隐藏项) */
|
||||
DB_INSPECT,
|
||||
/** 秤数据监控(隐藏项) */
|
||||
|
||||
@@ -223,8 +223,8 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
private var lastWeight = 0.0
|
||||
private var currentWeight = 0.0
|
||||
|
||||
/** 初始秤读数,净重 = 秤读数 - initialWeight */
|
||||
private var initialWeight = 0.0
|
||||
/** 初始秤读数,净重 = 秤读数 - initialWeight,从 SpTool.configWeight 读取 */
|
||||
private var initialWeight = SpTool.configWeight.toDouble()
|
||||
|
||||
/** 初始读数是否已从秤获取 */
|
||||
// private var initialWeightReady = false
|
||||
|
||||
@@ -99,6 +99,13 @@ class SettingActivity : BaseActivity() {
|
||||
title = "食材采集",
|
||||
onClick = { checkCameraPermission() }
|
||||
),
|
||||
SettingItem(
|
||||
type = SettingItem.Type.WEIGHT_CONFIG,
|
||||
title = "减重配置",
|
||||
onClick = {
|
||||
SingleFragmentActivity.start(this, SingleFragmentActivity.PageType.WEIGHT_CONFIG)
|
||||
}
|
||||
),
|
||||
SettingItem(
|
||||
type = SettingItem.Type.DB_INSPECT,
|
||||
title = "数据库查看",
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.shuwei.dish.match.ui.fragment.DbInspectFragment
|
||||
import com.shuwei.dish.match.ui.fragment.VectorCollectionFragment
|
||||
import com.shuwei.dish.match.ui.fragment.DeviceConfigFragment
|
||||
import com.shuwei.dish.match.ui.fragment.SeasoningConfigFragment
|
||||
import com.shuwei.dish.match.ui.fragment.WeightConfigFragment
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
|
||||
@@ -39,6 +40,9 @@ class SingleFragmentActivity : BaseActivity() {
|
||||
|
||||
/** 数据库调试查看页 */
|
||||
DB_INSPECT,
|
||||
|
||||
/** 默认减重配置页 */
|
||||
WEIGHT_CONFIG,
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -101,6 +105,7 @@ class SingleFragmentActivity : BaseActivity() {
|
||||
PageType.COOK_MODE -> "菜品模式"
|
||||
PageType.SEASONING_CONFIG -> "调料区设置"
|
||||
PageType.DB_INSPECT -> "数据库查看"
|
||||
PageType.WEIGHT_CONFIG -> "减重配置"
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,6 +116,7 @@ class SingleFragmentActivity : BaseActivity() {
|
||||
PageType.COOK_MODE -> DeviceConfigFragment()
|
||||
PageType.SEASONING_CONFIG -> SeasoningConfigFragment()
|
||||
PageType.DB_INSPECT -> DbInspectFragment()
|
||||
PageType.WEIGHT_CONFIG -> WeightConfigFragment()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.shuwei.dish.match.ui.fragment
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.shuwei.dish.match.base.BaseFragment
|
||||
import com.shuwei.dish.match.databinding.FragmentWeightConfigBinding
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
|
||||
/**
|
||||
* 默认减重配置 Fragment
|
||||
* 允许用户设置打开 PrepareFoodActivity 时的初始减重基准值(单位:克)
|
||||
*/
|
||||
class WeightConfigFragment : BaseFragment<FragmentWeightConfigBinding>() {
|
||||
|
||||
override fun inflateBinding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?
|
||||
): FragmentWeightConfigBinding {
|
||||
return FragmentWeightConfigBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
override fun initialize() {
|
||||
// 若已有配置值则回填到输入框
|
||||
val saved = SpTool.configWeight
|
||||
if (saved != 0) {
|
||||
binding.etConfigWeight.setText(saved.toString())
|
||||
}
|
||||
|
||||
binding.btnConfirm.clickWithDebounce {
|
||||
val input = binding.etConfigWeight.text.toString().trim()
|
||||
if (input.isEmpty()) {
|
||||
toast("请输入减重值")
|
||||
return@clickWithDebounce
|
||||
}
|
||||
val weight = input.toIntOrNull()
|
||||
if (weight == null || weight < 0) {
|
||||
toast("请输入有效的减重值")
|
||||
return@clickWithDebounce
|
||||
}
|
||||
SpTool.configWeight = weight
|
||||
toast("保存成功")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ object SpTool {
|
||||
const val SCALE_DEVICE_PORT = "scaleDevicePort"
|
||||
/** 食堂 ID,默认 "0" */
|
||||
const val CANTEEN_ID = "canteenId"
|
||||
/** 默认减重克数 */
|
||||
const val CONFIG_WEIGHT = "configWeight"
|
||||
|
||||
val pref = BaseApp.getSharedPref()!!
|
||||
|
||||
@@ -41,6 +43,13 @@ object SpTool {
|
||||
put(LAUNCH_PAGE_TYPE, value)
|
||||
}
|
||||
|
||||
/** 默认减重(克),打开 PrepareFoodActivity 时作为 initialWeight 基准值 */
|
||||
var configWeight: Int
|
||||
get() = getInt(CONFIG_WEIGHT, 0)
|
||||
set(value) {
|
||||
put(CONFIG_WEIGHT, value)
|
||||
}
|
||||
|
||||
/** 食堂 ID,持久化存储,默认 "0" */
|
||||
var canteenId: String
|
||||
get() = getString(CANTEEN_ID, "0")
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:background="@drawable/bg_other_page"
|
||||
tools:ignore="HardcodedText">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:orientation="vertical"
|
||||
android:padding="30dp"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="106dp"
|
||||
android:background="@drawable/bg_bottom_line">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:text="默认减重配置"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold" />
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="减重值(克)"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etConfigWeight"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:hint="请输入减重值"
|
||||
android:inputType="number"
|
||||
android:maxLength="6"
|
||||
android:padding="16dp"
|
||||
android:textColor="@color/black"
|
||||
android:textColorHint="@color/gray_b4"
|
||||
android:textSize="28sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnConfirm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:text="确认"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user