fix(scale): 修复主从设备IP显示异常及RecyclerView滑动崩溃
- 新增 NetworkUtil 统一获取本机IP,兼容 Android 12+(ConnectivityManager)和低版本(WifiManager) - 主设备IP改为实时读取,修复App启动时网络未就绪导致IP缓存为空的问题 - MasterScaleActivity/SlaveActivity 关闭RecyclerView默认ItemAnimator,消除高频刷新时的闪烁 - BaseActivity.hideSystemBars 加防重入标志,避免重复调用setDecorFitsSystemWindows触发布局重绘导致滑动崩溃 - 新增 CrashHandler,崩溃时记录日志并自动重启应用 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package com.shuwei.dish.match.scale
|
||||
|
||||
import android.content.Context
|
||||
import android.net.wifi.WifiManager
|
||||
import android.util.Log
|
||||
import com.shuwei.dish.match.base.DeviceRole
|
||||
import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.utils.NetworkUtil
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
@@ -70,17 +70,10 @@ object ScaleServiceManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 WifiManager 获取本机 WiFi IP 地址
|
||||
* 获取本机局域网 IP,委托给 NetworkUtil 统一处理版本兼容
|
||||
*/
|
||||
private fun getLocalIp(context: Context): String {
|
||||
return try {
|
||||
val wm = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||
val ip = wm.connectionInfo.ipAddress
|
||||
if (ip == 0) "" else
|
||||
"${ip and 0xFF}.${ip shr 8 and 0xFF}.${ip shr 16 and 0xFF}.${ip shr 24 and 0xFF}"
|
||||
} catch (e: Exception) {
|
||||
""
|
||||
}
|
||||
return NetworkUtil.getLocalIpAddress(context)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user