aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-01-25 22:24:23 +0100
committerChristian Schneppe <christian@pix-art.de>2019-01-25 22:24:23 +0100
commit83258c8a19d64fc4e451a57fc8097391b0437b75 (patch)
treed3affd21f6fbe2e596717af8275802ddd82922e2 /src/main/java/de/pixart/messenger/services
parentbc0dfddbd3c6853efac887df441029e94e54e0dd (diff)
maintain order of conversations in share with dialog
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index e123e8cff..43fd2f875 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -1852,10 +1852,23 @@ public class XmppConnectionService extends Service {
}
public void populateWithOrderedConversations(final List<Conversation> list) {
- populateWithOrderedConversations(list, true);
+ populateWithOrderedConversations(list, true, true);
}
- public void populateWithOrderedConversations(final List<Conversation> list, boolean includeNoFileUpload) {
+ public void populateWithOrderedConversations(final List<Conversation> list, final boolean includeNoFileUpload) {
+ populateWithOrderedConversations(list, includeNoFileUpload, true);
+ }
+
+ public void populateWithOrderedConversations(final List<Conversation> list, final boolean includeNoFileUpload, final boolean sort) {
+ final List<String> orderedUuids;
+ if (sort) {
+ orderedUuids = null;
+ } else {
+ orderedUuids = new ArrayList<>();
+ for (Conversation conversation : list) {
+ orderedUuids.add(conversation.getUuid());
+ }
+ }
list.clear();
if (includeNoFileUpload) {
list.addAll(getConversations());
@@ -1868,7 +1881,18 @@ public class XmppConnectionService extends Service {
}
}
try {
- Collections.sort(list);
+ if (orderedUuids != null) {
+ Collections.sort(list, (a, b) -> {
+ final int indexA = orderedUuids.indexOf(a.getUuid());
+ final int indexB = orderedUuids.indexOf(b.getUuid());
+ if (indexA == -1 || indexB == -1 || indexA == indexB) {
+ return a.compareTo(b);
+ }
+ return indexA - indexB;
+ });
+ } else {
+ Collections.sort(list);
+ }
} catch (IllegalArgumentException e) {
//ignore
}