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

Commit d54b0585 authored by mitulsheth's avatar mitulsheth
Browse files

Merge branch 'main' of https://gitlab.e.foundation/e/os/maps into adding_agents_skills

parents 2187a5e3 753e3461
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -216,6 +216,7 @@ dependencies {
    implementation(libs.ferrostar.maplibreui)
    implementation(libs.ferrostar.composeui)
    implementation(libs.okhttp3)
    implementation(libs.logging.interceptor)
    implementation(libs.androidaddressformatter)
    implementation(libs.eos.telemetry)

+60 −0
Original line number Diff line number Diff line
/*
 *     Cardinal Maps
 *     Copyright (C) 2026 Cardinal Maps Authors
 *
 *     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.data.navigation

import android.content.Context
import com.stadiamaps.ferrostar.core.SpokenInstructionObserver
import dagger.hilt.android.qualifiers.ApplicationContext
import earth.maps.cardinal.data.LocationRepository
import earth.maps.cardinal.data.OrientationRepository
import earth.maps.cardinal.data.RoutingMode
import earth.maps.cardinal.data.room.RoutingProfileRepository
import earth.maps.cardinal.routing.FerrostarWrapper
import earth.maps.cardinal.routing.RoutingOptions
import okhttp3.OkHttpClient
import javax.inject.Inject

class CardinalFerrostarWrapperFactory @Inject constructor(
    @ApplicationContext private val context: Context,
    private val locationRepository: LocationRepository,
    private val orientationRepository: OrientationRepository,
    private val androidTtsObserver: SpokenInstructionObserver,
    private val routingProfileRepository: RoutingProfileRepository,
    private val okHttpClient: OkHttpClient
) : FerrostarWrapperFactory {

    override fun create(
        mode: RoutingMode,
        endpoint: String,
        routingOptions: RoutingOptions?
    ): FerrostarWrapper {

        return FerrostarWrapper(
            context = context,
            locationRepository = locationRepository,
            orientationRepository = orientationRepository,
            mode = mode,
            localValhallaEndpoint = endpoint,
            androidTtsObserver = androidTtsObserver,
            routingProfileRepository = routingProfileRepository,
            routingOptions = routingOptions,
            okHttpClient = okHttpClient
        )
    }
}
+66 −0
Original line number Diff line number Diff line
/*
 *     Cardinal Maps
 *     Copyright (C) 2026 Cardinal Maps Authors
 *
 *     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.data.navigation

import earth.maps.cardinal.data.LatLng
import earth.maps.cardinal.domain.DeviationDetector

class CustomDeviationDetector(
    private val distanceCalculator: PolylineDistanceCalculator
) : DeviationDetector {

    private var lastRouteHash: Int = 0
    private var lastOffRouteTs: Long = 0L

    override fun isOffRoute(
        location: LatLng,
        route: List<LatLng>
    ): Boolean {

        if (route.size < MIN_ROUTE_POINTS) return false

        val currentHash = route.hashCode()
        if (currentHash != lastRouteHash) {
            distanceCalculator.resetCache()
            lastRouteHash = currentHash
        }

        val distance = distanceCalculator.distanceFromPolyline(location, route)

        val now = System.currentTimeMillis()

        val isOffRoute = if (distance > OFF_ROUTE_THRESHOLD_METERS) {
            if (now - lastOffRouteTs > OFF_ROUTE_DEBOUNCE_MS) {
                lastOffRouteTs = now
                true
            } else {
                false
            }
        } else {
            false
        }

        return isOffRoute
    }

    companion object {
        private const val OFF_ROUTE_THRESHOLD_METERS = 15.0
        private const val OFF_ROUTE_DEBOUNCE_MS = 1500L
        private const val MIN_ROUTE_POINTS = 2
    }
}
+58 −0
Original line number Diff line number Diff line
/*
 *     Cardinal Maps
 *     Copyright (C) 2026 Cardinal Maps Authors
 *
 *     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.data.navigation

import earth.maps.cardinal.data.LatLng
import earth.maps.cardinal.domain.DeviationDetector
import uniffi.ferrostar.Route
import uniffi.ferrostar.RouteDeviation
import uniffi.ferrostar.RouteDeviationDetector
import uniffi.ferrostar.RouteStep
import uniffi.ferrostar.UserLocation

class FerrostarRouteDeviationDetector(
    private val deviationDetector: DeviationDetector
) : RouteDeviationDetector {

    override fun checkRouteDeviation(
        location: UserLocation,
        route: Route,
        currentRouteStep: RouteStep
    ): RouteDeviation {

        val raw = LatLng(
            location.coordinates.lat,
            location.coordinates.lng
        )

        val geometry = route.geometry.map {
            LatLng(it.lat, it.lng)
        }

        return if (deviationDetector.isOffRoute(raw, geometry)) {
            RouteDeviation.OffRoute(DEVIATION_FROM_ROUTE_LINE)
        } else {
            RouteDeviation.NoDeviation
        }
    }

    companion object {
        private const val DEVIATION_FROM_ROUTE_LINE = 30.0
    }
}
+30 −0
Original line number Diff line number Diff line
/*
 *     Cardinal Maps
 *     Copyright (C) 2026 Cardinal Maps Authors
 *
 *     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.data.navigation

import earth.maps.cardinal.data.RoutingMode
import earth.maps.cardinal.routing.FerrostarWrapper
import earth.maps.cardinal.routing.RoutingOptions

interface FerrostarWrapperFactory {
    fun create(
        mode: RoutingMode,
        endpoint: String,
        routingOptions: RoutingOptions? = null
    ): FerrostarWrapper
}
Loading