Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d8d50cd authored by mitulsheth's avatar mitulsheth
Browse files

fix(ETA): Initial required time fix

parent ca8d2fc1
Loading
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -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(
@@ -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() {
@@ -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
    }

}