[状态栏]去掉定时请求topic状态的逻辑
This commit is contained in:
@@ -42,51 +42,51 @@ object StatusManager {
|
||||
private const val TAG = "StatusManager"
|
||||
|
||||
private lateinit var model: StatusModel
|
||||
private var timer: Job? = null
|
||||
// private var timer: Job? = null
|
||||
private var hasInit = false
|
||||
private val listeners by lazy { CopyOnWriteArrayList<IStatusListener>() }
|
||||
private var container: WeakReference<ViewGroup>? = null
|
||||
|
||||
private val listener = object : IMoGoAutopilotStatusListener {
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) {
|
||||
super.onAutopilotGuardian(guardianInfo)
|
||||
guardianInfo?.code?.takeIf {
|
||||
CallerLogger.d("$M_DEVA$TAG", "-- onAutopilotGuardian ---: code: $it")
|
||||
it.contains("RTK_STATUS", true) || it.contains("CAN", true) || it == "ILCT_RTK_OR_SLAM_CHANGE"
|
||||
}?.run {
|
||||
CallerLogger.d("$M_DEVA$TAG", "-- onAutopilotGuardian trigger req ---: code: $this")
|
||||
req()
|
||||
}
|
||||
}
|
||||
}
|
||||
// private val listener = object : IMoGoAutopilotStatusListener {
|
||||
// override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) {
|
||||
// super.onAutopilotGuardian(guardianInfo)
|
||||
// guardianInfo?.code?.takeIf {
|
||||
// CallerLogger.d("$M_DEVA$TAG", "-- onAutopilotGuardian ---: code: $it")
|
||||
// it.contains("RTK_STATUS", true) || it.contains("CAN", true) || it == "ILCT_RTK_OR_SLAM_CHANGE"
|
||||
// }?.run {
|
||||
// CallerLogger.d("$M_DEVA$TAG", "-- onAutopilotGuardian trigger req ---: code: $this")
|
||||
// req()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private val appStateListener = object : IAppStateListener {
|
||||
|
||||
override fun onAppStateChanged(isForeground: Boolean) {
|
||||
if (isForeground) {
|
||||
req()
|
||||
} else {
|
||||
timer?.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
// private val appStateListener = object : IAppStateListener {
|
||||
//
|
||||
// override fun onAppStateChanged(isForeground: Boolean) {
|
||||
// if (isForeground) {
|
||||
// req()
|
||||
// } else {
|
||||
// timer?.cancel()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private val flows: ArrayList<IFlow<out Status>> by lazy {
|
||||
ArrayList()
|
||||
}
|
||||
|
||||
private fun req() {
|
||||
timer?.cancel()
|
||||
model.viewModelScope.launch(Dispatchers.IO) {
|
||||
CallerAutoPilotManager.sendStatusQueryReq()
|
||||
while (true) {
|
||||
delay(60000) //一分钟主动请求一次
|
||||
CallerAutoPilotManager.sendStatusQueryReq()
|
||||
}
|
||||
}.also {
|
||||
timer = it
|
||||
}
|
||||
}
|
||||
// private fun req() {
|
||||
// timer?.cancel()
|
||||
// model.viewModelScope.launch(Dispatchers.IO) {
|
||||
// CallerAutoPilotManager.sendStatusQueryReq()
|
||||
// while (true) {
|
||||
// delay(60000) //一分钟主动请求一次
|
||||
// CallerAutoPilotManager.sendStatusQueryReq()
|
||||
// }
|
||||
// }.also {
|
||||
// timer = it
|
||||
// }
|
||||
// }
|
||||
|
||||
fun init(ctx: Context) {
|
||||
if (hasInit) {
|
||||
@@ -109,9 +109,9 @@ object StatusManager {
|
||||
|
||||
private fun onCreate(ctx: Context) {
|
||||
val values = model.status.value?.second ?: throw IllegalStateException("state is not right.")
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, listener)
|
||||
AppStateManager.registerAppStateListener(appStateListener)
|
||||
req()
|
||||
// CallerAutoPilotStatusListenerManager.addListener(TAG, listener)
|
||||
// AppStateManager.registerAppStateListener(appStateListener)
|
||||
// req()
|
||||
values.map {
|
||||
when (it) {
|
||||
is CanStatus -> CanImpl(ctx)
|
||||
@@ -166,9 +166,9 @@ object StatusManager {
|
||||
|
||||
private fun onDestroy(ctx: Context) {
|
||||
hasInit = false
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
AppStateManager.unRegisterAppStateListener(appStateListener)
|
||||
timer?.cancel()
|
||||
// CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
// AppStateManager.unRegisterAppStateListener(appStateListener)
|
||||
// timer?.cancel()
|
||||
flows.forEach {
|
||||
it.onDestroy()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user