[feedback]优化代码逻辑
[feedback]优化代码逻辑 [code]升级版本
This commit is contained in:
@@ -7,6 +7,7 @@ import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.lifecycle.Lifecycle.Event
|
||||
import androidx.lifecycle.Lifecycle.Event.ON_CREATE
|
||||
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
@@ -95,19 +96,6 @@ internal object BadCaseManager : LifecycleEventObserver {
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private fun register() {
|
||||
scope?.launch(Dispatchers.Default) {
|
||||
Reminder.registerGlobalStateChangeListener(object : IGlobalStateChangeListener {
|
||||
override fun onShow(reminder: IReminder) {
|
||||
if (reminder.key().startsWith("FeedBackFloatWindow_")) {
|
||||
feedbackFloatShow = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onHide(reminder: IReminder) {
|
||||
if (reminder.key().startsWith("FeedBackFloatWindow_")) {
|
||||
feedbackFloatShow = false
|
||||
}
|
||||
}
|
||||
})
|
||||
while (true) {
|
||||
CallerLogger.d("$M_DEVA$TAG", "---- 开始监听BadCase事件 ----")
|
||||
val old = record
|
||||
@@ -204,10 +192,10 @@ internal object BadCaseManager : LifecycleEventObserver {
|
||||
}
|
||||
|
||||
private fun CoroutineScope.showBadCaseInternal(record: AutoPilotRecord) = launch {
|
||||
viewHolder?.get()?.also {
|
||||
viewHolder?.get()?.also { itx ->
|
||||
presenter.updateLastModified(record.toLongTime())
|
||||
showEntry()
|
||||
it.onClick {
|
||||
itx.onClick {
|
||||
showBadCaseFloat(
|
||||
onDismiss = {
|
||||
hideFloat?.invoke()
|
||||
@@ -274,14 +262,33 @@ internal object BadCaseManager : LifecycleEventObserver {
|
||||
val activity = viewHolder?.get()?.context as? FragmentActivity ?: throw IllegalStateException("please ensure context is FragmentActivity.")
|
||||
BadCaseView(activity).also { itx ->
|
||||
itx.register(record, onDismiss, onSelect)
|
||||
activity.pop(itx, 960.PX, WindowManager.LayoutParams.MATCH_PARENT).also {
|
||||
activity.pop(itx, 960.PX, WindowManager.LayoutParams.MATCH_PARENT, key = "BadCaseFloatWindow_").also {
|
||||
hideFloat = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private val listener = object : IGlobalStateChangeListener {
|
||||
override fun onShow(reminder: IReminder) {
|
||||
if (reminder.key().startsWith("FeedBackFloatWindow_")) {
|
||||
feedbackFloatShow = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onHide(reminder: IReminder) {
|
||||
if (reminder.key().startsWith("FeedBackFloatWindow_")) {
|
||||
feedbackFloatShow = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStateChanged(source: LifecycleOwner, event: Event) {
|
||||
if (event == ON_CREATE) {
|
||||
Reminder.registerGlobalStateChangeListener(listener)
|
||||
}
|
||||
if (event == ON_DESTROY) {
|
||||
Reminder.unRegisterGlobalStateChangeListener(listener)
|
||||
dismissJob?.takeIf { it.isActive }?.cancel()
|
||||
onHide = null
|
||||
onShow = null
|
||||
|
||||
@@ -66,7 +66,7 @@ internal fun Context.toast(text: CharSequence, duration: Long = 2, unit: TimeUni
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
internal fun Context.pop(content: View, width: Int, height: Int, fitSystemWindow: Boolean = true, onOuterViewClicked:((focus: View) -> Unit)? = null): () -> Unit {
|
||||
internal fun Context.pop(content: View, width: Int, height: Int, key: String, fitSystemWindow: Boolean = true, onOuterViewClicked:((focus: View) -> Unit)? = null): () -> Unit {
|
||||
val activity = (this as? FragmentActivity) ?: throw IllegalStateException("please use Activity to trigger pop show.")
|
||||
var tempReminder: PopupWindowReminder? = null
|
||||
activity.lifecycleScope.launchWhenResumed {
|
||||
@@ -120,7 +120,7 @@ internal fun Context.pop(content: View, width: Int, height: Int, fitSystemWindow
|
||||
val reminder = object : PopupWindowReminder(pop) {
|
||||
|
||||
override fun key(): String {
|
||||
return "FeedBackFloatWindow_" + super.key()
|
||||
return key + super.key()
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
|
||||
@@ -154,6 +154,7 @@ internal object FeedbackManager {
|
||||
},
|
||||
width = 960.PX,
|
||||
height = WindowManager.LayoutParams.MATCH_PARENT,
|
||||
key = "FeedBackFloatWindow_",
|
||||
onOuterViewClicked = {
|
||||
KeyboardUtils.hideSoftInput(it)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user