mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Show dialog when permission was denied for good
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user