refactor(activity): 优化启动页跳转延迟及子设备页面稳定性,修复导航栏闪烁问题
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import android.util.Log
|
||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||
//import com.aithings.Weigher
|
||||
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
typealias WeightCallback = (address: Int, state: Int, weight: Double) -> Unit
|
||||
|
||||
@@ -17,8 +18,7 @@ object WeightUtil {
|
||||
const val STATE_OVER_WEIGHT = SensorScale.STATE_OVER_WEIGHT
|
||||
|
||||
var isConnected = false
|
||||
var weightFuncMap: MutableMap<String, WeightCallback?>? =
|
||||
null
|
||||
val weightFuncMap: ConcurrentHashMap<String, WeightCallback?> = ConcurrentHashMap()
|
||||
|
||||
fun init() {
|
||||
Weigher2.init()
|
||||
@@ -38,7 +38,7 @@ object WeightUtil {
|
||||
}
|
||||
val useWeight = (weight*1000).roundedOneDecimalPlace()
|
||||
Log.d(TAG, "readWeight, address=$address,state=$stateStr, weight=$useWeight")
|
||||
weightFuncMap?.forEach { (key, value) ->
|
||||
weightFuncMap.forEach { (key, value) ->
|
||||
value?.invoke(address, state, useWeight)
|
||||
}
|
||||
|
||||
@@ -82,18 +82,15 @@ object WeightUtil {
|
||||
}
|
||||
}
|
||||
|
||||
fun removeWeightListener(weightKey: String){
|
||||
weightFuncMap?.remove(weightKey)
|
||||
fun removeWeightListener(weightKey: String) {
|
||||
weightFuncMap.remove(weightKey)
|
||||
}
|
||||
|
||||
fun addWeightListener(
|
||||
weightKey: String,
|
||||
getWeight: WeightCallback = { _, _, _ -> }
|
||||
) {
|
||||
if (weightFuncMap == null) {
|
||||
weightFuncMap = mutableMapOf()
|
||||
}
|
||||
weightFuncMap?.put(weightKey, getWeight)
|
||||
weightFuncMap[weightKey] = getWeight
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user