maintain order of conversations in share with dialog
This commit is contained in:
parent
c11dd71510
commit
8124b24479
|
@ -55,6 +55,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
@ -1650,10 +1651,23 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void populateWithOrderedConversations(final List<Conversation> list) {
|
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();
|
list.clear();
|
||||||
if (includeNoFileUpload) {
|
if (includeNoFileUpload) {
|
||||||
list.addAll(getConversations());
|
list.addAll(getConversations());
|
||||||
|
@ -1666,7 +1680,18 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
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);
|
Collections.sort(list);
|
||||||
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
|
||||||
this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||||
}
|
}
|
||||||
if (xmppConnectionServiceBound) {
|
if (xmppConnectionServiceBound) {
|
||||||
xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0);
|
xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,8 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshUiReal() {
|
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();
|
mAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue