[V2X]优化V2X弹窗在子线程调用的逻辑

This commit is contained in:
renwj
2022-08-03 19:47:55 +08:00
parent 7a59119888
commit e7f57c1cfc
5 changed files with 86 additions and 35 deletions

View File

@@ -52,7 +52,7 @@ class AutoPilotBadCaseTest {
it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
index++
}
CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
// CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
}
.flowOn(Dispatchers.Default)
.collect()
@@ -86,7 +86,7 @@ class AutoPilotBadCaseTest {
it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
index++
}
CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
// CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
}
.flowOn(Dispatchers.Default)
.collect()
@@ -114,7 +114,7 @@ class AutoPilotBadCaseTest {
it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
index++
}
CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
// CallerDevaToolsManager.onReceiveBadCaseRecord(builder.build())
}
.flowOn(Dispatchers.Default)
.collect()

View File

@@ -20,6 +20,7 @@ import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWarningStatusListener
import com.mogo.eagle.core.function.hmi.notification.WarningFloat
import com.mogo.eagle.core.function.hmi.notification.anim.DefaultAnimator
import com.mogo.eagle.core.data.enums.SidePattern
import com.mogo.eagle.core.function.hmi.ui.*
import com.mogo.eagle.core.function.main.MainLauncherActivity
import com.mogo.eagle.core.utilcode.kotlin.shape
import com.mogo.eagle.core.utilcode.reminder.Reminder
@@ -27,14 +28,14 @@ import com.mogo.eagle.core.utilcode.reminder.api.impl.ActivityReminder
import com.mogo.eagle.core.utilcode.reminder.api.impl.PopupWindowReminder
import com.mogo.eagle.core.utilcode.reminder.api.impl.ViewReminder
import com.mogo.eagle.core.utilcode.util.AppStateManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.Integer.min
import java.util.concurrent.TimeUnit
import java.util.concurrent.*
import java.util.concurrent.TimeUnit.MILLISECONDS
@RunWith(AndroidJUnit4::class)
@@ -64,6 +65,46 @@ class ReminderTest {
return@runBlocking
}
@Test
fun testShowWarningV2x() = runBlocking {
val f = ensureMoGoHmiFragmentShow()
delay(5000)
(1 until 20).map {
it
}.asFlow()
.onEach {
f.showWarningV2X("10006", "test", "测试$it", "$it", null, true, 5000)
}
.flowOn(Dispatchers.Default)
.collect()
delay(3000000)
}
private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiFragment = suspendCancellableCoroutine {
launch.onActivity { itx ->
val executor = Executors.newSingleThreadScheduledExecutor()
executor.scheduleAtFixedRate({
var find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiFragment } as? MoGoHmiFragment
while (find == null) {
find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiFragment } as? MoGoHmiFragment
}
while (!find.isResumed) {
Thread.sleep(500)
}
it.resumeWith(Result.success(find))
try {
Thread.sleep(500)
executor.shutdownNow()
} catch (e: Throwable) {
e.printStackTrace()
}
}, 50, 500, MILLISECONDS)
}
}
@Test
fun testViewReminderOverride() = runBlocking(Dispatchers.Main) {
launch.onActivity {
@@ -357,14 +398,14 @@ class ReminderTest {
}
}
class TestPopupWindowReminder(private val anchor: View, private val popupWindow: PopupWindow): PopupWindowReminder(popupWindow) {
class TestPopupWindowReminder(private val anchor: View, override val popupWindow: PopupWindow): PopupWindowReminder(popupWindow) {
override fun show() {
popupWindow.showAtLocation(anchor, Gravity.CENTER, 0, 0)
}
}
class TestPopupWindowReminderOverride(private val anchor: View, private val popupWindow: PopupWindow): PopupWindowReminder(popupWindow) {
class TestPopupWindowReminderOverride(private val anchor: View, override val popupWindow: PopupWindow): PopupWindowReminder(popupWindow) {
override fun show() {
popupWindow.showAtLocation(anchor, Gravity.CENTER, 0, 0)

View File

@@ -146,6 +146,8 @@ import java.util.*
private var speakJob: Job? = null
private var showV2XJob: Job? = null
private var showingV2XTip: IReminder? = null
private var roadVideoDialog: RoadVideoDialog? = null
@@ -606,11 +608,9 @@ import java.util.*
CallerLogger.e("$M_HMI$TAG", "Show warningContent is null or empty!")
return
}
speakJob?.safeCancel()
val content = mViewNotificationProvider?.getNotificationView() ?: return
content.setWarningIcon(EventTypeEnum.getWarningIcon(v2xType))
content.setWarningContent(warningContent)
var reminder: IReminder? = null
Log.d("$M_HMI$TAG", "--- show v2x dialog 1 ---: info -> v2x-type: $v2xType : expireTime: $expireTime")
Reminder.enqueue(this@MoGoHmiFragment, object : PopupWindowReminder(PopupWindow(content, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT).also { itx ->
itx.isTouchable = false
@@ -633,43 +633,44 @@ import java.util.*
}
}) {
override fun show() {
showV2XJob?.safeCancel()
speakJob?.safeCancel()
val parent = it.window.decorView
parent.doOnAttach {
Log.d("$M_HMI$TAG", "--- show v2x dialog 2 ---: info -> v2x-type: $v2xType : expireTime: $expireTime")
popupWindow.showAtLocation(parent, content.layoutGravity, 0, 0)
}
}
override fun isOverride(): Boolean {
return true
}
}.also { itx -> reminder = itx }, object : IStateChangeListener {
}, object : IStateChangeListener {
override fun onShow(reminder: IReminder) {
listener?.onShow()
showingV2XTip = reminder
lifecycleScope.launch {
delay(expireTime)
}.also { itx ->
showV2XJob = itx
}.invokeOnCompletion { _ ->
reminder.hide()
}
if (ttsContent != null && !TextUtils.isEmpty(ttsContent) && playTTS) {
lifecycleScope.launch {
speak(it, ttsContent)
}.also {
speakJob = it
}.also { itx ->
speakJob = itx
}
}
}
override fun onHide(reminder: IReminder) {
listener?.onDismiss()
showingV2XTip = null
showWarning(WarningDirectionEnum.ALERT_WARNING_NON)
}
})
if (reminder == null) {
return
}
showingV2XTip = reminder
lifecycleScope.launch {
delay(expireTime)
reminder?.hide()
}
}
}

View File

@@ -100,17 +100,23 @@ object Reminder {
if (key.isEmpty()) {
throw IllegalStateException("reminder: ${reminder.javaClass.name}'s key can't be empty.")
}
if (enqueued.contains(key)) {
return
synchronized(enqueued) {
if (enqueued.contains(key)) {
return
}
enqueued += key
}
enqueued += key
attaches.getOrPut(attachTo) {
mutableListOf()
}.also {
it.add(WeakReference(reminder))
synchronized(attaches) {
attaches.getOrPut(attachTo) {
mutableListOf()
}.also {
it.add(WeakReference(reminder))
}
}
listener?.let {
reminderListeners[reminder] = it
synchronized(reminderListeners) {
listener?.let {
reminderListeners[reminder] = it
}
}
scope.launch {
if (reminder is ActivityReminder) {
@@ -131,11 +137,14 @@ object Reminder {
heap += reminder
dequeueHeap()
} else {
queue += reminder
val pre = findPreShowedReminder()
if (pre != null) {
pre.hide()
queue.clear()
queue += reminder
} else {
queue.clear()
queue += reminder
dequeue()
}
}

View File

@@ -4,7 +4,7 @@ import android.widget.PopupWindow
import androidx.lifecycle.LifecycleOwner
import com.mogo.eagle.core.utilcode.reminder.api.IReminder
abstract class PopupWindowReminder(val popupWindow: PopupWindow): IReminder {
abstract class PopupWindowReminder(open val popupWindow: PopupWindow): IReminder {
override fun lifecycleOwner(): LifecycleOwner = popupWindow.lifecycleOwner