mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Address review feedback for Connect via Bluetooth UI
This commit is contained in:
@@ -11,5 +11,5 @@ public interface FeatureFlags {
|
||||
|
||||
boolean shouldEnableDisappearingMessages();
|
||||
|
||||
boolean shouldEnableConnectViewBluetooth();
|
||||
boolean shouldEnableConnectViaBluetooth();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class BrambleCoreIntegrationTestModule {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldEnableConnectViewBluetooth() {
|
||||
public boolean shouldEnableConnectViaBluetooth() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -300,7 +300,7 @@ public class AppModule {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldEnableConnectViewBluetooth() {
|
||||
public boolean shouldEnableConnectViaBluetooth() {
|
||||
return IS_DEBUG_BUILD;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -110,14 +110,15 @@ class BluetoothConnecter {
|
||||
}
|
||||
|
||||
boolean areRequirementsFulfilled(Context ctx,
|
||||
ActivityResultLauncher<String> permissionRequest) {
|
||||
ActivityResultLauncher<String> permissionRequest,
|
||||
Runnable onLocationDenied) {
|
||||
boolean permissionGranted =
|
||||
SDK_INT < 23 || locationPermission == Permission.GRANTED;
|
||||
boolean locationEnabled = isLocationEnabled(ctx);
|
||||
if (permissionGranted && locationEnabled) return true;
|
||||
|
||||
if (locationPermission == Permission.PERMANENTLY_DENIED) {
|
||||
showDenialDialog(ctx);
|
||||
showDenialDialog(ctx, onLocationDenied);
|
||||
} else if (locationPermission == Permission.SHOW_RATIONALE) {
|
||||
showRationale(ctx, permissionRequest);
|
||||
} else if (!locationEnabled) {
|
||||
@@ -126,12 +127,13 @@ class BluetoothConnecter {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showDenialDialog(Context ctx) {
|
||||
private void showDenialDialog(Context ctx, Runnable onLocationDenied) {
|
||||
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme)
|
||||
.setTitle(R.string.permission_location_title)
|
||||
.setMessage(R.string.permission_location_denied_body)
|
||||
.setPositiveButton(R.string.ok, getGoToSettingsListener(ctx))
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setNegativeButton(R.string.cancel, (v, d) ->
|
||||
onLocationDenied.run())
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -103,13 +103,14 @@ public class BluetoothConnecterDialogFragment extends DialogFragment {
|
||||
// to prevent it from automatically dismissing the dialog.
|
||||
// The dialog is shown in onStart(), so we set the listener here later.
|
||||
AlertDialog dialog = (AlertDialog) getDialog();
|
||||
Button positiveButton = (Button) dialog.getButton(BUTTON_POSITIVE);
|
||||
Button positiveButton = dialog.getButton(BUTTON_POSITIVE);
|
||||
positiveButton.setOnClickListener(this::onStartClicked);
|
||||
}
|
||||
|
||||
private void onStartClicked(View v) {
|
||||
// The dialog starts a permission request which comes back as true
|
||||
// if the permission is already granted. So it is a generic entry point.
|
||||
// if the permission is already granted.
|
||||
// So we can use the request as a generic entry point to the whole flow.
|
||||
permissionRequest.launch(ACCESS_FINE_LOCATION);
|
||||
}
|
||||
|
||||
@@ -117,8 +118,16 @@ public class BluetoothConnecterDialogFragment extends DialogFragment {
|
||||
Activity a = requireActivity();
|
||||
// update permission result in BluetoothConnecter
|
||||
bluetoothConnecter.onLocationPermissionResult(a, result);
|
||||
// what to do when the user denies granting the location permission
|
||||
Runnable onLocationPermissionDenied = () -> {
|
||||
Toast.makeText(requireContext(),
|
||||
R.string.toast_connect_via_bluetooth_no_location_permission,
|
||||
LENGTH_LONG).show();
|
||||
dismiss();
|
||||
};
|
||||
// if requirements are fulfilled, request Bluetooth discoverability
|
||||
if (bluetoothConnecter.areRequirementsFulfilled(a, permissionRequest)) {
|
||||
if (bluetoothConnecter.areRequirementsFulfilled(a, permissionRequest,
|
||||
onLocationPermissionDenied)) {
|
||||
bluetoothDiscoverableRequest.launch(120); // for 2min
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ public class ConversationActivity extends BriarActivity
|
||||
this::showIntroductionOnboarding);
|
||||
}
|
||||
});
|
||||
if (!featureFlags.shouldEnableConnectViewBluetooth()) {
|
||||
if (!featureFlags.shouldEnableConnectViaBluetooth()) {
|
||||
menu.findItem(R.id.action_connect_via_bluetooth).setVisible(false);
|
||||
}
|
||||
// enable alias and bluetooth action once available
|
||||
|
||||
@@ -171,8 +171,9 @@
|
||||
<string name="menu_item_disappearing_messages">Disappearing messages</string>
|
||||
<string name="menu_item_connect_via_bluetooth">Connect via Bluetooth</string>
|
||||
<string name="dialog_title_connect_via_bluetooth">Connect via Bluetooth</string>
|
||||
<string name="dialog_message_connect_via_bluetooth">Your contact needs to be in close proximity for this to work. They need to press start at the same time as you and confirm the following system dialog.</string>
|
||||
<string name="toast_connect_via_bluetooth_not_discoverable">Can not continue without Bluetooth</string>
|
||||
<string name="dialog_message_connect_via_bluetooth">Your contact needs to be nearby for this to work.\n\nYou and your contact should both press \"Start\" at the same time.</string>
|
||||
<string name="toast_connect_via_bluetooth_not_discoverable">Cannot continue without Bluetooth</string>
|
||||
<string name="toast_connect_via_bluetooth_no_location_permission">Cannot continue without location permission</string>
|
||||
<string name="toast_connect_via_bluetooth_start">Connecting via Bluetooth…</string>
|
||||
<string name="toast_connect_via_bluetooth_success">Successfully connected via Bluetooth</string>
|
||||
<string name="toast_connect_via_bluetooth_error">Could not connect via Bluetooth</string>
|
||||
|
||||
@@ -94,6 +94,6 @@ internal class HeadlessModule(private val appDir: File) {
|
||||
override fun shouldEnableImageAttachments() = false
|
||||
override fun shouldEnableProfilePictures() = false
|
||||
override fun shouldEnableDisappearingMessages() = false
|
||||
override fun shouldEnableConnectViewBluetooth() = false
|
||||
override fun shouldEnableConnectViaBluetooth() = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ internal class HeadlessTestModule(private val appDir: File) {
|
||||
override fun shouldEnableImageAttachments() = false
|
||||
override fun shouldEnableProfilePictures() = false
|
||||
override fun shouldEnableDisappearingMessages() = false
|
||||
override fun shouldEnableConnectViewBluetooth() = false
|
||||
override fun shouldEnableConnectViaBluetooth() = false
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
Reference in New Issue
Block a user