feat(app): 添加 HomeV2Activity 并移除设备角色相关功能
- 在 AndroidManifest.xml 中注册新的 HomeV2Activity 页面 - 移除 BaseApp 中的设备角色判断和秤服务相关初始化代码 - 添加蓝色和橙色渐变按钮背景资源文件 - 修改 InitActivity 默认跳转至 HomeV2Activity 页面 - 移除与设备角色相关的路由逻辑代码
This commit is contained in:
@@ -59,6 +59,11 @@
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
|
||||
|
||||
<activity android:name=".ui.HomeV2Activity"
|
||||
android:theme="@style/Theme.DishMatch.NoSplash"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.CookingModeActivity"
|
||||
android:theme="@style/Theme.DishMatch.NoSplash"
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
package com.shuwei.dish.match.base
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import com.shuwei.dish.match.BuildConfig
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.db.DatabaseProvider
|
||||
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.WeightUtil
|
||||
import com.shuwei.dish.match.utils.Weigher2
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
|
||||
class BaseApp : Application() {
|
||||
|
||||
@@ -34,53 +24,54 @@ class BaseApp : Application() {
|
||||
GlobalData.appBaseUrl = savedBaseUrl
|
||||
}
|
||||
CrashHandler.init(this)
|
||||
val deviceId = if (BuildConfig.IS_TEST_DEVICE) ScaleDeviceConfig.DEVICE_ID_2 else AppUtil.getUDID(this)
|
||||
Log.d(TAG, "onCreate: deviceId=$deviceId, isTestDevice=${BuildConfig.IS_TEST_DEVICE}")
|
||||
GlobalData.deviceId = deviceId
|
||||
|
||||
// 根据设备 ID 判断角色:指定 ID 为主设备,其余为子设备
|
||||
// 主设备是/dev/ttyS7,子设备是/dev/ttyS4
|
||||
if (deviceId == ScaleDeviceConfig.DEVICE_ID_2) {
|
||||
GlobalData.deviceRole = DeviceRole.MASTER
|
||||
Weigher2.setDevicePort("/dev/ttyS7")
|
||||
} else {
|
||||
GlobalData.deviceRole = DeviceRole.SLAVE
|
||||
Weigher2.setDevicePort("/dev/ttyS4")
|
||||
}
|
||||
Log.d(TAG, "设备角色: ${GlobalData.deviceRole}")
|
||||
|
||||
// 启动秤服务(主设备多启动发现+聚合,子设备只启动服务端+注册)
|
||||
ScaleServiceManager.start(this)
|
||||
|
||||
// 初始化秤,进程级生命周期管理:最后一个 Activity 销毁时才停止读取
|
||||
WeightUtil.init()
|
||||
WeightUtil.getWeight()
|
||||
WeightUtil.startContinuousRead()
|
||||
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
|
||||
private var activityCount = 0
|
||||
override fun onActivityCreated(a: Activity, b: Bundle?) { activityCount++ }
|
||||
override fun onActivityDestroyed(a: Activity) {
|
||||
if (--activityCount <= 0) {
|
||||
WeightUtil.stopContinuousRead()
|
||||
}
|
||||
}
|
||||
override fun onActivityStarted(a: Activity) {}
|
||||
override fun onActivityResumed(a: Activity) {}
|
||||
override fun onActivityPaused(a: Activity) {}
|
||||
override fun onActivityStopped(a: Activity) {}
|
||||
override fun onActivitySaveInstanceState(a: Activity, b: Bundle) {}
|
||||
})
|
||||
// val deviceId = if (BuildConfig.IS_TEST_DEVICE) ScaleDeviceConfig.DEVICE_ID_2 else AppUtil.getUDID(this)
|
||||
// Log.d(TAG, "onCreate: deviceId=$deviceId, isTestDevice=${BuildConfig.IS_TEST_DEVICE}")
|
||||
// GlobalData.deviceId = deviceId
|
||||
//
|
||||
// // 根据设备 ID 判断角色:指定 ID 为主设备,其余为子设备
|
||||
// // 主设备是/dev/ttyS7,子设备是/dev/ttyS4
|
||||
// if (deviceId == ScaleDeviceConfig.DEVICE_ID_2) {
|
||||
// GlobalData.deviceRole = DeviceRole.MASTER
|
||||
// Weigher2.setDevicePort("/dev/ttyS7")
|
||||
// } else {
|
||||
// GlobalData.deviceRole = DeviceRole.SLAVE
|
||||
// Weigher2.setDevicePort("/dev/ttyS4")
|
||||
// }
|
||||
// Log.d(TAG, "设备角色: ${GlobalData.deviceRole}")
|
||||
//
|
||||
// // 启动秤服务(主设备多启动发现+聚合,子设备只启动服务端+注册)
|
||||
// ScaleServiceManager.start(this)
|
||||
//
|
||||
// // 初始化秤,进程级生命周期管理:最后一个 Activity 销毁时才停止读取
|
||||
// WeightUtil.init()
|
||||
// WeightUtil.getWeight()
|
||||
// WeightUtil.startContinuousRead()
|
||||
// registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
|
||||
// private var activityCount = 0
|
||||
// override fun onActivityCreated(a: Activity, b: Bundle?) { activityCount++ }
|
||||
// override fun onActivityDestroyed(a: Activity) {
|
||||
// if (--activityCount <= 0) {
|
||||
// WeightUtil.stopContinuousRead()
|
||||
// }
|
||||
// }
|
||||
// override fun onActivityStarted(a: Activity) {}
|
||||
// override fun onActivityResumed(a: Activity) {}
|
||||
// override fun onActivityPaused(a: Activity) {}
|
||||
// override fun onActivityStopped(a: Activity) {}
|
||||
// override fun onActivitySaveInstanceState(a: Activity, b: Bundle) {}
|
||||
// })
|
||||
|
||||
// GlobalData.deviceId = "39a7abdd06b3c7ab"
|
||||
val filter = IntentFilter(Intent.ACTION_BOOT_COMPLETED)
|
||||
registerReceiver(BootReceiver(), filter)
|
||||
ObjectBox.init(this)
|
||||
// ObjectBox.init(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = "BaseApp"
|
||||
var canteenId = "0"
|
||||
var appVersion: String = "1"
|
||||
|
||||
@Volatile
|
||||
private var sharedPref: SharedPreferences? = null
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.shuwei.dish.match.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.databinding.ActivityHomeV2Binding
|
||||
|
||||
/**
|
||||
* 主页V2 - 净菜包装页面
|
||||
*/
|
||||
class HomeV2Activity : BaseActivity() {
|
||||
|
||||
private lateinit var binding: ActivityHomeV2Binding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
statusBarDarkFont(enable = true)
|
||||
|
||||
binding = ActivityHomeV2Binding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
binding.btnCleanPack.setOnClickListener {
|
||||
// 净菜包点击
|
||||
}
|
||||
|
||||
binding.btnMealPack.setOnClickListener {
|
||||
// 餐品净菜包点击
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,8 @@ import androidx.activity.addCallback
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.base.DeviceRole
|
||||
import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.databinding.ActivityInitBinding
|
||||
import com.shuwei.dish.match.objbox.FoodModule
|
||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||
import com.shuwei.dish.match.utils.AddressUtil
|
||||
import com.shuwei.dish.match.utils.AppUtil
|
||||
import com.shuwei.dish.match.utils.NetworkUtil
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
@@ -91,27 +87,28 @@ class InitActivity : BaseActivity() {
|
||||
lifecycleScope.launch {
|
||||
if (withDelay) delay(2000)
|
||||
// 子设备:直接进入小屏专属页面,不走原有大屏业务流程
|
||||
if (GlobalData.deviceRole == DeviceRole.SLAVE) {
|
||||
startActivity<SlaveActivity>()
|
||||
// 延迟到下一帧 finish,避免与 LaunchActivityItem 事务竞态导致
|
||||
// "Activity client record must not be null" 偶发崩溃
|
||||
window.decorView.post { finish() }
|
||||
return@launch
|
||||
}
|
||||
// 主设备:走原有路由逻辑
|
||||
when (SpTool.cookMode) {
|
||||
0 -> {
|
||||
startActivity<CookingModeActivity>()
|
||||
}
|
||||
|
||||
1 -> {
|
||||
goSampling()
|
||||
}
|
||||
|
||||
else -> {
|
||||
startActivity<HomeActivity>()
|
||||
}
|
||||
}
|
||||
// if (GlobalData.deviceRole == DeviceRole.SLAVE) {
|
||||
// startActivity<SlaveActivity>()
|
||||
// // 延迟到下一帧 finish,避免与 LaunchActivityItem 事务竞态导致
|
||||
// // "Activity client record must not be null" 偶发崩溃
|
||||
// window.decorView.post { finish() }
|
||||
// return@launch
|
||||
// }
|
||||
// // 主设备:走原有路由逻辑
|
||||
// when (SpTool.cookMode) {
|
||||
// 0 -> {
|
||||
// startActivity<CookingModeActivity>()
|
||||
// }
|
||||
//
|
||||
// 1 -> {
|
||||
// goSampling()
|
||||
// }
|
||||
//
|
||||
// else -> {
|
||||
// startActivity<HomeActivity>()
|
||||
// }
|
||||
// }
|
||||
startActivity<HomeV2Activity>()
|
||||
// 延迟到下一帧 finish,避免与 LaunchActivityItem 事务竞态导致
|
||||
// "Activity client record must not be null" 偶发崩溃
|
||||
window.decorView.post { finish() }
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<!-- 从上到下:浅蓝(占比多)→ 深蓝,angle=270 表示从上到下 -->
|
||||
<gradient
|
||||
android:angle="270"
|
||||
android:startColor="#88BBFF"
|
||||
android:centerColor="#1A6EFF"
|
||||
android:centerX="0.65"
|
||||
android:endColor="#0032C8"
|
||||
android:type="linear" />
|
||||
<corners android:radius="16dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<!-- 从上到下:浅橙(占比多)→ 深橙,angle=270 表示从上到下 -->
|
||||
<gradient
|
||||
android:angle="270"
|
||||
android:startColor="#FFD08A"
|
||||
android:centerColor="#FF9632"
|
||||
android:centerX="0.65"
|
||||
android:endColor="#CC6400"
|
||||
android:type="linear" />
|
||||
<corners android:radius="16dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
tools:background="@color/bg_color"
|
||||
tools:ignore="HardcodedText">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="300dp"
|
||||
android:text="净菜包装"
|
||||
android:textColor="@color/home_sub_title"
|
||||
android:textSize="50sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnCleanPack"
|
||||
android:layout_width="500dp"
|
||||
android:layout_height="300dp"
|
||||
android:layout_marginTop="100dp"
|
||||
android:text="净菜包"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="35sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:background="@drawable/bg_gradient_blue_btn"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/btnMealPack"
|
||||
android:layout_width="500dp"
|
||||
android:layout_height="300dp"
|
||||
android:layout_marginTop="100dp"
|
||||
android:gravity="center"
|
||||
android:text="餐品净菜包"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="35sp"
|
||||
android:textStyle="bold"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:background="@drawable/bg_gradient_orange_btn"/>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user