feat: Replay disabled
This commit is contained in:
parent
fb62c8dd77
commit
9f0bd9e147
4 changed files with 70 additions and 7 deletions
|
@ -36,7 +36,7 @@ class MainActivity : AppCompatActivity() {
|
|||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var mapControl: MapControl
|
||||
|
||||
private val permissionsHelper = PermissionsHelper(WeakReference(this))
|
||||
val permissionsHelper = PermissionsHelper(WeakReference(this))
|
||||
|
||||
val mapboxNavigation: MapboxNavigation by requireMapboxNavigation(
|
||||
onResumedObserver = object : DefaultLifecycleObserver, MapboxNavigationObserver {
|
||||
|
|
|
@ -51,7 +51,7 @@ class MapControl(
|
|||
|
||||
val navigationStatusControl = NavigationStatusControl()
|
||||
|
||||
val replay = ReplayResources(this)
|
||||
val tripControl = TripControl(this, TripMode.GPS)
|
||||
|
||||
// Observers
|
||||
private lateinit var routeControl: RouteControl
|
||||
|
@ -129,7 +129,7 @@ class MapControl(
|
|||
enabled = true
|
||||
}
|
||||
|
||||
replay.replayOriginLocation()
|
||||
tripControl.initLocation()
|
||||
}
|
||||
|
||||
fun mapboxNavigation(): MapboxNavigation {
|
||||
|
@ -144,7 +144,7 @@ class MapControl(
|
|||
|
||||
navigationStatusControl.registerObserver(searchControl)
|
||||
|
||||
replay.onAttached(mapboxNavigation)
|
||||
tripControl.onAttached(mapboxNavigation)
|
||||
}
|
||||
|
||||
override fun onDetached(mapboxNavigation: MapboxNavigation) {
|
||||
|
@ -155,7 +155,7 @@ class MapControl(
|
|||
|
||||
navigationStatusControl.unregisterObserver(searchControl)
|
||||
|
||||
replay.onDetached(mapboxNavigation)
|
||||
tripControl.onDetached(mapboxNavigation)
|
||||
}
|
||||
|
||||
fun onDestroy() {
|
||||
|
|
|
@ -281,7 +281,7 @@ class RouteControl(private val mapControl: MapControl, ui: UI, private val conte
|
|||
mapControl.navigationCamera.requestNavigationCameraToOverview()
|
||||
|
||||
// start simulation
|
||||
mapControl.replay.startSimulation(routes.first().directionsRoute)
|
||||
mapControl.tripControl.startSession(routes.first().directionsRoute)
|
||||
|
||||
mapControl.context.apply {
|
||||
lifecycleScope.launch {
|
||||
|
@ -298,7 +298,7 @@ class RouteControl(private val mapControl: MapControl, ui: UI, private val conte
|
|||
mapControl.mapboxNavigation().setNavigationRoutes(listOf())
|
||||
|
||||
// stop simulation
|
||||
mapControl.replay.stopSimulation()
|
||||
mapControl.tripControl.stopSession()
|
||||
|
||||
// hide UI elements
|
||||
mapControl.ui.soundButton.visibility = View.INVISIBLE
|
||||
|
|
63
app/src/main/java/eu/ztsh/garmin/mapbox/TripControl.kt
Normal file
63
app/src/main/java/eu/ztsh/garmin/mapbox/TripControl.kt
Normal file
|
@ -0,0 +1,63 @@
|
|||
package eu.ztsh.garmin.mapbox
|
||||
|
||||
import com.mapbox.api.directions.v5.models.DirectionsRoute
|
||||
import com.mapbox.navigation.core.MapboxNavigation
|
||||
import eu.ztsh.garmin.MainActivity
|
||||
import eu.ztsh.garmin.mock.ReplayResources
|
||||
|
||||
class TripControl(private val mapControl: MapControl, private val tripMode: TripMode) {
|
||||
|
||||
val replay = ReplayResources(mapControl)
|
||||
|
||||
fun onAttached(mapboxNavigation: MapboxNavigation) {
|
||||
when (tripMode) {
|
||||
TripMode.REPLAY -> replay.onAttached(mapboxNavigation)
|
||||
TripMode.GPS -> startSession(mapboxNavigation)
|
||||
}
|
||||
}
|
||||
|
||||
fun onDetached(mapboxNavigation: MapboxNavigation) {
|
||||
when (tripMode) {
|
||||
TripMode.REPLAY -> replay.onDetached(mapboxNavigation)
|
||||
TripMode.GPS -> stopSession(mapboxNavigation)
|
||||
}
|
||||
}
|
||||
|
||||
fun initLocation() {
|
||||
if (tripMode == TripMode.REPLAY) {
|
||||
replay.replayOriginLocation()
|
||||
}
|
||||
}
|
||||
|
||||
fun startSession(mapboxNavigation: MapboxNavigation) {
|
||||
if (tripMode == TripMode.GPS) {
|
||||
(mapControl.context as MainActivity).permissionsHelper.checkPermissions {
|
||||
mapboxNavigation.startTripSession()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun startSession(directionsRoute: DirectionsRoute) {
|
||||
if (tripMode == TripMode.REPLAY) {
|
||||
replay.startSimulation(directionsRoute)
|
||||
}
|
||||
}
|
||||
|
||||
fun stopSession() {
|
||||
if (tripMode == TripMode.REPLAY) {
|
||||
replay.stopSimulation()
|
||||
}
|
||||
}
|
||||
|
||||
fun stopSession(mapboxNavigation: MapboxNavigation) {
|
||||
if (tripMode == TripMode.GPS) {
|
||||
mapboxNavigation.stopTripSession()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum class TripMode {
|
||||
GPS,
|
||||
REPLAY
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue