From 8cd3d7c59b91555f33ea4266505d9d9fcada2463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Thu, 19 Jul 2018 18:39:23 +0200 Subject: [PATCH] [LLP] always make plugin visible in location start --- .../locationlayer/LocationLayerPluginTest.kt | 21 +++++++++++++++++++ .../locationlayer/LocationLayerPlugin.java | 9 ++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt index 6106f4885..a460dbbcb 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.kt @@ -424,6 +424,27 @@ class LocationLayerPluginTest { executePluginTest(pluginAction) } + @Test + fun disablingPluginAndChangingStyleAllowsToEnableAgain() { + val pluginAction = object : GenericPluginAction.OnPerformGenericPluginAction { + override fun onGenericPluginAction(plugin: LocationLayerPlugin, mapboxMap: MapboxMap, + uiController: UiController, context: Context) { + + plugin.forceLocationUpdate(location) + uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) + + plugin.isLocationLayerEnabled = false + uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) + mapboxMap.setStyle(Style.LIGHT) + uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY) + plugin.isLocationLayerEnabled = true + uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) + assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true)) + } + } + executePluginTest(pluginAction) + } + @Test fun lifecycle_keepsEnabledWhenStoppedAndStarted() { val pluginAction = object : GenericPluginAction.OnPerformGenericPluginAction { diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 2cf811d9c..893a84f31 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -623,11 +623,10 @@ public void onStop() { } void onLocationLayerStart() { - if (isLocationLayerStarted || !isPluginStarted) { + if (!isPluginStarted) { return; } - isLocationLayerStarted = true; if (isEnabled) { if (locationEngine != null) { locationEngine.addLocationEngineListener(locationEngineListener); @@ -637,6 +636,12 @@ void onLocationLayerStart() { locationLayer.show(); setCameraMode(locationLayerCamera.getCameraMode()); } + + if (isLocationLayerStarted) { + return; + } + + isLocationLayerStarted = true; if (mapboxMap != null) { mapboxMap.addOnCameraMoveListener(onCameraMoveListener); mapboxMap.addOnCameraIdleListener(onCameraIdleListener);