初始化功能调试,启动页面优化

This commit is contained in:
2025-09-17 15:16:11 +08:00
parent a355828bab
commit 9c2c5f073e
13 changed files with 145 additions and 50 deletions
@@ -88,6 +88,7 @@ class HomeActivity : BaseActivity() {
super.onCreate(savedInstanceState)
binding = ActivityHomeBinding.inflate(layoutInflater)
EventBus.getDefault().register(this)
setBackground()
setContentView(binding.root)
updateLeftStatus("1-1冷藏柜 -°C / -%")
@@ -50,31 +50,32 @@ class InitActivity : BaseActivity() {
super.onCreate(savedInstanceState)
binding = ActivityInitBinding.inflate(layoutInflater)
setContentView(binding.root)
hideStatusBar()
// // 获取 ANDROID_ID
// val androidId =
// Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
// App.deviceId = androidId
// SpTool.put(SpTool.DEVICE_ID, androidId)
// App.configUrl = UrlConfig.BASE_URL
// App.canteenId = "0"
// 获取 ANDROID_ID
val androidId =
Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
App.deviceId = androidId
SpTool.put(SpTool.DEVICE_ID, androidId)
App.configUrl = UrlConfig.BASE_URL
App.canteenId = "0"
var deviceId = AppUtil.getUDID(this)
Log.d(TAG, "onCreate: deviceId=$deviceId")
// deviceId = "39a7abdd06b3c7ab"
// deviceId = "3ea47dc0-3cf0-3c2f-909c-265a9a65572e"
deviceId = "6ce7cd59-b875-38b2-b73d-88a570be3212"
App.deviceId = deviceId
// var deviceId = AppUtil.getUDID(this)
// Log.d(TAG, "onCreate: deviceId=$deviceId")
//// deviceId = "39a7abdd06b3c7ab"
//// deviceId = "3ea47dc0-3cf0-3c2f-909c-265a9a65572e"
// App.deviceId = deviceId
//
// SpTool.put(SpTool.DEVICE_ID, deviceId)
// val deviceConfigCache = SpTool.getString(SpTool.DEVICE_CONFIG_CACHE)
// val checkResult = checkConfigData(deviceConfigCache)
// if (checkResult.not()) {
// binding.ivQrCode.visible()
// binding.btnInit.visible()
// //进行初始化操作
// initConfig()
// return
// }
SpTool.put(SpTool.DEVICE_ID, deviceId)
val deviceConfigCache = SpTool.getString(SpTool.DEVICE_CONFIG_CACHE)
val checkResult = checkConfigData(deviceConfigCache)
if (checkResult.not()) {
binding.ivQrCode.visible()
binding.btnInit.visible()
//进行初始化操作
initConfig()
return
}
binding.ivQrCode.invisible()
binding.btnInit.invisible()
@@ -80,6 +80,7 @@ class ShelfActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityShelfBinding.inflate(layoutInflater)
setBackground()
setContentView(binding.root)
EventBus.getDefault().register(this)
// tvFoodWeight =binding.tvFoodWeight
@@ -46,14 +46,14 @@ open class BaseActivity : AppCompatActivity() {
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(false)
window.insetsController?.apply {
hide(WindowInsets.Type.statusBars()) // 隐藏状态栏
systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE // 滑动时临时显示
}
}
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// window.setDecorFitsSystemWindows(false)
// window.insetsController?.apply {
// hide(WindowInsets.Type.statusBars()) // 隐藏状态栏
// systemBarsBehavior =
// WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE // 滑动时临时显示
// }
// }
}
@@ -75,6 +75,10 @@ open class BaseActivity : AppCompatActivity() {
binding.tvRightStatus.setTextColor(color)
}
fun setBackground() {
binding.root.setBackgroundColor(ContextCompat.getColor(this,R.color.bg_page))
}
override fun setContentView(view: View?) {
if (view == binding.root) {
super.setContentView(view)
@@ -57,16 +57,16 @@ class NetViewModel : ViewModel() {
fun getDeviceConfig(deviceId: String, deviceToken: String) {
viewModelScope.launch {
_getDeviceTokenUiState.value = UiState.Loading
_getDeviceConfigUiState.value = UiState.Loading
runCatching {
val response = apiService.getDeviceInfo(equipmentCode = deviceId, token = deviceToken)
if (response.success) {
_getDeviceTokenUiState.value = UiState.Success(response)
_getDeviceConfigUiState.value = UiState.Success(response)
} else {
_getDeviceTokenUiState.value = UiState.Error(response.message ?: "请求失败")
_getDeviceConfigUiState.value = UiState.Error(response.message ?: "请求失败")
}
}.onFailure {
_getDeviceTokenUiState.value = UiState.Error(it.message ?: "请求异常")
_getDeviceConfigUiState.value = UiState.Error(it.message ?: "请求异常")
}
}
}