fix(global): App 启动时恢复本地保存的环境地址
- SpTool 新增 baseUrl 属性,统一管理环境地址的持久化读写 - EnvSwitchDialog 改用 SpTool.baseUrl 保存,移除直接调用 SpTool.put - BaseApp.onCreate 启动时读取 SpTool.baseUrl 并赋值给 GlobalData.appBaseUrl Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import com.shuwei.dish.match.objbox.ObjectBox
|
||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||
import com.shuwei.dish.match.utils.AppUtil
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
import com.shuwei.dish.match.utils.BootReceiver
|
||||
import com.shuwei.dish.match.utils.CrashHandler
|
||||
import com.shuwei.dish.match.utils.Weigher2
|
||||
@@ -31,6 +32,11 @@ class BaseApp : Application() {
|
||||
super.onCreate()
|
||||
// Set the application instance
|
||||
instance = this
|
||||
// 读取本地保存的环境地址,覆盖默认值
|
||||
val savedBaseUrl = SpTool.baseUrl
|
||||
if (savedBaseUrl.isNotEmpty()) {
|
||||
GlobalData.appBaseUrl = savedBaseUrl
|
||||
}
|
||||
// Initialize crash handler for error tracking
|
||||
CrashHandler.init(this)
|
||||
// Get and store the unique device ID
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.base.GlobalKey
|
||||
import com.shuwei.dish.match.databinding.DialogEnvSwitchContentBinding
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
@@ -47,7 +46,7 @@ class EnvSwitchDialog(
|
||||
else -> return@setPositiveButtonInterceptable false
|
||||
}
|
||||
GlobalData.appBaseUrl = newUrl
|
||||
SpTool.put(GlobalKey.KEY_BASE_URL, newUrl)
|
||||
SpTool.baseUrl = newUrl
|
||||
onEnvChanged(newUrl)
|
||||
true
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.shuwei.dish.match.utils
|
||||
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.base.GlobalKey
|
||||
import com.shuwei.dish.match.utils.ext.put
|
||||
|
||||
object SpTool {
|
||||
@@ -46,4 +47,11 @@ object SpTool {
|
||||
set(value) {
|
||||
put(CANTEEN_ID, value)
|
||||
}
|
||||
|
||||
/** 环境 BaseUrl,持久化存储,默认空字符串(空时使用 GlobalData 默认值) */
|
||||
var baseUrl: String
|
||||
get() = getString(GlobalKey.KEY_BASE_URL, "")
|
||||
set(value) {
|
||||
put(GlobalKey.KEY_BASE_URL, value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user