Unknown contact should go under #

This commit is contained in:
bemusementpark 2024-07-03 19:07:15 +09:30
parent 39f9b959ce
commit ca66d115a3

View File

@ -291,7 +291,10 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
if (result.query.isEmpty()) { if (result.query.isEmpty()) {
class NamedValue<T>(val name: String?, val value: T) class NamedValue<T>(val name: String?, val value: T)
val unknown = resources.getString(R.string.unknown) // Unknown is temporarily to be grouped together with numbers title.
// https://optf.atlassian.net/browse/SES-2287
val numbersTitle = "#"
val unknownTitle = numbersTitle
listOf( listOf(
GlobalSearchAdapter.Model.Header(R.string.contacts), GlobalSearchAdapter.Model.Header(R.string.contacts),
@ -305,12 +308,12 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
.let { name -> NamedValue(name?.uppercase(), it) } } .let { name -> NamedValue(name?.uppercase(), it) } }
// Digits are all grouped under a #, the rest are grouped by their first character.uppercased() // Digits are all grouped under a #, the rest are grouped by their first character.uppercased()
// If there is no name, they go under Unknown // If there is no name, they go under Unknown
.groupBy { it.name?.run { first().takeUnless(Char::isDigit)?.toString() ?: "#" } ?: unknown } .groupBy { it.name?.run { first().takeUnless(Char::isDigit)?.toString() ?: numbersTitle } ?: unknownTitle }
// place the # at the end, after all the names starting with alphabetic chars // place the # at the end, after all the names starting with alphabetic chars
.toSortedMap(compareBy { .toSortedMap(compareBy {
when (it) { when (it) {
unknown -> Char.MAX_VALUE unknownTitle -> Char.MAX_VALUE
"#" -> Char.MAX_VALUE - 1 numbersTitle -> Char.MAX_VALUE - 1
else -> it.first() else -> it.first()
} }
}) })