From f16ff32bd6c51f07fed104d78fbac91d9df1136d Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 21 May 2018 08:36:13 -0400 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20update=20stale=20state=20if=20i?= =?UTF-8?q?t=E2=80=99s=20not=20enabled=20in=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IsolatedActivityPluginTest.kt | 30 +++++++++++++++++++ .../plugins/locationlayer/LocationLayer.java | 4 +++ 2 files changed, 34 insertions(+) diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/IsolatedActivityPluginTest.kt b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/IsolatedActivityPluginTest.kt index 907a1290c..437b2c220 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/IsolatedActivityPluginTest.kt +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/IsolatedActivityPluginTest.kt @@ -130,6 +130,36 @@ class IsolatedActivityPluginTest { executePluginTest(pluginAction) } + // + // Location Layer Options + // + + @Test + fun locationLayerOptions_disablingStaleStateDoesWorkCorrectly() { + val pluginAction = object : GenericPluginAction.OnPerformGenericPluginAction { + override fun onGenericPluginAction(plugin: LocationLayerPlugin?, mapboxMap: MapboxMap?, + uiController: UiController, context: Context) { + mapView = fragment?.view as MapView? + + val options = LocationLayerOptions.builder(context) + .staleStateTimeout(500) + .enableStaleState(false) + .build() + LocationLayerPlugin(mapView!!, mapboxMap!!, null, options).apply { + renderMode = RenderMode.NORMAL + } + + uiController.loopMainThreadForAtLeast(700) + + val source: GeoJsonSource? = mapboxMap.getSourceAs(LOCATION_SOURCE) + source?.querySourceFeatures(null)?.forEach { + assertThat(it.getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(not(true))) + } + } + } + executePluginTest(pluginAction) + } + @After fun afterTest() { Timber.e("@After: unregister idle resource") diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java index a4c9f3565..277bf563f 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java @@ -383,6 +383,10 @@ private void styleForegroundGPS(LocationLayerOptions options) { } void setLocationsStale(boolean isStale) { + // If options has stale state disabled, just return here. + if (!options.enableStaleState()) { + return; + } locationFeature.addBooleanProperty(PROPERTY_LOCATION_STALE, isStale); refreshSource(); if (renderMode != RenderMode.GPS) {