[android] Don't stop location until Stop button is pressed (#3442)

* [android] Don't stop location until Stop button is pressed

The app displays "Current location is unknown. Do you want to continue
detection your location?" dialog after if location wasn't found after
30 seconds. Before this patch, we disabled GPS even before the user
pressed "Stop". With this patch, the app continue to search for location
while the dialog is displayed, until "Stop" button is clicked explicitly.

Signed-off-by: Roman Tsisyk <roman@tsisyk.com>

* Update android/src/com/mapswithme/maps/MwmActivity.java

Signed-off-by: Roman Tsisyk <roman@tsisyk.com>
Co-authored-by: Alexander Borsuk <170263+biodranik@users.noreply.github.com>
This commit is contained in:
Roman Tsisyk 2022-09-20 00:58:32 +03:00 committed by GitHub
parent 3e684305ee
commit 140e5fca59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 28 deletions

View file

@ -29,6 +29,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.mapswithme.maps.Framework.PlacePageActivationListener;
import com.mapswithme.maps.api.Const;
import com.mapswithme.maps.background.AppBackgroundTracker;
@ -1651,6 +1652,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public void onLocationUpdated(@NonNull Location location)
{
if (mLocationErrorDialog != null && mLocationErrorDialog.isShowing())
mLocationErrorDialog.dismiss();
if (!RoutingController.get().isNavigating())
return;
@ -1681,6 +1685,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(R.string.enable_location_services)
.setMessage(R.string.location_is_disabled_long_text)
.setOnDismissListener(dialog -> mLocationErrorDialog = null)
.setOnCancelListener(dialog -> mLocationErrorDialogAnnoying = true)
.setNegativeButton(R.string.close, (dialog, which) -> mLocationErrorDialogAnnoying = true);
final Intent intent = Utils.makeSystemLocationSettingIntent(this);
@ -1697,7 +1702,28 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public void onLocationNotFound()
{
showLocationNotFoundDialog();
if (mLocationErrorDialogAnnoying || (mLocationErrorDialog != null && mLocationErrorDialog.isShowing()))
return;
final String message = String.format("%s\n\n%s", getString(R.string.current_location_unknown_message),
getString(R.string.current_location_unknown_title));
mLocationErrorDialog = new AlertDialog.Builder(this)
.setMessage(message)
.setOnDismissListener(dialog -> mLocationErrorDialog = null)
.setNegativeButton(R.string.current_location_unknown_stop_button, (dialog, which) ->
{
LocationHelper.INSTANCE.setStopLocationUpdateByUser(true);
LocationHelper.INSTANCE.stop();
})
.setPositiveButton(R.string.current_location_unknown_continue_button, (dialog, which) ->
{
if (!LocationHelper.INSTANCE.isActive())
LocationHelper.INSTANCE.start();
LocationHelper.INSTANCE.switchToNextMode();
// TODO(AB): Leads to inconsistent UX: dialog won't appear later if user cancels and starts location search again.
mLocationErrorDialogAnnoying = true;
})
.show();
}
@Override
@ -1705,32 +1731,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
}
private void showLocationNotFoundDialog()
{
String message = String.format("%s\n\n%s", getString(R.string.current_location_unknown_message),
getString(R.string.current_location_unknown_title));
DialogInterface.OnClickListener stopClickListener = (dialog, which) ->
{
LocationHelper.INSTANCE.setStopLocationUpdateByUser(true);
LocationHelper.INSTANCE.stop();
};
DialogInterface.OnClickListener continueClickListener = (dialog, which) ->
{
if (!LocationHelper.INSTANCE.isActive())
LocationHelper.INSTANCE.start();
LocationHelper.INSTANCE.switchToNextMode();
};
new AlertDialog.Builder(this)
.setMessage(message)
.setNegativeButton(R.string.current_location_unknown_stop_button, stopClickListener)
.setPositiveButton(R.string.current_location_unknown_continue_button, continueClickListener)
.setCancelable(false)
.show();
}
@Override
public void onTransit(boolean foreground)
{

View file

@ -151,7 +151,6 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
private final LocationState.LocationPendingTimeoutListener mLocationPendingTimeoutListener = () -> {
if (mActive)
{
stop();
if (PermissionsUtils.isLocationGranted(mContext) && LocationUtils.areLocationServicesTurnedOn(mContext))
notifyLocationNotFound();
}