Diverse
This commit is contained in:
@@ -14,8 +14,8 @@ android {
|
||||
applicationId = "com.kouros.navigation"
|
||||
minSdk = 33
|
||||
targetSdk = 36
|
||||
versionCode = 18
|
||||
versionName = "0.1.3.18"
|
||||
versionCode = 23
|
||||
versionName = "0.1.3.23"
|
||||
base.archivesName = "navi-$versionName"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -94,7 +94,7 @@ dependencies {
|
||||
implementation(libs.androidx.compose.ui.graphics)
|
||||
implementation(libs.androidx.window)
|
||||
implementation(libs.androidx.compose.foundation.layout)
|
||||
|
||||
implementation("com.github.ticofab:android-gpx-parser:2.3.1")
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.content.Context
|
||||
import com.kouros.navigation.data.ObjectBox
|
||||
import com.kouros.navigation.di.appModule
|
||||
import com.kouros.navigation.model.ViewModel
|
||||
import com.kouros.navigation.utils.NavigationUtils.getRouteEngine
|
||||
import com.kouros.navigation.utils.NavigationUtils.getViewModel
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.android.ext.koin.androidLogger
|
||||
import org.koin.core.context.startKoin
|
||||
@@ -17,7 +17,7 @@ class MainApplication : Application() {
|
||||
super.onCreate()
|
||||
ObjectBox.init(this);
|
||||
appContext = applicationContext
|
||||
navigationViewModel = getRouteEngine(appContext!!)
|
||||
navigationViewModel = getViewModel(appContext!!)
|
||||
startKoin {
|
||||
androidLogger(Level.DEBUG)
|
||||
androidContext(this@MainApplication)
|
||||
|
||||
@@ -4,6 +4,7 @@ import NavigationSheet
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AppOpsManager
|
||||
import android.content.Context
|
||||
import android.location.LocationManager
|
||||
import android.os.Bundle
|
||||
import android.os.Process
|
||||
@@ -38,6 +39,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.kouros.data.R
|
||||
import com.kouros.navigation.MainApplication.Companion.navigationViewModel
|
||||
import com.kouros.navigation.data.Constants
|
||||
import com.kouros.navigation.data.Constants.DESTINATION_ARRIVAL_DISTANCE
|
||||
@@ -51,10 +53,14 @@ import com.kouros.navigation.utils.NavigationUtils.getIntKeyValue
|
||||
import com.kouros.navigation.utils.bearing
|
||||
import com.kouros.navigation.utils.calculateZoom
|
||||
import com.kouros.navigation.utils.location
|
||||
import io.ticofab.androidgpxparser.parser.GPXParser
|
||||
import io.ticofab.androidgpxparser.parser.domain.Gpx
|
||||
import io.ticofab.androidgpxparser.parser.domain.TrackSegment
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.joda.time.DateTime
|
||||
import org.maplibre.compose.camera.CameraPosition
|
||||
import org.maplibre.compose.location.DesiredAccuracy
|
||||
import org.maplibre.compose.location.Location
|
||||
@@ -84,6 +90,7 @@ class MainActivity : ComponentActivity() {
|
||||
routeData.value = routeModel.route.routeGeoJson
|
||||
simulate()
|
||||
//test()
|
||||
//gpx(applicationContext)
|
||||
}
|
||||
}
|
||||
val cameraPosition = MutableLiveData(
|
||||
@@ -199,6 +206,7 @@ class MainActivity : ComponentActivity() {
|
||||
applicationContext,
|
||||
userLocationState,
|
||||
step,
|
||||
nextStep,
|
||||
cameraPosition,
|
||||
routeData,
|
||||
tilt,
|
||||
@@ -244,11 +252,11 @@ class MainActivity : ComponentActivity() {
|
||||
if (route.currentStep + 1 <= legs.steps.size) {
|
||||
nextStepData.value = nextStep()
|
||||
}
|
||||
if (routeState.maneuverType == 39
|
||||
if (maneuverType in 39..42
|
||||
&& leftStepDistance() < DESTINATION_ARRIVAL_DISTANCE
|
||||
) {
|
||||
// stopNavigation()
|
||||
routeState = routeState.copy(arrived = true)
|
||||
arrived = true
|
||||
routeData.value = ""
|
||||
}
|
||||
}
|
||||
@@ -270,10 +278,15 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
fun stopNavigation(closeSheet: () -> Unit) {
|
||||
val latitude = routeModel.route.waypoints!![0][1]
|
||||
val longitude = routeModel.route.waypoints!![0][0]
|
||||
closeSheet()
|
||||
routeModel.stopNavigation()
|
||||
if (useMock) {
|
||||
mock.setMockLocation(latitude, longitude)
|
||||
}
|
||||
routeData.value = ""
|
||||
stepData.value = StepData("", 0.0, 0, 0,0, 0.0)
|
||||
stepData.value = StepData("", 0.0, 0, 0, 0, 0.0)
|
||||
}
|
||||
|
||||
fun simulateNavigation() {
|
||||
@@ -306,14 +319,13 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
fun simulate() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
if (routeModel.isNavigating()) {
|
||||
for ((index, waypoint) in routeModel.route.waypoints!!.withIndex()) {
|
||||
for ((index, waypoint) in routeModel.route.waypoints!!.withIndex()) {
|
||||
if (routeModel.isNavigating()) {
|
||||
var deviation = 0.0
|
||||
//if (index in 0..350 ) {
|
||||
if (index in 0..routeModel.route.waypoints!!.size) {
|
||||
mock.setMockLocation(waypoint[1] + deviation, waypoint[0])
|
||||
|
||||
delay(500L) //
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -321,14 +333,44 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
fun test() {
|
||||
for ((index, step) in routeModel.legs.steps.withIndex()) {
|
||||
println("${step.maneuver.waypoints.size}")
|
||||
for ((windex, waypoint) in step.maneuver.waypoints.withIndex()) {
|
||||
routeModel.updateLocation(location(waypoint[0], waypoint[1]), navigationViewModel)
|
||||
routeModel.currentStep()
|
||||
val step = routeModel.currentStep()
|
||||
println("Street: ${step.instruction} Dist: ${step.leftStepDistance} ${step.currentManeuverType}")
|
||||
if (index + 1 <= routeModel.legs.steps.size) {
|
||||
nextStepData.value = routeModel.nextStep()
|
||||
//nextStepData.value = routeModel.nextStep()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun gpx(context: Context) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val parser = GPXParser()
|
||||
val input = context.resources.openRawResource(R.raw.vh)
|
||||
val parsedGpx: Gpx? = parser.parse(input) // consider using a background thread
|
||||
parsedGpx?.let {
|
||||
val tracks = parsedGpx.tracks
|
||||
tracks.forEach { tr ->
|
||||
val segments: MutableList<TrackSegment?>? = tr.trackSegments
|
||||
segments!!.forEach { seg ->
|
||||
var lastTime = DateTime.now()
|
||||
seg!!.trackPoints.forEach { p ->
|
||||
val ext = p.extensions
|
||||
val speed: Double?
|
||||
if (ext != null) {
|
||||
speed = ext.speed
|
||||
mock.curSpeed = speed.toFloat()
|
||||
}
|
||||
val duration = p.time.millis - lastTime.millis
|
||||
mock.setMockLocation(p.latitude, p.longitude)
|
||||
if (duration > 0) {
|
||||
delay(duration / 5)
|
||||
}
|
||||
lastTime = p.time
|
||||
}
|
||||
}
|
||||
}
|
||||
println(routeModel.routeState.maneuverType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ fun MapView(
|
||||
applicationContext: Context,
|
||||
userLocationState: UserLocationState,
|
||||
step: StepData?,
|
||||
nextStep: StepData?,
|
||||
cameraPosition: MutableLiveData<CameraPosition>,
|
||||
routeData: MutableLiveData<String>,
|
||||
tilt: Double,
|
||||
@@ -57,7 +58,7 @@ fun MapView(
|
||||
|
||||
val rememberBaseStyle = rememberBaseStyle( baseStyle)
|
||||
Column {
|
||||
NavigationInfo(step)
|
||||
NavigationInfo(step, nextStep)
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
MapLibre(
|
||||
applicationContext,
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.kouros.navigation.data.StepData
|
||||
import com.kouros.navigation.utils.round
|
||||
|
||||
@Composable
|
||||
fun NavigationInfo(step: StepData?) {
|
||||
fun NavigationInfo(step: StepData?, nextStep: StepData?) {
|
||||
if (step != null && step.instruction.isNotEmpty()) {
|
||||
Card(modifier = Modifier.padding(top = 60.dp)) {
|
||||
Column() {
|
||||
@@ -39,11 +39,13 @@ fun NavigationInfo(step: StepData?) {
|
||||
}
|
||||
Text(text = step.instruction, fontSize = 20.sp)
|
||||
}
|
||||
Icon(
|
||||
painter = painterResource(step.icon),
|
||||
contentDescription = stringResource(id = R.string.accept_action_title),
|
||||
modifier = Modifier.size(48.dp, 48.dp),
|
||||
)
|
||||
if (nextStep != null && step.icon != nextStep.icon) {
|
||||
Icon(
|
||||
painter = painterResource(nextStep.icon),
|
||||
contentDescription = stringResource(id = R.string.accept_action_title),
|
||||
modifier = Modifier.size(48.dp, 48.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,38 +57,31 @@ fun SearchSheet(
|
||||
if (search.value != null) {
|
||||
searchResults.addAll(search.value!!)
|
||||
}
|
||||
Home(applicationContext, viewModel, location, closeSheet = { closeSheet() })
|
||||
if (searchResults.isNotEmpty()) {
|
||||
val textFieldState = rememberTextFieldState()
|
||||
val items = listOf(searchResults)
|
||||
if (items.isNotEmpty()) {
|
||||
SearchBar(
|
||||
textFieldState = textFieldState,
|
||||
searchPlaces = recentPlaces.value!!,
|
||||
searchResults = searchResults,
|
||||
viewModel = viewModel,
|
||||
context = applicationContext,
|
||||
location = location,
|
||||
closeSheet = { closeSheet() }
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
Home(applicationContext, viewModel, location, closeSheet = { closeSheet() })
|
||||
if (recentPlaces.value != null) {
|
||||
val textFieldState = rememberTextFieldState()
|
||||
val items = listOf(recentPlaces)
|
||||
if (items.isNotEmpty()) {
|
||||
SearchBar(
|
||||
textFieldState = textFieldState,
|
||||
searchPlaces = recentPlaces.value!!,
|
||||
searchResults = searchResults,
|
||||
viewModel = viewModel,
|
||||
context = applicationContext,
|
||||
location = location,
|
||||
closeSheet = { closeSheet() }
|
||||
)
|
||||
RecentPlaces(recentPlaces.value!!, viewModel, applicationContext, location, closeSheet)
|
||||
}
|
||||
}
|
||||
// if (searchResults.isNotEmpty()) {
|
||||
val textFieldState = rememberTextFieldState()
|
||||
val items = listOf(searchResults)
|
||||
// if (items.isNotEmpty()) {
|
||||
SearchBar(
|
||||
textFieldState = textFieldState,
|
||||
searchPlaces = emptyList<Place>(),
|
||||
searchResults = searchResults,
|
||||
viewModel = viewModel,
|
||||
context = applicationContext,
|
||||
location = location,
|
||||
closeSheet = { closeSheet() }
|
||||
|
||||
)
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -138,15 +131,7 @@ fun SearchBar(
|
||||
closeSheet: () -> Unit
|
||||
) {
|
||||
var expanded by rememberSaveable { mutableStateOf(true) }
|
||||
Box(
|
||||
modifier
|
||||
.fillMaxSize()
|
||||
.semantics { isTraversalGroup = true }
|
||||
) {
|
||||
SearchBar(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopCenter)
|
||||
.semantics { traversalIndex = 0f },
|
||||
inputField = {
|
||||
SearchBarDefaults.InputField(
|
||||
leadingIcon = {
|
||||
@@ -179,7 +164,6 @@ fun SearchBar(
|
||||
SearchPlaces(searchResults, viewModel, context, location, closeSheet)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchPlaces(viewModel: ViewModel, location: Location, it: String) {
|
||||
|
||||
Reference in New Issue
Block a user