From 846864c33da0a142b04b190971c73dba5a8689c8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 25 Mar 2019 22:54:10 +0100 Subject: [PATCH] adding some search related improvements --- .../pro/fragments/ItemsFragment.kt | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index 913b9127..b43a189e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -249,16 +249,39 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb } fun searchQueryChanged(text: String) { + val searchText = text.trim() Thread { - val filtered = storedItems.filter { it.name.contains(text, true) } as ArrayList - filtered.sortBy { !it.name.startsWith(text, true) } - activity?.runOnUiThread { - getRecyclerAdapter()?.updateItems(filtered, text) - } + when { + searchText.isEmpty() -> activity?.runOnUiThread { + mView.apply { + 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() + fileDirItems.addAll(searchFiles(searchText, currentPath)) - if (text.trim().length > 2) { - val fileDirItems = ArrayList() - fileDirItems.addAll(searchFiles(text.trim(), currentPath)) + activity?.runOnUiThread { + getRecyclerAdapter()?.updateItems(fileDirItems, text) + mView.apply { + items_list.beVisibleIf(fileDirItems.isNotEmpty()) + items_placeholder.beVisibleIf(fileDirItems.isEmpty()) + items_placeholder_2.beGone() + } + } + } } }.start() }