mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Fixed the controllers and am now saving the current fragment
This commit is contained in:
@@ -10,6 +10,8 @@ import org.briarproject.android.controller.BriarController;
|
||||
import org.briarproject.android.controller.BriarControllerImpl;
|
||||
import org.briarproject.android.controller.ConfigController;
|
||||
import org.briarproject.android.controller.ConfigControllerImpl;
|
||||
import org.briarproject.android.controller.DBController;
|
||||
import org.briarproject.android.controller.DBControllerImpl;
|
||||
import org.briarproject.android.controller.NavDrawerController;
|
||||
import org.briarproject.android.controller.NavDrawerControllerImpl;
|
||||
import org.briarproject.android.controller.PasswordController;
|
||||
@@ -89,6 +91,13 @@ public class ActivityModule {
|
||||
return briarControllerImpl;
|
||||
}
|
||||
|
||||
@ActivityScope
|
||||
@Provides
|
||||
protected DBController provideDBController(
|
||||
DBControllerImpl dbController) {
|
||||
return dbController;
|
||||
}
|
||||
|
||||
@ActivityScope
|
||||
@Provides
|
||||
protected NavDrawerController provideNavDrawerController(
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.android;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
@@ -25,6 +26,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
public abstract void injectActivity(ActivityComponent component);
|
||||
|
||||
public void addLifecycleController(ActivityLifecycleController alc) {
|
||||
Log.d(getClass().getSimpleName(), "addLifecycleController: " + lifecycleControllers.size());
|
||||
lifecycleControllers.add(alc);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import org.briarproject.android.controller.BriarController;
|
||||
import org.briarproject.android.controller.DBController;
|
||||
import org.briarproject.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.android.panic.ExitActivity;
|
||||
|
||||
@@ -33,6 +34,9 @@ public abstract class BriarActivity extends BaseActivity {
|
||||
|
||||
@Inject
|
||||
protected BriarController briarController;
|
||||
// TODO remove this when the deprecated method runOnDbThread is removed
|
||||
@Inject
|
||||
protected DBController dbController;
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int request, int result, Intent data) {
|
||||
@@ -87,7 +91,7 @@ public abstract class BriarActivity extends BaseActivity {
|
||||
|
||||
@Deprecated
|
||||
public void runOnDbThread(Runnable task) {
|
||||
briarController.runOnDbThread(task);
|
||||
dbController.runOnDbThread(task);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.android;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
import org.acra.annotation.ReportsCrashes;
|
||||
import org.briarproject.CoreModule;
|
||||
@@ -34,7 +33,7 @@ public class BriarApplicationImpl extends Application
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
ACRA.init(this);
|
||||
// ACRA.init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,6 +45,8 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
public static final String INTENT_CONTACTS = "intent_contacts";
|
||||
public static final String INTENT_FORUMS = "intent_forums";
|
||||
|
||||
private static final String KEY_CURRENT_FRAGMENT_ID = "key_current_id";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(NavDrawerActivity.class.getName());
|
||||
|
||||
@@ -60,6 +62,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
private List<Transport> transports;
|
||||
private BaseAdapter transportsAdapter;
|
||||
private int currentFragmentId = R.id.nav_btn_contacts;
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
@@ -103,8 +106,13 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
R.string.nav_drawer_open_description,
|
||||
R.string.nav_drawer_close_description);
|
||||
drawerLayout.setDrawerListener(drawerToggle);
|
||||
if (state == null)
|
||||
LOG.info("NavDrawerActivity created: " + (state == null));
|
||||
if (state == null) {
|
||||
startFragment(activityComponent.newContactListFragment());
|
||||
} else {
|
||||
currentFragmentId = state.getInt(KEY_CURRENT_FRAGMENT_ID);
|
||||
loadCurrentFragment();
|
||||
}
|
||||
checkAuthorHandle(getIntent());
|
||||
|
||||
initializeTransports(getLayoutInflater());
|
||||
@@ -113,6 +121,12 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
welcomeMessageCheck();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(KEY_CURRENT_FRAGMENT_ID, currentFragmentId);
|
||||
}
|
||||
|
||||
private void welcomeMessageCheck() {
|
||||
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
|
||||
if (!prefs.getBoolean(PREF_SEEN_WELCOME_MESSAGE, false)) {
|
||||
@@ -159,10 +173,8 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
});
|
||||
}
|
||||
|
||||
public void onNavigationClick(View view) {
|
||||
drawerLayout.closeDrawer(START);
|
||||
clearBackStack();
|
||||
switch (view.getId()) {
|
||||
private void loadCurrentFragment() {
|
||||
switch (currentFragmentId) {
|
||||
case R.id.nav_btn_contacts:
|
||||
startFragment(activityComponent.newContactListFragment());
|
||||
break;
|
||||
@@ -178,6 +190,13 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
public void onNavigationClick(View view) {
|
||||
drawerLayout.closeDrawer(START);
|
||||
clearBackStack();
|
||||
currentFragmentId = view.getId();
|
||||
loadCurrentFragment();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
|
||||
@@ -4,8 +4,6 @@ import org.briarproject.android.controller.handler.ResultHandler;
|
||||
|
||||
public interface BriarController extends ActivityLifecycleController {
|
||||
|
||||
void runOnDbThread(final Runnable task);
|
||||
|
||||
void startAndBindService();
|
||||
|
||||
boolean hasEncryptionKey();
|
||||
|
||||
@@ -9,10 +9,7 @@ import org.briarproject.android.BriarService;
|
||||
import org.briarproject.android.BriarService.BriarServiceConnection;
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -29,13 +26,6 @@ public class BriarControllerImpl implements BriarController {
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@DatabaseExecutor
|
||||
protected volatile Executor dbExecutor;
|
||||
@Inject
|
||||
protected volatile LifecycleManager lifecycleManager;
|
||||
|
||||
private boolean bound = false;
|
||||
|
||||
@Inject
|
||||
@@ -70,6 +60,7 @@ public class BriarControllerImpl implements BriarController {
|
||||
activity.startService(new Intent(activity, BriarService.class));
|
||||
bound = activity.bindService(new Intent(activity, BriarService.class),
|
||||
serviceConnection, 0);
|
||||
LOG.info("Briar service started " + bound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,23 +91,9 @@ public class BriarControllerImpl implements BriarController {
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void unbindService() {
|
||||
protected void unbindService() {
|
||||
LOG.info("Briar service unbind " + bound);
|
||||
if (bound) activity.unbindService(serviceConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runOnDbThread(final Runnable task) {
|
||||
dbExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
task.run();
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while waiting for database");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
public interface DBController {
|
||||
|
||||
void runOnDbThread(Runnable task);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class DBControllerImpl implements DBController {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(BriarControllerImpl.class.getName());
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@DatabaseExecutor
|
||||
protected volatile Executor dbExecutor;
|
||||
@Inject
|
||||
protected volatile LifecycleManager lifecycleManager;
|
||||
|
||||
@Inject
|
||||
public DBControllerImpl() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runOnDbThread(final Runnable task) {
|
||||
dbExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
task.run();
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while waiting for database");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import org.briarproject.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
|
||||
public interface NavDrawerController extends BriarController {
|
||||
public interface NavDrawerController extends ActivityLifecycleController {
|
||||
|
||||
void setTransportListener(TransportStateListener transportListener);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import javax.inject.Inject;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public class NavDrawerControllerImpl extends BriarControllerImpl
|
||||
public class NavDrawerControllerImpl extends DBControllerImpl
|
||||
implements NavDrawerController, EventListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -51,21 +51,24 @@ public class NavDrawerControllerImpl extends BriarControllerImpl
|
||||
|
||||
@Override
|
||||
public void onActivityCreate() {
|
||||
super.onActivityCreate();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResume() {
|
||||
super.onActivityResume();
|
||||
eventBus.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPause() {
|
||||
super.onActivityPause();
|
||||
eventBus.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroy() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof TransportEnabledEvent) {
|
||||
@@ -131,4 +134,5 @@ public class NavDrawerControllerImpl extends BriarControllerImpl
|
||||
public LocalAuthor removeAuthorHandle(long handle) {
|
||||
return referenceManager.removeReference(handle, LocalAuthor.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user