Diverse Änderungen
This commit is contained in:
@@ -2,6 +2,6 @@ package com.kouros.navigation.data
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val NavigationColor = Color(0xFF1965D9)
|
||||
val NavigationColor = Color(0xFF094DB6)
|
||||
|
||||
val RouteColor = Color(0xFF2E75E1)
|
||||
val RouteColor = Color(0xFF5582D0)
|
||||
|
||||
@@ -22,6 +22,8 @@ import android.net.Uri
|
||||
import io.objectbox.annotation.Entity
|
||||
import io.objectbox.annotation.Id
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.time.LocalDate
|
||||
import java.util.Date
|
||||
|
||||
data class Category(
|
||||
val id: String,
|
||||
@@ -41,7 +43,8 @@ data class Place(
|
||||
var street: String? = null,
|
||||
var distance: Float = 0F,
|
||||
@Transient
|
||||
var avatar: Uri? = null
|
||||
var avatar: Uri? = null,
|
||||
var lastDate: Long = 0
|
||||
)
|
||||
|
||||
data class ContactData(
|
||||
@@ -148,7 +151,9 @@ object Constants {
|
||||
|
||||
const val NEXT_STEP_THRESHOLD = 100.0
|
||||
|
||||
const val MAXIMAL_ROUTE_DEVIATION = 70.0
|
||||
const val MAXIMAL_SNAP_CORRECTION = 50.0
|
||||
|
||||
const val MAXIMAL_ROUTE_DEVIATION = 100.0
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,11 @@ data class Route (
|
||||
|
||||
fun maneuverLocations(): List<Point> {
|
||||
val beginShapeIndex = currentManeuver().beginShapeIndex
|
||||
val endShapeIndex = currentManeuver().endShapeIndex
|
||||
val endShapeIndex = if (currentManeuver().endShapeIndex >= waypoints.size) {
|
||||
waypoints.size
|
||||
} else {
|
||||
currentManeuver().endShapeIndex + 1
|
||||
}
|
||||
return pointLocations.subList(beginShapeIndex, endShapeIndex)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,6 @@ data class SearchResult(
|
||||
@SerializedName("address") var address: Address,
|
||||
@SerializedName("name") var name: String = "",
|
||||
@SerializedName("display_name") var displayName: String = "",
|
||||
@SerializedName("boundingbox") var boundingbox: ArrayList<String> = arrayListOf()
|
||||
|
||||
@SerializedName("boundingbox") var boundingbox: ArrayList<String> = arrayListOf(),
|
||||
var distance : Float = 0.0F
|
||||
)
|
||||
@@ -22,11 +22,12 @@ data class Maneuvers(
|
||||
@SerializedName("length") var length: Double = 0.0,
|
||||
@SerializedName("cost") var cost: Double = 0.0,
|
||||
@SerializedName("verbal_multi_cue") var verbalMultiCue: Boolean = false,
|
||||
@SerializedName("begin_shape_index") var beginShapeIndex: Int,
|
||||
@SerializedName("end_shape_index") var endShapeIndex: Int,
|
||||
@SerializedName("begin_shape_index") var beginShapeIndex: Int = 0,
|
||||
@SerializedName("end_shape_index") var endShapeIndex: Int = 0,
|
||||
@SerializedName("highway") var highway: Boolean = false,
|
||||
@SerializedName("sign") var sign: Sign = Sign(),
|
||||
@SerializedName("travel_mode") var travelMode: String = "",
|
||||
@SerializedName("travel_type") var travelType: String = "",
|
||||
@SerializedName("roundabout_exit_count") var roundaboutExitCount: Int = 0
|
||||
|
||||
)
|
||||
@@ -27,7 +27,7 @@ open class RouteModel() {
|
||||
/*
|
||||
current shapeIndex
|
||||
*/
|
||||
private var currentShapeIndex = 0
|
||||
private var currentShapeIndex = 0
|
||||
|
||||
var distanceToStepEnd = 0F
|
||||
|
||||
@@ -63,7 +63,7 @@ open class RouteModel() {
|
||||
|
||||
fun updateLocation(location: Location) {
|
||||
var nearestDistance = 100000.0f
|
||||
route.currentManeuverIndex = -1
|
||||
route.currentManeuverIndex = -1
|
||||
// find maneuver
|
||||
for ((i, maneuver) in route.maneuvers.withIndex()) {
|
||||
val beginShapeIndex = maneuver.beginShapeIndex
|
||||
@@ -83,8 +83,15 @@ open class RouteModel() {
|
||||
if (maneuver.streetNames != null && maneuver.streetNames.isNotEmpty()) {
|
||||
text = maneuver.streetNames[0]
|
||||
}
|
||||
val curLocation = location(route.pointLocations[currentShapeIndex].latitude(), route.pointLocations[currentShapeIndex].longitude())
|
||||
val nextLocation = location(route.pointLocations[currentShapeIndex+1].latitude(), route.pointLocations[currentShapeIndex+1].longitude())
|
||||
// TODO: +1 check
|
||||
val curLocation = location(
|
||||
route.pointLocations[currentShapeIndex].latitude(),
|
||||
route.pointLocations[currentShapeIndex].longitude()
|
||||
)
|
||||
val nextLocation = location(
|
||||
route.pointLocations[currentShapeIndex + 1].latitude(),
|
||||
route.pointLocations[currentShapeIndex + 1].longitude()
|
||||
)
|
||||
bearing = curLocation.bearingTo(nextLocation)
|
||||
val distanceStepLeft = leftStepDistance() * 1000
|
||||
when (distanceStepLeft) {
|
||||
@@ -120,17 +127,14 @@ open class RouteModel() {
|
||||
distanceToStepEnd = 0F
|
||||
val loc1 = Location(LocationManager.GPS_PROVIDER)
|
||||
val loc2 = Location(LocationManager.GPS_PROVIDER)
|
||||
loc1.longitude = route.waypoints[i][0]
|
||||
loc1.latitude = route.waypoints[i][1]
|
||||
loc2.longitude = route.waypoints[i + 1][0]
|
||||
loc2.latitude = route.waypoints[i + 1][1]
|
||||
bearing = loc1.bearingTo(loc2).absoluteValue
|
||||
for (j in i + 1..endShapeIndex) {
|
||||
loc1.longitude = route.waypoints[j - 1][0]
|
||||
loc1.latitude = route.waypoints[j - 1][1]
|
||||
loc2.longitude = route.waypoints[j][0]
|
||||
loc2.latitude = route.waypoints[j][1]
|
||||
distanceToStepEnd += loc1.distanceTo(loc2)
|
||||
if (i + 1 < route.waypoints.size) {
|
||||
for (j in i + 1..endShapeIndex) {
|
||||
loc1.longitude = route.waypoints[j - 1][0]
|
||||
loc1.latitude = route.waypoints[j - 1][1]
|
||||
loc2.longitude = route.waypoints[j][0]
|
||||
loc2.latitude = route.waypoints[j][1]
|
||||
distanceToStepEnd += loc1.distanceTo(loc2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,14 @@ import com.kouros.navigation.data.ObjectBox.boxStore
|
||||
import com.kouros.navigation.data.Place
|
||||
import com.kouros.navigation.data.Place_
|
||||
import com.kouros.navigation.data.nominatim.Search
|
||||
import com.kouros.navigation.data.nominatim.SearchResult
|
||||
import com.kouros.navigation.utils.location
|
||||
import io.objectbox.kotlin.boxFor
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneOffset
|
||||
|
||||
class ViewModel(private val repository: NavigationRepository) : ViewModel() {
|
||||
|
||||
@@ -32,8 +36,8 @@ class ViewModel(private val repository: NavigationRepository) : ViewModel() {
|
||||
MutableLiveData<List<Place>>()
|
||||
}
|
||||
|
||||
val searchPlaces: MutableLiveData<Search> by lazy {
|
||||
MutableLiveData<Search>()
|
||||
val searchPlaces: MutableLiveData<List<SearchResult>> by lazy {
|
||||
MutableLiveData<List<SearchResult>>()
|
||||
}
|
||||
|
||||
val contactAddress: MutableLiveData<List<Place>> by lazy {
|
||||
@@ -44,15 +48,20 @@ class ViewModel(private val repository: NavigationRepository) : ViewModel() {
|
||||
fun loadPlaces(location: Location) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val pl = mutableListOf<Place>()
|
||||
val placeBox = boxStore.boxFor(Place::class)
|
||||
pl.addAll(placeBox.all)
|
||||
for (place in pl) {
|
||||
val query = placeBox
|
||||
.query(Place_.name.notEqual(""))
|
||||
.orderDesc(Place_.lastDate)
|
||||
.build()
|
||||
val results = query.find()
|
||||
query.close()
|
||||
for (place in results) {
|
||||
val plLocation = location(place.latitude, place.longitude)
|
||||
val distance = repository.getRouteDistance(location, plLocation)
|
||||
place.distance = distance.toFloat()
|
||||
println(place.lastDate)
|
||||
}
|
||||
places.postValue(pl)
|
||||
places.postValue(results)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
@@ -121,12 +130,21 @@ class ViewModel(private val repository: NavigationRepository) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun searchPlaces(search: String) {
|
||||
fun searchPlaces(search: String, location: Location) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val placesJson = repository.searchPlaces(search)
|
||||
val gson = GsonBuilder().serializeNulls().create()
|
||||
val places = gson.fromJson(placesJson, Search::class.java)
|
||||
searchPlaces.postValue(places)
|
||||
val distPlaces = mutableListOf<SearchResult>()
|
||||
places.forEach {
|
||||
val plLocation =
|
||||
location(latitude = it.lat.toDouble(), longitude = it.lon.toDouble())
|
||||
val distance = plLocation.distanceTo(location)
|
||||
it.distance = distance
|
||||
distPlaces.add(it)
|
||||
}
|
||||
val sortedList = distPlaces.sortedWith(compareBy({ it.distance }))
|
||||
searchPlaces.postValue(sortedList)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,9 +158,12 @@ class ViewModel(private val repository: NavigationRepository) : ViewModel() {
|
||||
.build()
|
||||
val results = query.find()
|
||||
query.close()
|
||||
if (results.isEmpty()) {
|
||||
placeBox.put(place)
|
||||
if (results.isNotEmpty()) {
|
||||
placeBox.remove(results.first())
|
||||
}
|
||||
val current = LocalDateTime.now(ZoneOffset.UTC)
|
||||
place.lastDate = current.atZone(ZoneOffset.UTC).toEpochSecond()
|
||||
placeBox.put(place)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
@@ -160,7 +181,7 @@ class ViewModel(private val repository: NavigationRepository) : ViewModel() {
|
||||
val results = query.find()
|
||||
query.close()
|
||||
if (results.isNotEmpty()) {
|
||||
placeBox.remove(place)
|
||||
placeBox.remove(results.first())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
||||
@@ -56,21 +56,16 @@ object NavigationUtils {
|
||||
apply()
|
||||
}
|
||||
}
|
||||
fun snapLocation(location: Location, stepCoordinates: List<Point>): Location {
|
||||
fun snapLocation(location: Location, stepCoordinates: List<Point>) : Location {
|
||||
val newLocation = location(latitude = location.latitude, longitude = location.longitude)
|
||||
val oldPoint = Point.fromLngLat(location.longitude, location.latitude)
|
||||
val oldLocation = location(location.latitude, location.longitude)
|
||||
if (stepCoordinates.size > 1) {
|
||||
val pointFeature = TurfMisc.nearestPointOnLine(oldPoint, stepCoordinates)
|
||||
val point = pointFeature.geometry() as Point
|
||||
location.latitude = point.latitude()
|
||||
location.longitude = point.longitude()
|
||||
val distance = oldLocation.distanceTo(location)
|
||||
if (distance > MAXIMAL_ROUTE_DEVIATION) {
|
||||
println("Distance to big")
|
||||
return location(0.0, 0.0)
|
||||
}
|
||||
newLocation.latitude = point.latitude()
|
||||
newLocation.longitude = point.longitude()
|
||||
}
|
||||
return location
|
||||
return newLocation
|
||||
}
|
||||
|
||||
fun decodePolyline(encoded: String, vararg precisionOptional: Int): List<List<Double>> {
|
||||
|
||||
Reference in New Issue
Block a user