Show dialog when permission was denied for good

This commit is contained in:
Torsten Grote
2021-03-09 15:21:57 -03:00
parent a9c4669c75
commit 539730f8ec
2 changed files with 18 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.android.conversation; package org.briarproject.briar.android.conversation;
import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.content.Context; import android.content.Context;
@@ -25,9 +26,11 @@ import androidx.annotation.UiThread;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import static android.Manifest.permission.ACCESS_FINE_LOCATION; import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static androidx.core.app.ActivityCompat.shouldShowRequestPermissionRationale;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger; import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logException; import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.android.util.UiUtils.getGoToSettingsListener;
class BluetoothConnecter { class BluetoothConnecter {
@@ -63,7 +66,7 @@ class BluetoothConnecter {
} }
@UiThread @UiThread
void onLocationPermissionResult(boolean result, void onLocationPermissionResult(Activity activity, boolean result,
ActivityResultLauncher<Integer> bluetoothDiscoverableRequest) { ActivityResultLauncher<Integer> bluetoothDiscoverableRequest) {
if (result) { if (result) {
if (isBluetoothSupported()) { if (isBluetoothSupported()) {
@@ -71,9 +74,11 @@ class BluetoothConnecter {
} else { } else {
showToast(R.string.toast_connect_via_bluetooth_error); showToast(R.string.toast_connect_via_bluetooth_error);
} }
} else { } else if (shouldShowRequestPermissionRationale(activity,
// could also show the same dialog as KeyAgreementActivity ACCESS_FINE_LOCATION)) {
showToast(R.string.permission_location_denied_body); showToast(R.string.permission_location_denied_body);
} else {
showRationale(activity);
} }
} }
@@ -81,6 +86,15 @@ class BluetoothConnecter {
return bt != null && bluetoothPlugin != null; return bt != null && bluetoothPlugin != null;
} }
private void showRationale(Context ctx) {
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme)
.setTitle(R.string.permission_location_title)
.setMessage(R.string.permission_location_request_body)
.setPositiveButton(R.string.ok, getGoToSettingsListener(ctx))
.setNegativeButton(R.string.cancel, null)
.show();
}
@UiThread @UiThread
void onBluetoothDiscoverable(boolean result, ContactItem contact) { void onBluetoothDiscoverable(boolean result, ContactItem contact) {
if (result) { if (result) {

View File

@@ -225,7 +225,7 @@ public class ConversationActivity extends BriarActivity
private final ActivityResultLauncher<String> permissionRequest = private final ActivityResultLauncher<String> permissionRequest =
registerForActivityResult(new RequestPermission(), result -> { registerForActivityResult(new RequestPermission(), result -> {
BluetoothConnecter bc = viewModel.getBluetoothConnecter(); BluetoothConnecter bc = viewModel.getBluetoothConnecter();
bc.onLocationPermissionResult(result, bc.onLocationPermissionResult(this, result,
bluetoothDiscoverableRequest); bluetoothDiscoverableRequest);
}); });