Verified Commit ea528071 authored by Torsten Grote's avatar Torsten Grote
Browse files

Address review feedback for Connect via Bluetooth UI

parent 0b89d29c
Pipeline #6462 skipped with stage
...@@ -11,5 +11,5 @@ public interface FeatureFlags { ...@@ -11,5 +11,5 @@ public interface FeatureFlags {
boolean shouldEnableDisappearingMessages(); boolean shouldEnableDisappearingMessages();
boolean shouldEnableConnectViewBluetooth(); boolean shouldEnableConnectViaBluetooth();
} }
...@@ -40,7 +40,7 @@ public class BrambleCoreIntegrationTestModule { ...@@ -40,7 +40,7 @@ public class BrambleCoreIntegrationTestModule {
} }
@Override @Override
public boolean shouldEnableConnectViewBluetooth() { public boolean shouldEnableConnectViaBluetooth() {
return true; return true;
} }
}; };
......
...@@ -300,7 +300,7 @@ public class AppModule { ...@@ -300,7 +300,7 @@ public class AppModule {
} }
@Override @Override
public boolean shouldEnableConnectViewBluetooth() { public boolean shouldEnableConnectViaBluetooth() {
return IS_DEBUG_BUILD; return IS_DEBUG_BUILD;
} }
}; };
......
...@@ -110,14 +110,15 @@ class BluetoothConnecter { ...@@ -110,14 +110,15 @@ class BluetoothConnecter {
} }
boolean areRequirementsFulfilled(Context ctx, boolean areRequirementsFulfilled(Context ctx,
ActivityResultLauncher<String> permissionRequest) { ActivityResultLauncher<String> permissionRequest,
Runnable onLocationDenied) {
boolean permissionGranted = boolean permissionGranted =
SDK_INT < 23 || locationPermission == Permission.GRANTED; SDK_INT < 23 || locationPermission == Permission.GRANTED;
boolean locationEnabled = isLocationEnabled(ctx); boolean locationEnabled = isLocationEnabled(ctx);
if (permissionGranted && locationEnabled) return true; if (permissionGranted && locationEnabled) return true;
if (locationPermission == Permission.PERMANENTLY_DENIED) { if (locationPermission == Permission.PERMANENTLY_DENIED) {
showDenialDialog(ctx); showDenialDialog(ctx, onLocationDenied);
} else if (locationPermission == Permission.SHOW_RATIONALE) { } else if (locationPermission == Permission.SHOW_RATIONALE) {
showRationale(ctx, permissionRequest); showRationale(ctx, permissionRequest);
} else if (!locationEnabled) { } else if (!locationEnabled) {
...@@ -126,12 +127,13 @@ class BluetoothConnecter { ...@@ -126,12 +127,13 @@ class BluetoothConnecter {
return false; return false;
} }
private void showDenialDialog(Context ctx) { private void showDenialDialog(Context ctx, Runnable onLocationDenied) {
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme) new AlertDialog.Builder(ctx, R.style.BriarDialogTheme)
.setTitle(R.string.permission_location_title) .setTitle(R.string.permission_location_title)
.setMessage(R.string.permission_location_denied_body) .setMessage(R.string.permission_location_denied_body)
.setPositiveButton(R.string.ok, getGoToSettingsListener(ctx)) .setPositiveButton(R.string.ok, getGoToSettingsListener(ctx))
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, (v, d) ->
onLocationDenied.run())
.show(); .show();
} }
......
...@@ -103,13 +103,14 @@ public class BluetoothConnecterDialogFragment extends DialogFragment { ...@@ -103,13 +103,14 @@ public class BluetoothConnecterDialogFragment extends DialogFragment {
// to prevent it from automatically dismissing the dialog. // to prevent it from automatically dismissing the dialog.
// The dialog is shown in onStart(), so we set the listener here later. // The dialog is shown in onStart(), so we set the listener here later.
AlertDialog dialog = (AlertDialog) getDialog(); AlertDialog dialog = (AlertDialog) getDialog();
Button positiveButton = (Button) dialog.getButton(BUTTON_POSITIVE); Button positiveButton = dialog.getButton(BUTTON_POSITIVE);
positiveButton.setOnClickListener(this::onStartClicked); positiveButton.setOnClickListener(this::onStartClicked);
} }
private void onStartClicked(View v) { private void onStartClicked(View v) {
// The dialog starts a permission request which comes back as true // 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); permissionRequest.launch(ACCESS_FINE_LOCATION);
} }
...@@ -117,8 +118,16 @@ public class BluetoothConnecterDialogFragment extends DialogFragment { ...@@ -117,8 +118,16 @@ public class BluetoothConnecterDialogFragment extends DialogFragment {
Activity a = requireActivity(); Activity a = requireActivity();
// update permission result in BluetoothConnecter // update permission result in BluetoothConnecter
bluetoothConnecter.onLocationPermissionResult(a, result); 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 requirements are fulfilled, request Bluetooth discoverability
if (bluetoothConnecter.areRequirementsFulfilled(a, permissionRequest)) { if (bluetoothConnecter.areRequirementsFulfilled(a, permissionRequest,
onLocationPermissionDenied)) {
bluetoothDiscoverableRequest.launch(120); // for 2min bluetoothDiscoverableRequest.launch(120); // for 2min
} }
} }
......
...@@ -371,7 +371,7 @@ public class ConversationActivity extends BriarActivity ...@@ -371,7 +371,7 @@ public class ConversationActivity extends BriarActivity
this::showIntroductionOnboarding); this::showIntroductionOnboarding);
} }
}); });
if (!featureFlags.shouldEnableConnectViewBluetooth()) { if (!featureFlags.shouldEnableConnectViaBluetooth()) {
menu.findItem(R.id.action_connect_via_bluetooth).setVisible(false); menu.findItem(R.id.action_connect_via_bluetooth).setVisible(false);
} }
// enable alias and bluetooth action once available // enable alias and bluetooth action once available
......
...@@ -171,8 +171,9 @@ ...@@ -171,8 +171,9 @@
<string name="menu_item_disappearing_messages">Disappearing messages</string> <string name="menu_item_disappearing_messages">Disappearing messages</string>
<string name="menu_item_connect_via_bluetooth">Connect via Bluetooth</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_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="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">Can not continue without Bluetooth</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_start">Connecting via Bluetooth…</string>
<string name="toast_connect_via_bluetooth_success">Successfully connected 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> <string name="toast_connect_via_bluetooth_error">Could not connect via Bluetooth</string>
......
...@@ -94,6 +94,6 @@ internal class HeadlessModule(private val appDir: File) { ...@@ -94,6 +94,6 @@ internal class HeadlessModule(private val appDir: File) {
override fun shouldEnableImageAttachments() = false override fun shouldEnableImageAttachments() = false
override fun shouldEnableProfilePictures() = false override fun shouldEnableProfilePictures() = false
override fun shouldEnableDisappearingMessages() = false override fun shouldEnableDisappearingMessages() = false
override fun shouldEnableConnectViewBluetooth() = false override fun shouldEnableConnectViaBluetooth() = false
} }
} }
...@@ -82,7 +82,7 @@ internal class HeadlessTestModule(private val appDir: File) { ...@@ -82,7 +82,7 @@ internal class HeadlessTestModule(private val appDir: File) {
override fun shouldEnableImageAttachments() = false override fun shouldEnableImageAttachments() = false
override fun shouldEnableProfilePictures() = false override fun shouldEnableProfilePictures() = false
override fun shouldEnableDisappearingMessages() = false override fun shouldEnableDisappearingMessages() = false
override fun shouldEnableConnectViewBluetooth() = false override fun shouldEnableConnectViaBluetooth() = false
} }
@Provides @Provides
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment