mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Merge branch '543-flicker-when-forum-invitation-is-removed-from-list' into 'master'
Remove forum invitations from list instead of reloading Closes #543 See merge request !255
This commit is contained in:
@@ -12,6 +12,7 @@ import android.widget.TextView;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.TextAvatarView;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.forum.ForumSharingMessage;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -94,6 +95,10 @@ class ForumInvitationAdapter extends
|
||||
forums.addAll(list);
|
||||
}
|
||||
|
||||
public void remove(ForumInvitationItem item) {
|
||||
forums.remove(item);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
forums.clear();
|
||||
}
|
||||
@@ -154,7 +159,7 @@ class ForumInvitationAdapter extends
|
||||
@Override
|
||||
public boolean areContentsTheSame(ForumInvitationItem oldItem,
|
||||
ForumInvitationItem newItem) {
|
||||
return oldItem.getForum().equals(newItem.getForum()) &&
|
||||
return oldItem.isSubscribed() == newItem.isSubscribed() &&
|
||||
oldItem.getContacts().equals(newItem.getContacts());
|
||||
}
|
||||
|
||||
|
||||
@@ -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,39 +122,33 @@ public class ForumInvitationsActivity extends BriarActivity
|
||||
LOG.info("No forums available, finishing");
|
||||
finish();
|
||||
} else {
|
||||
adapter.clear();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +160,12 @@ public class ForumInvitationsActivity extends BriarActivity
|
||||
int res = R.string.forum_declined_toast;
|
||||
if (accept) res = R.string.forum_joined_toast;
|
||||
Toast.makeText(this, res, LENGTH_SHORT).show();
|
||||
|
||||
// remove item and finish if it was the last
|
||||
adapter.remove(item);
|
||||
if (adapter.getItemCount() == 0) {
|
||||
supportFinishAfterTransition();
|
||||
}
|
||||
}
|
||||
|
||||
private void respondToInvitation(final ForumInvitationItem item,
|
||||
@@ -174,7 +182,6 @@ public class ForumInvitationsActivity extends BriarActivity
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
loadForums();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user