WIP Abort discovering when user wants add-nearby

parent 4a631a0e
Pipeline #6467 skipped with stage
......@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.Toast;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
......@@ -20,6 +21,7 @@ import androidx.activity.result.contract.ActivityResultContracts.RequestMultiple
import androidx.lifecycle.ViewModelProvider;
import static android.view.View.FOCUS_DOWN;
import static android.widget.Toast.LENGTH_LONG;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
......@@ -73,6 +75,13 @@ public class AddNearbyContactIntroFragment extends BaseFragment {
scrollView = v.findViewById(R.id.scrollView);
View button = v.findViewById(R.id.continueButton);
button.setOnClickListener(view -> {
if (viewModel.isDiscovering()) {
Toast.makeText(requireActivity(),
// TODO
"Already doing BT-connect, try again later",
LENGTH_LONG).show();
return;
}
viewModel.onContinueClicked();
if (permissionManager.checkPermissions()) {
viewModel.showQrCodeFragmentIfAllowed();
......
......@@ -44,6 +44,7 @@ import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
import org.briarproject.bramble.api.system.AndroidExecutor;
import org.briarproject.bramble.plugin.bluetooth.BluetoothPlugin;
import org.briarproject.briar.R;
import org.briarproject.briar.android.contact.add.nearby.AddContactState.ContactExchangeFinished;
import org.briarproject.briar.android.contact.add.nearby.AddContactState.ContactExchangeResult.Error;
......@@ -149,7 +150,9 @@ class AddNearbyContactViewModel extends AndroidViewModel
@Nullable
private final BluetoothAdapter bt;
@Nullable
private final Plugin wifiPlugin, bluetoothPlugin;
private final Plugin wifiPlugin;
@Nullable
private final BluetoothPlugin bluetoothPlugin;
// UiThread
private BluetoothDecision bluetoothDecision = BluetoothDecision.UNKNOWN;
......@@ -195,7 +198,8 @@ class AddNearbyContactViewModel extends AndroidViewModel
this.connectionManager = connectionManager;
bt = BluetoothAdapter.getDefaultAdapter();
wifiPlugin = pluginManager.getPlugin(LanTcpConstants.ID);
bluetoothPlugin = pluginManager.getPlugin(BluetoothConstants.ID);
bluetoothPlugin = (BluetoothPlugin) pluginManager
.getPlugin(BluetoothConstants.ID);
qrCodeDecoder = new QrCodeDecoder(androidExecutor, ioExecutor, this);
eventBus.addListener(this);
IntentFilter filter = new IntentFilter(ACTION_SCAN_MODE_CHANGED);
......@@ -364,6 +368,14 @@ class AddNearbyContactViewModel extends AndroidViewModel
}
}
boolean isDiscovering() {
if (!isBluetoothSupported() || !bluetoothPlugin.isDiscovering()) {
return false;
}
bluetoothPlugin.stopDiscoverAndConnect();
return true;
}
@SuppressWarnings("StatementWithEmptyBody")
@UiThread
void showQrCodeFragmentIfAllowed() {
......
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