Nominatim
This commit is contained in:
@@ -28,9 +28,7 @@ abstract class NavigationRepository {
|
||||
abstract fun getTraffic(context: Context, location: Location, carOrientation: Float): String
|
||||
fun getRouteDistance(
|
||||
currentLocation: Location,
|
||||
location: Location,
|
||||
carOrientation: Float,
|
||||
context: Context
|
||||
location: Location
|
||||
): Double {
|
||||
if (currentLocation.latitude == 0.0)
|
||||
return 0.0
|
||||
@@ -77,7 +75,7 @@ abstract class NavigationRepository {
|
||||
"Accept",
|
||||
"application/json"
|
||||
) // The format of response we want to get from the server
|
||||
httpURLConnection.setRequestProperty("User-Agent", "email=nominatim@kouros-online.de");
|
||||
httpURLConnection.setRequestProperty("User-Agent", "email=nominatim@kouros-online.de")
|
||||
httpURLConnection.requestMethod = "GET"
|
||||
val responseCode = httpURLConnection.responseCode
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
|
||||
@@ -5,8 +5,6 @@ import android.content.Context
|
||||
import android.location.Location
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||
import androidx.compose.runtime.toMutableStateList
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@@ -103,32 +101,6 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the most recent place from Preferences and calculates its distance.
|
||||
* Posts the result to recentPlace LiveData if distance > 1km.
|
||||
*/
|
||||
fun loadRecentPlace(location: Location, carOrientation: Float, context: Context) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val settingsRepository = getSettingsRepository(context)
|
||||
val recentPlaces = settingsRepository.recentPlacesFlow.first()
|
||||
val gson = GsonBuilder().serializeNulls().create()
|
||||
val places = gson.fromJson(recentPlaces, Places::class.java)
|
||||
for (place in places.places.sortedBy { it.lastDate }) {
|
||||
val plLocation = location(place.longitude, place.latitude)
|
||||
val distance = plLocation.distanceTo(location)
|
||||
place.distance = distance
|
||||
if (place.distance > 200F) {
|
||||
recentPlace.postValue(place)
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all recent places from Preferences and calculates distances.
|
||||
* Posts the sorted list to places LiveData.
|
||||
@@ -151,9 +123,7 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
|
||||
val distance =
|
||||
repository.getRouteDistance(
|
||||
location,
|
||||
plLocation,
|
||||
carOrientation,
|
||||
context
|
||||
plLocation
|
||||
)
|
||||
place.distance = distance.toFloat()
|
||||
place.id = id
|
||||
@@ -494,14 +464,6 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
|
||||
deletePlace(context, place)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a place from recent destinations in Preferences.
|
||||
*/
|
||||
fun deleteRecent(context: Context, place: Place) {
|
||||
place.category = Constants.RECENT
|
||||
deletePlace(context, place)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a place from Preferences matching name and category.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user