mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch 'amber-transport-icons' into 'plugin-toggles'
Use amber icon when enabling transports See merge request briar/briar!1210
This commit is contained in:
@@ -23,6 +23,7 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||
import org.briarproject.bramble.api.plugin.LanTcpConstants;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.briar.R;
|
||||
@@ -64,6 +65,8 @@ import static androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ENABLING;
|
||||
import static org.briarproject.briar.android.BriarService.EXTRA_STARTUP_FAILED;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
|
||||
import static org.briarproject.briar.android.navdrawer.IntentRouter.handleExternalIntent;
|
||||
@@ -375,21 +378,21 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
|
||||
Transport tor = new Transport();
|
||||
tor.id = TorConstants.ID;
|
||||
tor.enabled = controller.isTransportRunning(tor.id);
|
||||
tor.state = controller.getTransportState(tor.id);
|
||||
tor.iconId = R.drawable.transport_tor;
|
||||
tor.textId = R.string.transport_tor;
|
||||
transports.add(tor);
|
||||
|
||||
Transport bt = new Transport();
|
||||
bt.id = BluetoothConstants.ID;
|
||||
bt.enabled = controller.isTransportRunning(bt.id);
|
||||
bt.state = controller.getTransportState(bt.id);
|
||||
bt.iconId = R.drawable.transport_bt;
|
||||
bt.textId = R.string.transport_bt;
|
||||
transports.add(bt);
|
||||
|
||||
Transport lan = new Transport();
|
||||
lan.id = LanTcpConstants.ID;
|
||||
lan.enabled = controller.isTransportRunning(lan.id);
|
||||
lan.state = controller.getTransportState(lan.id);
|
||||
lan.iconId = R.drawable.transport_lan;
|
||||
lan.textId = R.string.transport_lan;
|
||||
transports.add(lan);
|
||||
@@ -423,9 +426,12 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
|
||||
Transport t = getItem(position);
|
||||
int c;
|
||||
if (t.enabled) {
|
||||
if (t.state == ACTIVE) {
|
||||
c = ContextCompat.getColor(NavDrawerActivity.this,
|
||||
R.color.briar_green_light);
|
||||
} else if (t.state == ENABLING) {
|
||||
c = ContextCompat.getColor(NavDrawerActivity.this,
|
||||
R.color.briar_yellow);
|
||||
} else {
|
||||
c = ContextCompat.getColor(NavDrawerActivity.this,
|
||||
android.R.color.tertiary_text_light);
|
||||
@@ -444,35 +450,31 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
};
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void setTransport(TransportId id, boolean enabled) {
|
||||
private void updateTransports() {
|
||||
if (transports == null || transportsAdapter == null) return;
|
||||
for (Transport t : transports) {
|
||||
t.state = controller.getTransportState(t.id);
|
||||
}
|
||||
transportsAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateUpdate(TransportId id, State state) {
|
||||
if (transports == null || transportsAdapter == null) return;
|
||||
for (Transport t : transports) {
|
||||
if (t.id.equals(id)) {
|
||||
t.enabled = enabled;
|
||||
t.state = state;
|
||||
transportsAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTransports() {
|
||||
if (transports == null || transportsAdapter == null) return;
|
||||
for (Transport t : transports) {
|
||||
t.enabled = controller.isTransportRunning(t.id);
|
||||
}
|
||||
transportsAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateUpdate(TransportId id, boolean enabled) {
|
||||
setTransport(id, enabled);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private static class Transport {
|
||||
|
||||
private TransportId id;
|
||||
private boolean enabled;
|
||||
private State state;
|
||||
private int iconId;
|
||||
private int textId;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android.navdrawer;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||
@@ -10,7 +11,7 @@ import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||
@NotNullByDefault
|
||||
public interface NavDrawerController extends ActivityLifecycleController {
|
||||
|
||||
boolean isTransportRunning(TransportId transportId);
|
||||
State getTransportState(TransportId transportId);
|
||||
|
||||
void showExpiryWarning(ResultHandler<Boolean> handler);
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
import org.briarproject.briar.android.controller.DbControllerImpl;
|
||||
@@ -30,7 +30,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.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.DISABLED;
|
||||
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;
|
||||
@@ -86,18 +86,14 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof TransportActiveEvent) {
|
||||
TransportId id = ((TransportActiveEvent) e).getTransportId();
|
||||
if (e instanceof TransportStateEvent) {
|
||||
TransportStateEvent t = (TransportStateEvent) e;
|
||||
TransportId id = t.getTransportId();
|
||||
State state = t.getState();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("TransportActiveEvent: " + id.getString());
|
||||
LOG.info("TransportStateEvent: " + id + " is " + state);
|
||||
}
|
||||
listener.stateUpdate(id, true);
|
||||
} else if (e instanceof TransportInactiveEvent) {
|
||||
TransportId id = ((TransportInactiveEvent) e).getTransportId();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("TransportInactiveEvent: " + id.getString());
|
||||
}
|
||||
listener.stateUpdate(id, false);
|
||||
listener.stateUpdate(id, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,9 +171,9 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransportRunning(TransportId transportId) {
|
||||
public State getTransportState(TransportId transportId) {
|
||||
Plugin plugin = pluginManager.getPlugin(transportId);
|
||||
return plugin != null && plugin.getState() == ACTIVE;
|
||||
return plugin == null ? DISABLED : plugin.getState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
@@ -7,5 +8,5 @@ import androidx.annotation.UiThread;
|
||||
interface TransportStateListener {
|
||||
|
||||
@UiThread
|
||||
void stateUpdate(TransportId id, boolean enabled);
|
||||
void stateUpdate(TransportId id, State state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user