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

Commit

Permalink
Add OnDidFailLoadingTileListener. (#704)
Browse files Browse the repository at this point in the history
* Add OnDidFailLoadingTileListener.

* Fix typo.

* Add unit tests.

* Bump gl-core to 5.3.0

* Add changelog for 9.7.0 release.
  • Loading branch information
pengdev authored Sep 26, 2021
1 parent 096a0bd commit daafc0b
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 5 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

Mapbox welcomes participation and contributions from everyone. Please read [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) to get started.

## 9.7.0 - September 24, 2021
[Changes](https://github.com/mapbox/mapbox-gl-native-android/compare/android-v9.6.2...android-v9.7.0) since [Mapbox Maps SDK for Android 9.6.2](https://github.com/mapbox/mapbox-gl-native-android/releases/tag/android-v9.6.2)
### Improvements and bug fixes
- Fix the race condition when updating LocationCompoent's position. ([#703](https://github.com/mapbox/mapbox-gl-native-android/pull/703))
- Handle exceptions thrown at layout initialization (including those thrown from vector tile parsing) and add `OnDidFailLoadingTileListener`, which will be trigged when tile failed to load. ([#704](https://github.com/mapbox/mapbox-gl-native-android/pull/704))
### Dependencies
- Update core library to 5.3.0

## 9.6.2 - July 7, 2021
[Changes](https://github.com/mapbox/mapbox-gl-native-android/compare/android-v9.6.1...android-v9.6.2) since [Mapbox Maps SDK for Android 9.6.1](https://github.com/mapbox/mapbox-gl-native-android/releases/tag/android-v9.6.0)
[Changes](https://github.com/mapbox/mapbox-gl-native-android/compare/android-v9.6.1...android-v9.6.2) since [Mapbox Maps SDK for Android 9.6.1](https://github.com/mapbox/mapbox-gl-native-android/releases/tag/android-v9.6.1)
### Dependencies
- Update telemetry to 8.1.0 (okhttp3 variant) and events-core 5.0.0 to make project compatible with Android 12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
= new CopyOnWriteArrayList<>();
private final List<MapView.OnDidFailLoadingMapListener> onDidFailLoadingMapListenerList
= new CopyOnWriteArrayList<>();
private final List<MapView.OnDidFailLoadingTileListener> onDidFailLoadingTileListenerList
= new CopyOnWriteArrayList<>();
private final List<MapView.OnWillStartRenderingFrameListener> onWillStartRenderingFrameList
= new CopyOnWriteArrayList<>();
private final List<MapView.OnDidFinishRenderingFrameListener> onDidFinishRenderingFrameList
Expand Down Expand Up @@ -120,6 +122,20 @@ public void onDidFailLoadingMap(String error) {
}
}

@Override
public void onDidFailLoadingTile(String error) {
try {
if (!onDidFailLoadingTileListenerList.isEmpty()) {
for (MapView.OnDidFailLoadingTileListener onDidFailLoadingTileListener : onDidFailLoadingTileListenerList) {
onDidFailLoadingTileListener.onDidFailLoadingTile(error);
}
}
} catch (Throwable err) {
Logger.e(TAG, "Exception in onDidFailLoadingTile", err);
throw err;
}
}

@Override
public void onWillStartRenderingFrame() {
try {
Expand Down Expand Up @@ -303,6 +319,14 @@ void removeOnDidFailLoadingMapListener(MapView.OnDidFailLoadingMapListener liste
onDidFailLoadingMapListenerList.remove(listener);
}

void addOnDidFailLoadingTileListener(MapView.OnDidFailLoadingTileListener listener) {
onDidFailLoadingTileListenerList.add(listener);
}

void removeOnDidFailLoadingTileListener(MapView.OnDidFailLoadingTileListener listener) {
onDidFailLoadingTileListenerList.remove(listener);
}

void addOnWillStartRenderingFrameListener(MapView.OnWillStartRenderingFrameListener listener) {
onWillStartRenderingFrameList.add(listener);
}
Expand Down Expand Up @@ -382,6 +406,7 @@ void clear() {
onWillStartLoadingMapListenerList.clear();
onDidFinishLoadingMapListenerList.clear();
onDidFailLoadingMapListenerList.clear();
onDidFailLoadingTileListenerList.clear();
onWillStartRenderingFrameList.clear();
onDidFinishRenderingFrameList.clear();
onWillStartRenderingMapListenerList.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,24 @@ public void removeOnDidFailLoadingMapListener(@NonNull OnDidFailLoadingMapListen
mapChangeReceiver.removeOnDidFailLoadingMapListener(listener);
}

/**
* Set a callback that's invoked when the tile failed to load.
*
* @param listener The callback that's invoked when the tile failed to load
*/
public void addOnDidFailLoadingTileListener(@NonNull OnDidFailLoadingTileListener listener) {
mapChangeReceiver.addOnDidFailLoadingTileListener(listener);
}

/**
* Set a callback that's invoked when the tile failed to load.
*
* @param listener The callback that's invoked when the tile failed to load
*/
public void removeOnDidFailLoadingTileListener(@NonNull OnDidFailLoadingTileListener listener) {
mapChangeReceiver.removeOnDidFailLoadingTileListener(listener);
}

/**
* Set a callback that's invoked when the map will start rendering a frame.
*
Expand Down Expand Up @@ -1022,6 +1040,21 @@ public interface OnDidFailLoadingMapListener {
void onDidFailLoadingMap(String errorMessage);
}

/**
* Interface definition for a callback to be invoked when the tile failed to load.
* <p>
* {@link MapView#addOnDidFailLoadingTileListener(OnDidFailLoadingTileListener)}
* </p>
*/
public interface OnDidFailLoadingTileListener {
/**
* Called when the tile failed to load.
*
* @param errorMessage The reason why the tile failed to load
*/
void onDidFailLoadingTile(String errorMessage);
}

/**
* Interface definition for a callback to be invoked when the map will start rendering a frame.
* <p>
Expand Down Expand Up @@ -1053,7 +1086,7 @@ public interface OnDidFinishRenderingFrameListener {
/**
* Interface definition for a callback to be invoked when the map will start rendering the map.
* <p>
* {@link MapView#addOnDidFailLoadingMapListener(OnDidFailLoadingMapListener)}
* {@link MapView#addOnWillStartRenderingMapListener(OnWillStartRenderingMapListener)}
* </p>
*/
public interface OnWillStartRenderingMapListener {
Expand Down Expand Up @@ -1098,7 +1131,7 @@ public interface OnDidBecomeIdleListener {
/**
* Interface definition for a callback to be invoked when the map has loaded the style.
* <p>
* {@link MapView#addOnDidFailLoadingMapListener(OnDidFailLoadingMapListener)}
* {@link MapView#addOnDidFinishLoadingStyleListener(OnDidFinishLoadingStyleListener)}
* </p>
*/
public interface OnDidFinishLoadingStyleListener {
Expand All @@ -1111,7 +1144,7 @@ public interface OnDidFinishLoadingStyleListener {
/**
* Interface definition for a callback to be invoked when a map source has changed.
* <p>
* {@link MapView#addOnDidFailLoadingMapListener(OnDidFailLoadingMapListener)}
* {@link MapView#addOnSourceChangedListener(OnSourceChangedListener)}
* </p>
*/
public interface OnSourceChangedListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,13 @@ private void onDidFailLoadingMap(String error) {
}
}

@Keep
private void onDidFailLoadingTile(String error) {
if (stateCallback != null) {
stateCallback.onDidFailLoadingTile(error);
}
}

@Keep
private void onWillStartRenderingFrame() {
if (stateCallback != null) {
Expand Down Expand Up @@ -1645,6 +1652,8 @@ interface StateCallback extends StyleCallback {

void onDidFailLoadingMap(String error);

void onDidFailLoadingTile(String error);

void onWillStartRenderingFrame();

void onDidFinishRenderingFrame(boolean fully);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class MapChangeReceiverTest {
@Mock
private MapView.OnDidFailLoadingMapListener onDidFailLoadingMapListener;

@Mock
private MapView.OnDidFailLoadingTileListener onDidFailLoadingTileListener;

@Mock
private MapView.OnWillStartRenderingFrameListener onWillStartRenderingFrameListener;

Expand Down Expand Up @@ -314,6 +317,36 @@ public void testOnDidFailLoadingMapListener() {
}
}

@Test
public void testOnDidFailLoadingTileListener() {
mapChangeEventManager.addOnDidFailLoadingTileListener(onDidFailLoadingTileListener);
mapChangeEventManager.onDidFailLoadingTile(TEST_STRING);
verify(onDidFailLoadingTileListener).onDidFailLoadingTile(TEST_STRING);
mapChangeEventManager.removeOnDidFailLoadingTileListener(onDidFailLoadingTileListener);
mapChangeEventManager.onDidFailLoadingTile(TEST_STRING);
verify(onDidFailLoadingTileListener).onDidFailLoadingTile(TEST_STRING);

mapChangeEventManager.addOnDidFailLoadingTileListener(onDidFailLoadingTileListener);
Logger.setLoggerDefinition(loggerDefinition);
Exception exc = new RuntimeException();
doThrow(exc).when(onDidFailLoadingTileListener).onDidFailLoadingTile(TEST_STRING);
try {
mapChangeEventManager.onDidFailLoadingTile(TEST_STRING);
Assert.fail("The exception should've been re-thrown.");
} catch (RuntimeException throwable) {
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
}

Error err = new ExecutionError("", new Error());
doThrow(err).when(onDidFailLoadingTileListener).onDidFailLoadingTile(TEST_STRING);
try {
mapChangeEventManager.onDidFailLoadingTile(TEST_STRING);
Assert.fail("The exception should've been re-thrown.");
} catch (ExecutionError throwable) {
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
}
}

@Test
public void testOnWillStartRenderingFrameListener() {
mapChangeEventManager.addOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener);
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ext {
ktlint : '0.34.0',
commonsIO : '2.6',
mapboxSdkVersions: '1.1.0',
mapboxSdkCore : '5.2.2',
mapboxSdkCore : '5.3.0',
mapboxSdkRegistryPlugin: '0.3.0',
okio : '2.4.3'
]
Expand Down

0 comments on commit daafc0b

Please sign in to comment.