Loading cardinal-android/app/src/main/java/earth/maps/cardinal/routing/FerrostarWrapperRepository.kt +28 −5 Original line number Diff line number Diff line Loading @@ -62,7 +62,10 @@ class FerrostarWrapperRepository @Inject constructor( val androidTtsObserver = AndroidTtsObserver(context) /** * Suspends until the repository is initialized with a Valhalla endpoint. * Suspends the caller until the repository has been initialized with a Valhalla endpoint. * * Once [_isInitialized] becomes true, this function resumes. If the repository * is already initialized, it returns immediately. */ suspend fun awaitInitialization() { _isInitialized.filter { it }.first() Loading Loading @@ -136,8 +139,14 @@ class FerrostarWrapperRepository @Inject constructor( } /** * Updates the routing options for the specified mode by modifying the existing wrapper. * If the wrapper is not yet initialized, the options are stored and applied once initialized. * Updates the [RoutingOptions] for the specified [mode] by modifying the existing wrapper. * * If the wrapper for the given [mode] is not yet initialized (i.e., [setValhallaEndpoint] * hasn't been called), the options are stored in [pendingOptions] and applied * automatically once initialization completes. * * @param mode The [RoutingMode] to update (e.g., PEDESTRIAN, AUTO). * @param routingOptions The new configuration options to apply. */ fun setOptionsForMode(mode: RoutingMode, routingOptions: RoutingOptions) { val wrapper = getWrapperForMode(mode) Loading @@ -151,8 +160,16 @@ class FerrostarWrapperRepository @Inject constructor( } /** * Resets the routing options for the specified mode to defaults by recreating the wrapper. * If the wrapper is not yet initialized, the default options are stored and applied once initialized. * Resets the [RoutingOptions] for the specified [mode] to their default values. * * This retrieves the defaults from [routingProfileRepository]. If the [FerrostarWrapper] * for this mode is already initialized, the options are applied immediately. * * If the wrapper is not yet initialized (i.e., [setValhallaEndpoint] hasn't been called), * the default options are stored in [pendingOptions] and applied automatically * during initialization. * * @param mode The [RoutingMode] to reset (e.g., PEDESTRIAN, BICYCLE). */ fun resetOptionsToDefaultsForMode(mode: RoutingMode) { val defaultOptions = routingProfileRepository.createDefaultOptionsForMode(mode) Loading @@ -168,6 +185,12 @@ class FerrostarWrapperRepository @Inject constructor( } } /** * Resolves the internal [FerrostarWrapper] instance associated with a specific [RoutingMode].* * @param mode The [RoutingMode] for which to retrieve the wrapper. * @return The corresponding [FerrostarWrapper] (e.g., [_walking], [_cycling]), * or `null` if the mode is unrecognized or the wrapper hasn't been initialized via [setValhallaEndpoint]. */ private fun getWrapperForMode(mode: RoutingMode): FerrostarWrapper? = when (mode) { RoutingMode.PEDESTRIAN -> _walking RoutingMode.BICYCLE -> _cycling Loading Loading
cardinal-android/app/src/main/java/earth/maps/cardinal/routing/FerrostarWrapperRepository.kt +28 −5 Original line number Diff line number Diff line Loading @@ -62,7 +62,10 @@ class FerrostarWrapperRepository @Inject constructor( val androidTtsObserver = AndroidTtsObserver(context) /** * Suspends until the repository is initialized with a Valhalla endpoint. * Suspends the caller until the repository has been initialized with a Valhalla endpoint. * * Once [_isInitialized] becomes true, this function resumes. If the repository * is already initialized, it returns immediately. */ suspend fun awaitInitialization() { _isInitialized.filter { it }.first() Loading Loading @@ -136,8 +139,14 @@ class FerrostarWrapperRepository @Inject constructor( } /** * Updates the routing options for the specified mode by modifying the existing wrapper. * If the wrapper is not yet initialized, the options are stored and applied once initialized. * Updates the [RoutingOptions] for the specified [mode] by modifying the existing wrapper. * * If the wrapper for the given [mode] is not yet initialized (i.e., [setValhallaEndpoint] * hasn't been called), the options are stored in [pendingOptions] and applied * automatically once initialization completes. * * @param mode The [RoutingMode] to update (e.g., PEDESTRIAN, AUTO). * @param routingOptions The new configuration options to apply. */ fun setOptionsForMode(mode: RoutingMode, routingOptions: RoutingOptions) { val wrapper = getWrapperForMode(mode) Loading @@ -151,8 +160,16 @@ class FerrostarWrapperRepository @Inject constructor( } /** * Resets the routing options for the specified mode to defaults by recreating the wrapper. * If the wrapper is not yet initialized, the default options are stored and applied once initialized. * Resets the [RoutingOptions] for the specified [mode] to their default values. * * This retrieves the defaults from [routingProfileRepository]. If the [FerrostarWrapper] * for this mode is already initialized, the options are applied immediately. * * If the wrapper is not yet initialized (i.e., [setValhallaEndpoint] hasn't been called), * the default options are stored in [pendingOptions] and applied automatically * during initialization. * * @param mode The [RoutingMode] to reset (e.g., PEDESTRIAN, BICYCLE). */ fun resetOptionsToDefaultsForMode(mode: RoutingMode) { val defaultOptions = routingProfileRepository.createDefaultOptionsForMode(mode) Loading @@ -168,6 +185,12 @@ class FerrostarWrapperRepository @Inject constructor( } } /** * Resolves the internal [FerrostarWrapper] instance associated with a specific [RoutingMode].* * @param mode The [RoutingMode] for which to retrieve the wrapper. * @return The corresponding [FerrostarWrapper] (e.g., [_walking], [_cycling]), * or `null` if the mode is unrecognized or the wrapper hasn't been initialized via [setValhallaEndpoint]. */ private fun getWrapperForMode(mode: RoutingMode): FerrostarWrapper? = when (mode) { RoutingMode.PEDESTRIAN -> _walking RoutingMode.BICYCLE -> _cycling Loading