Skip to content

Make MapboxNavigationApp.setup create new instance #6288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ jobs:

static-analysis:
executor: ndk-r22-latest-executor
resource_class: medium+
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steps:
- when:
condition:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Mapbox welcomes participation and contributions from everyone.
- Introduced `MapboxManeuverView#maneuverViewState` to allow users to observe changes to `MapboxManeuverViewState` when the view expands and collapses. [#6286](https://github.com/mapbox/mapbox-navigation-android/pull/6286)
- Introduced `NavigationViewApi#onManeuverCollapsed` and `NavigationViewApi#onManeuverExpanded` callback which is triggered upon changes to `MapboxManeuverViewState`. [#6286](https://github.com/mapbox/mapbox-navigation-android/pull/6286)
- Implemented logic that would display `BannerComponents` of `type` `GuidanceView` and `subType` `BannerComponents#SAPA`, `BannerComponents#CITYREAL`, `BannerComponents#AFTERTOLL`, `BannerComponents#SIGNBOARD`, `BannerComponents#TOLLBRANCH`, `BannerComponents#EXPRESSWAY_ENTRANCE`, `BannerComponents#EXPRESSWAY_EXIT` using `JunctionViewApi`. [#6285](https://github.com/mapbox/mapbox-navigation-android/pull/6285)
- Calling `MapboxNavigationApp.setup` will create a new `MapboxNavigation` instance with new `NavigationOptions` even if the app has been setup. [#6285](https://github.com/mapbox/mapbox-navigation-android/pull/6285)
#### Bug fixes and improvements
- Fixed an issue with `NavigationView` that caused overview camera to have wrong pitch. [#6278](https://github.com/mapbox/mapbox-navigation-android/pull/6278)
- Fixed an issue with `NavigationView` that caused camera issues after reroute or switching to an alternative route. [#6283](https://github.com/mapbox/mapbox-navigation-android/pull/6283)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.mapbox.navigation.core.lifecycle
import android.app.Application
import androidx.lifecycle.LifecycleOwner
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.utils.internal.logI
import kotlin.reflect.KClass

/**
Expand All @@ -24,16 +23,7 @@ internal class MapboxNavigationAppDelegate {
}

if (isSetup) {
logI(
"""
MapboxNavigationApp.setup was ignored because it has already been setup.
If you want to use new NavigationOptions, you must first call
MapboxNavigationApp.disable() and then call MapboxNavigationApp.setup(..).
Calling setup multiple times, is harmless otherwise.
""".trimIndent(),
LOG_CATEGORY
)
return this
disable()
}

mapboxNavigationOwner.setup(navigationOptionsProvider)
Expand Down Expand Up @@ -80,8 +70,4 @@ internal class MapboxNavigationAppDelegate {

fun <T : MapboxNavigationObserver> getObservers(kClass: KClass<T>): List<T> =
mapboxNavigationOwner.getObservers(kClass)

private companion object {
private const val LOG_CATEGORY = "MapboxNavigationAppDelegate"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import com.mapbox.navigation.base.options.NavigationOptions
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.core.MapboxNavigationProvider
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.runs
import io.mockk.unmockkAll
import io.mockk.verify
import io.mockk.verifyOrder
Expand Down Expand Up @@ -110,23 +112,29 @@ class MapboxNavigationAppDelegateTest {
}

@Test
fun `verify multiple setup calls are ignored`() {
mapboxNavigationApp.setup { navigationOptions }
val firstObserver = mockk<MapboxNavigationObserver>(relaxUnitFun = true)
val secondObserver = mockk<MapboxNavigationObserver>(relaxUnitFun = true)
mapboxNavigationApp.registerObserver(firstObserver)
mapboxNavigationApp.registerObserver(secondObserver)
fun `verify setup will detach old and attach a new`() {
val attachedSlot = mutableListOf<MapboxNavigation>()
val detachedSlot = mutableListOf<MapboxNavigation>()
val observer = mockk<MapboxNavigationObserver> {
every { onAttached(capture(attachedSlot)) } just runs
every { onDetached(capture(detachedSlot)) } just runs
}
mapboxNavigationApp.registerObserver(observer)

val testLifecycleOwner = CarAppLifecycleOwnerTest.TestLifecycleOwner()
mapboxNavigationApp.attach(testLifecycleOwner)
mapboxNavigationApp.setup { navigationOptions }
testLifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.RESUMED
mapboxNavigationApp.setup { navigationOptions }

verify(exactly = 1) { firstObserver.onAttached(any()) }
verify(exactly = 1) { secondObserver.onAttached(any()) }
verify(exactly = 0) { firstObserver.onDetached(any()) }
verify(exactly = 0) { secondObserver.onDetached(any()) }
assertEquals(2, attachedSlot.size)
assertEquals(1, detachedSlot.size)
assertEquals(attachedSlot[0], detachedSlot[0])
verifyOrder {
observer.onAttached(attachedSlot[0])
observer.onDetached(attachedSlot[0])
observer.onAttached(attachedSlot[1])
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
import com.mapbox.navigation.qa_test_app.R
import com.mapbox.navigation.qa_test_app.databinding.ActivityMainBinding
import com.mapbox.navigation.qa_test_app.domain.TestActivityDescription
Expand Down Expand Up @@ -54,9 +53,6 @@ class MainActivity : AppCompatActivity() {
(binding.activitiesList.adapter as GenericListAdapter<TestActivityDescription, *>).swap(
TestActivitySuite.testActivities
)

// Each example is responsible for setting up their NavigationOptions.
MapboxNavigationApp.disable()
}

override fun onRequestPermissionsResult(
Expand Down