Move comment
This commit is contained in:
parent
92d7ebe94f
commit
9ecceafb96
@ -59,8 +59,6 @@ class EmojiSearchResultViewModel @AssistedInject constructor(
|
|||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
query = action.queryString,
|
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)
|
results = dataSource.filterWith(action.queryString)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,13 @@ class EmojiDataSource @Inject constructor(
|
|||||||
fun filterWith(query: String): List<EmojiItem> {
|
fun filterWith(query: String): List<EmojiItem> {
|
||||||
val words = query.split("\\s".toRegex())
|
val words = query.split("\\s".toRegex())
|
||||||
|
|
||||||
|
// First add emojis with name matching query, sorted by name
|
||||||
return (rawData.emojis.values
|
return (rawData.emojis.values
|
||||||
.filter { emojiItem ->
|
.filter { emojiItem ->
|
||||||
emojiItem.name.contains(query, true)
|
emojiItem.name.contains(query, true)
|
||||||
}
|
}
|
||||||
.sortedBy { it.name } +
|
.sortedBy { it.name } +
|
||||||
|
// Then emojis with keyword matching any of the word in the query, sorted by name
|
||||||
rawData.emojis.values
|
rawData.emojis.values
|
||||||
.filter { emojiItem ->
|
.filter { emojiItem ->
|
||||||
words.fold(true, { prev, word ->
|
words.fold(true, { prev, word ->
|
||||||
@ -49,6 +51,7 @@ class EmojiDataSource @Inject constructor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
.sortedBy { it.name })
|
.sortedBy { it.name })
|
||||||
|
// and ensure they will not be present twice
|
||||||
.distinct()
|
.distinct()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user