[android] fix possible duplicates in list

When doing reloads of list items such as when adding test contacts,
we loaded different versions of those items and added them to the list.
According to the documentation
https://developer.android.com/reference/android/support/v7/util/SortedList.html#add
> If the sorting criteria of the item is changed,
> SortedList won't be able to find its duplicate in the list
> which will result in having a duplicate of the Item in the list.

For the contact list at least, new contacts caused reloads of the entire list
and new messages caused the contacts to be sorted differently.
Thus we ended up with duplicate contacts in the list.

This commit fixes this by replacing the contacts in the list instead of adding them.
It applies the same fix to forums and private groups
which use the same logic and are thus also affected.

Fixes #1210
This commit is contained in:
Torsten Grote
2019-10-15 16:25:10 -03:00
parent f45d00e23c
commit 0d4cb05ac0
4 changed files with 7 additions and 3 deletions

View File

@@ -267,7 +267,7 @@ public class ContactListFragment extends BaseFragment implements EventListener,
if (revision == adapter.getRevision()) {
adapter.incrementRevision();
if (contacts.isEmpty()) list.showData();
else adapter.addAll(contacts);
else adapter.replaceAll(contacts);
} else {
LOG.info("Concurrent update, reloading");
loadContacts();

View File

@@ -182,7 +182,7 @@ public class ForumListFragment extends BaseEventFragment implements
if (revision == adapter.getRevision()) {
adapter.incrementRevision();
if (forums.isEmpty()) list.showData();
else adapter.addAll(forums);
else adapter.replaceAll(forums);
} else {
LOG.info("Concurrent update, reloading");
loadForums();

View File

@@ -194,7 +194,7 @@ public class GroupListFragment extends BaseFragment implements
if (revision == adapter.getRevision()) {
adapter.incrementRevision();
if (groups.isEmpty()) list.showData();
else adapter.addAll(groups);
else adapter.replaceAll(groups);
} else {
LOG.info("Concurrent update, reloading");
loadGroups();

View File

@@ -79,6 +79,10 @@ public abstract class BriarAdapter<T, V extends ViewHolder>
this.items.addAll(items);
}
public void replaceAll(Collection<T> items) {
this.items.replaceAll(items);
}
public void setItems(Collection<T> items) {
this.items.beginBatchedUpdates();
this.items.clear();