@@ -4,6 +4,7 @@ import android.arch.lifecycle.LifecycleOwner
44import android.arch.lifecycle.Observer
55import android.location.Location
66import android.support.design.widget.BottomSheetBehavior
7+ import android.view.View
78import android.view.View.INVISIBLE
89import android.view.View.VISIBLE
910import com.mapbox.api.directions.v5.models.DirectionsRoute
@@ -17,13 +18,11 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds
1718import com.mapbox.mapboxsdk.maps.MapboxMap
1819import com.mapbox.services.android.navigation.testapp.NavigationApplication
1920import com.mapbox.services.android.navigation.testapp.R
20- import com.mapbox.services.android.navigation.testapp.example.ui.offline.OfflineFilesLoadedCallback
2121import com.mapbox.services.android.navigation.testapp.example.utils.formatArrivalTime
2222import com.mapbox.services.android.navigation.ui.v5.camera.DynamicCamera
2323import com.mapbox.services.android.navigation.v5.milestone.BannerInstructionMilestone
2424import com.mapbox.services.android.navigation.v5.milestone.Milestone
2525import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress
26- import timber.log.Timber
2726import kotlin.math.roundToInt
2827
2928class ExamplePresenter (private val view : ExampleView , private val viewModel : ExampleViewModel ) {
@@ -37,11 +36,6 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
3736 }
3837
3938 private var state: PresenterState = PresenterState .SHOW_LOCATION
40- private val offlineCallback = object : OfflineFilesLoadedCallback {
41- override fun onFilesLoaded () {
42- Timber .d(" Offline files loaded" )
43- }
44- }
4539
4640 fun onPermissionResult (granted : Boolean ) {
4741 if (granted) {
@@ -59,6 +53,10 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
5953 view.updateAutocompleteBottomSheetState(BottomSheetBehavior .STATE_EXPANDED )
6054 }
6155
56+ fun onAttributionsClick (attributionView : View ) {
57+ view.showAttributionDialog(attributionView)
58+ }
59+
6260 fun onSettingsFabClick () {
6361 view.showSettings()
6462 }
@@ -75,16 +73,16 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
7573 }
7674
7775 fun onNavigationFabClick () {
78- viewModel.route.value?. let {
76+ if ( viewModel.canNavigate()) {
7977 state = PresenterState .NAVIGATE
8078 view.addMapProgressChangeListener(viewModel.retrieveNavigation())
81- viewModel.startNavigationWith(it)
8279 view.updateNavigationFabVisibility(INVISIBLE )
8380 view.updateCancelFabVisibility(VISIBLE )
8481 view.updateNavigationDataVisibility(VISIBLE )
8582 view.updateAutocompleteBottomSheetHideable(true )
8683 view.updateAutocompleteBottomSheetState(BottomSheetBehavior .STATE_HIDDEN )
8784 view.adjustMapPaddingForNavigation()
85+ viewModel.startNavigation()
8886 }
8987 }
9088
@@ -143,20 +141,20 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
143141 }
144142 }
145143
146- fun onRouteFound (route : DirectionsRoute ? ) {
147- route ?.let { directionsRoute ->
144+ fun onRouteFound (routes : List < DirectionsRoute > ? ) {
145+ routes ?.let { directionsRoutes ->
148146 when (state) {
149147 PresenterState .FIND_ROUTE -> {
150148 state = PresenterState .ROUTE_FOUND
151- view.updateRoute(directionsRoute )
149+ view.updateRoutes(directionsRoutes )
152150 view.updateDirectionsFabVisibility(INVISIBLE )
153151 view.updateNavigationFabVisibility(VISIBLE )
154152 viewModel.destination.value?.let { destination ->
155153 moveCameraToInclude(destination)
156154 }
157155 }
158156 PresenterState .NAVIGATE -> {
159- viewModel.startNavigationWith(directionsRoute )
157+ view.updateRoutes(directionsRoutes )
160158 }
161159 else -> {
162160 // TODO no impl
@@ -165,6 +163,13 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
165163 }
166164 }
167165
166+ fun onNewRouteSelected (directionsRoute : DirectionsRoute ) {
167+ viewModel.updatePrimaryRoute(directionsRoute)
168+ if (state == PresenterState .NAVIGATE ) {
169+ viewModel.startNavigation()
170+ }
171+ }
172+
168173 fun onProgressUpdate (progress : RouteProgress ? ) {
169174 progress?.let {
170175 view.updateArrivalTime(it.formatArrivalTime(NavigationApplication .instance))
@@ -174,9 +179,9 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
174179 }
175180
176181 fun onMapLongClick (point : LatLng ) {
177- viewModel.reverseGeocode(point);
182+ viewModel.reverseGeocode(point)
178183 }
179-
184+
180185 fun onMilestoneUpdate (milestone : Milestone ? ) {
181186 milestone?.let {
182187 if (milestone is BannerInstructionMilestone ) {
@@ -187,13 +192,21 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
187192 }
188193 }
189194
195+ fun onBackPressed (): Boolean {
196+ if (! viewModel.collapsedBottomSheet) {
197+ view.updateAutocompleteBottomSheetState(BottomSheetBehavior .STATE_COLLAPSED )
198+ return false
199+ }
200+ return true
201+ }
202+
190203 fun onDestroy () {
191204 viewModel.onDestroy()
192205 }
193206
194207 fun subscribe (owner : LifecycleOwner ) {
195208 viewModel.location.observe(owner, Observer { onLocationUpdate(it) })
196- viewModel.route .observe(owner, Observer { onRouteFound(it) })
209+ viewModel.routes .observe(owner, Observer { onRouteFound(it) })
197210 viewModel.progress.observe(owner, Observer { onProgressUpdate(it) })
198211 viewModel.milestone.observe(owner, Observer { onMilestoneUpdate(it) })
199212 viewModel.geocode.observe(owner, Observer {
@@ -202,7 +215,6 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
202215 }
203216 })
204217 viewModel.activateLocationEngine()
205- viewModel.loadOfflineFiles(offlineCallback)
206218 }
207219
208220 fun buildDynamicCameraFrom (mapboxMap : MapboxMap ) {
@@ -246,12 +258,4 @@ class ExamplePresenter(private val view: ExampleView, private val viewModel: Exa
246258 view.updateMapCameraFor(bounds, padding, TWO_SECONDS )
247259 }
248260 }
249-
250- fun onBackPressed (): Boolean {
251- if (! viewModel.collapsedBottomSheet) {
252- view.updateAutocompleteBottomSheetState(BottomSheetBehavior .STATE_COLLAPSED )
253- return false
254- }
255- return true
256- }
257261}
0 commit comments