From 11f95114955fdcdfb48ba1e5211a5594c96c5cd5 Mon Sep 17 00:00:00 2001 From: Vishan Seru Date: Tue, 5 Sep 2017 20:53:55 +0530 Subject: [PATCH] When location permission request is denied in NearbyActivity, instead of the NoPermissionsFragment, now an AlertDialog is shown providing options to either retry the permission request or cancel and quit the activity. --- .../nrw/commons/nearby/NearbyActivity.java | 24 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java index d58eb3566..cd08840f9 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java @@ -2,6 +2,7 @@ package fr.free.nrw.commons.nearby; import android.Manifest; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.location.LocationManager; @@ -158,15 +159,30 @@ public class NearbyActivity extends NavigationBaseActivity { if (progressBar != null) { progressBar.setVisibility(View.GONE); } - FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); - Fragment noPermissionsFragment = new NoPermissionsFragment(); - fragmentTransaction.replace(R.id.container, noPermissionsFragment); - fragmentTransaction.commit(); + + showLocationPermissionDeniedErrorDialog(); } } } } + private void showLocationPermissionDeniedErrorDialog() { + new AlertDialog.Builder(this) + .setMessage(R.string.nearby_needs_permissions) + .setCancelable(false) + .setPositiveButton(R.string.give_permission, (dialog, which) -> { + //will ask for the location permission again + checkLocationPermission(); + }) + .setNegativeButton(R.string.cancel, (dialog, which) -> { + //dismiss dialog and finish activity + dialog.cancel(); + finish(); + }) + .create() + .show(); + } + private void checkGps() { LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c24891222..d2fe29216 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -203,5 +203,6 @@ Tap this message (or hit back) to skip this step. Error while caching pictures A unique descriptive title for the file, which will serve as a filename. You may use plain language with spaces. Do not include the file extension Please describe the media as much as possible: Where was it taken? What does it show? What is the context? Please describe the objects or persons. Reveal information that can not be easily guessed, for instance the time of day if it is a landscape. If the media shows something unusual, please explain what makes it unusual. + Give permission