This commit is contained in:
Dimitris
2026-03-15 17:18:02 +01:00
parent 619ceb9f83
commit 5198725879
46 changed files with 840 additions and 1326 deletions

View File

@@ -176,15 +176,21 @@ class RouteModelTest {
@Test
fun simulate() {
for ((index, waypoint) in routeModel.curRoute.waypoints.withIndex()) {
val curLocation = location(waypoint[0], waypoint[1])
if (routeModel.isNavigating()) {
val curLocation = location(waypoint[0], waypoint[1])
if (index in 0..routeModel.curRoute.waypoints.size) {
//runBlocking { delay(1000) }
val start = System.currentTimeMillis()
routeModel.updateLocation(curLocation, NavigationViewModel(TomTomRepository()))
val stepData = routeModel.currentStep()
println("${stepData.instruction} ${System.currentTimeMillis() - start}")
// val nextData = routeModel.nextStep()
//println("${stepData.instruction} ${System.currentTimeMillis() - start}")
if (stepData.lane.isNotEmpty()) {
println(stepData.street)
stepData.lane.forEach {
println("${it.indications} ${it.valid}")
}
}
// val nextData = routeModel.nextStep()
}
}
}
@@ -192,17 +198,17 @@ class RouteModelTest {
@Test
fun `leftStepDistance Inglolstädter `() {
val location: Location = location( 11.584578, 48.183653)
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()) )
val location: Location = location(11.584578, 48.183653)
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
val step = routeModel.currentStep()
assertEquals(step.leftStepDistance, 645.0, 1.0)
}
@Test
fun `leftStepDistance Vogelhart `() {
val location: Location = location( 11.578911, 48.185565)
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()) )
val location: Location = location(11.578911, 48.185565)
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
val step = routeModel.currentStep()
assertEquals(step.leftStepDistance , 34.0, 1.0)
assertEquals(step.leftStepDistance, 34.0, 1.0)
}
}

View File

@@ -2,13 +2,11 @@ package com.kouros.navigation.car.map
import android.location.Location
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.BasicText
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
@@ -17,10 +15,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.scale
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.drawText
@@ -36,7 +32,6 @@ import com.kouros.navigation.data.NavigationColor
import com.kouros.navigation.data.RouteColor
import com.kouros.navigation.data.SpeedColor
import com.kouros.navigation.utils.isMetricSystem
import com.kouros.navigation.utils.location
import org.maplibre.compose.camera.CameraPosition
import org.maplibre.compose.camera.CameraState
import org.maplibre.compose.camera.rememberCameraState
@@ -63,7 +58,6 @@ import org.maplibre.compose.sources.Source
import org.maplibre.compose.sources.getBaseSource
import org.maplibre.compose.sources.rememberGeoJsonSource
import org.maplibre.compose.style.BaseStyle
import org.maplibre.spatialk.geojson.BoundingBox
import org.maplibre.spatialk.geojson.Position

View File

@@ -114,7 +114,11 @@ class RouteCarModel : RouteModel() {
)
.setRemainingTimeColor(CarColor.GREEN)
.setRemainingDistanceColor(CarColor.BLUE)
.setTripText(CarText.create("$traffic min"))
if (traffic > 0) {
travelBuilder.setTripText(CarText.create("$traffic min"))
travelBuilder.setTripIcon(createCarIcon(carContext, R.drawable.warning_24px))
}
if (navState.travelMessage.isNotEmpty()) {
travelBuilder.setTripIcon(createCarIcon(carContext, R.drawable.warning_24px))
travelBuilder.setTripText(CarText.create(navState.travelMessage))
@@ -143,7 +147,7 @@ class RouteCarModel : RouteModel() {
}
val laneType =
Lane.Builder()
.addDirection(LaneDirection.create(laneDirection, true))
.addDirection(LaneDirection.create(laneDirection, it.valid))
.build()
step.addLane(laneType)
}

View File

