diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/paged/ContactSearchAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/paged/ContactSearchAdapter.kt index dce8fe5c3d..370839a584 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/paged/ContactSearchAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/paged/ContactSearchAdapter.kt @@ -576,14 +576,19 @@ open class ContactSearchAdapter( if (getRecipient(model).isGroup) { number.text = getRecipient(model).participantIds .take(10) - .map { id -> Recipient.resolved(id) } - .sortedWith(IsSelfComparator()).joinToString(", ") { - if (it.isSelf) { - context.getString(R.string.ConversationTitleView_you) - } else { - it.getShortDisplayName(context) - } + .map { id -> + val recipient = Recipient.resolved(id) + RecipientDisplayName( + recipient = recipient, + displayName = if (recipient.isSelf) { + context.getString(R.string.ConversationTitleView_you) + } else { + recipient.getShortDisplayName(context) + } + ) } + .sortedWith(compareBy({ it.recipient.isSelf }, { it.displayName })) + .joinToString(", ") { it.displayName } } } @@ -761,21 +766,6 @@ open class ContactSearchAdapter( } } - private class IsSelfComparator : Comparator { - override fun compare(lhs: Recipient?, rhs: Recipient?): Int { - val isLeftSelf = lhs?.isSelf == true - val isRightSelf = rhs?.isSelf == true - - return if (isLeftSelf == isRightSelf) { - 0 - } else if (isLeftSelf) { - 1 - } else { - -1 - } - } - } - interface StoryContextMenuCallbacks { fun onOpenStorySettings(story: ContactSearchData.Story) fun onRemoveGroupStory(story: ContactSearchData.Story, isSelected: Boolean) @@ -813,6 +803,7 @@ open class ContactSearchAdapter( fun onUnknownRecipientClicked(view: View, unknownRecipient: ContactSearchData.UnknownRecipient, isSelected: Boolean) { throw NotImplementedError() } + fun onChatTypeClicked(view: View, chatTypeRow: ContactSearchData.ChatTypeRow, isSelected: Boolean) } @@ -834,3 +825,5 @@ open class ContactSearchAdapter( override fun onKnownRecipientLongClick(view: View, data: ContactSearchData.KnownRecipient): Boolean = false } } + +private data class RecipientDisplayName(val recipient: Recipient, val displayName: String)