Move comment

This commit is contained in:
Benoit Marty 2019-12-22 21:56:35 +01:00
parent 92d7ebe94f
commit 9ecceafb96
2 changed files with 3 additions and 2 deletions

View File

@ -59,8 +59,6 @@ class EmojiSearchResultViewModel @AssistedInject constructor(
setState {
copy(
query = action.queryString,
// First add emojis with name matching query, sorted by name
// Then emojis with keyword matching any of the word in the query, sorted by name
results = dataSource.filterWith(action.queryString)
)
}

View File

@ -37,11 +37,13 @@ class EmojiDataSource @Inject constructor(
fun filterWith(query: String): List<EmojiItem> {
val words = query.split("\\s".toRegex())
// First add emojis with name matching query, sorted by name
return (rawData.emojis.values
.filter { emojiItem ->
emojiItem.name.contains(query, true)
}
.sortedBy { it.name } +
// Then emojis with keyword matching any of the word in the query, sorted by name
rawData.emojis.values
.filter { emojiItem ->
words.fold(true, { prev, word ->
@ -49,6 +51,7 @@ class EmojiDataSource @Inject constructor(
})
}
.sortedBy { it.name })
// and ensure they will not be present twice
.distinct()
}