Skip to content

Commit

Permalink
Update location request flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Agontuk committed Aug 24, 2019
1 parent 798e6f6 commit fdeca45
Showing 1 changed file with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,57 @@ public class RNFusedLocationModule extends ReactContextBaseJavaModule {
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) {
if (requestCode == REQUEST_SETTINGS_SINGLE_UPDATE) {
if (resultCode == Activity.RESULT_OK || mForceRequestLocation) {
if (resultCode == Activity.RESULT_OK) {
// Location settings changed successfully, request user location.
getUserLocation();
} else if (resultCode == Activity.RESULT_CANCELED) {
return;
}

if (!mForceRequestLocation) {
invokeError(
LocationError.SETTINGS_NOT_SATISFIED.getValue(),
"Location settings are not satisfied.",
true
);
return;
}

if (!LocationUtils.isLocationEnabled(getContext())) {
invokeError(
LocationError.POSITION_UNAVAILABLE.getValue(),
"No location provider available.",
true
);
return;
}

getUserLocation();
} else if (requestCode == REQUEST_SETTINGS_CONTINUOUS_UPDATE) {
if (resultCode == Activity.RESULT_OK || mForceRequestLocation) {
if (resultCode == Activity.RESULT_OK ) {
// Location settings changed successfully, request user location.
getLocationUpdates();
} else if (resultCode == Activity.RESULT_CANCELED) {
return;
}

if (!mForceRequestLocation) {
invokeError(
LocationError.SETTINGS_NOT_SATISFIED.getValue(),
"Location settings are not satisfied.",
false
);
return;
}

if (!LocationUtils.isLocationEnabled(getContext())) {
invokeError(
LocationError.POSITION_UNAVAILABLE.getValue(),
"No location provider available.",
false
);
return;
}

getLocationUpdates();
}
}
};
Expand Down Expand Up @@ -127,15 +157,6 @@ public void getCurrentPosition(ReadableMap options, final Callback success, fina
return;
}

if (!LocationUtils.isLocationEnabled(context)) {
invokeError(
LocationError.POSITION_UNAVAILABLE.getValue(),
"No location provider available.",
true
);
return;
}

if (!LocationUtils.isGooglePlayServicesAvailable(context)) {
invokeError(
LocationError.PLAY_SERVICE_NOT_AVAILABLE.getValue(),
Expand Down

0 comments on commit fdeca45

Please sign in to comment.