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

Commit d4bec252 authored by Mitul Sheth's avatar Mitul Sheth
Browse files

Merge branch 'bug_long_itinerary_error_message-ai-review' into 'main'

fix(message): This itinerary is too long

See merge request !62
parents 5562383a ddf2af11
Loading
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
package earth.maps.cardinal.data

import androidx.annotation.VisibleForTesting
import earth.maps.cardinal.ui.directions.DirectionUiError
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -29,6 +30,7 @@ data class RouteState(
    val isLoading: Boolean = false,
    val error: String? = null,
    val selectedRouteIndex: Int? = null,
    val directionError: DirectionUiError? = null,
)

class RouteStateRepository {
@@ -40,7 +42,7 @@ class RouteStateRepository {
    }

    fun setRoutes(routes: List<Route>) {
        _routeState.value = _routeState.value.copy(routes = routes, isLoading = false, error = null)
        _routeState.value = _routeState.value.copy(routes = routes, isLoading = false, error = null, directionError = null)
    }

    fun selectRoute(index: Int) {
@@ -51,6 +53,10 @@ class RouteStateRepository {
        _routeState.value = _routeState.value.copy(isLoading = false, error = error)
    }

    fun setDirectionError(directionUiError: DirectionUiError?) {
        _routeState.value = _routeState.value.copy(isLoading = false, directionError = directionUiError, error = null)
    }

    fun clear() {
        _routeState.value = RouteState()
    }
+34 −0
Original line number Diff line number Diff line
/*
 *     Copyright (C) 2026 e Foundation
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package earth.maps.cardinal.ui.directions

import uniffi.ferrostar.ParsingException

sealed class DirectionUiError {
    object DistanceExceeded : DirectionUiError()
    data class Unknown(val message: String?) : DirectionUiError()
}

enum class DirectionCodes(val value: String) {
    DISTANCE_EXCEEDED("DistanceExceeded")
}

fun ParsingException.InvalidStatusCode.toRouteError(): DirectionUiError =
    when (this.code) {
        DirectionCodes.DISTANCE_EXCEEDED.value -> DirectionUiError.DistanceExceeded
        else -> DirectionUiError.Unknown(this.message)
    }
+16 −3
Original line number Diff line number Diff line
@@ -25,11 +25,9 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
@@ -72,7 +70,6 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.max
import androidx.navigation.NavController
import earth.maps.cardinal.R.dimen
import earth.maps.cardinal.R.drawable
@@ -499,6 +496,22 @@ private fun NonTransitRouteResults(
            )
        }

        routeState.directionError != null -> {
            val message = when (routeState.directionError) {
                DirectionUiError.DistanceExceeded -> stringResource(string.long_itinerary_error_message)
                is DirectionUiError.Unknown -> routeState.directionError.message?.let {
                    stringResource(string.directions_error, it)
                } ?: stringResource(string.unknown_error)
            }
            Text(
                text = message,
                color = MaterialTheme.colorScheme.error,
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(dimensionResource(dimen.padding))
            )
        }

        routeState.routes.isNotEmpty() -> {
            FerrostarRouteResults(
                routeState = routeState,
+3 −1
Original line number Diff line number Diff line
@@ -50,11 +50,11 @@ import earth.maps.cardinal.ui.core.Screen
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import uniffi.ferrostar.GeographicCoordinate
import uniffi.ferrostar.ParsingException
import uniffi.ferrostar.UserLocation
import uniffi.ferrostar.Waypoint
import uniffi.ferrostar.WaypointKind
@@ -179,6 +179,8 @@ class DirectionsViewModel @Inject constructor(
                }

                routeStateRepository.setRoutes(routes)
            } catch (invalidStatusCode: ParsingException.InvalidStatusCode) {
                routeStateRepository.setDirectionError(invalidStatusCode.toRouteError())
            } catch (e: Exception) {
                Log.e(TAG, "Error while fetching route", e)
                routeStateRepository.setError(
+2 −0
Original line number Diff line number Diff line
@@ -155,6 +155,8 @@
    <string name="routing_profile">Routing Profile</string>
    <string name="routing_mode">Routing Mode</string>
    <string name="directions">Directions</string>
    <string name="long_itinerary_error_message">This itinerary is too long</string>
    <string name="unknown_error">Unknown error occurred</string>
    <string name="from">From</string>
    <string name="to">To</string>
    <string name="routing_profile_format">Profile: %1$s</string>
Loading