Loading cardinal-android/app/src/main/java/earth/maps/cardinal/ui/navigation/NavigationChrome.kt +16 −6 Original line number Diff line number Diff line Loading @@ -129,10 +129,17 @@ fun CardinalProgressView( val smoothedSpeedMs = viewModel.getSmoothedSpeed(uiState.location?.speed?.value ?: 0.0) val remainingMeters = progress.distanceRemaining val correctedSeconds = remainingMeters / smoothedSpeedMs val correctedProgress = remember(progress, correctedSeconds) { val correctedProgress = remember(progress, smoothedSpeedMs) { val finalDuration = if (smoothedSpeedMs != null) { // We have enough data for a dynamic estimate (remainingMeters / smoothedSpeedMs) } else { // Fallback to the original route estimate during "warm-up" progress.durationRemaining } progress.copy( durationRemaining = maxOf(correctedSeconds, progress.durationRemaining) durationRemaining = finalDuration ) } TripProgressView( Loading Loading @@ -217,10 +224,12 @@ class NavigationChromeViewModel @Inject constructor( } } fun getSmoothedSpeed(currentSpeedInMs: Double): Float { fun getSmoothedSpeed(currentSpeedInMs: Double): Float? { if (speedBuffer.size >= SPEED_WINDOW_SIZE) speedBuffer.removeAt(0) speedBuffer.add(currentSpeedInMs.coerceAtLeast(0.5)) return speedBuffer.average().toFloat() speedBuffer.add(currentSpeedInMs.coerceAtLeast(MINIMUM_SPEED)) if (speedBuffer.size < SPEED_WINDOW_SIZE) return null val average = speedBuffer.average() return if (average < MINIMUM_SPEED) null else average.toFloat() } override fun onCleared() { Loading @@ -231,6 +240,7 @@ class NavigationChromeViewModel @Inject constructor( companion object { private val DELAY = 5.seconds private const val SPEED_WINDOW_SIZE = 5 private const val MINIMUM_SPEED = 0.5 } } Loading
cardinal-android/app/src/main/java/earth/maps/cardinal/ui/navigation/NavigationChrome.kt +16 −6 Original line number Diff line number Diff line Loading @@ -129,10 +129,17 @@ fun CardinalProgressView( val smoothedSpeedMs = viewModel.getSmoothedSpeed(uiState.location?.speed?.value ?: 0.0) val remainingMeters = progress.distanceRemaining val correctedSeconds = remainingMeters / smoothedSpeedMs val correctedProgress = remember(progress, correctedSeconds) { val correctedProgress = remember(progress, smoothedSpeedMs) { val finalDuration = if (smoothedSpeedMs != null) { // We have enough data for a dynamic estimate (remainingMeters / smoothedSpeedMs) } else { // Fallback to the original route estimate during "warm-up" progress.durationRemaining } progress.copy( durationRemaining = maxOf(correctedSeconds, progress.durationRemaining) durationRemaining = finalDuration ) } TripProgressView( Loading Loading @@ -217,10 +224,12 @@ class NavigationChromeViewModel @Inject constructor( } } fun getSmoothedSpeed(currentSpeedInMs: Double): Float { fun getSmoothedSpeed(currentSpeedInMs: Double): Float? { if (speedBuffer.size >= SPEED_WINDOW_SIZE) speedBuffer.removeAt(0) speedBuffer.add(currentSpeedInMs.coerceAtLeast(0.5)) return speedBuffer.average().toFloat() speedBuffer.add(currentSpeedInMs.coerceAtLeast(MINIMUM_SPEED)) if (speedBuffer.size < SPEED_WINDOW_SIZE) return null val average = speedBuffer.average() return if (average < MINIMUM_SPEED) null else average.toFloat() } override fun onCleared() { Loading @@ -231,6 +240,7 @@ class NavigationChromeViewModel @Inject constructor( companion object { private val DELAY = 5.seconds private const val SPEED_WINDOW_SIZE = 5 private const val MINIMUM_SPEED = 0.5 } }