DefaultBetterRoutePromptViewModel

class DefaultBetterRoutePromptViewModel(navigationManager: NavigationManager, timeoutDuration: Duration = 30.seconds, updateDelayMs: Long = 100) : BetterRoutePromptViewModel

Default implementation of BetterRoutePromptViewModel. Manages better route suggestions during navigation with automatic timeout.

Features:

  • Automatically dismisses suggestions after configurable timeout

  • Shows remaining time as a percentage for UI progress indicators

  • Integrates with NavigationManager for real-time route updates

Parameters

navigationManager

The navigation manager providing route updates

timeoutDuration

Duration before auto-dismissal (default: 30 seconds)

updateDelayMs

Delay between progress updates in milliseconds (default: 100ms)

Constructors

Link copied to clipboard
constructor(navigationManager: NavigationManager, timeoutDuration: Duration = 30.seconds, updateDelayMs: Long = 100)

Properties

Link copied to clipboard
open override val betterRoutePrompt: StateFlow<BetterRoutePrompt?>

Observable state of the current better route suggestion. Null when no better route is available.

Link copied to clipboard
open override val dismissalProgress: StateFlow<Double>

Observable state of the remaining time progress (0.0 to 1.0). 1.0 = full time remaining, 0.0 = timeout reached. Updates approximately 10 times per second for smooth progress animations.

Functions

Link copied to clipboard
open override fun accept()

Accepts the suggested better route. Cancels the timeout timer and notifies the navigation system to switch routes.

Link copied to clipboard
open override fun onCleared()

Cleans up resources when the view model is no longer needed. Closes better route source connection and cancels all coroutines.

Link copied to clipboard
open override fun reject()

Rejects the suggested better route. Cancels the timeout timer and continues with the current route.