Skip to content

Commit 0286b29

Browse files
committed
highlight searched text
1 parent 3771cc4 commit 0286b29

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ext {
4545
}
4646

4747
dependencies {
48-
implementation 'com.simplemobiletools:commons:3.19.1'
48+
implementation 'com.simplemobiletools:commons:4.0.13'
4949

5050
implementation files('../libs/RootTools.jar')
5151

app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MainActivity : SimpleActivity() {
4242
override fun onCreate(savedInstanceState: Bundle?) {
4343
super.onCreate(savedInstanceState)
4444
setContentView(R.layout.activity_main)
45-
appLaunched()
45+
appLaunched(BuildConfig.APPLICATION_ID)
4646

4747
fragment = (fragment_holder as ItemsFragment).apply {
4848
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package com.simplemobiletools.filemanager.activities
22

33
import com.simplemobiletools.commons.activities.BaseSimpleActivity
4+
import com.simplemobiletools.filemanager.R
45

5-
open class SimpleActivity : BaseSimpleActivity()
6+
open class SimpleActivity : BaseSimpleActivity() {
7+
override fun getAppIconIDs() = arrayListOf(
8+
R.mipmap.ic_launcher
9+
)
10+
11+
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
12+
}

app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
4848
private lateinit var fileDrawable: Drawable
4949
private var currentItemsHash = fileDirItems.hashCode()
5050
private val hasOTGConnected = activity.hasOTGConnected()
51+
private var textToHighlight = ""
52+
private var adjustedPrimaryColor = activity.getAdjustedPrimaryColor()
5153

5254
init {
5355
setupDragListener(true)
@@ -463,14 +465,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
463465
return selectedMedia
464466
}
465467

466-
fun updateItems(newItems: ArrayList<FileDirItem>) {
468+
fun updateItems(newItems: ArrayList<FileDirItem>, highlightText: String = "") {
467469
if (newItems.hashCode() != currentItemsHash) {
468470
currentItemsHash = newItems.hashCode()
471+
textToHighlight = highlightText
469472
fileDirItems = newItems.clone() as ArrayList<FileDirItem>
470473
notifyDataSetChanged()
471474
finishActMode()
472-
fastScroller?.measureRecyclerView()
475+
} else if (textToHighlight != highlightText) {
476+
textToHighlight = highlightText
477+
notifyDataSetChanged()
473478
}
479+
fastScroller?.measureRecyclerView()
474480
}
475481

476482
override fun onViewRecycled(holder: ViewHolder) {
@@ -482,7 +488,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
482488

483489
private fun setupView(view: View, fileDirItem: FileDirItem) {
484490
view.apply {
485-
item_name.text = fileDirItem.name
491+
val fileName = fileDirItem.name
492+
item_name.text = if (textToHighlight.isEmpty()) fileName else fileName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
486493
item_name.setTextColor(textColor)
487494
item_details.setTextColor(textColor)
488495

app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
251251
val filtered = storedItems.filter { it.name.contains(text, true) } as ArrayList
252252
filtered.sortBy { !it.name.startsWith(text, true) }
253253
activity?.runOnUiThread {
254-
(items_list.adapter as? ItemsAdapter)?.updateItems(filtered)
254+
(items_list.adapter as? ItemsAdapter)?.updateItems(filtered, text)
255255
}
256256
}.start()
257257
}

0 commit comments

Comments
 (0)