mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Always check whether context has been destroyed.
This commit is contained in:
@@ -144,7 +144,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void displayForum(final Forum f) {
|
||||
runOnUiThread(new Runnable() {
|
||||
runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent i = new Intent(CreateForumActivity.this,
|
||||
|
||||
@@ -267,9 +267,8 @@ public class ForumActivity extends BriarActivity implements
|
||||
// root post
|
||||
forumController.createPost(StringUtils.toUtf8(text), resultHandler);
|
||||
} else {
|
||||
forumController
|
||||
.createPost(StringUtils.toUtf8(text), replyEntry.getId(),
|
||||
resultHandler);
|
||||
forumController.createPost(StringUtils.toUtf8(text),
|
||||
replyEntry.getId(), resultHandler);
|
||||
}
|
||||
textInput.hideSoftKeyboard();
|
||||
textInput.setVisibility(GONE);
|
||||
@@ -344,7 +343,7 @@ public class ForumActivity extends BriarActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalEntryAdded(ForumPostHeader header) {
|
||||
public void onForumPostReceived(ForumPostHeader header) {
|
||||
forumController.loadPost(header,
|
||||
new UiResultExceptionHandler<ForumEntry, DbException>(this) {
|
||||
@Override
|
||||
@@ -357,6 +356,10 @@ public class ForumActivity extends BriarActivity implements
|
||||
// TODO add proper exception handling
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForumRemoved() {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.android.forum;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.DestroyableContext;
|
||||
import org.briarproject.android.controller.ActivityLifecycleController;
|
||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
@@ -38,9 +39,13 @@ public interface ForumController extends ActivityLifecycleController {
|
||||
void createPost(byte[] body, MessageId parentId,
|
||||
ResultExceptionHandler<ForumEntry, DbException> resultHandler);
|
||||
|
||||
interface ForumPostListener {
|
||||
interface ForumPostListener extends DestroyableContext {
|
||||
|
||||
@UiThread
|
||||
void onExternalEntryAdded(ForumPostHeader header);
|
||||
void onForumPostReceived(ForumPostHeader header);
|
||||
|
||||
@UiThread
|
||||
void onForumRemoved();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,21 +51,19 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ForumControllerImpl.class.getName());
|
||||
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
@Inject
|
||||
@CryptoExecutor
|
||||
protected Executor cryptoExecutor;
|
||||
Executor cryptoExecutor;
|
||||
@Inject
|
||||
volatile ForumPostFactory forumPostFactory;
|
||||
@Inject
|
||||
protected volatile CryptoComponent crypto;
|
||||
volatile CryptoComponent crypto;
|
||||
@Inject
|
||||
protected volatile ForumManager forumManager;
|
||||
volatile ForumManager forumManager;
|
||||
@Inject
|
||||
protected volatile EventBus eventBus;
|
||||
volatile EventBus eventBus;
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
volatile IdentityManager identityManager;
|
||||
|
||||
private final Map<MessageId, byte[]> bodyCache = new ConcurrentHashMap<>();
|
||||
private final AtomicLong newestTimeStamp = new AtomicLong();
|
||||
@@ -81,7 +79,7 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreate() {
|
||||
public void onActivityCreate(Activity activity) {
|
||||
if (activity instanceof ForumPostListener) {
|
||||
listener = (ForumPostListener) activity;
|
||||
} else {
|
||||
@@ -114,10 +112,10 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
LOG.info("Forum post received, adding...");
|
||||
final ForumPostHeader fph = pe.getForumPostHeader();
|
||||
updateNewestTimestamp(fph.getTimestamp());
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onExternalEntryAdded(fph);
|
||||
listener.onForumPostReceived(fph);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -125,10 +123,10 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
GroupRemovedEvent s = (GroupRemovedEvent) e;
|
||||
if (s.getGroup().getId().equals(forum.getId())) {
|
||||
LOG.info("Forum removed");
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.finish();
|
||||
listener.onForumRemoved();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -56,13 +56,13 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
private Snackbar snackbar;
|
||||
|
||||
@Inject
|
||||
protected AndroidNotificationManager notificationManager;
|
||||
AndroidNotificationManager notificationManager;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected volatile ForumManager forumManager;
|
||||
volatile ForumManager forumManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
public static ForumListFragment newInstance() {
|
||||
|
||||
@@ -181,7 +181,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
}
|
||||
|
||||
private void displayForums(final Collection<ForumListItem> forums) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (forums.size() > 0) adapter.addAll(forums);
|
||||
@@ -211,10 +211,9 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
}
|
||||
|
||||
private void displayAvailableForums(final int availableCount) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getActivity() == null) return;
|
||||
if (availableCount == 0) {
|
||||
snackbar.dismiss();
|
||||
} else {
|
||||
@@ -245,16 +244,16 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
removeForum(g.getGroup().getId());
|
||||
}
|
||||
} else if (e instanceof ForumPostReceivedEvent) {
|
||||
ForumPostReceivedEvent m = (ForumPostReceivedEvent) e;
|
||||
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
||||
LOG.info("Forum post added, updating...");
|
||||
updateItem(m.getGroupId(), m.getForumPostHeader());
|
||||
updateItem(f.getGroupId(), f.getForumPostHeader());
|
||||
} else if (e instanceof ForumInvitationReceivedEvent) {
|
||||
loadAvailableForums();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateItem(final GroupId g, final ForumPostHeader m) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int position = adapter.findItemPosition(g);
|
||||
@@ -268,7 +267,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
}
|
||||
|
||||
private void removeForum(final GroupId g) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int position = adapter.findItemPosition(g);
|
||||
|
||||
Reference in New Issue
Block a user