ExitNumber, Flow

This commit is contained in:
Dimitris
2026-04-05 09:22:06 +02:00
parent f4cac4361b
commit 5105d4eb9a
5 changed files with 46 additions and 5 deletions
@@ -221,6 +221,10 @@ private fun exitNumber(
) {
0
} else {
instruction.exitNumber.toInt()
try {
instruction.exitNumber.toInt()
} catch (e: NumberFormatException) {
0
}
}
}
@@ -3,6 +3,8 @@ package com.kouros.navigation.model
//import com.kouros.navigation.data.Preferences.boxStore
import android.content.Context
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.toMutableStateList
import androidx.lifecycle.MutableLiveData
@@ -22,6 +24,9 @@ import com.kouros.navigation.utils.Levenshtein
import com.kouros.navigation.utils.getSettingsRepository
import com.kouros.navigation.utils.location
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@@ -102,6 +107,16 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
}
val gson: com.google.gson.Gson = GsonBuilder().create()
/**
* Retrieves recent places from Preferences as a Flow.
*/
fun recentPlacesFlow(context: Context, location: Location,): Flow<Place> = callbackFlow {
for (place in recentPlaces.value!!) {
trySend(place)
}
awaitClose {
}
}
/**
* Loads all recent places from Preferences and calculates distances.