mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Switched AppBus for ResultHandler, Controller for Helper. Added the basics for LifecycleControllers and implemented it for BriarActivity and NavDrawerActivity
This commit is contained in:
@@ -14,28 +14,19 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.contact.ContactListFragment;
|
||||
import org.briarproject.android.forum.ForumListFragment;
|
||||
import org.briarproject.android.controller.NavDrawerController;
|
||||
import org.briarproject.android.controller.ResultHandler;
|
||||
import org.briarproject.android.controller.TransportStateListener;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.util.CustomAnimations;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.android.api.ReferenceManager;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.TransportDisabledEvent;
|
||||
import org.briarproject.api.event.TransportEnabledEvent;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.plugins.Plugin;
|
||||
import org.briarproject.api.plugins.PluginManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -43,11 +34,8 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
BaseFragment.BaseFragmentListener, EventListener {
|
||||
BaseFragment.BaseFragmentListener, TransportStateListener {
|
||||
|
||||
public final static String PREF_SEEN_WELCOME_MESSAGE = "welcome_message";
|
||||
|
||||
@@ -60,14 +48,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
|
||||
@Inject
|
||||
protected ReferenceManager referenceManager;
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
@Inject
|
||||
protected PluginManager pluginManager;
|
||||
@Inject
|
||||
protected volatile EventBus eventBus;
|
||||
NavDrawerController controller;
|
||||
|
||||
private Toolbar toolbar;
|
||||
private DrawerLayout drawerLayout;
|
||||
@@ -106,11 +87,11 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
setContentView(R.layout.activity_nav_drawer);
|
||||
|
||||
toolbar = (Toolbar)findViewById(R.id.toolbar);
|
||||
drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
|
||||
transportsView = (GridView)findViewById(R.id.transportsView);
|
||||
progressTitle = (TextView)findViewById(R.id.title_progress_bar);
|
||||
progressViewGroup = (ViewGroup)findViewById(R.id.container_progress);
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
transportsView = (GridView) findViewById(R.id.transportsView);
|
||||
progressTitle = (TextView) findViewById(R.id.title_progress_bar);
|
||||
progressViewGroup = (ViewGroup) findViewById(R.id.container_progress);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
@@ -151,22 +132,14 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
eventBus.addListener(this);
|
||||
updateTransports();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
eventBus.removeListener(this);
|
||||
}
|
||||
|
||||
private void checkAuthorHandle(Intent intent) {
|
||||
long handle = intent.getLongExtra(KEY_LOCAL_AUTHOR_HANDLE, -1);
|
||||
if (handle != -1) {
|
||||
LocalAuthor a = controller.removeAuthorHandle(handle);
|
||||
// The activity was launched from the setup wizard
|
||||
LocalAuthor a = referenceManager.removeReference(handle,
|
||||
LocalAuthor.class);
|
||||
if (a != null) {
|
||||
showLoadingScreen(true, R.string.progress_title_please_wait);
|
||||
storeLocalAuthor(a);
|
||||
@@ -185,27 +158,18 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
}
|
||||
|
||||
private void storeLocalAuthor(final LocalAuthor a) {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
identityManager.addLocalAuthor(a);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing author took " + duration + " ms");
|
||||
controller.storeLocalAuthor(a,
|
||||
new ResultHandler<Void, DbException>() {
|
||||
@Override
|
||||
public void onResult(Void result) {
|
||||
hideLoadingScreen();
|
||||
}
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
hideLoadingScreen();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onException(DbException exception) {
|
||||
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onNavigationClick(View view) {
|
||||
@@ -281,24 +245,21 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
Transport tor = new Transport();
|
||||
tor.id = new TransportId("tor");
|
||||
Plugin torPlugin = pluginManager.getPlugin(tor.id);
|
||||
tor.enabled = torPlugin != null && torPlugin.isRunning();
|
||||
tor.enabled = controller.transportRunning(tor.id);
|
||||
tor.iconId = R.drawable.transport_tor;
|
||||
tor.textId = R.string.transport_tor;
|
||||
transports.add(tor);
|
||||
|
||||
Transport bt = new Transport();
|
||||
bt.id = new TransportId("bt");
|
||||
Plugin btPlugin = pluginManager.getPlugin(bt.id);
|
||||
bt.enabled = btPlugin != null && btPlugin.isRunning();
|
||||
bt.enabled = controller.transportRunning(bt.id);
|
||||
bt.iconId = R.drawable.transport_bt;
|
||||
bt.textId = R.string.transport_bt;
|
||||
transports.add(bt);
|
||||
|
||||
Transport lan = new Transport();
|
||||
lan.id = new TransportId("lan");
|
||||
Plugin lanPlugin = pluginManager.getPlugin(lan.id);
|
||||
lan.enabled = lanPlugin != null && lanPlugin.isRunning();
|
||||
lan.enabled = controller.transportRunning(lan.id);
|
||||
lan.iconId = R.drawable.transport_lan;
|
||||
lan.textId = R.string.transport_lan;
|
||||
transports.add(lan);
|
||||
@@ -365,27 +326,14 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
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();
|
||||
t.enabled = controller.transportRunning(t.id);
|
||||
}
|
||||
transportsAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof TransportEnabledEvent) {
|
||||
TransportId id = ((TransportEnabledEvent) e).getTransportId();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("TransportEnabledEvent: " + id.getString());
|
||||
}
|
||||
setTransport(id, true);
|
||||
} else if (e instanceof TransportDisabledEvent) {
|
||||
TransportId id = ((TransportDisabledEvent) e).getTransportId();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("TransportDisabledEvent: " + id.getString());
|
||||
}
|
||||
setTransport(id, false);
|
||||
}
|
||||
public void stateUpdate(TransportId id, boolean enabled) {
|
||||
setTransport(id, enabled);
|
||||
}
|
||||
|
||||
private static class Transport {
|
||||
|
||||
Reference in New Issue
Block a user