mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
highlight searched text
This commit is contained in:
@ -45,7 +45,7 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.19.1'
|
||||
implementation 'com.simplemobiletools:commons:4.0.13'
|
||||
|
||||
implementation files('../libs/RootTools.jar')
|
||||
|
||||
|
@ -42,7 +42,7 @@ class MainActivity : SimpleActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
appLaunched()
|
||||
appLaunched(BuildConfig.APPLICATION_ID)
|
||||
|
||||
fragment = (fragment_holder as ItemsFragment).apply {
|
||||
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
|
||||
|
@ -1,5 +1,12 @@
|
||||
package com.simplemobiletools.filemanager.activities
|
||||
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.filemanager.R
|
||||
|
||||
open class SimpleActivity : BaseSimpleActivity()
|
||||
open class SimpleActivity : BaseSimpleActivity() {
|
||||
override fun getAppIconIDs() = arrayListOf(
|
||||
R.mipmap.ic_launcher
|
||||
)
|
||||
|
||||
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
||||
private lateinit var fileDrawable: Drawable
|
||||
private var currentItemsHash = fileDirItems.hashCode()
|
||||
private val hasOTGConnected = activity.hasOTGConnected()
|
||||
private var textToHighlight = ""
|
||||
private var adjustedPrimaryColor = activity.getAdjustedPrimaryColor()
|
||||
|
||||
init {
|
||||
setupDragListener(true)
|
||||
@ -463,14 +465,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
||||
return selectedMedia
|
||||
}
|
||||
|
||||
fun updateItems(newItems: ArrayList<FileDirItem>) {
|
||||
fun updateItems(newItems: ArrayList<FileDirItem>, highlightText: String = "") {
|
||||
if (newItems.hashCode() != currentItemsHash) {
|
||||
currentItemsHash = newItems.hashCode()
|
||||
textToHighlight = highlightText
|
||||
fileDirItems = newItems.clone() as ArrayList<FileDirItem>
|
||||
notifyDataSetChanged()
|
||||
finishActMode()
|
||||
fastScroller?.measureRecyclerView()
|
||||
} else if (textToHighlight != highlightText) {
|
||||
textToHighlight = highlightText
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
fastScroller?.measureRecyclerView()
|
||||
}
|
||||
|
||||
override fun onViewRecycled(holder: ViewHolder) {
|
||||
@ -482,7 +488,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
||||
|
||||
private fun setupView(view: View, fileDirItem: FileDirItem) {
|
||||
view.apply {
|
||||
item_name.text = fileDirItem.name
|
||||
val fileName = fileDirItem.name
|
||||
item_name.text = if (textToHighlight.isEmpty()) fileName else fileName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||
item_name.setTextColor(textColor)
|
||||
item_details.setTextColor(textColor)
|
||||
|
||||
|
@ -251,7 +251,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
val filtered = storedItems.filter { it.name.contains(text, true) } as ArrayList
|
||||
filtered.sortBy { !it.name.startsWith(text, true) }
|
||||
activity?.runOnUiThread {
|
||||
(items_list.adapter as? ItemsAdapter)?.updateItems(filtered)
|
||||
(items_list.adapter as? ItemsAdapter)?.updateItems(filtered, text)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
Reference in New Issue
Block a user