mirror of
https://github.com/status-im/react-native-mapbox-gl.git
synced 2026-08-31 21:11:09 +00:00
Added Offline Pack State to progress object and normalized Android RegionStatus output with iOS
This commit is contained in:
@@ -104,6 +104,7 @@ public class ReactNativeMapboxGLModule extends ReactContextBaseJavaModule {
|
||||
HashMap<String, Object> userTrackingMode = new HashMap<String, Object>();
|
||||
HashMap<String, Object> mapStyles = new HashMap<String, Object>();
|
||||
HashMap<String, Object> userLocationVerticalAlignment = new HashMap<String, Object>();
|
||||
HashMap<String, Object> offlinePackState = new HashMap<String, Object>();
|
||||
|
||||
// User tracking constants
|
||||
userTrackingMode.put("none", 0);
|
||||
@@ -124,6 +125,13 @@ public class ReactNativeMapboxGLModule extends ReactContextBaseJavaModule {
|
||||
userLocationVerticalAlignment.put("top", 1);
|
||||
userLocationVerticalAlignment.put("bottom", 2);
|
||||
|
||||
// Offline Pack State constants
|
||||
offlinePackState.put("unknown", 0);
|
||||
offlinePackState.put("inactive", 1);
|
||||
offlinePackState.put("active", 2);
|
||||
offlinePackState.put("complete", 3);
|
||||
offlinePackState.put("invalid", 4);
|
||||
|
||||
// Other constants
|
||||
constants.put("unknownResourceCount", Long.MAX_VALUE);
|
||||
constants.put("metricsEnabled", MapboxEventManager.getMapboxEventManager().isTelemetryEnabled());
|
||||
@@ -131,6 +139,7 @@ public class ReactNativeMapboxGLModule extends ReactContextBaseJavaModule {
|
||||
constants.put("userTrackingMode", userTrackingMode);
|
||||
constants.put("mapStyles", mapStyles);
|
||||
constants.put("userLocationVerticalAlignment", userLocationVerticalAlignment);
|
||||
constants.put("offlinePackState", offlinePackState);
|
||||
|
||||
return constants;
|
||||
}
|
||||
@@ -331,6 +340,7 @@ public class ReactNativeMapboxGLModule extends ReactContextBaseJavaModule {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
result.putInt("state", normalizeOfflineRegionState(status));
|
||||
result.putInt("countOfBytesCompleted", (int)status.getCompletedResourceSize());
|
||||
result.putInt("countOfResourcesCompleted", (int)status.getCompletedResourceCount());
|
||||
result.putInt("countOfResourcesExpected", (int)status.getRequiredResourceCount());
|
||||
@@ -339,6 +349,41 @@ public class ReactNativeMapboxGLModule extends ReactContextBaseJavaModule {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Normalizes offline region status state for the sake of parity with iOS for React Native
|
||||
* Essentially we force Android state to be the same as iOS state for ease of cross-platform development
|
||||
*
|
||||
* On iOS:
|
||||
* 0: Unknown
|
||||
* 1: Inactive
|
||||
* 2: Active
|
||||
* 3: Complete
|
||||
* 4: Invalid (iOS ONLY)
|
||||
*
|
||||
* On Android:
|
||||
* 0: Inactive (Complete is inactive, AND countOfResourcesCompleted == countOfResourcesExpected)
|
||||
* 1: Active
|
||||
*/
|
||||
static int normalizeOfflineRegionState(OfflineRegionStatus status) {
|
||||
int state = (int)status.getDownloadState();
|
||||
boolean isComplete = (boolean)status.isComplete();
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (isComplete) {
|
||||
state = 3;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
state = 2;
|
||||
break;
|
||||
default:
|
||||
state = 0;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
static String getOfflineRegionName(OfflineRegion region) {
|
||||
try {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(region.getMetadata());
|
||||
|
||||
Reference in New Issue
Block a user