Merge branch '551-destroyable-context' into 'master'

Always check whether the context has been destroyed

#551 has the same root cause as #610, which is that when a background operation completes, we need to check whether the activity or fragment that started the operation has been destroyed before doing anything with the UI. 

DestroyableActivity has been renamed to DestroyableContext because it's now implemented by some fragments as well. Various existing listener interfaces now extend DestroyableContext.

I also modified the ActivityLifecycleController interface so the activity is passed into the onActivityCreate() method rather than being injected - @ernir please check I haven't broken anything!

Closes #551

See merge request !341
This commit is contained in:
akwizgran
2016-10-10 15:00:15 +00:00
49 changed files with 310 additions and 340 deletions

View File

@@ -20,7 +20,6 @@ import org.briarproject.android.controller.PasswordController;
import org.briarproject.android.controller.PasswordControllerImpl; import org.briarproject.android.controller.PasswordControllerImpl;
import org.briarproject.android.controller.SetupController; import org.briarproject.android.controller.SetupController;
import org.briarproject.android.controller.SetupControllerImpl; import org.briarproject.android.controller.SetupControllerImpl;
import org.briarproject.android.controller.TransportStateListener;
import org.briarproject.android.forum.ForumController; import org.briarproject.android.forum.ForumController;
import org.briarproject.android.forum.ForumControllerImpl; import org.briarproject.android.forum.ForumControllerImpl;
@@ -52,27 +51,27 @@ public class ActivityModule {
@ActivityScope @ActivityScope
@Provides @Provides
protected SetupController provideSetupController( SetupController provideSetupController(
SetupControllerImpl setupControllerImpl) { SetupControllerImpl setupControllerImpl) {
return setupControllerImpl; return setupControllerImpl;
} }
@ActivityScope @ActivityScope
@Provides @Provides
protected ConfigController provideConfigController( ConfigController provideConfigController(
ConfigControllerImpl configControllerImpl) { ConfigControllerImpl configControllerImpl) {
return configControllerImpl; return configControllerImpl;
} }
@ActivityScope @ActivityScope
@Provides @Provides
protected SharedPreferences provideSharedPreferences(Activity activity) { SharedPreferences provideSharedPreferences(Activity activity) {
return activity.getSharedPreferences("db", Context.MODE_PRIVATE); return activity.getSharedPreferences("db", Context.MODE_PRIVATE);
} }
@ActivityScope @ActivityScope
@Provides @Provides
protected PasswordController providePasswordController( PasswordController providePasswordController(
PasswordControllerImpl passwordControllerImpl) { PasswordControllerImpl passwordControllerImpl) {
return passwordControllerImpl; return passwordControllerImpl;
} }
@@ -87,8 +86,7 @@ public class ActivityModule {
@ActivityScope @ActivityScope
@Provides @Provides
protected DbController provideDBController( DbController provideDBController(DbControllerImpl dbController) {
DbControllerImpl dbController) {
return dbController; return dbController;
} }
@@ -109,26 +107,21 @@ public class ActivityModule {
@ActivityScope @ActivityScope
@Provides @Provides
protected FeedController provideFeedController( FeedController provideFeedController(FeedControllerImpl feedController) {
FeedControllerImpl feedController) {
return feedController; return feedController;
} }
@ActivityScope @ActivityScope
@Provides @Provides
protected NavDrawerController provideNavDrawerController( NavDrawerController provideNavDrawerController(
NavDrawerControllerImpl navDrawerControllerImpl) { NavDrawerControllerImpl navDrawerController) {
activity.addLifecycleController(navDrawerControllerImpl); activity.addLifecycleController(navDrawerController);
if (activity instanceof TransportStateListener) { return navDrawerController;
navDrawerControllerImpl.setTransportListener(
(TransportStateListener) activity);
}
return navDrawerControllerImpl;
} }
@ActivityScope @ActivityScope
@Provides @Provides
protected BriarServiceConnection provideBriarServiceConnection() { BriarServiceConnection provideBriarServiceConnection() {
return new BriarServiceConnection(); return new BriarServiceConnection();
} }

View File

@@ -2,7 +2,6 @@ package org.briarproject.android;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.support.annotation.UiThread;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@@ -18,7 +17,7 @@ import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS; import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
public abstract class BaseActivity extends AppCompatActivity public abstract class BaseActivity extends AppCompatActivity
implements DestroyableActivity { implements DestroyableContext {
protected ActivityComponent activityComponent; protected ActivityComponent activityComponent;
@@ -49,7 +48,7 @@ public abstract class BaseActivity extends AppCompatActivity
injectActivity(activityComponent); injectActivity(activityComponent);
for (ActivityLifecycleController alc : lifecycleControllers) { for (ActivityLifecycleController alc : lifecycleControllers) {
alc.onActivityCreate(); alc.onActivityCreate(this);
} }
} }
@@ -87,9 +86,14 @@ public abstract class BaseActivity extends AppCompatActivity
} }
} }
@UiThread @Override
public boolean hasBeenDestroyed() { public void runOnUiThreadUnlessDestroyed(final Runnable r) {
return destroyed; runOnUiThread(new Runnable() {
@Override
public void run() {
if (!destroyed && !isFinishing()) r.run();
}
});
} }
public void showSoftKeyboardForced(View view) { public void showSoftKeyboardForced(View view) {

View File

@@ -94,7 +94,7 @@ public abstract class BriarActivity extends BaseActivity {
@Deprecated @Deprecated
protected void finishOnUiThread() { protected void finishOnUiThread() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
finish(); finish();

View File

@@ -1,7 +1,6 @@
package org.briarproject.android; package org.briarproject.android;
import android.support.annotation.AnimRes; import android.support.annotation.AnimRes;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
@@ -12,6 +11,8 @@ import org.briarproject.android.contact.ContactListFragment;
import org.briarproject.android.forum.ForumListFragment; import org.briarproject.android.forum.ForumListFragment;
import org.briarproject.android.fragment.BaseFragment; import org.briarproject.android.fragment.BaseFragment;
import static android.support.v4.app.FragmentManager.POP_BACK_STACK_INCLUSIVE;
/** /**
* This class should be extended by classes that wish to utilise fragments in * This class should be extended by classes that wish to utilise fragments in
* Briar, it encapsulates all fragment related code. * Briar, it encapsulates all fragment related code.
@@ -33,11 +34,8 @@ public abstract class BriarFragmentActivity extends BriarActivity {
} }
void clearBackStack() { void clearBackStack() {
getSupportFragmentManager() getSupportFragmentManager().popBackStackImmediate(null,
.popBackStackImmediate( POP_BACK_STACK_INCLUSIVE);
null,
FragmentManager.POP_BACK_STACK_INCLUSIVE
);
} }
@Override @Override

View File

@@ -1,12 +0,0 @@
package org.briarproject.android;
import android.support.annotation.UiThread;
public interface DestroyableActivity {
void runOnUiThread(Runnable runnable);
@UiThread
boolean hasBeenDestroyed();
}

View File

@@ -0,0 +1,6 @@
package org.briarproject.android;
public interface DestroyableContext {
void runOnUiThreadUnlessDestroyed(Runnable runnable);
}

View File

@@ -27,7 +27,7 @@ import org.briarproject.android.controller.NavDrawerController;
import org.briarproject.android.controller.TransportStateListener; import org.briarproject.android.controller.TransportStateListener;
import org.briarproject.android.controller.handler.UiResultHandler; import org.briarproject.android.controller.handler.UiResultHandler;
import org.briarproject.android.forum.ForumListFragment; import org.briarproject.android.forum.ForumListFragment;
import org.briarproject.android.fragment.BaseFragment; import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
@@ -43,7 +43,7 @@ import static android.support.v4.widget.DrawerLayout.LOCK_MODE_UNLOCKED;
import static android.view.View.INVISIBLE; import static android.view.View.INVISIBLE;
public class NavDrawerActivity extends BriarFragmentActivity implements public class NavDrawerActivity extends BriarFragmentActivity implements
BaseFragment.BaseFragmentListener, TransportStateListener, BaseFragmentListener, TransportStateListener,
OnNavigationItemSelectedListener { OnNavigationItemSelectedListener {
static final String INTENT_CONTACTS = "intent_contacts"; static final String INTENT_CONTACTS = "intent_contacts";
@@ -58,9 +58,8 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
private ActionBarDrawerToggle drawerToggle; private ActionBarDrawerToggle drawerToggle;
@Inject @Inject
protected NavDrawerController controller; NavDrawerController controller;
private Toolbar toolbar;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private TextView progressTitle; private TextView progressTitle;
private ViewGroup progressViewGroup; private ViewGroup progressViewGroup;
@@ -78,11 +77,9 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
// clearBackStack(); // clearBackStack();
if (intent.getBooleanExtra(INTENT_FORUMS, false)) { if (intent.getBooleanExtra(INTENT_FORUMS, false)) {
startFragment(ForumListFragment.newInstance()); startFragment(ForumListFragment.newInstance());
} } else if (intent.getBooleanExtra(INTENT_CONTACTS, false)) {
else if (intent.getBooleanExtra(INTENT_CONTACTS, false)) {
startFragment(ContactListFragment.newInstance()); startFragment(ContactListFragment.newInstance());
} } else if (intent.getBooleanExtra(INTENT_BLOGS, false)) {
else if (intent.getBooleanExtra(INTENT_BLOGS, false)) {
startFragment(FeedFragment.newInstance()); startFragment(FeedFragment.newInstance());
} }
setIntent(null); setIntent(null);
@@ -100,7 +97,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
exitIfStartupFailed(getIntent()); exitIfStartupFailed(getIntent());
setContentView(R.layout.activity_nav_drawer); setContentView(R.layout.activity_nav_drawer);
toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigation = NavigationView navigation =
(NavigationView) findViewById(R.id.navigation); (NavigationView) findViewById(R.id.navigation);
@@ -318,7 +315,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
} }
private void setTransport(final TransportId id, final boolean enabled) { private void setTransport(final TransportId id, final boolean enabled) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (transports == null || transportsAdapter == null) return; if (transports == null || transportsAdapter == null) return;

View File

@@ -3,6 +3,7 @@ package org.briarproject.android.blogs;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import org.briarproject.android.DestroyableContext;
import org.briarproject.android.controller.handler.ResultExceptionHandler; import org.briarproject.android.controller.handler.ResultExceptionHandler;
import org.briarproject.api.blogs.BlogPostHeader; import org.briarproject.api.blogs.BlogPostHeader;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
@@ -33,9 +34,13 @@ interface BaseController {
void setOnBlogPostAddedListener(OnBlogPostAddedListener listener); void setOnBlogPostAddedListener(OnBlogPostAddedListener listener);
interface OnBlogPostAddedListener { interface OnBlogPostAddedListener extends DestroyableContext {
@UiThread @UiThread
void onBlogPostAdded(BlogPostHeader header, boolean local); void onBlogPostAdded(BlogPostHeader header, boolean local);
@UiThread
void onBlogRemoved();
} }
} }

View File

@@ -1,6 +1,5 @@
package org.briarproject.android.blogs; package org.briarproject.android.blogs;
import android.app.Activity;
import android.support.annotation.CallSuper; import android.support.annotation.CallSuper;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@@ -39,16 +38,14 @@ abstract class BaseControllerImpl extends DbControllerImpl
Logger.getLogger(BaseControllerImpl.class.getName()); Logger.getLogger(BaseControllerImpl.class.getName());
@Inject @Inject
protected Activity activity; EventBus eventBus;
@Inject @Inject
protected EventBus eventBus; AndroidNotificationManager notificationManager;
@Inject @Inject
protected AndroidNotificationManager notificationManager; IdentityManager identityManager;
@Inject
protected IdentityManager identityManager;
@Inject @Inject
protected volatile BlogManager blogManager; volatile BlogManager blogManager;
private final Map<MessageId, String> bodyCache = new ConcurrentHashMap<>(); private final Map<MessageId, String> bodyCache = new ConcurrentHashMap<>();
private final Map<MessageId, BlogPostHeader> headerCache = private final Map<MessageId, BlogPostHeader> headerCache =
@@ -75,12 +72,12 @@ abstract class BaseControllerImpl extends DbControllerImpl
@CallSuper @CallSuper
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof BlogPostAddedEvent) { if (e instanceof BlogPostAddedEvent) {
final BlogPostAddedEvent m = (BlogPostAddedEvent) e; final BlogPostAddedEvent b = (BlogPostAddedEvent) e;
LOG.info("New blog post added"); LOG.info("New blog post added");
activity.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
listener.onBlogPostAdded(m.getHeader(), m.isLocal()); listener.onBlogPostAdded(b.getHeader(), b.isLocal());
} }
}); });
} }
@@ -110,8 +107,7 @@ abstract class BaseControllerImpl extends DbControllerImpl
}); });
} }
protected Collection<BlogPostItem> loadItems(GroupId groupId) Collection<BlogPostItem> loadItems(GroupId groupId) throws DbException {
throws DbException {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Collection<BlogPostHeader> headers = Collection<BlogPostHeader> headers =
blogManager.getPostHeaders(groupId); blogManager.getPostHeaders(groupId);

View File

@@ -22,7 +22,7 @@ import static org.briarproject.android.util.AndroidUtils.MIN_RESOLUTION;
abstract class BasePostFragment extends BaseFragment { abstract class BasePostFragment extends BaseFragment {
private final Logger LOG = private static final Logger LOG =
Logger.getLogger(BasePostFragment.class.getName()); Logger.getLogger(BasePostFragment.class.getName());
private View view; private View view;

View File

@@ -90,6 +90,7 @@ abstract class BasePostPagerFragment extends BaseFragment
abstract void loadBlogPost(BlogPostHeader header); abstract void loadBlogPost(BlogPostHeader header);
@UiThread
protected void onBlogPostsLoaded(MessageId select, protected void onBlogPostsLoaded(MessageId select,
Collection<BlogPostItem> posts) { Collection<BlogPostItem> posts) {
@@ -98,6 +99,7 @@ abstract class BasePostPagerFragment extends BaseFragment
selectPost(select); selectPost(select);
} }
@UiThread
protected void onBlogPostsLoadedException(DbException exception) { protected void onBlogPostsLoadedException(DbException exception) {
// TODO: Decide how to handle errors in the UI // TODO: Decide how to handle errors in the UI
finish(); finish();
@@ -174,4 +176,8 @@ abstract class BasePostPagerFragment extends BaseFragment
} }
} }
@Override
public void onBlogRemoved() {
finish();
}
} }

View File

@@ -1,5 +1,7 @@
package org.briarproject.android.blogs; package org.briarproject.android.blogs;
import android.app.Activity;
import org.briarproject.android.controller.ActivityLifecycleController; import org.briarproject.android.controller.ActivityLifecycleController;
import org.briarproject.android.controller.handler.ResultExceptionHandler; import org.briarproject.android.controller.handler.ResultExceptionHandler;
import org.briarproject.api.blogs.Blog; import org.briarproject.api.blogs.Blog;
@@ -32,7 +34,7 @@ public class BlogControllerImpl extends BaseControllerImpl
} }
@Override @Override
public void onActivityCreate() { public void onActivityCreate(Activity activity) {
} }
@Override @Override
@@ -69,11 +71,10 @@ public class BlogControllerImpl extends BaseControllerImpl
GroupRemovedEvent s = (GroupRemovedEvent) e; GroupRemovedEvent s = (GroupRemovedEvent) e;
if (s.getGroup().getId().equals(groupId)) { if (s.getGroup().getId().equals(groupId)) {
LOG.info("Blog removed"); LOG.info("Blog removed");
activity.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
// TODO: Not the controller's job, add a listener method listener.onBlogRemoved();
activity.finish();
} }
}); });
} }

View File

@@ -160,8 +160,8 @@ public class BlogFragment extends BaseFragment implements
getActivity().onBackPressed(); getActivity().onBackPressed();
return true; return true;
case R.id.action_write_blog_post: case R.id.action_write_blog_post:
Intent i = Intent i = new Intent(getActivity(),
new Intent(getActivity(), WriteBlogPostActivity.class); WriteBlogPostActivity.class);
i.putExtra(GROUP_ID, groupId.getBytes()); i.putExtra(GROUP_ID, groupId.getBytes());
i.putExtra(BLOG_NAME, blogName); i.putExtra(BLOG_NAME, blogName);
startActivityForResult(i, REQUEST_WRITE_POST, startActivityForResult(i, REQUEST_WRITE_POST,
@@ -224,7 +224,7 @@ public class BlogFragment extends BaseFragment implements
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI // TODO: Decide how to handle errors in the UI
getActivity().finish(); finish();
} }
} }
); );
@@ -338,7 +338,7 @@ public class BlogFragment extends BaseFragment implements
Toast.makeText(getActivity(), Toast.makeText(getActivity(),
R.string.blogs_blog_removed, LENGTH_SHORT) R.string.blogs_blog_removed, LENGTH_SHORT)
.show(); .show();
getActivity().supportFinishAfterTransition(); finish();
} }
@Override @Override
@@ -349,4 +349,8 @@ public class BlogFragment extends BaseFragment implements
}); });
} }
@Override
public void onBlogRemoved() {
finish();
}
} }

View File

@@ -41,6 +41,7 @@ public class BlogPostPagerFragment extends BasePostPagerFragment {
} }
@Override
void loadBlogPosts(final MessageId select) { void loadBlogPosts(final MessageId select) {
blogController.loadBlogPosts( blogController.loadBlogPosts(
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>( new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
@@ -57,6 +58,7 @@ public class BlogPostPagerFragment extends BasePostPagerFragment {
}); });
} }
@Override
void loadBlogPost(BlogPostHeader header) { void loadBlogPost(BlogPostHeader header) {
blogController.loadBlogPost(header, blogController.loadBlogPost(header,
new UiResultExceptionHandler<BlogPostItem, DbException>( new UiResultExceptionHandler<BlogPostItem, DbException>(
@@ -73,5 +75,4 @@ public class BlogPostPagerFragment extends BasePostPagerFragment {
} }
}); });
} }
} }

View File

@@ -231,4 +231,9 @@ public class FeedFragment extends BaseFragment implements
} }
s.show(); s.show();
} }
@Override
public void onBlogRemoved() {
finish();
}
} }

View File

@@ -74,5 +74,4 @@ public class FeedPostPagerFragment extends BasePostPagerFragment {
} }
}); });
} }
} }

View File

@@ -65,12 +65,7 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { listener = (BaseFragmentListener) context;
listener = (BaseFragmentListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(
"Using class must implement BaseFragmentListener");
}
} }
@Override @Override
@@ -93,12 +88,6 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
return v; return v;
} }
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
listener.getActivityComponent().inject(this);
}
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();

View File

@@ -42,10 +42,11 @@ public class RssFeedImportActivity extends BriarActivity {
@Inject @Inject
@IoExecutor @IoExecutor
protected Executor ioExecutor; Executor ioExecutor;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
private volatile GroupId groupId = null; private volatile GroupId groupId = null;
@Inject @Inject
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
volatile FeedManager feedManager; volatile FeedManager feedManager;
@@ -139,7 +140,7 @@ public class RssFeedImportActivity extends BriarActivity {
} }
private void feedImported() { private void feedImported() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
supportFinishAfterTransition(); supportFinishAfterTransition();
@@ -148,11 +149,9 @@ public class RssFeedImportActivity extends BriarActivity {
} }
private void importFailed() { private void importFailed() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (RssFeedImportActivity.this.hasBeenDestroyed()) return;
// hide progress bar, show publish button // hide progress bar, show publish button
progressBar.setVisibility(GONE); progressBar.setVisibility(GONE);
importButton.setVisibility(VISIBLE); importButton.setVisibility(VISIBLE);

View File

@@ -40,6 +40,7 @@ public class RssFeedManageActivity extends BriarActivity
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
private volatile GroupId groupId = null; private volatile GroupId groupId = null;
@Inject @Inject
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
volatile FeedManager feedManager; volatile FeedManager feedManager;
@@ -135,7 +136,7 @@ public class RssFeedManageActivity extends BriarActivity
} }
private void addFeeds(final List<Feed> feeds) { private void addFeeds(final List<Feed> feeds) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (feeds.size() == 0) list.showData(); if (feeds.size() == 0) list.showData();
@@ -145,7 +146,7 @@ public class RssFeedManageActivity extends BriarActivity
} }
private void onFeedDeleted(final Feed feed) { private void onFeedDeleted(final Feed feed) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
adapter.remove(feed); adapter.remove(feed);
@@ -154,7 +155,7 @@ public class RssFeedManageActivity extends BriarActivity
} }
private void onDeleteError() { private void onDeleteError() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
Snackbar.make(list, Snackbar.make(list,

View File

@@ -44,7 +44,7 @@ public class WriteBlogPostActivity extends BriarActivity
Logger.getLogger(WriteBlogPostActivity.class.getName()); Logger.getLogger(WriteBlogPostActivity.class.getName());
@Inject @Inject
protected AndroidNotificationManager notificationManager; AndroidNotificationManager notificationManager;
private TextInputView input; private TextInputView input;
private ProgressBar progressBar; private ProgressBar progressBar;
@@ -52,7 +52,7 @@ public class WriteBlogPostActivity extends BriarActivity
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
private volatile GroupId groupId; private volatile GroupId groupId;
@Inject @Inject
protected volatile IdentityManager identityManager; volatile IdentityManager identityManager;
@Inject @Inject
volatile BlogPostFactory blogPostFactory; volatile BlogPostFactory blogPostFactory;
@Inject @Inject
@@ -168,7 +168,7 @@ public class WriteBlogPostActivity extends BriarActivity
} }
private void postPublished() { private void postPublished() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
setResult(RESULT_OK); setResult(RESULT_OK);
@@ -178,7 +178,7 @@ public class WriteBlogPostActivity extends BriarActivity
} }
private void postFailedToPublish() { private void postFailedToPublish() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
// hide progress bar, show publish button // hide progress bar, show publish button

View File

@@ -63,33 +63,29 @@ import static org.briarproject.android.BriarActivity.GROUP_ID;
public class ContactListFragment extends BaseFragment implements EventListener { public class ContactListFragment extends BaseFragment implements EventListener {
public final static String TAG = "ContactListFragment"; public static final String TAG = ContactListFragment.class.getName();
private static final Logger LOG = Logger.getLogger(TAG);
private static final Logger LOG =
Logger.getLogger(ContactListFragment.class.getName());
@Inject @Inject
ConnectionRegistry connectionRegistry; ConnectionRegistry connectionRegistry;
@Inject @Inject
protected EventBus eventBus; EventBus eventBus;
@Inject @Inject
protected AndroidNotificationManager notificationManager; AndroidNotificationManager notificationManager;
private ContactListAdapter adapter = null; private ContactListAdapter adapter;
private BriarRecyclerView list = null; private BriarRecyclerView list;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject @Inject
protected volatile ContactManager contactManager; volatile ContactManager contactManager;
@Inject @Inject
protected volatile IdentityManager identityManager; volatile IdentityManager identityManager;
@Inject @Inject
protected volatile ConversationManager conversationManager; volatile ConversationManager conversationManager;
public static ContactListFragment newInstance() { public static ContactListFragment newInstance() {
Bundle args = new Bundle(); Bundle args = new Bundle();
ContactListFragment fragment = new ContactListFragment(); ContactListFragment fragment = new ContactListFragment();
fragment.setArguments(args); fragment.setArguments(args);
return fragment; return fragment;
@@ -230,7 +226,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
} }
private void displayContacts(final List<ContactListItem> contacts) { private void displayContacts(final List<ContactListItem> contacts) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (contacts.size() == 0) list.showData(); if (contacts.size() == 0) list.showData();
@@ -284,7 +280,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
} }
private void updateItem(final ContactId c, final ConversationItem m) { private void updateItem(final ContactId c, final ConversationItem m) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
int position = adapter.findItemPosition(c); int position = adapter.findItemPosition(c);
@@ -298,7 +294,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
} }
private void updateItem(final GroupId g, final ConversationItem m) { private void updateItem(final GroupId g, final ConversationItem m) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
int position = adapter.findItemPosition(g); int position = adapter.findItemPosition(g);
@@ -312,7 +308,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
} }
private void removeItem(final ContactId c) { private void removeItem(final ContactId c) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
int position = adapter.findItemPosition(c); int position = adapter.findItemPosition(c);
@@ -323,7 +319,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
} }
private void setConnected(final ContactId c, final boolean connected) { private void setConnected(final ContactId c, final boolean connected) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
int position = adapter.findItemPosition(c); int position = adapter.findItemPosition(c);

View File

@@ -130,21 +130,21 @@ public class ConversationActivity extends BriarActivity
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject @Inject
protected volatile ContactManager contactManager; volatile ContactManager contactManager;
@Inject @Inject
protected volatile MessagingManager messagingManager; volatile MessagingManager messagingManager;
@Inject @Inject
protected volatile EventBus eventBus; volatile EventBus eventBus;
@Inject @Inject
protected volatile SettingsManager settingsManager; volatile SettingsManager settingsManager;
@Inject @Inject
volatile PrivateMessageFactory privateMessageFactory; volatile PrivateMessageFactory privateMessageFactory;
@Inject @Inject
protected volatile IntroductionManager introductionManager; volatile IntroductionManager introductionManager;
@Inject @Inject
protected volatile ForumSharingManager forumSharingManager; volatile ForumSharingManager forumSharingManager;
@Inject @Inject
protected volatile BlogSharingManager blogSharingManager; volatile BlogSharingManager blogSharingManager;
private volatile GroupId groupId = null; private volatile GroupId groupId = null;
private volatile ContactId contactId = null; private volatile ContactId contactId = null;
@@ -309,7 +309,7 @@ public class ConversationActivity extends BriarActivity
} }
private void displayContactDetails() { private void displayContactDetails() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
toolbarAvatar.setImageDrawable( toolbarAvatar.setImageDrawable(
@@ -374,7 +374,7 @@ public class ConversationActivity extends BriarActivity
private void displayMessages(final Collection<PrivateMessageHeader> headers, private void displayMessages(final Collection<PrivateMessageHeader> headers,
final Collection<IntroductionMessage> introductions, final Collection<IntroductionMessage> introductions,
final Collection<InvitationMessage> invitations) { final Collection<InvitationMessage> invitations) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
textInputView.setSendButtonEnabled(true); textInputView.setSendButtonEnabled(true);
@@ -446,7 +446,7 @@ public class ConversationActivity extends BriarActivity
} }
private void displayMessageBody(final MessageId m, final byte[] body) { private void displayMessageBody(final MessageId m, final byte[] body) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
bodyCache.put(m, body); bodyCache.put(m, body);
@@ -466,7 +466,7 @@ public class ConversationActivity extends BriarActivity
} }
private void addConversationItem(final ConversationItem item) { private void addConversationItem(final ConversationItem item) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
adapter.add(item); adapter.add(item);
@@ -599,7 +599,7 @@ public class ConversationActivity extends BriarActivity
} }
private void markMessageReadIfNew(final BaseMessageHeader h) { private void markMessageReadIfNew(final BaseMessageHeader h) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
ConversationItem item = adapter.getLastItem(); ConversationItem item = adapter.getLastItem();
@@ -635,7 +635,7 @@ public class ConversationActivity extends BriarActivity
private void markMessages(final Collection<MessageId> messageIds, private void markMessages(final Collection<MessageId> messageIds,
final boolean sent, final boolean seen) { final boolean sent, final boolean seen) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
Set<MessageId> messages = new HashSet<>(messageIds); Set<MessageId> messages = new HashSet<>(messageIds);
@@ -747,7 +747,7 @@ public class ConversationActivity extends BriarActivity
} }
private void finishAfterContactRemoved() { private void finishAfterContactRemoved() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
String deleted = getString(R.string.contact_deleted_toast); String deleted = getString(R.string.contact_deleted_toast);
@@ -781,7 +781,7 @@ public class ConversationActivity extends BriarActivity
} }
private void enableIntroductionAction(final MenuItem item) { private void enableIntroductionAction(final MenuItem item) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
item.setEnabled(true); item.setEnabled(true);
@@ -790,7 +790,7 @@ public class ConversationActivity extends BriarActivity
} }
private void showIntroductionOnboarding() { private void showIntroductionOnboarding() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
// find view of overflow icon // find view of overflow icon
@@ -877,7 +877,7 @@ public class ConversationActivity extends BriarActivity
} }
private void introductionResponseError() { private void introductionResponseError() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
Toast.makeText(ConversationActivity.this, Toast.makeText(ConversationActivity.this,

View File

@@ -1,7 +1,10 @@
package org.briarproject.android.controller; package org.briarproject.android.controller;
import android.app.Activity;
public interface ActivityLifecycleController { public interface ActivityLifecycleController {
void onActivityCreate();
void onActivityCreate(Activity activity);
void onActivityResume(); void onActivityResume();

View File

@@ -20,11 +20,11 @@ public class BriarControllerImpl implements BriarController {
Logger.getLogger(BriarControllerImpl.class.getName()); Logger.getLogger(BriarControllerImpl.class.getName());
@Inject @Inject
protected BriarServiceConnection serviceConnection; BriarServiceConnection serviceConnection;
@Inject @Inject
protected DatabaseConfig databaseConfig; DatabaseConfig databaseConfig;
@Inject @Inject
protected Activity activity; Activity activity;
private boolean bound = false; private boolean bound = false;
@@ -35,7 +35,7 @@ public class BriarControllerImpl implements BriarController {
@Override @Override
@CallSuper @CallSuper
public void onActivityCreate() { public void onActivityCreate(Activity activity) {
if (databaseConfig.getEncryptionKey() != null) startAndBindService(); if (databaseConfig.getEncryptionKey() != null) startAndBindService();
} }
@@ -90,7 +90,7 @@ public class BriarControllerImpl implements BriarController {
}.start(); }.start();
} }
protected void unbindService() { private void unbindService() {
if (bound) activity.unbindService(serviceConnection); if (bound) activity.unbindService(serviceConnection);
} }

View File

@@ -6,8 +6,6 @@ import org.briarproject.api.identity.LocalAuthor;
public interface NavDrawerController extends ActivityLifecycleController { public interface NavDrawerController extends ActivityLifecycleController {
void setTransportListener(TransportStateListener transportListener);
boolean isTransportRunning(TransportId transportId); boolean isTransportRunning(TransportId transportId);
void storeLocalAuthor(LocalAuthor author, void storeLocalAuthor(LocalAuthor author,

View File

@@ -30,19 +30,17 @@ public class NavDrawerControllerImpl extends DbControllerImpl
Logger.getLogger(NavDrawerControllerImpl.class.getName()); Logger.getLogger(NavDrawerControllerImpl.class.getName());
@Inject @Inject
protected ReferenceManager referenceManager; ReferenceManager referenceManager;
@Inject @Inject
protected PluginManager pluginManager; PluginManager pluginManager;
@Inject @Inject
protected EventBus eventBus; EventBus eventBus;
@Inject
protected Activity activity;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject @Inject
protected volatile IdentityManager identityManager; protected volatile IdentityManager identityManager;
private TransportStateListener transportStateListener; private TransportStateListener listener;
@Inject @Inject
public NavDrawerControllerImpl() { public NavDrawerControllerImpl() {
@@ -50,8 +48,8 @@ public class NavDrawerControllerImpl extends DbControllerImpl
} }
@Override @Override
public void onActivityCreate() { public void onActivityCreate(Activity activity) {
listener = (TransportStateListener) activity;
} }
@Override @Override
@@ -88,21 +86,14 @@ public class NavDrawerControllerImpl extends DbControllerImpl
private void transportStateUpdate(final TransportId id, private void transportStateUpdate(final TransportId id,
final boolean enabled) { final boolean enabled) {
activity.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (transportStateListener != null) { listener.stateUpdate(id, enabled);
transportStateListener.stateUpdate(id, enabled);
}
} }
}); });
} }
@Override
public void setTransportListener(TransportStateListener transportListener) {
this.transportStateListener = transportListener;
}
@Override @Override
public boolean isTransportRunning(TransportId transportId) { public boolean isTransportRunning(TransportId transportId) {
Plugin plugin = pluginManager.getPlugin(transportId); Plugin plugin = pluginManager.getPlugin(transportId);

View File

@@ -1,8 +1,9 @@
package org.briarproject.android.controller; package org.briarproject.android.controller;
import org.briarproject.android.DestroyableContext;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
public interface TransportStateListener { public interface TransportStateListener extends DestroyableContext {
void stateUpdate(TransportId id, boolean enabled); void stateUpdate(TransportId id, boolean enabled);
} }

View File

@@ -2,35 +2,33 @@ package org.briarproject.android.controller.handler;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import org.briarproject.android.DestroyableActivity; import org.briarproject.android.DestroyableContext;
public abstract class UiResultExceptionHandler<R, E extends Exception> public abstract class UiResultExceptionHandler<R, E extends Exception>
implements ResultExceptionHandler<R, E> { implements ResultExceptionHandler<R, E> {
private final DestroyableActivity listener; private final DestroyableContext listener;
protected UiResultExceptionHandler(DestroyableActivity listener) { protected UiResultExceptionHandler(DestroyableContext listener) {
this.listener = listener; this.listener = listener;
} }
@Override @Override
public void onResult(final R result) { public void onResult(final R result) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!listener.hasBeenDestroyed()) onResultUi(result);
onResultUi(result);
} }
}); });
} }
@Override @Override
public void onException(final E exception) { public void onException(final E exception) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!listener.hasBeenDestroyed()) onExceptionUi(exception);
onExceptionUi(exception);
} }
}); });
} }

View File

@@ -2,24 +2,22 @@ package org.briarproject.android.controller.handler;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import org.briarproject.android.DestroyableActivity; import org.briarproject.android.DestroyableContext;
import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
public abstract class UiResultHandler<R> implements ResultHandler<R> { public abstract class UiResultHandler<R> implements ResultHandler<R> {
private final DestroyableActivity listener; private final DestroyableContext listener;
protected UiResultHandler(DestroyableActivity listener) { protected UiResultHandler(DestroyableContext listener) {
this.listener = listener; this.listener = listener;
} }
@Override @Override
public void onResult(final R result) { public void onResult(final R result) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!listener.hasBeenDestroyed()) onResultUi(result);
onResultUi(result);
} }
}); });
} }

View File

@@ -144,7 +144,7 @@ public class CreateForumActivity extends BriarActivity
} }
private void displayForum(final Forum f) { private void displayForum(final Forum f) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
Intent i = new Intent(CreateForumActivity.this, Intent i = new Intent(CreateForumActivity.this,

View File

@@ -267,9 +267,8 @@ public class ForumActivity extends BriarActivity implements
// root post // root post
forumController.createPost(StringUtils.toUtf8(text), resultHandler); forumController.createPost(StringUtils.toUtf8(text), resultHandler);
} else { } else {
forumController forumController.createPost(StringUtils.toUtf8(text),
.createPost(StringUtils.toUtf8(text), replyEntry.getId(), replyEntry.getId(), resultHandler);
resultHandler);
} }
textInput.hideSoftKeyboard(); textInput.hideSoftKeyboard();
textInput.setVisibility(GONE); textInput.setVisibility(GONE);
@@ -344,7 +343,7 @@ public class ForumActivity extends BriarActivity implements
} }
@Override @Override
public void onExternalEntryAdded(ForumPostHeader header) { public void onForumPostReceived(ForumPostHeader header) {
forumController.loadPost(header, forumController.loadPost(header,
new UiResultExceptionHandler<ForumEntry, DbException>(this) { new UiResultExceptionHandler<ForumEntry, DbException>(this) {
@Override @Override
@@ -357,6 +356,10 @@ public class ForumActivity extends BriarActivity implements
// TODO add proper exception handling // TODO add proper exception handling
} }
}); });
}
@Override
public void onForumRemoved() {
finish();
} }
} }

View File

@@ -3,6 +3,7 @@ package org.briarproject.android.forum;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import org.briarproject.android.DestroyableContext;
import org.briarproject.android.controller.ActivityLifecycleController; import org.briarproject.android.controller.ActivityLifecycleController;
import org.briarproject.android.controller.handler.ResultExceptionHandler; import org.briarproject.android.controller.handler.ResultExceptionHandler;
import org.briarproject.android.controller.handler.ResultHandler; import org.briarproject.android.controller.handler.ResultHandler;
@@ -38,9 +39,13 @@ public interface ForumController extends ActivityLifecycleController {
void createPost(byte[] body, MessageId parentId, void createPost(byte[] body, MessageId parentId,
ResultExceptionHandler<ForumEntry, DbException> resultHandler); ResultExceptionHandler<ForumEntry, DbException> resultHandler);
interface ForumPostListener { interface ForumPostListener extends DestroyableContext {
@UiThread @UiThread
void onExternalEntryAdded(ForumPostHeader header); void onForumPostReceived(ForumPostHeader header);
@UiThread
void onForumRemoved();
} }
} }

View File

@@ -51,21 +51,19 @@ public class ForumControllerImpl extends DbControllerImpl
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(ForumControllerImpl.class.getName()); Logger.getLogger(ForumControllerImpl.class.getName());
@Inject
protected Activity activity;
@Inject @Inject
@CryptoExecutor @CryptoExecutor
protected Executor cryptoExecutor; Executor cryptoExecutor;
@Inject @Inject
volatile ForumPostFactory forumPostFactory; volatile ForumPostFactory forumPostFactory;
@Inject @Inject
protected volatile CryptoComponent crypto; volatile CryptoComponent crypto;
@Inject @Inject
protected volatile ForumManager forumManager; volatile ForumManager forumManager;
@Inject @Inject
protected volatile EventBus eventBus; volatile EventBus eventBus;
@Inject @Inject
protected volatile IdentityManager identityManager; volatile IdentityManager identityManager;
private final Map<MessageId, byte[]> bodyCache = new ConcurrentHashMap<>(); private final Map<MessageId, byte[]> bodyCache = new ConcurrentHashMap<>();
private final AtomicLong newestTimeStamp = new AtomicLong(); private final AtomicLong newestTimeStamp = new AtomicLong();
@@ -81,7 +79,7 @@ public class ForumControllerImpl extends DbControllerImpl
} }
@Override @Override
public void onActivityCreate() { public void onActivityCreate(Activity activity) {
if (activity instanceof ForumPostListener) { if (activity instanceof ForumPostListener) {
listener = (ForumPostListener) activity; listener = (ForumPostListener) activity;
} else { } else {
@@ -114,10 +112,10 @@ public class ForumControllerImpl extends DbControllerImpl
LOG.info("Forum post received, adding..."); LOG.info("Forum post received, adding...");
final ForumPostHeader fph = pe.getForumPostHeader(); final ForumPostHeader fph = pe.getForumPostHeader();
updateNewestTimestamp(fph.getTimestamp()); updateNewestTimestamp(fph.getTimestamp());
activity.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
listener.onExternalEntryAdded(fph); listener.onForumPostReceived(fph);
} }
}); });
} }
@@ -125,10 +123,10 @@ public class ForumControllerImpl extends DbControllerImpl
GroupRemovedEvent s = (GroupRemovedEvent) e; GroupRemovedEvent s = (GroupRemovedEvent) e;
if (s.getGroup().getId().equals(forum.getId())) { if (s.getGroup().getId().equals(forum.getId())) {
LOG.info("Forum removed"); LOG.info("Forum removed");
activity.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
activity.finish(); listener.onForumRemoved();
} }
}); });
} }

View File

@@ -56,13 +56,13 @@ public class ForumListFragment extends BaseEventFragment implements
private Snackbar snackbar; private Snackbar snackbar;
@Inject @Inject
protected AndroidNotificationManager notificationManager; AndroidNotificationManager notificationManager;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject @Inject
protected volatile ForumManager forumManager; volatile ForumManager forumManager;
@Inject @Inject
protected volatile ForumSharingManager forumSharingManager; volatile ForumSharingManager forumSharingManager;
public static ForumListFragment newInstance() { public static ForumListFragment newInstance() {
@@ -181,7 +181,7 @@ public class ForumListFragment extends BaseEventFragment implements
} }
private void displayForums(final Collection<ForumListItem> forums) { private void displayForums(final Collection<ForumListItem> forums) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (forums.size() > 0) adapter.addAll(forums); if (forums.size() > 0) adapter.addAll(forums);
@@ -211,10 +211,9 @@ public class ForumListFragment extends BaseEventFragment implements
} }
private void displayAvailableForums(final int availableCount) { private void displayAvailableForums(final int availableCount) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (getActivity() == null) return;
if (availableCount == 0) { if (availableCount == 0) {
snackbar.dismiss(); snackbar.dismiss();
} else { } else {
@@ -245,16 +244,16 @@ public class ForumListFragment extends BaseEventFragment implements
removeForum(g.getGroup().getId()); removeForum(g.getGroup().getId());
} }
} else if (e instanceof ForumPostReceivedEvent) { } else if (e instanceof ForumPostReceivedEvent) {
ForumPostReceivedEvent m = (ForumPostReceivedEvent) e; ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
LOG.info("Forum post added, updating..."); LOG.info("Forum post added, updating...");
updateItem(m.getGroupId(), m.getForumPostHeader()); updateItem(f.getGroupId(), f.getForumPostHeader());
} else if (e instanceof ForumInvitationReceivedEvent) { } else if (e instanceof ForumInvitationReceivedEvent) {
loadAvailableForums(); loadAvailableForums();
} }
} }
private void updateItem(final GroupId g, final ForumPostHeader m) { private void updateItem(final GroupId g, final ForumPostHeader m) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
int position = adapter.findItemPosition(g); int position = adapter.findItemPosition(g);
@@ -268,7 +267,7 @@ public class ForumListFragment extends BaseEventFragment implements
} }
private void removeForum(final GroupId g) { private void removeForum(final GroupId g) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
int position = adapter.findItemPosition(g); int position = adapter.findItemPosition(g);

View File

@@ -7,9 +7,10 @@ import android.support.annotation.UiThread;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import org.briarproject.android.ActivityComponent; import org.briarproject.android.ActivityComponent;
import org.briarproject.android.DestroyableActivity; import org.briarproject.android.DestroyableContext;
public abstract class BaseFragment extends Fragment { public abstract class BaseFragment extends Fragment
implements DestroyableContext {
protected BaseFragmentListener listener; protected BaseFragmentListener listener;
@@ -20,12 +21,7 @@ public abstract class BaseFragment extends Fragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { listener = (BaseFragmentListener) context;
listener = (BaseFragmentListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(
"Using class must implement BaseFragmentListener");
}
} }
@Override @Override
@@ -37,7 +33,7 @@ public abstract class BaseFragment extends Fragment {
@Override @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) { public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
this.injectFragment(listener.getActivityComponent()); injectFragment(listener.getActivityComponent());
listener.onFragmentCreated(getUniqueTag()); listener.onFragmentCreated(getUniqueTag());
} }
@@ -46,7 +42,7 @@ public abstract class BaseFragment extends Fragment {
getActivity().supportFinishAfterTransition(); getActivity().supportFinishAfterTransition();
} }
public interface BaseFragmentListener extends DestroyableActivity { public interface BaseFragmentListener extends DestroyableContext {
void runOnDbThread(Runnable runnable); void runOnDbThread(Runnable runnable);
@@ -56,4 +52,9 @@ public abstract class BaseFragment extends Fragment {
@UiThread @UiThread
void onFragmentCreated(String tag); void onFragmentCreated(String tag);
} }
@Override
public void runOnUiThreadUnlessDestroyed(Runnable r) {
listener.runOnUiThreadUnlessDestroyed(r);
}
} }

View File

@@ -75,15 +75,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { listener = (SettingsActivity) context;
listener = (SettingsActivity) context; androidExecutor = listener.getAndroidExecutor();
androidExecutor = listener.getAndroidExecutor(); settingsManager = listener.getSettingsManager();
settingsManager = listener.getSettingsManager(); eventBus = listener.getEventBus();
eventBus = listener.getEventBus();
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
+ " is not a SettingsActivity");
}
} }
@Override @Override
@@ -195,7 +190,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
} }
private void displaySettings() { private void displaySettings() {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
enableBluetooth.setValue(Boolean.toString(bluetoothSetting)); enableBluetooth.setValue(Boolean.toString(bluetoothSetting));

View File

@@ -39,10 +39,8 @@ import static java.util.logging.Level.WARNING;
public class ContactChooserFragment extends BaseFragment { public class ContactChooserFragment extends BaseFragment {
public final static String TAG = "ContactChooserFragment"; public static final String TAG = ContactChooserFragment.class.getName();
private static final Logger LOG = Logger.getLogger(TAG);
private static final Logger LOG =
Logger.getLogger(ContactChooserFragment.class.getName());
private IntroductionActivity introductionActivity; private IntroductionActivity introductionActivity;
private BriarRecyclerView list; private BriarRecyclerView list;
@@ -72,12 +70,7 @@ public class ContactChooserFragment extends BaseFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { introductionActivity = (IntroductionActivity) context;
introductionActivity = (IntroductionActivity) context;
} catch (ClassCastException e) {
throw new InstantiationError(
"This fragment is only meant to be attached to the IntroductionActivity");
}
} }
@Override @Override
@@ -182,7 +175,7 @@ public class ContactChooserFragment extends BaseFragment {
private void displayContacts(final AuthorId localAuthorId, private void displayContacts(final AuthorId localAuthorId,
final List<ContactListItem> contacts) { final List<ContactListItem> contacts) {
introductionActivity.runOnUiThread(new Runnable() { introductionActivity.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
adapter.setLocalAuthor(localAuthorId); adapter.setLocalAuthor(localAuthorId);

View File

@@ -37,12 +37,12 @@ import static java.util.logging.Level.WARNING;
public class IntroductionMessageFragment extends BaseFragment public class IntroductionMessageFragment extends BaseFragment
implements TextInputView.TextInputListener { implements TextInputView.TextInputListener {
public final static String TAG = "IntroductionMessageFragment"; public static final String TAG =
IntroductionMessageFragment.class.getName();
private static final Logger LOG = Logger.getLogger(TAG);
private final static String CONTACT_ID_1 = "contact1"; private final static String CONTACT_ID_1 = "contact1";
private final static String CONTACT_ID_2 = "contact2"; private final static String CONTACT_ID_2 = "contact2";
private static final Logger LOG =
Logger.getLogger(IntroductionMessageFragment.class.getName());
private IntroductionActivity introductionActivity; private IntroductionActivity introductionActivity;
private ViewHolder ui; private ViewHolder ui;
@@ -72,12 +72,7 @@ public class IntroductionMessageFragment extends BaseFragment
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { introductionActivity = (IntroductionActivity) context;
introductionActivity = (IntroductionActivity) context;
} catch (ClassCastException e) {
throw new java.lang.InstantiationError(
"This fragment is only meant to be attached to the IntroductionActivity");
}
} }
@Override @Override
@@ -142,7 +137,7 @@ public class IntroductionMessageFragment extends BaseFragment
} }
private void setUpViews(final Contact c1, final Contact c2) { private void setUpViews(final Contact c1, final Contact c2) {
introductionActivity.runOnUiThread(new Runnable() { introductionActivity.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
contact1 = c1; contact1 = c1;
@@ -209,7 +204,7 @@ public class IntroductionMessageFragment extends BaseFragment
} }
private void introductionError() { private void introductionError() {
introductionActivity.runOnUiThread(new Runnable() { introductionActivity.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
Toast.makeText(introductionActivity, Toast.makeText(introductionActivity,

View File

@@ -205,6 +205,7 @@ public class AddContactActivity extends BriarActivity
void loadLocalAuthor() { void loadLocalAuthor() {
runOnDbThread(new Runnable() { runOnDbThread(new Runnable() {
@Override
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@@ -222,7 +223,7 @@ public class AddContactActivity extends BriarActivity
} }
void setLocalAuthorId(final AuthorId localAuthorId) { void setLocalAuthorId(final AuthorId localAuthorId) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
AddContactActivity.this.localAuthorId = localAuthorId; AddContactActivity.this.localAuthorId = localAuthorId;
@@ -283,8 +284,10 @@ public class AddContactActivity extends BriarActivity
} }
} }
@Override
public void connectionSucceeded() { public void connectionSucceeded() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() { public void run() {
connected = true; connected = true;
setView(new ConfirmationCodeView(AddContactActivity.this, setView(new ConfirmationCodeView(AddContactActivity.this,
@@ -293,8 +296,10 @@ public class AddContactActivity extends BriarActivity
}); });
} }
@Override
public void connectionFailed() { public void connectionFailed() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() { public void run() {
connectionFailed = true; connectionFailed = true;
setView(new ErrorView(AddContactActivity.this, setView(new ErrorView(AddContactActivity.this,
@@ -304,9 +309,11 @@ public class AddContactActivity extends BriarActivity
}); });
} }
@Override
public void keyAgreementSucceeded(final int localCode, public void keyAgreementSucceeded(final int localCode,
final int remoteCode) { final int remoteCode) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() { public void run() {
localConfirmationCode = localCode; localConfirmationCode = localCode;
remoteConfirmationCode = remoteCode; remoteConfirmationCode = remoteCode;
@@ -315,8 +322,10 @@ public class AddContactActivity extends BriarActivity
}); });
} }
@Override
public void keyAgreementFailed() { public void keyAgreementFailed() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() { public void run() {
connectionFailed = true; connectionFailed = true;
setView(new ErrorView(AddContactActivity.this, setView(new ErrorView(AddContactActivity.this,
@@ -326,8 +335,10 @@ public class AddContactActivity extends BriarActivity
}); });
} }
@Override
public void remoteConfirmationSucceeded() { public void remoteConfirmationSucceeded() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() { public void run() {
remoteCompared = true; remoteCompared = true;
remoteMatched = true; remoteMatched = true;
@@ -339,8 +350,10 @@ public class AddContactActivity extends BriarActivity
}); });
} }
@Override
public void remoteConfirmationFailed() { public void remoteConfirmationFailed() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() { public void run() {
remoteCompared = true; remoteCompared = true;
remoteMatched = false; remoteMatched = false;
@@ -352,8 +365,10 @@ public class AddContactActivity extends BriarActivity
}); });
} }
@Override
public void pseudonymExchangeSucceeded(final String remoteName) { public void pseudonymExchangeSucceeded(final String remoteName) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() { public void run() {
contactName = remoteName; contactName = remoteName;
showToastAndFinish(); showToastAndFinish();
@@ -361,8 +376,10 @@ public class AddContactActivity extends BriarActivity
}); });
} }
@Override
public void pseudonymExchangeFailed() { public void pseudonymExchangeFailed() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() { public void run() {
setView(new ErrorView(AddContactActivity.this, setView(new ErrorView(AddContactActivity.this,
R.string.connection_failed, R.string.connection_failed,
@@ -386,34 +403,42 @@ public class AddContactActivity extends BriarActivity
this.handle = handle; this.handle = handle;
} }
@Override
public void connectionSucceeded() { public void connectionSucceeded() {
// Wait for key agreement to succeed or fail // Wait for key agreement to succeed or fail
} }
@Override
public void connectionFailed() { public void connectionFailed() {
referenceManager.removeReference(handle, InvitationTask.class); referenceManager.removeReference(handle, InvitationTask.class);
} }
@Override
public void keyAgreementSucceeded(int localCode, int remoteCode) { public void keyAgreementSucceeded(int localCode, int remoteCode) {
// Wait for remote confirmation to succeed or fail // Wait for remote confirmation to succeed or fail
} }
@Override
public void keyAgreementFailed() { public void keyAgreementFailed() {
referenceManager.removeReference(handle, InvitationTask.class); referenceManager.removeReference(handle, InvitationTask.class);
} }
@Override
public void remoteConfirmationSucceeded() { public void remoteConfirmationSucceeded() {
// Wait for the pseudonym exchange to succeed or fail // Wait for the pseudonym exchange to succeed or fail
} }
@Override
public void remoteConfirmationFailed() { public void remoteConfirmationFailed() {
referenceManager.removeReference(handle, InvitationTask.class); referenceManager.removeReference(handle, InvitationTask.class);
} }
@Override
public void pseudonymExchangeSucceeded(String remoteName) { public void pseudonymExchangeSucceeded(String remoteName) {
referenceManager.removeReference(handle, InvitationTask.class); referenceManager.removeReference(handle, InvitationTask.class);
} }
@Override
public void pseudonymExchangeFailed() { public void pseudonymExchangeFailed() {
referenceManager.removeReference(handle, InvitationTask.class); referenceManager.removeReference(handle, InvitationTask.class);
} }

View File

@@ -43,12 +43,7 @@ public class IntroFragment extends BaseFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { screenSeenListener = (IntroScreenSeenListener) context;
screenSeenListener = (IntroScreenSeenListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(
"Using class must implement IntroScreenSeenListener");
}
} }
@Override @Override

View File

@@ -128,7 +128,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
} }
private void keyAgreementFinished(final KeyAgreementResult result) { private void keyAgreementFinished(final KeyAgreementResult result) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
startContactExchange(result); startContactExchange(result);
@@ -162,7 +162,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
@Override @Override
public void contactExchangeSucceeded(final Author remoteAuthor) { public void contactExchangeSucceeded(final Author remoteAuthor) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
String contactName = remoteAuthor.getName(); String contactName = remoteAuthor.getName();
@@ -177,7 +177,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
@Override @Override
public void duplicateContact(final Author remoteAuthor) { public void duplicateContact(final Author remoteAuthor) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
String contactName = remoteAuthor.getName(); String contactName = remoteAuthor.getName();
@@ -192,7 +192,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
@Override @Override
public void contactExchangeFailed() { public void contactExchangeFailed() {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
Toast.makeText(KeyAgreementActivity.this, Toast.makeText(KeyAgreementActivity.this,

View File

@@ -18,7 +18,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.AlphaAnimation; import android.view.animation.AlphaAnimation;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@@ -67,23 +66,21 @@ public class ShowQrCodeFragment extends BaseEventFragment
private static final Logger LOG = Logger.getLogger(TAG); private static final Logger LOG = Logger.getLogger(TAG);
@Inject @Inject
protected KeyAgreementTaskFactory keyAgreementTaskFactory; KeyAgreementTaskFactory keyAgreementTaskFactory;
@Inject @Inject
protected PayloadEncoder payloadEncoder; PayloadEncoder payloadEncoder;
@Inject @Inject
protected PayloadParser payloadParser; PayloadParser payloadParser;
@Inject @Inject
protected AndroidExecutor androidExecutor; AndroidExecutor androidExecutor;
@Inject @Inject
@IoExecutor @IoExecutor
protected Executor ioExecutor; Executor ioExecutor;
private CameraView cameraView; private CameraView cameraView;
private ViewGroup cameraOverlay;
private View statusView; private View statusView;
private TextView status; private TextView status;
private ImageView qrCode; private ImageView qrCode;
private ProgressBar mainProgressBar;
private TextView mainProgressTitle; private TextView mainProgressTitle;
private ViewGroup mainProgressContainer; private ViewGroup mainProgressContainer;
@@ -124,11 +121,9 @@ public class ShowQrCodeFragment extends BaseEventFragment
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
cameraView = (CameraView) view.findViewById(R.id.camera_view); cameraView = (CameraView) view.findViewById(R.id.camera_view);
cameraOverlay = (ViewGroup) view.findViewById(R.id.camera_overlay);
statusView = view.findViewById(R.id.status_container); statusView = view.findViewById(R.id.status_container);
status = (TextView) view.findViewById(R.id.connect_status); status = (TextView) view.findViewById(R.id.connect_status);
qrCode = (ImageView) view.findViewById(R.id.qr_code); qrCode = (ImageView) view.findViewById(R.id.qr_code);
mainProgressBar = (ProgressBar) view.findViewById(R.id.progress_bar);
mainProgressTitle = mainProgressTitle =
(TextView) view.findViewById(R.id.title_progress_bar); (TextView) view.findViewById(R.id.title_progress_bar);
mainProgressContainer = mainProgressContainer =
@@ -286,11 +281,12 @@ public class ShowQrCodeFragment extends BaseEventFragment
KeyAgreementAbortedEvent event = (KeyAgreementAbortedEvent) e; KeyAgreementAbortedEvent event = (KeyAgreementAbortedEvent) e;
keyAgreementAborted(event.didRemoteAbort()); keyAgreementAborted(event.didRemoteAbort());
} else if (e instanceof KeyAgreementFinishedEvent) { } else if (e instanceof KeyAgreementFinishedEvent) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
mainProgressContainer.setVisibility(VISIBLE); mainProgressContainer.setVisibility(VISIBLE);
mainProgressTitle.setText(R.string.exchanging_contact_details); mainProgressTitle.setText(
R.string.exchanging_contact_details);
} }
}); });
} }
@@ -309,9 +305,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
String input = String input =
Base64.encodeToString(payloadEncoder.encode(payload), Base64.encodeToString(payloadEncoder.encode(payload),
0); 0);
Bitmap bitmap = return QrCodeUtils.createQrCode(dm, input);
QrCodeUtils.createQrCode(dm, input);
return bitmap;
} }
@Override @Override
@@ -328,7 +322,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
} }
private void setQrCode(final Payload localPayload) { private void setQrCode(final Payload localPayload) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
generateBitmapQR(localPayload); generateBitmapQR(localPayload);
@@ -337,7 +331,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
} }
private void keyAgreementFailed() { private void keyAgreementFailed() {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
reset(); reset();
@@ -349,7 +343,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
} }
private void keyAgreementWaiting() { private void keyAgreementWaiting() {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
status.setText(R.string.waiting_for_contact); status.setText(R.string.waiting_for_contact);
@@ -358,7 +352,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
} }
private void keyAgreementStarted() { private void keyAgreementStarted() {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
mainProgressContainer.setVisibility(VISIBLE); mainProgressContainer.setVisibility(VISIBLE);
@@ -368,7 +362,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
} }
private void keyAgreementAborted(final boolean remoteAborted) { private void keyAgreementAborted(final boolean remoteAborted) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
reset(); reset();
@@ -385,7 +379,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
@Override @Override
public void handleResult(final Result result) { public void handleResult(final Result result) {
listener.runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
LOG.info("Got result from decoder"); LOG.info("Got result from decoder");

View File

@@ -46,10 +46,8 @@ import static org.briarproject.api.sharing.SharingConstants.GROUP_ID;
public class ContactSelectorFragment extends BaseFragment implements public class ContactSelectorFragment extends BaseFragment implements
BaseContactListAdapter.OnItemClickListener { BaseContactListAdapter.OnItemClickListener {
public final static String TAG = "ContactSelectorFragment"; public static final String TAG = ContactSelectorFragment.class.getName();
private static final Logger LOG = Logger.getLogger(TAG);
private static final Logger LOG =
Logger.getLogger(ContactSelectorFragment.class.getName());
private ShareActivity shareActivity; private ShareActivity shareActivity;
private Menu menu; private Menu menu;
@@ -84,12 +82,7 @@ public class ContactSelectorFragment extends BaseFragment implements
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { shareActivity = (ShareActivity) context;
shareActivity = (ShareActivity) context;
} catch (ClassCastException e) {
throw new InstantiationError(
"This fragment is only meant to be attached to a subclass of ShareActivity");
}
} }
@Override @Override
@@ -221,7 +214,7 @@ public class ContactSelectorFragment extends BaseFragment implements
} }
private void displayContacts(final List<ContactListItem> contacts) { private void displayContacts(final List<ContactListItem> contacts) {
shareActivity.runOnUiThread(new Runnable() { shareActivity.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!contacts.isEmpty()) adapter.addAll(contacts); if (!contacts.isEmpty()) adapter.addAll(contacts);

View File

@@ -32,7 +32,7 @@ abstract class InvitationsActivity extends BriarActivity
private BriarRecyclerView list; private BriarRecyclerView list;
@Inject @Inject
protected EventBus eventBus; EventBus eventBus;
@Override @Override
public void onCreate(Bundle state) { public void onCreate(Bundle state) {
@@ -103,7 +103,7 @@ abstract class InvitationsActivity extends BriarActivity
protected void displayInvitations( protected void displayInvitations(
final Collection<InvitationItem> invitations, final boolean clear) { final Collection<InvitationItem> invitations, final boolean clear) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (invitations.isEmpty()) { if (invitations.isEmpty()) {

View File

@@ -14,6 +14,7 @@ import org.briarproject.api.db.DbException;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import java.util.Collection; import java.util.Collection;
import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
@@ -23,6 +24,7 @@ import static java.util.logging.Level.WARNING;
public class ShareBlogMessageFragment extends ShareMessageFragment { public class ShareBlogMessageFragment extends ShareMessageFragment {
public final static String TAG = ShareBlogMessageFragment.class.getName(); public final static String TAG = ShareBlogMessageFragment.class.getName();
private static final Logger LOG = Logger.getLogger(TAG);
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject @Inject
@@ -52,6 +54,12 @@ public class ShareBlogMessageFragment extends ShareMessageFragment {
component.inject(this); component.inject(this);
} }
@Override
public String getUniqueTag() {
return TAG;
}
@Override
protected void share(final String msg) { protected void share(final String msg) {
listener.runOnDbThread(new Runnable() { listener.runOnDbThread(new Runnable() {
@Override @Override
@@ -69,8 +77,9 @@ public class ShareBlogMessageFragment extends ShareMessageFragment {
}); });
} }
@Override
protected void sharingError() { protected void sharingError() {
runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
int res = R.string.blogs_sharing_error; int res = R.string.blogs_sharing_error;

View File

@@ -14,6 +14,7 @@ import org.briarproject.api.forum.ForumSharingManager;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import java.util.Collection; import java.util.Collection;
import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
@@ -23,6 +24,7 @@ import static java.util.logging.Level.WARNING;
public class ShareForumMessageFragment extends ShareMessageFragment { public class ShareForumMessageFragment extends ShareMessageFragment {
public final static String TAG = ShareForumMessageFragment.class.getName(); public final static String TAG = ShareForumMessageFragment.class.getName();
private static final Logger LOG = Logger.getLogger(TAG);
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject @Inject
@@ -49,6 +51,12 @@ public class ShareForumMessageFragment extends ShareMessageFragment {
component.inject(this); component.inject(this);
} }
@Override
public String getUniqueTag() {
return TAG;
}
@Override
protected void share(final String msg) { protected void share(final String msg) {
listener.runOnDbThread(new Runnable() { listener.runOnDbThread(new Runnable() {
@Override @Override
@@ -67,8 +75,9 @@ public class ShareForumMessageFragment extends ShareMessageFragment {
}); });
} }
@Override
protected void sharingError() { protected void sharingError() {
runOnUiThread(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
int res = R.string.forum_share_error; int res = R.string.forum_share_error;

View File

@@ -18,7 +18,6 @@ import org.briarproject.api.sync.GroupId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
@@ -29,10 +28,6 @@ import static org.briarproject.api.sharing.SharingConstants.GROUP_ID;
abstract class ShareMessageFragment extends BaseFragment abstract class ShareMessageFragment extends BaseFragment
implements TextInputListener { implements TextInputListener {
public final static String TAG = ShareMessageFragment.class.getName();
protected static final Logger LOG = Logger.getLogger(TAG);
protected ViewHolder ui; protected ViewHolder ui;
private ShareActivity shareActivity; private ShareActivity shareActivity;
@@ -56,12 +51,7 @@ abstract class ShareMessageFragment extends BaseFragment
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { shareActivity = (ShareActivity) context;
shareActivity = (ShareActivity) context;
} catch (ClassCastException e) {
throw new InstantiationError(
"This fragment is only meant to be attached to the ShareForumActivity");
}
} }
@Override @Override
@@ -104,11 +94,6 @@ abstract class ShareMessageFragment extends BaseFragment
} }
} }
@Override
public String getUniqueTag() {
return TAG;
}
protected void setTitle(int res) { protected void setTitle(int res) {
shareActivity.setTitle(res); shareActivity.setTitle(res);
} }
@@ -136,10 +121,6 @@ abstract class ShareMessageFragment extends BaseFragment
return groupId; return groupId;
} }
protected void runOnUiThread(Runnable runnable) {
listener.runOnUiThread(runnable);
}
protected static class ViewHolder { protected static class ViewHolder {
protected final LargeTextInputView message; protected final LargeTextInputView message;

View File

@@ -27,16 +27,16 @@ import static java.util.logging.Level.WARNING;
abstract class SharingStatusActivity extends BriarActivity { abstract class SharingStatusActivity extends BriarActivity {
private static final Logger LOG =
Logger.getLogger(SharingStatusActivity.class.getName());
private GroupId groupId; private GroupId groupId;
private BriarRecyclerView sharedByList, sharedWithList; private BriarRecyclerView sharedByList, sharedWithList;
private SharingStatusAdapter sharedByAdapter, sharedWithAdapter; private SharingStatusAdapter sharedByAdapter, sharedWithAdapter;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject @Inject
protected volatile IdentityManager identityManager; volatile IdentityManager identityManager;
public final static String TAG = SharingStatusActivity.class.getName();
private static final Logger LOG = Logger.getLogger(TAG);
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -120,7 +120,7 @@ abstract class SharingStatusActivity extends BriarActivity {
} }
private void displaySharedBy(final List<ContactListItem> contacts) { private void displaySharedBy(final List<ContactListItem> contacts) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (contacts.isEmpty()) { if (contacts.isEmpty()) {
@@ -156,7 +156,7 @@ abstract class SharingStatusActivity extends BriarActivity {
} }
private void displaySharedWith(final List<ContactListItem> contacts) { private void displaySharedWith(final List<ContactListItem> contacts) {
runOnUiThread(new Runnable() { runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (contacts.isEmpty()) { if (contacts.isEmpty()) {

View File

@@ -24,17 +24,14 @@ import org.thoughtcrime.securesms.components.emoji.EmojiDrawer.EmojiEventListene
import org.thoughtcrime.securesms.components.emoji.EmojiEditText; import org.thoughtcrime.securesms.components.emoji.EmojiEditText;
import org.thoughtcrime.securesms.components.emoji.EmojiToggle; import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
import java.util.logging.Logger;
import static android.content.Context.INPUT_METHOD_SERVICE; import static android.content.Context.INPUT_METHOD_SERVICE;
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
import static android.view.KeyEvent.KEYCODE_BACK;
@UiThread @UiThread
public class TextInputView extends KeyboardAwareLinearLayout public class TextInputView extends KeyboardAwareLinearLayout
implements EmojiEventListener { implements EmojiEventListener {
private static final String TAG = TextInputView.class.getName();
private static final Logger LOG = Logger.getLogger(TAG);
protected final ViewHolder ui; protected final ViewHolder ui;
protected TextInputListener listener; protected TextInputListener listener;
@@ -59,7 +56,7 @@ public class TextInputView extends KeyboardAwareLinearLayout
protected void inflateLayout(Context context) { protected void inflateLayout(Context context) {
LayoutInflater inflater = (LayoutInflater) context LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.text_input_view, this, true); inflater.inflate(R.layout.text_input_view, this, true);
} }
@@ -91,7 +88,7 @@ public class TextInputView extends KeyboardAwareLinearLayout
ui.editText.setOnKeyListener(new OnKeyListener() { ui.editText.setOnKeyListener(new OnKeyListener() {
@Override @Override
public boolean onKey(View v, int keyCode, KeyEvent event) { public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && isEmojiDrawerOpen()) { if (keyCode == KEYCODE_BACK && isEmojiDrawerOpen()) {
hideEmojiDrawer(); hideEmojiDrawer();
return true; return true;
} }
@@ -207,10 +204,11 @@ public class TextInputView extends KeyboardAwareLinearLayout
} }
protected class ViewHolder { protected class ViewHolder {
private final EmojiToggle emojiToggle; private final EmojiToggle emojiToggle;
protected final EmojiEditText editText; final EmojiEditText editText;
protected final View sendButton; final View sendButton;
protected final EmojiDrawer emojiDrawer; final EmojiDrawer emojiDrawer;
private ViewHolder() { private ViewHolder() {
emojiToggle = (EmojiToggle) findViewById(R.id.emoji_toggle); emojiToggle = (EmojiToggle) findViewById(R.id.emoji_toggle);