Navigation Screen to Session, Remove NavigationService
This commit is contained in:
@@ -43,6 +43,7 @@ import com.google.android.gms.location.LocationServices
|
||||
import com.kouros.data.R
|
||||
import com.kouros.navigation.MainApplication.Companion.navigationViewModel
|
||||
import com.kouros.navigation.car.TextToSpeechManager
|
||||
import com.kouros.navigation.car.navigation.NavigationService
|
||||
import com.kouros.navigation.data.Constants.DESTINATION_ARRIVAL_DISTANCE
|
||||
import com.kouros.navigation.data.Constants.INSTRUCTION_DISTANCE
|
||||
import com.kouros.navigation.data.Constants.TAG
|
||||
@@ -79,6 +80,8 @@ import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
var navigationService: NavigationService? = null
|
||||
|
||||
var isBound: Boolean = false
|
||||
val routeData = MutableLiveData("")
|
||||
val routeModel = RouteModel()
|
||||
@@ -99,6 +102,20 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
// Monitors the state of the connection to the navigation service.
|
||||
private val serviceConnection: ServiceConnection = object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||
val binder: NavigationService.LocalBinder = service as NavigationService.LocalBinder
|
||||
navigationService = binder.service
|
||||
isBound = true
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
navigationService = null
|
||||
isBound = false
|
||||
}
|
||||
}
|
||||
|
||||
val cameraPosition = MutableLiveData(
|
||||
CameraPosition(
|
||||
zoom = 15.0, target = Position(latitude = 48.1857475, longitude = 11.5793627)
|
||||
@@ -151,6 +168,27 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
Log.i(TAG, "In onStart()")
|
||||
bindService(
|
||||
Intent(this, NavigationService::class.java),
|
||||
serviceConnection,
|
||||
BIND_AUTO_CREATE
|
||||
)
|
||||
requestPermissions(arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 1)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
Log.i(TAG, "In onStop(). bound $isBound")
|
||||
if (isBound) {
|
||||
unbindService(serviceConnection)
|
||||
isBound = false
|
||||
navigationService = null
|
||||
}
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun StartScreen(
|
||||
@@ -318,6 +356,7 @@ class MainActivity : ComponentActivity() {
|
||||
routeModel.navState = routeModel.navState.copy(routingEngine = routingEngine)
|
||||
routeModel.startNavigation(newRoute)
|
||||
routeData.value = routeModel.curRoute.routeGeoJson
|
||||
navigationService?.startNavigation()
|
||||
}
|
||||
fun stopNavigation(closeSheet: () -> Unit) {
|
||||
closeSheet()
|
||||
@@ -325,6 +364,7 @@ class MainActivity : ComponentActivity() {
|
||||
getSettingsViewModel(applicationContext).onLastRouteChanged("")
|
||||
routeData.value = ""
|
||||
stepData.value = StepData("", "", 0.0, 0, 0, 0, 0.0)
|
||||
navigationService?.stopNavigation()
|
||||
}
|
||||
|
||||
fun textToSpeech() {
|
||||
|
||||
Reference in New Issue
Block a user