diff --git a/core/mogo-core-function-call/build.gradle b/core/mogo-core-function-call/build.gradle index 2b20e901f8..184ae88924 100644 --- a/core/mogo-core-function-call/build.gradle +++ b/core/mogo-core-function-call/build.gradle @@ -55,12 +55,14 @@ dependencies { implementation rootProject.ext.dependencies.mogo_core_utils implementation rootProject.ext.dependencies.mogo_core_function_api implementation rootProject.ext.dependencies.mogoserviceapi + implementation rootProject.ext.dependencies.mogocommons } else { implementation project(':libraries:mogo-adas') implementation project(':core:mogo-core-data') implementation project(':core:mogo-core-utils') implementation project(':core:mogo-core-function-api') implementation project(':services:mogo-service-api') + implementation project(':foudations:mogo-commons') } } diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/map/CallerVisualAngleManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/map/CallerVisualAngleManager.kt index 704685e473..4e2a302dad 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/map/CallerVisualAngleManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/map/CallerVisualAngleManager.kt @@ -9,6 +9,7 @@ import androidx.lifecycle.Lifecycle.Event import androidx.lifecycle.Lifecycle.Event.ON_DESTROY import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner +import com.mogo.cloud.commons.utils.CoordinateUtils import com.mogo.eagle.core.data.config.FunctionBuildConfig import com.mogo.eagle.core.data.map.* import com.mogo.eagle.core.data.map.MapRoadInfo.StopLine @@ -64,39 +65,48 @@ object CallerVisualAngleManager { private val beginLocation = AtomicReference() + private val distanceOfCarToStopLine = AtomicReference() private val listener = object : OnRoadListener { private var roadId = "" - override fun onRoadIdInfo(roadId: String) { - val oldRoadId = this.roadId - Log.d("RWJ", "-- onRoadIdInfo --: prev: ${this.roadId} -> curr: $roadId") - if (oldRoadId != roadId) { - if (hasCrossRoad) { + Log.d(TAG, "-- onRoadIdInfo --: prev: ${this.roadId} -> curr: $roadId") + val startLoc = beginLocation.get() + val currLoc = 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 hasCrossRoad = false - changeVisualAngle(CrossRoad(false)) - } - } else { - if (hasCrossRoad) { - val beginLoc = beginLocation.get() - val endLoc = CallerMapLocationListenerManager.getCurrentLocation() - if (beginLoc != null && endLoc != null && abs(beginLoc.bearing - endLoc.bearing) >= 170) { - Log.d("RWJ", "-- onRoadIdInfo XX--: prev: ${this.roadId} -> curr: $roadId") - hasCrossRoad = false - changeVisualAngle(CrossRoad(false)) - } + beginLocation.set(null) } } + if (triggerClose) { + changeVisualAngle(CrossRoad(false)) + } this.roadId = roadId } override fun onStopLineInfo(info: StopLine) { - Log.d("RWJ", "-- onStopLineInfo --: ${info.distanceOfCarToStopLine}") + Log.d(TAG, "-- onStopLineInfo --: ${info.distanceOfCarToStopLine}") if (!hasCrossRoad && info.distanceOfCarToStopLine <= 30.0) { hasCrossRoad = true + distanceOfCarToStopLine.set(info.distanceOfCarToStopLine) beginLocation.set(CallerMapLocationListenerManager.getCurrentLocation()) changeVisualAngle(CrossRoad(true)) }