Launcher Icons, NotificationService

This commit is contained in:
Dimitris
2026-03-24 17:04:05 +01:00
parent bc8a53a5d8
commit 5098dad9d6
76 changed files with 930 additions and 478 deletions

View File

@@ -2,7 +2,9 @@ package com.kouros.navigation.data
import androidx.compose.ui.graphics.Color
val NavigationColor = Color(0xFF16BBB6)
val NavigationColorLight = Color(0xFF066462)
val NavigationColorDark = Color(0xFF10DED9)
val RouteColor = Color(0xFF7B06E1)

View File

@@ -77,9 +77,10 @@ data class Locations (
)
data class SearchFilter(
var avoidMotorway: Boolean = false,
var avoidTollway : Boolean = false,
var avoidFerry : Boolean = false,
val avoidMotorway: Boolean = false,
val avoidTollway : Boolean = false,
val avoidFerry : Boolean = false,
val engineType : Int = 0,
)
@@ -139,11 +140,27 @@ object Constants {
const val TILT = 60.0
}
/**
* Enum representing different map view modes.
* - VIEW: Active navigation mode with follow-car camera
* - PREVIEW: Route overview before starting navigation
* - PAN_VIEW: User-controlled map panning
* - AMENITY_VIEW: Displaying POI/amenity locations
*/
enum class ViewStyle {
VIEW, PREVIEW, PAN_VIEW, AMENITY_VIEW
}
enum class RouteEngine {
VALHALLA, OSRM, TOMTOM
}
enum class EngineType {
COMBUSTION, ELECTRIC
}
enum class NavigationThemeColor(val color: Long) {
RED(0xFFD32F2F),
ORANGE(0xFFF57C00),

View File

@@ -2,6 +2,7 @@ package com.kouros.navigation.data
import android.content.Context
import android.location.Location
import android.util.Log
import com.kouros.navigation.utils.GeoUtils.calculateSquareRadius
import java.net.Authenticator
import java.net.HttpURLConnection
@@ -66,7 +67,7 @@ abstract class NavigationRepository {
}
})
}
println(url)
Log.d("fetchUrl", url)
val httpURLConnection = URL(url).openConnection() as HttpURLConnection
httpURLConnection.setRequestProperty(
"Accept",
@@ -81,7 +82,7 @@ abstract class NavigationRepository {
return response
}
} catch (e: Exception) {
println("Exception ${e.message}")
Log.e("fetchUrl", e.toString())
}
return ""
}

View File

@@ -1,5 +1,6 @@
package com.kouros.navigation.data
import android.util.Log
import com.google.gson.GsonBuilder
import com.kouros.navigation.data.osrm.OsrmResponse
import com.kouros.navigation.data.osrm.OsrmRoute

View File

@@ -8,6 +8,7 @@ import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.kouros.navigation.data.EngineType
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
@@ -55,6 +56,8 @@ class DataStoreManager(private val context: Context) {
val TRIP_SUGGESTION = booleanPreferencesKey("TripSuggestion")
val ENGINE_TYPE = intPreferencesKey("EngineType")
}
// Read values
@@ -136,6 +139,12 @@ class DataStoreManager(private val context: Context) {
preferences[PreferencesKeys.TRIP_SUGGESTION] == true
}
val engineTypeFlow: Flow<Int> =
context.dataStore.data.map { preferences ->
preferences[PreferencesKeys.ENGINE_TYPE]
?: EngineType.COMBUSTION.ordinal
}
// Save values
suspend fun setShow3D(enabled: Boolean) {
context.dataStore.edit { preferences ->
@@ -220,4 +229,10 @@ class DataStoreManager(private val context: Context) {
preferences[PreferencesKeys.TRIP_SUGGESTION] = enabled
}
}
suspend fun setEngineType(mode: Int) {
context.dataStore.edit { prefs ->
prefs[PreferencesKeys.ENGINE_TYPE] = mode
}
}
}

View File

