mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Sort contacts by latest activity.
When you receive a message from a contact, it will be moved to the top of the list with a nice animation. Also with this commit, not the entire data set is invalidated each time data changes, but only the parts of the data that really require an update. Furthermore, the ContactListItemComparator that is not needed anymore is removed.
This commit is contained in:
@@ -227,10 +227,11 @@ public class ContactListActivity extends BriarActivity
|
||||
final Collection<PrivateMessageHeader> headers) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ContactListItem item = adapter.findItem(c);
|
||||
int position = adapter.findItemPosition(c);
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
if (item != null) {
|
||||
item.setHeaders(headers);
|
||||
adapter.notifyDataSetChanged();
|
||||
adapter.updateItem(position, item);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -255,10 +256,11 @@ public class ContactListActivity extends BriarActivity
|
||||
private void setConnected(final ContactId c, final boolean connected) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ContactListItem item = adapter.findItem(c);
|
||||
int position = adapter.findItemPosition(c);
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
if (item != null) {
|
||||
item.setConnected(connected);
|
||||
adapter.notifyDataSetChanged();
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -48,8 +48,13 @@ public class ContactListAdapter
|
||||
@Override
|
||||
public int compare(ContactListItem c1,
|
||||
ContactListItem c2) {
|
||||
return (int) (c1.getTimestamp() -
|
||||
c2.getTimestamp());
|
||||
// sort items by time
|
||||
// and do not take unread messages into account
|
||||
long time1 = c1.getTimestamp();
|
||||
long time2 = c2.getTimestamp();
|
||||
if (time1 < time2) return 1;
|
||||
if (time1 > time2) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,6 +150,10 @@ public class ContactListAdapter
|
||||
return contacts.get(position);
|
||||
}
|
||||
|
||||
public void updateItem(int position, ContactListItem item) {
|
||||
contacts.updateItemAt(position, item);
|
||||
}
|
||||
|
||||
public ContactListItem findItem(ContactId c) {
|
||||
int count = getItemCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -154,6 +163,15 @@ public class ContactListAdapter
|
||||
return null; // Not found
|
||||
}
|
||||
|
||||
public int findItemPosition(ContactId c) {
|
||||
int count = getItemCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
ContactListItem item = getItem(i);
|
||||
if (item.getContact().getId().equals(c)) return i;
|
||||
}
|
||||
return -1; // Not found
|
||||
}
|
||||
|
||||
public void addAll(final List<ContactListItem> contacts) {
|
||||
this.contacts.addAll(contacts);
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
class ContactListItemComparator implements Comparator<ContactListItem> {
|
||||
|
||||
static final ContactListItemComparator INSTANCE =
|
||||
new ContactListItemComparator();
|
||||
|
||||
public int compare(ContactListItem a, ContactListItem b) {
|
||||
String aName = a.getContact().getAuthor().getName();
|
||||
String bName = b.getContact().getAuthor().getName();
|
||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user