[状态栏]添加展示和隐藏接口
This commit is contained in:
@@ -105,5 +105,10 @@ class DevaToolsProvider : IDevaToolsProvider {
|
||||
|
||||
override fun showStatusBar(ctx: Context) {
|
||||
StatusManager.init(ctx)
|
||||
StatusManager.show()
|
||||
}
|
||||
|
||||
override fun hideStatusBar() {
|
||||
StatusManager.hide()
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.zhjt.mogo_core_function_devatools.status
|
||||
|
||||
import android.content.*
|
||||
import android.view.*
|
||||
import android.view.WindowManager.LayoutParams
|
||||
import androidx.core.view.*
|
||||
import androidx.lifecycle.*
|
||||
import androidx.lifecycle.Lifecycle.Event
|
||||
@@ -32,6 +33,7 @@ import com.zhjt.mogo_core_function_devatools.status.ui.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import mogo_msg.MogoReportMsg
|
||||
import java.lang.ref.*
|
||||
|
||||
object StatusManager {
|
||||
|
||||
@@ -43,6 +45,10 @@ object StatusManager {
|
||||
|
||||
private var timer: Job? = null
|
||||
|
||||
private var context: WeakReference<Context>? = null
|
||||
|
||||
private var hasInit = false
|
||||
|
||||
private val listener = object : IMoGoAutopilotStatusListener {
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMsg.MogoReportMessage?) {
|
||||
super.onAutopilotGuardian(guardianInfo)
|
||||
@@ -83,6 +89,10 @@ object StatusManager {
|
||||
}
|
||||
|
||||
fun init(ctx: Context) {
|
||||
if (hasInit) {
|
||||
return
|
||||
}
|
||||
hasInit = true
|
||||
val owner = ctx as? ViewModelStoreOwner ?: throw IllegalStateException("ctx: $ctx is a instance of ViewModelStoreOwner.")
|
||||
model = ViewModelProvider(owner).get(StatusModel::class.java)
|
||||
ctx.lifeCycleOwner.lifecycle.addObserver(object : LifecycleEventObserver {
|
||||
@@ -95,6 +105,7 @@ object StatusManager {
|
||||
}
|
||||
}
|
||||
})
|
||||
context = WeakReference(ctx)
|
||||
}
|
||||
|
||||
private fun onCreate(ctx: Context) {
|
||||
@@ -119,24 +130,27 @@ object StatusManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
hidePop?.invoke()
|
||||
val content = StatusView(model, ctx)
|
||||
content.doOnAttach {
|
||||
for (f in flows) {
|
||||
f.onCreate()
|
||||
}
|
||||
}
|
||||
ctx.normalPop(content,
|
||||
width = 665.PX,
|
||||
height = WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
gravity = Gravity.END,
|
||||
startX = 55.PX,
|
||||
isFocusable = false).also { hidePop = it }
|
||||
}
|
||||
|
||||
fun show() {
|
||||
context?.get()?.also { ctx ->
|
||||
hidePop?.invoke()
|
||||
val content = StatusView(model, ctx)
|
||||
content.doOnAttach {
|
||||
for (f in flows) {
|
||||
f.onCreate()
|
||||
}
|
||||
}
|
||||
ctx.normalPop(content, width = 665.PX, height = LayoutParams.WRAP_CONTENT, gravity = Gravity.END, startX = 55.PX, isFocusable = false).also { hidePop = it }
|
||||
}
|
||||
}
|
||||
|
||||
fun hide() {
|
||||
hidePop?.invoke()
|
||||
}
|
||||
|
||||
private fun onDestroy(ctx: Context) {
|
||||
hasInit = false
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
AppStateManager.unRegisterAppStateListener(appStateListener)
|
||||
timer?.cancel()
|
||||
|
||||
Reference in New Issue
Block a user