mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Add STARTING_STOPPING state, use flags for reasons disabled.
This commit is contained in:
@@ -53,6 +53,7 @@ import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.DISABLED;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.INACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_BLUETOOTH_DISCOVERABLE;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PERMISSION_CAMERA_LOCATION;
|
||||
|
||||
@@ -258,7 +259,9 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
private boolean shouldEnableWifi() {
|
||||
if (hasEnabledWifi) return false;
|
||||
Plugin p = pluginManager.getPlugin(LanTcpConstants.ID);
|
||||
return p != null && p.getState() == DISABLED;
|
||||
if (p == null) return false;
|
||||
State state = p.getState();
|
||||
return state == STARTING_STOPPING || state == DISABLED;
|
||||
}
|
||||
|
||||
private void requestBluetoothDiscoverable() {
|
||||
@@ -284,7 +287,9 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
if (bluetoothDecision != BluetoothDecision.ACCEPTED) return false;
|
||||
if (hasEnabledBluetooth) return false;
|
||||
Plugin p = pluginManager.getPlugin(BluetoothConstants.ID);
|
||||
return p != null && p.getState() == DISABLED;
|
||||
if (p == null) return false;
|
||||
State state = p.getState();
|
||||
return state == STARTING_STOPPING || state == DISABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ import static java.util.concurrent.TimeUnit.DAYS;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.DISABLED;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
@@ -194,7 +194,7 @@ public class NavDrawerViewModel extends AndroidViewModel
|
||||
|
||||
private State getTransportState(TransportId id) {
|
||||
Plugin plugin = pluginManager.getPlugin(id);
|
||||
return plugin == null ? DISABLED : plugin.getState();
|
||||
return plugin == null ? STARTING_STOPPING : plugin.getState();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -17,6 +17,7 @@ import static androidx.core.content.ContextCompat.getColor;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.DISABLED;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ENABLING;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.briar.android.navdrawer.NavDrawerViewModel.TRANSPORT_IDS;
|
||||
|
||||
class PluginViewController {
|
||||
@@ -38,10 +39,13 @@ class PluginViewController {
|
||||
for (TransportId t : TRANSPORT_IDS) {
|
||||
// a OnCheckedChangeListener would get triggered on programmatic updates
|
||||
SwitchCompat switchCompat = getSwitch(t);
|
||||
switchCompat.setOnClickListener(buttonView ->
|
||||
// TODO check reason first and change settings if needed
|
||||
viewModel.setPluginEnabled(t, switchCompat.isChecked())
|
||||
);
|
||||
switchCompat.setOnClickListener(buttonView -> {
|
||||
// TODO check reason first and change settings if needed
|
||||
viewModel.setPluginEnabled(t, switchCompat.isChecked());
|
||||
// Revert the switch to its previous state until the plugin
|
||||
// changes its state
|
||||
switchCompat.toggle();
|
||||
});
|
||||
viewModel.getPluginState(t)
|
||||
.observe(owner, state -> stateUpdate(t, state));
|
||||
}
|
||||
@@ -60,7 +64,9 @@ class PluginViewController {
|
||||
}
|
||||
|
||||
private void updateSwitch(SwitchCompat switchCompat, State state) {
|
||||
switchCompat.setChecked(state != DISABLED);
|
||||
boolean checked = state != STARTING_STOPPING && state != DISABLED;
|
||||
switchCompat.setChecked(checked);
|
||||
switchCompat.setEnabled(state != STARTING_STOPPING);
|
||||
}
|
||||
|
||||
private ImageView getIcon(TransportId id) {
|
||||
|
||||
Reference in New Issue
Block a user