diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-01-25 22:24:23 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-01-25 22:24:23 +0100 |
commit | 83258c8a19d64fc4e451a57fc8097391b0437b75 (patch) | |
tree | d3affd21f6fbe2e596717af8275802ddd82922e2 | |
parent | bc0dfddbd3c6853efac887df441029e94e54e0dd (diff) |
maintain order of conversations in share with dialog
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 30 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ShareWithActivity.java | 5 |
2 files changed, 30 insertions, 5 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 } diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index 0d1a3286d..8e80208d0 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -130,7 +130,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); } if (xmppConnectionServiceBound) { - xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0); + xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0, false); } } @@ -182,7 +182,8 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } public void refreshUiReal() { - xmppConnectionService.populateWithOrderedConversations(mConversations, this.share != null && this.share.uris.size() == 0); + //TODO inject desired order to not resort on refresh + xmppConnectionService.populateWithOrderedConversations(mConversations, this.share != null && this.share.uris.size() == 0, false); mAdapter.notifyDataSetChanged(); } |