mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-21 21:29:00 +00:00
tokenize equipment search
This commit is contained in:
parent
a50bb81493
commit
9fe345f72e
2 changed files with 12 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<corners android:radius="6dp" />
|
||||
<corners android:radius="12dp" />
|
||||
<solid android:color="@color/window_background" />
|
||||
</shape>
|
||||
|
|
@ -135,7 +135,17 @@ class EquipmentDetailFragment :
|
|||
if (query.isNullOrBlank()) {
|
||||
return@combine equipment
|
||||
}
|
||||
equipment.filter { it.text.contains(query, true) || it.notes.contains(query, true) }
|
||||
val tokens = query.split(" ")
|
||||
val tokenCount = tokens.size
|
||||
equipment.filter {
|
||||
var matchCount = 0
|
||||
for (token in tokens) {
|
||||
if (it.text.contains(token, true) || it.notes.contains(token, true)) {
|
||||
matchCount += 1
|
||||
}
|
||||
}
|
||||
return@filter matchCount == tokenCount
|
||||
}
|
||||
}
|
||||
.map { it.sortedBy { equipment -> equipment.text } }
|
||||
.collect { adapter.data = it }
|
||||
|
|
|
|||
Loading…
Reference in a new issue