Add STARTING_STOPPING state, use flags for reasons disabled.

This commit is contained in:
akwizgran
2020-01-30 14:49:22 +00:00
parent 1b402ba0c2
commit cb936d95c5
11 changed files with 127 additions and 115 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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) {