mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-19 21:30:37 +01:00
adding some search related improvements
This commit is contained in:
parent
f0fe018ebb
commit
846864c33d
@ -249,16 +249,39 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun searchQueryChanged(text: String) {
|
fun searchQueryChanged(text: String) {
|
||||||
|
val searchText = text.trim()
|
||||||
Thread {
|
Thread {
|
||||||
val filtered = storedItems.filter { it.name.contains(text, true) } as ArrayList
|
when {
|
||||||
filtered.sortBy { !it.name.startsWith(text, true) }
|
searchText.isEmpty() -> activity?.runOnUiThread {
|
||||||
activity?.runOnUiThread {
|
mView.apply {
|
||||||
getRecyclerAdapter()?.updateItems(filtered, text)
|
if (items_list.isGone()) {
|
||||||
}
|
items_list.beVisible()
|
||||||
|
getRecyclerAdapter()?.updateItems(storedItems)
|
||||||
|
}
|
||||||
|
items_placeholder.beGone()
|
||||||
|
items_placeholder_2.beGone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
searchText.length == 1 -> activity?.runOnUiThread {
|
||||||
|
mView.apply {
|
||||||
|
items_list.beGone()
|
||||||
|
items_placeholder.beVisible()
|
||||||
|
items_placeholder_2.beVisible()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val fileDirItems = ArrayList<FileDirItem>()
|
||||||
|
fileDirItems.addAll(searchFiles(searchText, currentPath))
|
||||||
|
|
||||||
if (text.trim().length > 2) {
|
activity?.runOnUiThread {
|
||||||
val fileDirItems = ArrayList<FileDirItem>()
|
getRecyclerAdapter()?.updateItems(fileDirItems, text)
|
||||||
fileDirItems.addAll(searchFiles(text.trim(), currentPath))
|
mView.apply {
|
||||||
|
items_list.beVisibleIf(fileDirItems.isNotEmpty())
|
||||||
|
items_placeholder.beVisibleIf(fileDirItems.isEmpty())
|
||||||
|
items_placeholder_2.beGone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user