Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[offline][android] Add setOffline method #537

Merged
merged 3 commits into from
Mar 30, 2021
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 @@ -5,7 +5,7 @@

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import android.content.Context;
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -64,14 +64,17 @@ public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
installOfflineMapTiles(tilesDb);
result.success(null);
break;
case "setOffline":
boolean offline = methodCall.argument("offline");
ConnectivityReceiver.instance(context).setConnected(offline ? false : null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be offline ? false : true or simply !offline

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConnectivityReceiver.setConnected is an override for the device state (src)

Calling setConnected(true) will cause ConnectivityReceiver to think its permanently online.

The intention of this method is to allow forcing offline mode. The alternative would be to expose setConnected(bool?), but I think that's a little confusing unless you read the docs and I can't think of many use-cases for forcing online outside of testing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that makes sense - LGTM

result.success(null);
break;
case "mergeOfflineRegions":
OfflineManagerUtils.mergeRegions(result, context, methodCall.argument("path"));
break;

case "setOfflineTileCountLimit":
OfflineManagerUtils.setOfflineTileCountLimit(result, context, methodCall.<Number>argument("limit").longValue());
break;

case "downloadOfflineRegion":
// Get args from caller
Map<String, Object> definitionMap = (Map<String, Object>) methodCall.argument("definition");
Expand Down
12 changes: 12 additions & 0 deletions lib/src/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ Future<void> installOfflineMapTiles(String tilesDb) async {
);
}

Future<dynamic> setOffline(
bool offline, {
String accessToken,
}) =>
_globalChannel.invokeMethod(
'setOffline',
<String, dynamic>{
'offline': offline,
'accessToken': accessToken,
},
);

Future<List<OfflineRegion>> mergeOfflineRegions(
String path, {
String accessToken,
Expand Down