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

Commit

Permalink
[android] - throw exception when another style is loading, correct Ru…
Browse files Browse the repository at this point in the history
…ntimeStyleTest when removing layer at, add javadoc to isFullyLoaded
  • Loading branch information
tobrun committed Dec 10, 2018
1 parent a85263b commit 9535604
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ private void initialize(@NonNull final Context context, @NonNull Style style,
}

if (!style.isFullyLoaded()) {
throw new IllegalStateException("Style hasn't fully loaded yet, can't initialize LocationComponent.");
throw new IllegalStateException("Style is invalid, provide the most recently loaded one.");
}

this.style = style;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ public List<Source> getSources() {
*/
public void addSource(@NonNull Source source) {
if (!fullyLoaded) {
// we are loading a new style
return;
throw new IllegalStateException(
"Calling addSource on old Style instance, use the more recently loaded Style instead."
);
}

sources.put(source.getId(), source);
Expand Down Expand Up @@ -195,8 +196,9 @@ public boolean removeSource(@NonNull Source source) {
*/
public void addLayer(@NonNull Layer layer) {
if (!fullyLoaded) {
// we are loading a new style
return;
throw new IllegalStateException(
"Calling addLayer on old Style instance, use the more recently loaded Style instead."
);
}

layers.put(layer.getId(), layer);
Expand All @@ -211,8 +213,9 @@ public void addLayer(@NonNull Layer layer) {
*/
public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
if (!fullyLoaded) {
// we are loading a new style
return;
throw new IllegalStateException(
"Calling addLayerBelow on old Style instance, use the more recently loaded Style instead."
);
}

layers.put(layer.getId(), layer);
Expand All @@ -227,8 +230,9 @@ public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
*/
public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
if (!fullyLoaded) {
// we are loading a new style
return;
throw new IllegalStateException(
"Calling addLayerAbove on old Style instance, use the more recently loaded Style instead."
);
}

layers.put(layer.getId(), layer);
Expand All @@ -244,8 +248,9 @@ public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
*/
public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) {
if (!fullyLoaded) {
// we are loading a new style
return;
throw new IllegalStateException(
"Calling addLayerAt on old Style instance, use the more recently loaded Style instead."
);
}

layers.put(layer.getId(), layer);
Expand Down Expand Up @@ -368,8 +373,9 @@ public void addImage(@NonNull String name, @NonNull Bitmap image) {
*/
public void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf) {
if (!fullyLoaded) {
// we are loading a new style
return;
throw new IllegalStateException(
"Calling addImage on old Style instance, use the more recently loaded Style instead."
);
}

nativeMapView.addImage(name, image, sdf);
Expand All @@ -380,8 +386,9 @@ public void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf) {
*/
public void addImages(@NonNull HashMap<String, Bitmap> images) {
if (!fullyLoaded) {
// we are loading a new style
return;
throw new IllegalStateException(
"Calling addImages on old Style instance, use the more recently loaded Style instead."
);
}

nativeMapView.addImages(images);
Expand Down Expand Up @@ -431,8 +438,9 @@ public Bitmap getImage(@NonNull String id) {
*/
public void setTransition(@NonNull TransitionOptions transitionOptions) {
if (!fullyLoaded) {
// we are loading a new style
return;
throw new IllegalStateException(
"Calling setTransition on old Style instance, use the more recently loaded Style instead."
);
}

nativeMapView.setTransitionDuration(transitionOptions.getDuration());
Expand Down Expand Up @@ -541,6 +549,12 @@ void onDidFinishLoadingStyle() {
}
}

/**
* Returns true if the style is fully loaded. Returns false if style hasn't been fully loaded or a new style is
* underway of being loaded.
*
* @return True if fully loaded, false otherwise
*/
public boolean isFullyLoaded() {
return fullyLoaded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void perform(UiController uiController, View view) {

// Test remove by index bounds checks
Timber.i("Remove layer at index > size");
assertNull(mapboxMap.getStyle().removeLayerAt(Integer.MAX_VALUE));
assertFalse(mapboxMap.getStyle().removeLayerAt(Integer.MAX_VALUE));
}
});
}
Expand Down

0 comments on commit 9535604

Please sign in to comment.