@@ -3,6 +3,7 @@ package com.kouros.navigation.data.tomtom
import android.content.Context
import android.location.Location
import com.kouros.data.R
import com.kouros.navigation.data.EngineType
import com.kouros.navigation.data.NavigationRepository
import com.kouros.navigation.data.SearchFilter
import com.kouros.navigation.utils.GeoUtils.calculateSquareRadius
@@ -19,9 +20,9 @@ const val tomtomTrafficUrl = "https://api.tomtom.com/traffic/services/5/incident
private const val tomtomFields =
"{incidents{type,geometry{type,coordinates},properties{iconCategory,events{description}}}}"
const val useLocal = true
const val useLocal = false
const val useLocalTraffic = true
const val useLocalTraffic = false
class TomTomRepository : NavigationRepository() {
@@ -38,6 +39,7 @@ class TomTomRepository : NavigationRepository() {
false
)
}
var engineType = "combustion"
var filter = ""
if (searchFilter.avoidMotorway) {
filter = "$filter&avoid=motorways"
@@ -48,6 +50,9 @@ class TomTomRepository : NavigationRepository() {
if (searchFilter.avoidFerry) {
filter = "$filter&avoid=ferries"
}
if (searchFilter.engineType == EngineType.ELECTRIC.ordinal) {
engineType = "electric"
}
val repository = getSettingsRepository(context)
val tomtomApiKey = runBlocking { repository.tomTomApiKeyFlow.first() }
val currentLocale = Locale.getDefault()
@@ -60,7 +65,7 @@ class TomTomRepository : NavigationRepository() {
"&instructionsType=text&language=$language&sectionType=lanes" +
"&routeRepresentation=encodedPolyline" +
"&maxAlternatives=2" +
"&vehicleEngineType=combustion$filter&key=$tomtomApiKey"
"&vehicleEngineType=$engineType$filter&key=$tomtomApiKey"
return fetchUrl(
url,
false

View File

@@ -163,7 +163,7 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
}
}
}
recentPlaces.postValue(pl)
recentPlaces.postValue(pl.sortedBy { it.distance })
} catch (e: Exception) {
e.printStackTrace()
}
@@ -538,7 +538,8 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
val avoidMotorway = runBlocking { repository.avoidMotorwayFlow.first() }
val avoidTollway = runBlocking { repository.avoidTollwayFlow.first() }
val avoidFerry = runBlocking { repository.avoidFerryFlow.first() }
return SearchFilter(avoidMotorway, avoidTollway, avoidFerry)
val engineType = runBlocking { repository.engineTypeFlow.first() }
return SearchFilter(avoidMotorway, avoidTollway, avoidFerry, engineType)
}
/**

View File

@@ -1,6 +1,7 @@
package com.kouros.navigation.model
import android.location.Location
import android.util.Log
import androidx.car.app.navigation.model.Step
import com.kouros.navigation.data.Constants.MAXIMUM_LOCATION_DISTANCE
import com.kouros.navigation.data.Constants.NEAREST_LOCATION_DISTANCE

View File

@@ -96,6 +96,12 @@ class SettingsViewModel(private val repository: SettingsRepository) : ViewModel(
false
)
val engineType = repository.engineTypeFlow.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5_000),
0
)
fun onShow3DChanged(enabled: Boolean) {
viewModelScope.launch { repository.setShow3D(enabled) }
}
@@ -148,4 +154,9 @@ class SettingsViewModel(private val repository: SettingsRepository) : ViewModel(
fun onTripSuggestion(enabled: Boolean) {
viewModelScope.launch { repository.setTripSuggestion(enabled) }
}
fun onEngineTypeChanged(mode: Int) {
viewModelScope.launch { repository.setEngineType(mode) }
}
}

View File

@@ -47,6 +47,9 @@ class SettingsRepository(
val tripSuggestionFlow: Flow<Boolean> =
dataStoreManager.tripSuggestionFlow
val engineTypeFlow: Flow<Int> =
dataStoreManager.engineTypeFlow
suspend fun setShow3D(enabled: Boolean) {
dataStoreManager.setShow3D(enabled)
}
@@ -102,4 +105,8 @@ class SettingsRepository(
suspend fun setTripSuggestion(enabled: Boolean) {
dataStoreManager.setTripSuggestion(enabled)
}
suspend fun setEngineType(mode: Int) {
dataStoreManager.setEngineType(mode)
}
}

View File

@@ -10,7 +10,6 @@ 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
@@ -29,6 +28,8 @@ import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
import kotlin.time.toDuration
object NavigationUtils {
@@ -50,7 +51,7 @@ fun calculateZoom(speed: Double?): Double {
}
val speedKmh = (speed * 3.6).toInt()
val zoom = when (speedKmh) {
in 0..10 -> 18.0
in 0..10 -> 17.0
in 11..30 -> 17.5
in 31..65 -> 17.0
in 66..70 -> 16.5
@@ -128,14 +129,20 @@ fun Double.round(numFractionDigits: Int): Double {
return (this * factor).roundToInt() / factor
}
fun duration(preview: Boolean, bearing: Double, lastBearing: Double): Duration {
fun duration(
preview: Boolean,
bearing: Double,
lastBearing: Double,
lastLocationUpdate: LocalDateTime
): Duration {
if (preview) {
return 3.seconds
}
val cameraDuration = if ((lastBearing - bearing).absoluteValue > 20.0) {
2.seconds
} else {
1.seconds
val updateDuration = java.time.Duration.between(LocalDateTime.now(), lastLocationUpdate)
((updateDuration!!.toMillis().absoluteValue * 1.2).toDuration(DurationUnit.MILLISECONDS))
}
return cameraDuration
}

View File

@@ -66,4 +66,9 @@
<string name="general">Allgemein</string>
<string name="traffic">Verkehr anzeigen</string>
<string name="trip_suggestion">Fahrten-Vorschläge</string>
<string name="drive_settings">Drive settings</string>
<string name="car_settings">Car settings</string>
<string name="combustion">Combustion</string>
<string name="electric">Electric</string>
<string name="engine_type">Engine type</string>
</resources>

View File

@@ -50,4 +50,9 @@
<string name="general">Γενικά</string>
<string name="traffic">Εμφάνιση κίνησης</string>
<string name="trip_suggestion">Προτάσεις διαδρομής</string>
<string name="drive_settings">Drive settings</string>
<string name="car_settings">Car settings</string>
<string name="combustion">Combustion</string>
<string name="electric">Electric</string>
<string name="engine_type">Engine type</string>
</resources>

View File

@@ -50,4 +50,9 @@
<string name="general">Ogólne</string>
<string name="traffic">Pokaż natężenie ruchu</string>
<string name="trip_suggestion">Sugestie dotyczące podróży</string>
<string name="drive_settings">Drive settings</string>
<string name="car_settings">Car settings</string>
<string name="combustion">Combustion</string>
<string name="electric">Electric</string>
<string name="engine_type">Engine type</string>
</resources>

View File

@@ -53,4 +53,9 @@
<string name="general">General</string>
<string name="traffic">Show traffic</string>
<string name="trip_suggestion">Trip suggestions</string>
<string name="drive_settings">Drive settings</string>
<string name="car_settings">Car settings</string>
<string name="combustion">Combustion</string>
<string name="electric">Electric</string>
<string name="engine_type">Engine type</string>
</resources>