This commit is contained in:
Dimitris
2026-03-12 15:34:34 +01:00
parent 61ce09f393
commit 619ceb9f83
28 changed files with 1815 additions and 634 deletions

View File

@@ -43,7 +43,8 @@ data class Place(
var street: String? = null,
var distance: Float = 0F,
//var avatar: Uri? = null,
var lastDate: Long = 0
var lastDate: Long = 0,
var routeIndex: Int = 0
)
data class ContactData(

View File

@@ -23,12 +23,14 @@ data class Route(
val routeEngine: Int,
val routes: List<com.kouros.navigation.data.route.Routes>,
var currentStepIndex: Int = 0,
var routeIndex : Int = 0,
) {
data class Builder(
var routeEngine: Int = 0,
var summary: Summary = Summary(),
var routes: List<com.kouros.navigation.data.route.Routes> = emptyList(),
var routeIndex : Int = 0
) {
fun routeType(routeEngine: Int) = apply { this.routeEngine = routeEngine }
@@ -38,6 +40,8 @@ data class Route(
}
fun routeEngine(routeEngine: Int) = apply { this.routeEngine = routeEngine }
fun routeIndex(routeIndex: Int) = apply { this.routeIndex = routeIndex}
fun route(route: String) = apply {
if (route.isNotEmpty() && route != "[]") {
val gson = GsonBuilder().serializeNulls().create()
@@ -68,6 +72,7 @@ data class Route(
return Route(
routeEngine = this.routeEngine,
routes = this.routes,
routeIndex = this.routeIndex
)
}
@@ -75,6 +80,7 @@ data class Route(
return Route(
routeEngine = 0,
routes = emptyList(),
routeIndex = 0
)
}
}
@@ -82,7 +88,7 @@ data class Route(
fun legs(): List<Leg> {
return if (routes.isNotEmpty()) {
routes.first().legs
routes[routeIndex].legs
} else {
emptyList()
}

View File

@@ -58,6 +58,7 @@ class TomTomRepository : NavigationRepository() {
"&vehicleMaxSpeed=120&vehicleCommercial=false" +
"&instructionsType=text&language=$language&sectionType=lanes" +
"&routeRepresentation=encodedPolyline" +
"&maxAlternatives=2" +
"&vehicleEngineType=combustion$filter&key=$tomtomApiKey"
return fetchUrl(
url,

View File

@@ -3,10 +3,8 @@ package com.kouros.navigation.model
//import com.kouros.navigation.data.Preferences.boxStore
import android.content.Context
import android.location.Location
import android.util.Log
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.toMutableStateList
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
@@ -58,7 +56,7 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
}
/** LiveData containing list of recent navigation destinations */
val places: MutableLiveData<List<Place>> by lazy {
val recentPlaces: MutableLiveData<List<Place>> by lazy {
MutableLiveData()
}
@@ -144,11 +142,11 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
val settingsRepository = getSettingsRepository(context)
val rp = settingsRepository.recentPlacesFlow.first()
val gson = GsonBuilder().serializeNulls().create()
val recentPlaces = gson.fromJson(rp, Places::class.java)
val places = gson.fromJson(rp, Places::class.java)
val pl = mutableListOf<Place>()
var id: Long = 0
if (rp.isNotEmpty()) {
for (place in recentPlaces.places) {
for (place in places.places) {
if (place.category.equals(Constants.RECENT)) {
val plLocation = location(place.longitude, place.latitude)
if (place.latitude != 0.0) {
@@ -167,7 +165,7 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
}
}
}
places.postValue(pl)
recentPlaces.postValue(pl)
} catch (e: Exception) {
e.printStackTrace()
}

View File

@@ -34,6 +34,7 @@ open class RouteModel {
route = Route.Builder()
.routeEngine(navState.routingEngine)
.route(routeString)
.routeIndex(navState.currentRouteIndex)
.build()
)
if (hasLegs()) {
@@ -42,7 +43,7 @@ open class RouteModel {
}
fun hasLegs(): Boolean {
return navState.route.routes.isNotEmpty() && navState.route.routes[0].legs.isNotEmpty()
return navState.route.routes.isNotEmpty() && navState.route.routes[navState.currentRouteIndex].legs.isNotEmpty()
}
fun stopNavigation() {

View File

@@ -9,8 +9,11 @@ import com.kouros.navigation.data.osrm.OsrmRepository
import com.kouros.navigation.data.tomtom.TomTomRepository
import com.kouros.navigation.data.valhalla.ValhallaRepository
import com.kouros.navigation.model.NavigationViewModel
import com.kouros.navigation.utils.GeoUtils.calculateSquareRadius
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import java.lang.Math.toDegrees
import java.lang.Math.toRadians
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
@@ -19,6 +22,8 @@ import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.Locale
import kotlin.math.absoluteValue
import kotlin.math.cos
import kotlin.math.ln
import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.time.Duration
@@ -29,7 +34,7 @@ object NavigationUtils {
fun getViewModel(context: Context): NavigationViewModel {
val repository = getSettingsRepository(context)
val routeEngine = runBlocking { repository.routingEngineFlow.first() }
val routeEngine = runBlocking { repository.routingEngineFlow.first() }
return when (routeEngine) {
RouteEngine.VALHALLA.ordinal -> NavigationViewModel(ValhallaRepository())
RouteEngine.OSRM.ordinal -> NavigationViewModel(OsrmRepository())
@@ -53,15 +58,36 @@ fun calculateZoom(speed: Double?): Double {
return zoom
}
fun previewZoom(previewDistance: Double): Double {
when (previewDistance / 1000) {
in 0.0..10.0 -> return 13.5
in 10.0..20.0 -> return 11.5
in 20.0..30.0 -> return 10.5
}
return 9.5
fun previewZoom(centerLocation: Location, previewDistance: Double): Double {
return calculateZoomFromBoundingBox(centerLocation, previewDistance / 1000)
}
fun calculateZoomFromBoundingBox(centerLocation: Location, previewDistance: Double): Double {
val earthRadius = 6371.0
val maxLat = centerLocation.latitude + toDegrees(previewDistance / earthRadius)
val minLat = centerLocation.latitude - toDegrees(previewDistance / earthRadius)
val maxLon = centerLocation.longitude + toDegrees(previewDistance / earthRadius / cos(toRadians(centerLocation.latitude)))
val minLon = centerLocation.longitude - toDegrees(previewDistance / earthRadius / cos(toRadians(centerLocation.latitude)))
var zoomLevel: Double
val latDiff = maxLat - minLat
val lngDiff = maxLon - minLon
val maxDiff = if(lngDiff > latDiff) lngDiff else latDiff
if (maxDiff < 360 / 2.0.pow(20.0)) {
zoomLevel = 21.0
} else {
zoomLevel = (-1 * ((ln(maxDiff) / ln(2.0)) - (ln(360.0) / ln(2.0))));
if (zoomLevel < 1)
zoomLevel = 1.0;
}
return zoomLevel + 1.2
}
fun calculateTilt(newZoom: Double, tilt: Double): Double =
if (newZoom < 13) {
0.0
@@ -119,10 +145,10 @@ fun isMetricSystem(): Boolean {
return !setOf("US", "UK", "LR", "MM").contains(country)
}
fun formattedDistance(distanceMode : Int, distance: Double): Pair<Double, Int> {
fun formattedDistance(distanceMode: Int, distance: Double): Pair<Double, Int> {
var currentDistance = distance
var displayUnit: Int
if (distanceMode == 1 || distanceMode == 0 && isMetricSystem()) {
if (distanceMode == 1 || distanceMode == 0 && isMetricSystem()) {
displayUnit = if (currentDistance > 1000.0) {
currentDistance /= 1000.0
Distance.UNIT_KILOMETERS

File diff suppressed because it is too large Load Diff