[2.13.0]路口视角触发关闭逻辑优化
This commit is contained in:
@@ -50,6 +50,8 @@ dependencies {
|
||||
// MoGo 数据埋点工具
|
||||
implementation rootProject.ext.dependencies.analytics
|
||||
|
||||
compileOnly rootProject.ext.dependencies.mogocustommap
|
||||
|
||||
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
||||
implementation rootProject.ext.dependencies.mogo_core_data
|
||||
implementation rootProject.ext.dependencies.mogo_core_utils
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.mogo.eagle.core.utilcode.kotlin.safeCancel
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_DEVA
|
||||
import com.mogo.map.uicontroller.VisualAngleMode
|
||||
import com.zhidaoauto.map.sdk.open.tools.MapTools
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.android.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.internal.synchronized
|
||||
@@ -63,42 +64,43 @@ object CallerVisualAngleManager {
|
||||
val displayThreshold: Long //最大展示时长 > 0; 表示最长展示多长时间, -1 表示,一直展示,直到触发默认视角, 0: 默认视角专用值,
|
||||
}
|
||||
|
||||
private val beginLocation = AtomicReference<MogoLocation>()
|
||||
private val triggerLocation = AtomicReference<MogoLocation>()
|
||||
|
||||
private val distanceOfCarToStopLine = AtomicReference<Double>()
|
||||
private val distanceOfCarToStopLine = AtomicReference(0.0)
|
||||
|
||||
private val travelled by lazy { AtomicReference(0.0) }
|
||||
|
||||
private val listener = object : OnRoadListener {
|
||||
private var roadId = ""
|
||||
private val roadId = AtomicReference<String>()
|
||||
private val triggerRoadId = AtomicReference<String>()
|
||||
|
||||
override fun onRoadIdInfo(roadId: String) {
|
||||
val oldRoadId = this.roadId
|
||||
Log.d(TAG, "-- onRoadIdInfo --: prev: ${this.roadId} -> curr: $roadId")
|
||||
val startLoc = beginLocation.get()
|
||||
val currLoc = CallerMapLocationListenerManager.getCurrentLocation()
|
||||
this.roadId.set(roadId)
|
||||
Log.d(TAG, "-- onRoadIdInfo --: prev: ${this.triggerRoadId.get()} -> curr: $roadId")
|
||||
val loc = CallerMapLocationListenerManager.getCurrentLocation()
|
||||
var triggerClose = false
|
||||
val distance = distanceOfCarToStopLine.get()
|
||||
if (hasCrossRoad && distance > 0 && oldRoadId != roadId && startLoc != null && currLoc != null && CoordinateUtils.calculateLineDistance(startLoc.longitude, startLoc.latitude, currLoc.longitude, currLoc.latitude).also {
|
||||
Log.d(TAG, "d1: $it, d2: $distance")
|
||||
} >= distance) {
|
||||
distanceOfCarToStopLine.set(0.0)
|
||||
hasCrossRoad = false
|
||||
Log.d(TAG, "-- onRoadIdInfo --: trigger close --")
|
||||
triggerClose = true
|
||||
}
|
||||
if (!triggerClose && hasCrossRoad && oldRoadId == roadId) {
|
||||
val beginLoc = beginLocation.get()
|
||||
val endLoc = CallerMapLocationListenerManager.getCurrentLocation()
|
||||
if (beginLoc != null && endLoc != null && abs(beginLoc.bearing - endLoc.bearing) >= 170) {
|
||||
Log.d(TAG, "-- onRoadIdInfo --: trigger close 2 --")
|
||||
triggerClose = true
|
||||
val distance = distanceOfCarToStopLine.get() + 5
|
||||
if (hasCrossRoad && distance > 0) {
|
||||
val prev = triggerLocation.get()
|
||||
if (prev != null && loc != null) {
|
||||
travelled.set(MapTools.distance(loc.longitude, loc.latitude, prev.longitude, prev.latitude) + travelled.get())
|
||||
triggerLocation.set(loc)
|
||||
}
|
||||
val oldRoadId = triggerRoadId.get()
|
||||
Log.d(TAG, "-- onRoadIdInfo --: travelled --: ${travelled.get()}")
|
||||
if ((travelled.get() > distance) && oldRoadId != null && oldRoadId != roadId) {
|
||||
distanceOfCarToStopLine.set(0.0)
|
||||
hasCrossRoad = false
|
||||
beginLocation.set(null)
|
||||
triggerRoadId.set(null)
|
||||
travelled.set(0.0)
|
||||
triggerLocation.set(null)
|
||||
Log.d(TAG, "-- onRoadIdInfo --: trigger close --")
|
||||
triggerClose = true
|
||||
}
|
||||
}
|
||||
if (triggerClose) {
|
||||
changeVisualAngle(CrossRoad(false))
|
||||
}
|
||||
this.roadId = roadId
|
||||
}
|
||||
|
||||
|
||||
@@ -106,8 +108,9 @@ object CallerVisualAngleManager {
|
||||
Log.d(TAG, "-- onStopLineInfo --: ${info.distanceOfCarToStopLine}")
|
||||
if (!hasCrossRoad && info.distanceOfCarToStopLine <= 30.0) {
|
||||
hasCrossRoad = true
|
||||
triggerRoadId.set(this.roadId.get())
|
||||
distanceOfCarToStopLine.set(info.distanceOfCarToStopLine)
|
||||
beginLocation.set(CallerMapLocationListenerManager.getCurrentLocation())
|
||||
triggerLocation.set(CallerMapLocationListenerManager.getCurrentLocation())
|
||||
changeVisualAngle(CrossRoad(true))
|
||||
}
|
||||
}
|
||||
@@ -236,12 +239,11 @@ object CallerVisualAngleManager {
|
||||
}
|
||||
}
|
||||
|
||||
private val heap by lazy {
|
||||
private val queue by lazy {
|
||||
PriorityQueue<Record>()
|
||||
}
|
||||
|
||||
@OptIn(InternalCoroutinesApi::class)
|
||||
fun changeVisualAngle(scene: Scene) {
|
||||
fun changeVisualAngle(current: Scene) {
|
||||
val appIdentityMode = FunctionBuildConfig.appIdentityMode
|
||||
if (AppIdentityModeUtils.isBus(appIdentityMode) && AppIdentityModeUtils.isPassenger(appIdentityMode)) {
|
||||
return
|
||||
@@ -252,85 +254,68 @@ object CallerVisualAngleManager {
|
||||
val displayed = getDisplayed()
|
||||
if (displayed == null) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 2 ---")
|
||||
val top = getTop() //堆顶
|
||||
if (top != null) {
|
||||
if (top.target.priority >= scene.priority) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 3 ---")
|
||||
top.triggerTime = triggerTime
|
||||
doChangeAngle(top)
|
||||
synchronized(heap){
|
||||
heap += Record(scene, triggerTime = -1)
|
||||
}
|
||||
} else {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 4 ---")
|
||||
doChangeAngle(Record(scene, triggerTime = triggerTime))
|
||||
}
|
||||
} else {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 5 ---")
|
||||
doChangeAngle(Record(scene, triggerTime = triggerTime))
|
||||
}
|
||||
doChangeAngle(Record(current, triggerTime = triggerTime))
|
||||
} else {
|
||||
val prev = displayed.target
|
||||
Log.d("${M_DEVA}${TAG}", "--- 6 --- old: $prev -> cur: $scene")
|
||||
Log.d("${M_DEVA}${TAG}", "--- 3 --- old: $prev -> cur: $current")
|
||||
val prevTriggerTime = displayed.triggerTime
|
||||
if (scene !is Default && prev.priority >= scene.priority && (prev is RoadEvent || prev is TooClose)) {
|
||||
|
||||
if (current !is Default && prev.priority > current.priority && (prev is RoadEvent || prev is TooClose)) {
|
||||
val displayDuration = triggerTime - prevTriggerTime
|
||||
Log.d("${M_DEVA}${TAG}", "--- 7 ---:duration: $displayDuration")
|
||||
Log.d("${M_DEVA}${TAG}", "--- 4 ---:场景[$prev], 已展示时长: duration: $displayDuration")
|
||||
if (displayDuration < prev.displayThreshold) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 8 --- old: $prev -> cur: $scene")
|
||||
Log.d("${M_DEVA}${TAG}", "--- 5 --- 场景[$prev]:仍在保护展示时长内,直接return")
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
if (prev.priority > scene.priority) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 9 --- old: $prev -> cur: $scene")
|
||||
if (prev.displayThreshold < 0) {
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
if (scene is Turning) {
|
||||
val isOpen = scene.open
|
||||
if (prev is Turning && current is Turning) {
|
||||
val isOpen = current.open
|
||||
if (!isOpen) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 10 --- old: $prev -> cur: $scene")
|
||||
Log.d("${M_DEVA}${TAG}", "--- 7 --- 场景[$current], 收到关闭通知")
|
||||
queue -= displayed
|
||||
changeVisualAngle(Default())
|
||||
heap -= displayed
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
if (scene is CrossRoad) {
|
||||
val isOpen = scene.open
|
||||
if (prev is CrossRoad && current is CrossRoad) {
|
||||
val isOpen = current.open
|
||||
if (!isOpen) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 11 --- old: $prev -> cur: $scene")
|
||||
Log.d("${M_DEVA}${TAG}", "--- 8 --- old: $prev -> cur: $current")
|
||||
queue -= displayed
|
||||
changeVisualAngle(Default())
|
||||
heap -= displayed
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
||||
if (scene is Default) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 12 ---")
|
||||
if (prev.priority > current.priority && prev.displayThreshold < 0) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 6 --- 场景[$prev]正在展示,尚未收到关闭,场景,依然展示当前场景,直接return")
|
||||
return@launch
|
||||
}
|
||||
|
||||
if (current is Default) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 9 ---")
|
||||
defaultDelayJob?.safeCancel()
|
||||
launch {
|
||||
val delay = scene.unit.toMillis(scene.delay)
|
||||
Log.d("${M_DEVA}${TAG}", "--- 13 ---")
|
||||
val delay = current.unit.toMillis(current.delay)
|
||||
Log.d("${M_DEVA}${TAG}", "--- 10 ---")
|
||||
delay(delay)
|
||||
Log.d("${M_DEVA}${TAG}", "--- 14 ---")
|
||||
doChangeAngle(Record(scene, triggerTime = triggerTime))
|
||||
heap -= displayed
|
||||
queue -= displayed
|
||||
Log.d("${M_DEVA}${TAG}", "--- 11 ---")
|
||||
doChangeAngle(Record(current, triggerTime = triggerTime))
|
||||
}.also { itx ->
|
||||
itx.invokeOnCompletion {
|
||||
if (it is CancellationException) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 15 ---")
|
||||
Log.d("${M_DEVA}${TAG}", "--- 12 ---")
|
||||
}
|
||||
}
|
||||
defaultDelayJob = itx
|
||||
}
|
||||
} else {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 16 ---")
|
||||
Log.d("${M_DEVA}${TAG}", "--- 13 ---")
|
||||
defaultDelayJob?.safeCancel()
|
||||
if (displayed.target.priority < scene.priority) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 17 ---")
|
||||
doChangeAngle(Record(scene, triggerTime = triggerTime))
|
||||
if (displayed.target.priority < current.priority) {
|
||||
Log.d("${M_DEVA}${TAG}", "--- 14 ---")
|
||||
queue -= displayed
|
||||
doChangeAngle(Record(current, triggerTime = triggerTime))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,8 +329,8 @@ object CallerVisualAngleManager {
|
||||
Log.d("${M_DEVA}${TAG}", "--- doChangeAngle ---: ${record.target}")
|
||||
if (record.target !is Default) {
|
||||
record.isDisplay = true
|
||||
synchronized(heap) {
|
||||
heap += record
|
||||
synchronized(queue) {
|
||||
queue += record
|
||||
}
|
||||
}
|
||||
it.changeMapVisualAngle(angle, null)
|
||||
@@ -356,8 +341,6 @@ object CallerVisualAngleManager {
|
||||
* 是否有正在展示的
|
||||
*/
|
||||
@Synchronized
|
||||
private fun getDisplayed() = heap.find { it.isDisplay }
|
||||
private fun getDisplayed() = queue.firstOrNull()
|
||||
|
||||
@Synchronized
|
||||
private fun getTop() = heap.firstOrNull()
|
||||
}
|
||||
Reference in New Issue
Block a user