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

Clear Forum Invitation adapter only when invitations could be removed

parent cf6aa019
No related branches found
No related tags found
No related merge requests found
......@@ -71,10 +71,17 @@ public class ForumInvitationsActivity extends BriarActivity
public void onResume() {
super.onResume();
eventBus.addListener(this);
loadForums();
loadForums(false);
}
private void loadForums() {
@Override
public void onPause() {
super.onPause();
eventBus.removeListener(this);
adapter.clear();
}
private void loadForums(final boolean clear) {
runOnDbThread(new Runnable() {
@Override
public void run() {
......@@ -97,7 +104,7 @@ public class ForumInvitationsActivity extends BriarActivity
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Load took " + duration + " ms");
displayForums(forums);
displayForums(forums, clear);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
......@@ -106,7 +113,8 @@ public class ForumInvitationsActivity extends BriarActivity
});
}
private void displayForums(final Collection<ForumInvitationItem> forums) {
private void displayForums(final Collection<ForumInvitationItem> forums,
final boolean clear) {
runOnUiThread(new Runnable() {
@Override
public void run() {
......@@ -114,38 +122,33 @@ public class ForumInvitationsActivity extends BriarActivity
LOG.info("No forums available, finishing");
finish();
} else {
if (clear) adapter.clear();
adapter.addAll(forums);
}
}
});
}
@Override
public void onPause() {
super.onPause();
eventBus.removeListener(this);
}
@Override
public void eventOccurred(Event e) {
if (e instanceof ContactRemovedEvent) {
LOG.info("Contact removed, reloading");
loadForums();
loadForums(true);
} else if (e instanceof GroupAddedEvent) {
GroupAddedEvent g = (GroupAddedEvent) e;
if (g.getGroup().getClientId().equals(forumManager.getClientId())) {
LOG.info("Forum added, reloading");
loadForums();
loadForums(false);
}
} else if (e instanceof GroupRemovedEvent) {
GroupRemovedEvent g = (GroupRemovedEvent) e;
if (g.getGroup().getClientId().equals(forumManager.getClientId())) {
LOG.info("Forum removed, reloading");
loadForums();
loadForums(true);
}
} else if (e instanceof ForumInvitationReceivedEvent) {
LOG.info("Available forums updated, reloading");
loadForums();
loadForums(false);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment