Skip to content
Snippets Groups Projects
Commit 28b7fd96 authored by Torsten Grote's avatar Torsten Grote
Browse files

Merge branch '186-update-dashboard-icons' into 'master'

Update dashboard icons when resuming activity.

Fixes #186. 

The issue is that DashboardActivity doesn't receive events while it's paused. This appears to be device-dependent because it depends on the relative speed of resuming the activity vs delivering the event. If the activity resumes quickly enough, it will register its event listener and catch the event. If not, it won't update its icons until it's recreated, e.g. by rotating the screen.

See merge request !31
parents a3ecd939 8084d08a
No related branches found
No related tags found
No related merge requests found
......@@ -71,14 +71,13 @@ public class DashboardActivity extends BriarActivity implements EventListener {
@Override
public void onResume() {
super.onResume();
updateTransports();
eventBus.addListener(this);
}
@Override
public void onPause() {
super.onPause();
eventBus.removeListener(this);
}
......@@ -282,8 +281,7 @@ public class DashboardActivity extends BriarActivity implements EventListener {
Transport tor = new Transport();
tor.id = new TransportId("tor");
Plugin torPlugin = pluginManager.getPlugin(tor.id);
if (torPlugin == null) tor.enabled = false;
else tor.enabled = torPlugin.isRunning();
tor.enabled = torPlugin != null && torPlugin.isRunning();
tor.iconId = R.drawable.transport_tor;
tor.textId = R.string.transport_tor;
transports.add(tor);
......@@ -291,8 +289,7 @@ public class DashboardActivity extends BriarActivity implements EventListener {
Transport bt = new Transport();
bt.id = new TransportId("bt");
Plugin btPlugin = pluginManager.getPlugin(bt.id);
if (btPlugin == null) bt.enabled = false;
else bt.enabled = btPlugin.isRunning();
bt.enabled = btPlugin != null && btPlugin.isRunning();
bt.iconId = R.drawable.transport_bt;
bt.textId = R.string.transport_bt;
transports.add(bt);
......@@ -300,8 +297,7 @@ public class DashboardActivity extends BriarActivity implements EventListener {
Transport lan = new Transport();
lan.id = new TransportId("lan");
Plugin lanPlugin = pluginManager.getPlugin(lan.id);
if (lanPlugin == null) lan.enabled = false;
else lan.enabled = lanPlugin.isRunning();
lan.enabled = lanPlugin != null && lanPlugin.isRunning();
lan.iconId = R.drawable.transport_lan;
lan.textId = R.string.transport_lan;
transports.add(lan);
......@@ -357,19 +353,26 @@ public class DashboardActivity extends BriarActivity implements EventListener {
runOnUiThread(new Runnable() {
public void run() {
if (transports == null || transportsAdapter == null) return;
for (Transport t : transports) {
if (t.id.equals(id)) {
t.enabled = enabled;
transportsAdapter.notifyDataSetChanged();
break;
}
}
transportsAdapter.notifyDataSetChanged();
}
});
}
private void updateTransports() {
if (transports == null || transportsAdapter == null) return;
for (Transport t : transports) {
Plugin plugin = pluginManager.getPlugin(t.id);
t.enabled = plugin != null && plugin.isRunning();
}
transportsAdapter.notifyDataSetChanged();
}
private static class Transport {
TransportId id;
boolean enabled;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment