Recent Places Sort by navigations, DEVIATION Maximum

This commit is contained in:
Dimitris
2026-05-30 10:22:27 +02:00
parent 21d9688b99
commit df1ceb5c44
7 changed files with 20 additions and 25 deletions
+2 -2
View File
@@ -17,8 +17,8 @@ android {
applicationId = "com.kouros.navigation" applicationId = "com.kouros.navigation"
minSdk = 33 minSdk = 33
targetSdk = 37 targetSdk = 37
versionCode = 118 versionCode = 121
versionName = "0.3.1.118" versionName = "0.3.1.121"
base.archivesName = "navi-$versionName" base.archivesName = "navi-$versionName"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }
@@ -243,7 +243,7 @@ private fun SearchPlaces(
latitude = place.lat.toDouble(), latitude = place.lat.toDouble(),
postalCode = place.address.postcode, postalCode = place.address.postcode,
city = place.address.city, city = place.address.city,
street = place.address.road street = place.address.road,
) )
viewModel.saveRecent(context, pl) viewModel.saveRecent(context, pl)
val toLocation = val toLocation =
@@ -479,7 +479,7 @@ class NavigationSession : CarSession(), NavigationListener, NavigationObserverCa
checkArrival() checkArrival()
} }
val end = System.currentTimeMillis() val end = System.currentTimeMillis()
Log.d(TAG, "UpdateLocation ${end-start} ms") //Log.d(TAG, "UpdateLocation ${end-start} ms")
} }
/** /**
@@ -492,8 +492,7 @@ class NavigationSession : CarSession(), NavigationListener, NavigationObserverCa
): Boolean { ): Boolean {
val distance = location.distanceTo(snappedLocation) val distance = location.distanceTo(snappedLocation)
when { when {
distance > MAXIMAL_ROUTE_DEVIATION -> { distance > MAXIMAL_ROUTE_DEVIATION && distance < MAXIMAL_ROUTE_DEVIATION * 10-> {
Log.d(TAG, "Recalculate $distance ")
stopNavigation() stopNavigation()
navigationScreen.calculateNewRoute(routeModel.navState.destination) navigationScreen.calculateNewRoute(routeModel.navState.destination)
return false return false
@@ -549,7 +548,6 @@ class NavigationSession : CarSession(), NavigationListener, NavigationObserverCa
* Checks for arrival * Checks for arrival
*/ */
fun checkArrival() { fun checkArrival() {
Log.d(TAG, "maneuverType ${routeModel.navState.maneuverType} Distance ${routeModel.routeCalculator.leftStepDistance()}")
if (routeModel.isManeuverArrival() if (routeModel.isManeuverArrival()
&& routeModel.routeCalculator.leftStepDistance() < DESTINATION_ARRIVAL_DISTANCE && routeModel.routeCalculator.leftStepDistance() < DESTINATION_ARRIVAL_DISTANCE
) { ) {
@@ -189,7 +189,7 @@ open class NavigationScreen(
.setActionStrip(actionStripBuilder.build()) .setActionStrip(actionStripBuilder.build())
.setMapActionStrip(mapActionStrip) .setMapActionStrip(mapActionStrip)
.setPanModeListener { isInPanMode: Boolean -> .setPanModeListener { isInPanMode: Boolean ->
Log.d(TAG, "PanMode $isInPanMode")
} }
.build() .build()
} }
@@ -126,21 +126,10 @@ class PlaceListScreen(
* Creates an Action to navigate to a specific place. * Creates an Action to navigate to a specific place.
*/ */
private fun clickOnPlace(itPlace: Place) { private fun clickOnPlace(itPlace: Place) {
place = Place(
0,
itPlace.name,
itPlace.category,
itPlace.latitude,
itPlace.longitude,
itPlace.postalCode,
itPlace.city,
itPlace.street,
// avatar = null
)
if (surfaceRenderer.navigation) { if (surfaceRenderer.navigation) {
startStopOverScreen(place) startStopOverScreen(itPlace)
} else { } else {
starPreviewScreen(place) starPreviewScreen(itPlace)
} }
} }
@@ -45,6 +45,7 @@ data class Place(
var postalCode: String = "", var postalCode: String = "",
var city: String = "", var city: String = "",
var street: String = "", var street: String = "",
var navigations: Int = 0,
@Transient @Transient
var distance: Float = 0F, var distance: Float = 0F,
//var avatar: Uri? = null, //var avatar: Uri? = null,
@@ -139,9 +140,9 @@ object Constants {
val isarring = location( 11.609696, 48.155116) val isarring = location( 11.609696, 48.155116)
const val NEXT_STEP_THRESHOLD = 500.0 const val NEXT_STEP_THRESHOLD = 500.0
const val MAXIMAL_SNAP_CORRECTION = 50.0 const val MAXIMAL_SNAP_CORRECTION = 40.0
const val MAXIMAL_ROUTE_DEVIATION = 150.0 const val MAXIMAL_ROUTE_DEVIATION = 100.0
const val DESTINATION_ARRIVAL_DISTANCE = 10.0 const val DESTINATION_ARRIVAL_DISTANCE = 10.0
@@ -2,6 +2,7 @@ package com.kouros.navigation.model
import android.content.Context import android.content.Context
import android.location.Location import android.location.Location
import android.util.Log
import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.toMutableStateList import androidx.compose.runtime.toMutableStateList
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
@@ -13,6 +14,7 @@ import com.kouros.navigation.data.Constants
import com.kouros.navigation.data.Constants.FAVORITES import com.kouros.navigation.data.Constants.FAVORITES
import com.kouros.navigation.data.Constants.SPEED_BEARING_DEVIATION import com.kouros.navigation.data.Constants.SPEED_BEARING_DEVIATION
import com.kouros.navigation.data.Constants.SPEED_UPDATE_DISTANCE import com.kouros.navigation.data.Constants.SPEED_UPDATE_DISTANCE
import com.kouros.navigation.data.Constants.TAG
import com.kouros.navigation.data.Constants.TANKER_KOENIG_DELAY import com.kouros.navigation.data.Constants.TANKER_KOENIG_DELAY
import com.kouros.navigation.data.NavigationRepository import com.kouros.navigation.data.NavigationRepository
import com.kouros.navigation.data.Place import com.kouros.navigation.data.Place
@@ -183,11 +185,15 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
place.id = id place.id = id
id += 1 id += 1
} }
pl.add(place) if (place.distance == 0F || place.distance > 500F) {
pl.add(place)
}
} }
} }
} }
recentPlaces.postValue(pl.sortedBy { it.distance }) val sortedList = pl.sortedWith(compareByDescending<Place> { it.navigations }
.thenByDescending { it.distance })
recentPlaces.postValue(sortedList)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
@@ -647,6 +653,7 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
val current = LocalDateTime.now(ZoneOffset.UTC) val current = LocalDateTime.now(ZoneOffset.UTC)
place.lastDate = current.atZone(ZoneOffset.UTC).toEpochSecond() place.lastDate = current.atZone(ZoneOffset.UTC).toEpochSecond()
place.route = "" place.route = ""
place.navigations += 1
places.add(place) places.add(place)
recentPlaces.postValue(places) recentPlaces.postValue(places)
settingsRepository.setRecentPlaces(gson.toJson(Places(places))) settingsRepository.setRecentPlaces(gson.toJson(Places(places)))