Skip to content

Commit cd42632

Browse files
committed
adding some storage search improvements
1 parent bce66e3 commit cd42632

File tree

2 files changed

+389
-333
lines changed

2 files changed

+389
-333
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.simplemobiletools.filemanager.pro.fragments
22

33
import android.annotation.SuppressLint
4+
import android.app.Activity
45
import android.app.usage.StorageStatsManager
56
import android.content.ContentResolver
67
import android.content.Context
@@ -31,6 +32,7 @@ import java.util.*
3132
class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener {
3233
private val SIZE_DIVIDER = 100000
3334
private var allDeviceListItems = ArrayList<ListItem>()
35+
private var lastSearchedText = ""
3436

3537
override fun setupFragment(activity: SimpleActivity) {
3638
if (this.activity == null) {
@@ -64,7 +66,6 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
6466
override fun onResume(textColor: Int) {
6567
getSizes()
6668
context.updateTextColors(storage_fragment)
67-
search_holder.setBackgroundColor(context.getProperBackgroundColor())
6869

6970
val properPrimaryColor = context.getProperPrimaryColor()
7071
main_storage_usage_progressbar.setIndicatorColor(properPrimaryColor)
@@ -93,6 +94,10 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
9394
val pinkColor = context.resources.getColor(R.color.md_pink_700)
9495
others_progressbar.setIndicatorColor(pinkColor)
9596
others_progressbar.trackColor = pinkColor.adjustAlpha(LOWER_ALPHA)
97+
98+
search_holder.setBackgroundColor(context.getProperBackgroundColor())
99+
progress_bar.setIndicatorColor(properPrimaryColor)
100+
progress_bar.trackColor = properPrimaryColor.adjustAlpha(LOWER_ALPHA)
96101
}
97102

98103
private fun launchMimetypeActivity(mimetype: String) {
@@ -239,6 +244,8 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
239244
}
240245

241246
override fun searchQueryChanged(text: String) {
247+
lastSearchedText = text
248+
242249
if (text.isNotEmpty()) {
243250
if (search_holder.alpha < 1f) {
244251
search_holder.fadeIn()
@@ -250,10 +257,31 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
250257
}.start()
251258
}
252259

253-
if (text.isNotEmpty()) {
254-
val filtered = allDeviceListItems.filter { it.mName.contains(text, true) }.toMutableList() as ArrayList<ListItem>
255-
(search_results_list.adapter as? ItemsAdapter)?.updateItems(filtered, text)
256-
search_placeholder.beVisibleIf(filtered.isEmpty())
260+
if (text.length == 1) {
261+
search_results_list.beGone()
262+
search_placeholder.beVisible()
263+
search_placeholder_2.beVisible()
264+
hideProgressBar()
265+
} else if (text.isEmpty()) {
266+
search_results_list.beGone()
267+
hideProgressBar()
268+
} else {
269+
showProgressBar()
270+
ensureBackgroundThread {
271+
val start = System.currentTimeMillis()
272+
val filtered = allDeviceListItems.filter { it.mName.contains(text, true) }.toMutableList() as ArrayList<ListItem>
273+
if (lastSearchedText != text) {
274+
return@ensureBackgroundThread
275+
}
276+
277+
(context as? Activity)?.runOnUiThread {
278+
(search_results_list.adapter as? ItemsAdapter)?.updateItems(filtered, text)
279+
search_results_list.beVisible()
280+
search_placeholder.beVisibleIf(filtered.isEmpty())
281+
search_placeholder_2.beGone()
282+
hideProgressBar()
283+
}
284+
}
257285
}
258286
}
259287

@@ -281,7 +309,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
281309
}
282310

283311
private fun addItems() {
284-
ItemsAdapter(context as SimpleActivity, allDeviceListItems, this, search_results_list, false, null, false) {
312+
ItemsAdapter(context as SimpleActivity, ArrayList(), this, search_results_list, false, null, false) {
285313
clickedPath((it as FileDirItem).path)
286314
}.apply {
287315
search_results_list.adapter = this
@@ -338,6 +366,14 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
338366
return fileDirItems
339367
}
340368

369+
private fun showProgressBar() {
370+
progress_bar.show()
371+
}
372+
373+
private fun hideProgressBar() {
374+
progress_bar.hide()
375+
}
376+
341377
private fun getRecyclerAdapter() = search_results_list.adapter as? ItemsAdapter
342378

343379
override fun refreshFragment() {

0 commit comments

Comments
 (0)