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;
import android.app.Activity;
import android.app.Application;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
@@ -25,9 +26,11 @@ import androidx.annotation.UiThread;
import androidx.appcompat.app.AlertDialog;
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.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.android.util.UiUtils.getGoToSettingsListener;
class BluetoothConnecter {
@@ -63,7 +66,7 @@ class BluetoothConnecter {
}
@UiThread
void onLocationPermissionResult(boolean result,
void onLocationPermissionResult(Activity activity, boolean result,
ActivityResultLauncher<Integer> bluetoothDiscoverableRequest) {
if (result) {
if (isBluetoothSupported()) {
@@ -71,9 +74,11 @@ class BluetoothConnecter {
} else {
showToast(R.string.toast_connect_via_bluetooth_error);
}
} else {
// could also show the same dialog as KeyAgreementActivity
} else if (shouldShowRequestPermissionRationale(activity,
ACCESS_FINE_LOCATION)) {
showToast(R.string.permission_location_denied_body);
} else {
showRationale(activity);
}
}
@@ -81,6 +86,15 @@ class BluetoothConnecter {
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
void onBluetoothDiscoverable(boolean result, ContactItem contact) {
if (result) {

View File

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