@@ -4,6 +4,8 @@ import android.location.Location
import android.location.LocationManager
import android.os.SystemClock
import androidx.lifecycle.LifecycleCoroutineScope
import com.kouros.navigation.data.Constants.homeVogelhart
import com.kouros.navigation.utils.location
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@@ -17,6 +19,10 @@ class Simulation {
lifecycleScope: LifecycleCoroutineScope,
updateLocation: (Location) -> Unit
) {
// A92
//updateLocation(location(11.709508, 48.338923 ))
//updateLocation(homeVogelhart)
if (routeModel.navState.route.isRouteValid()) {
val points = routeModel.curRoute.waypoints
if (points.isEmpty()) return
@@ -38,7 +44,7 @@ class Simulation {
// Update your app's state as if a real GPS update occurred
updateLocation(fakeLocation)
// Wait before moving to the next point (e.g., every 1 second)
delay(1000)
delay(500)
lastLocation = fakeLocation
}
routeModel.stopNavigation()

View File

@@ -1,5 +1,6 @@
package com.kouros.navigation.car.screen
import androidx.activity.OnBackPressedCallback
import androidx.car.app.CarContext
import androidx.car.app.Screen
import androidx.car.app.model.Action
@@ -40,8 +41,17 @@ class CategoriesScreen(
Category(id = CHARGING_STATION, name = carContext.getString(R.string.charging_station))
)
private val backPressedCallback = object : OnBackPressedCallback(false) {
override fun handleOnBackPressed() {
navigationViewModel.elements.value = emptyList()
invalidate()
}
}
init {
navigationViewModel.elements.value = emptyList()
navigationViewModel.elements.observe(this, categoryObserver)
carContext.onBackPressedDispatcher.addCallback(this, backPressedCallback)
}
override fun onGetTemplate(): Template {

View File

@@ -530,8 +530,7 @@ class NavigationScreen(
* Pushes the search screen and handles the search result.
*/
private fun startSearchScreen() {
navigationViewModel.recentPlaces.value = emptyList()
navigationViewModel.previewRoute.value = ""
screenManager
.pushForResult(
SearchScreen(

View File

@@ -39,11 +39,12 @@ class PlaceListScreen(
private val places: List<Place>
) : Screen(carContext) {
val routeModel = RouteCarModel()
var place = Place()
var mPlaces = mutableListOf<Place>()
val previewObserver = Observer<String> { route ->
if (route.isNotEmpty()) {
val repository = getSettingsRepository(carContext)
@@ -70,21 +71,25 @@ class PlaceListScreen(
}
init {
loadPlaces()
// loadPlaces()
navigationViewModel.recentPlaces.value = emptyList()
navigationViewModel.previewRoute.value = ""
mPlaces.addAll(places)
navigationViewModel.previewRoute.observe(this, previewObserver)
}
override fun onGetTemplate(): Template {
val itemListBuilder = ItemList.Builder()
.setNoItemsMessage(carContext.getString(R.string.no_places))
places.forEach {
mPlaces.forEach {
val street = if (it.street != null) {
it.street
} else {
""
}
val row = Row.Builder()
// .setImage(contactIcon(it.avatar, it.category))
.setImage(contactIcon(null, it.category))
.setTitle("$street ${it.city}")
.setOnClickListener {
place = Place(
@@ -155,7 +160,7 @@ class PlaceListScreen(
carContext,
R.string.recent_Item_deleted, CarToast.LENGTH_LONG
).show()
loadPlaces()
mPlaces.remove(place)
invalidate()
}
.build()

View File

@@ -3,16 +3,17 @@ package com.kouros.navigation.car.screen.settings
import androidx.car.app.CarContext
import androidx.car.app.Screen
import androidx.car.app.model.Action
import androidx.car.app.model.CarIcon
import androidx.car.app.model.Header
import androidx.car.app.model.ItemList
import androidx.car.app.model.ListTemplate
import androidx.car.app.model.Row
import androidx.car.app.model.Template
import androidx.car.app.model.Toggle
import androidx.core.graphics.drawable.IconCompat
import androidx.lifecycle.lifecycleScope
import com.kouros.data.R
import com.kouros.navigation.car.screen.settings.PasswordSettings
import com.kouros.navigation.car.screen.settings.RoutingSettings
import com.kouros.navigation.car.navigation.NavigationUtils
import com.kouros.navigation.model.NavigationViewModel
import com.kouros.navigation.utils.getSettingsViewModel
import kotlinx.coroutines.flow.first
@@ -61,7 +62,8 @@ class NavigationSettings(
listBuilder.addItem(
buildRowForTemplate(
R.string.avoid_highways_row_title,
highwayToggle
highwayToggle,
NavigationUtils(carContext).createCarIcon(R.drawable.baseline_add_road_24)
)
)
@@ -71,7 +73,7 @@ class NavigationSettings(
settingsViewModel.onAvoidTollway(checked)
tollWayToggleState = !tollWayToggleState
}.setChecked(tollWayToggleState).build()
listBuilder.addItem(buildRowForTemplate(R.string.avoid_tolls_row_title, tollwayToggle))
listBuilder.addItem(buildRowForTemplate(R.string.avoid_tolls_row_title, tollwayToggle, NavigationUtils(carContext).createCarIcon(R.drawable.baseline_toll_24)))
// Ferry
val ferryToggle: Toggle =
@@ -79,7 +81,7 @@ class NavigationSettings(
settingsViewModel.onAvoidFerry(checked)
ferryToggleState = !ferryToggleState
}.setChecked(ferryToggleState).build()
listBuilder.addItem(buildRowForTemplate(R.string.avoid_ferries, ferryToggle))
listBuilder.addItem(buildRowForTemplate(R.string.avoid_ferries, ferryToggle, NavigationUtils(carContext).createCarIcon(R.drawable.baseline_directions_boat_filled_24)))
// CarLocation
val carLocationToggle: Toggle =
@@ -91,7 +93,8 @@ class NavigationSettings(
listBuilder.addItem(
buildRowForTemplate(
R.string.use_car_location,
carLocationToggle
carLocationToggle,
NavigationUtils(carContext).createCarIcon(R.drawable.ic_place_white_24dp)
)
)
@@ -118,10 +121,11 @@ class NavigationSettings(
.build()
}
private fun buildRowForTemplate(title: Int, toggle: Toggle): Row {
private fun buildRowForTemplate(title: Int, toggle: Toggle, icon: CarIcon): Row {
return Row.Builder()
.setTitle(carContext.getString(title))
.setToggle(toggle)
.setImage(icon)
.build()
}