Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Prevent default style reload when string style json was set #11520

Merged
merged 1 commit into from
Mar 26, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
*/
void onStart() {
nativeMapView.update();
if (TextUtils.isEmpty(nativeMapView.getStyleUrl())) {
if (TextUtils.isEmpty(nativeMapView.getStyleUrl()) && TextUtils.isEmpty(nativeMapView.getStyleJson())) {
// if user hasn't loaded a Style yet
nativeMapView.setStyleUrl(Style.MAPBOX_STREETS);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.mapbox.mapboxsdk.testapp.style;


import android.support.test.espresso.UiController;

import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;

import org.junit.Test;

import java.io.IOException;

import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static org.junit.Assert.assertEquals;

/**
* Tests around style loading
*/
public class StyleLoaderTest extends BaseActivityTest {


@Override
protected Class getActivityClass() {
return EspressoTestActivity.class;
}

@Test
public void testSetGetStyleJsonString() throws Exception {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
try {
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
mapboxMap.setStyleJson(expected);
String actual = mapboxMap.getStyleJson();
assertEquals("Style json should match", expected, actual);
} catch (IOException exception) {
exception.printStackTrace();
}
}
});
}

@Test
public void testDefaultStyleLoadWithActivityLifecycleChange() throws Exception {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
try {
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
mapboxMap.setStyleJson(expected);

// fake activity stop/start
MapView mapView = (MapView) rule.getActivity().findViewById(R.id.mapView);
mapView.onPause();
mapView.onStop();

mapView.onStart();
mapView.onResume();

String actual = mapboxMap.getStyleJson();
assertEquals("Style URL should be empty", "", mapboxMap.getStyleUrl());
assertEquals("Style json should match", expected, actual);
} catch (IOException exception) {
exception.printStackTrace();
}
}
});
}
}