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 {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:3.19.1'
|
implementation 'com.simplemobiletools:commons:4.0.13'
|
||||||
|
|
||||||
implementation files('../libs/RootTools.jar')
|
implementation files('../libs/RootTools.jar')
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
appLaunched()
|
appLaunched(BuildConfig.APPLICATION_ID)
|
||||||
|
|
||||||
fragment = (fragment_holder as ItemsFragment).apply {
|
fragment = (fragment_holder as ItemsFragment).apply {
|
||||||
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
|
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
package com.simplemobiletools.filemanager.activities
|
package com.simplemobiletools.filemanager.activities
|
||||||
|
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
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 lateinit var fileDrawable: Drawable
|
||||||
private var currentItemsHash = fileDirItems.hashCode()
|
private var currentItemsHash = fileDirItems.hashCode()
|
||||||
private val hasOTGConnected = activity.hasOTGConnected()
|
private val hasOTGConnected = activity.hasOTGConnected()
|
||||||
|
private var textToHighlight = ""
|
||||||
|
private var adjustedPrimaryColor = activity.getAdjustedPrimaryColor()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setupDragListener(true)
|
setupDragListener(true)
|
||||||
@ -463,14 +465,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
|||||||
return selectedMedia
|
return selectedMedia
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateItems(newItems: ArrayList<FileDirItem>) {
|
fun updateItems(newItems: ArrayList<FileDirItem>, highlightText: String = "") {
|
||||||
if (newItems.hashCode() != currentItemsHash) {
|
if (newItems.hashCode() != currentItemsHash) {
|
||||||
currentItemsHash = newItems.hashCode()
|
currentItemsHash = newItems.hashCode()
|
||||||
|
textToHighlight = highlightText
|
||||||
fileDirItems = newItems.clone() as ArrayList<FileDirItem>
|
fileDirItems = newItems.clone() as ArrayList<FileDirItem>
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
fastScroller?.measureRecyclerView()
|
} else if (textToHighlight != highlightText) {
|
||||||
|
textToHighlight = highlightText
|
||||||
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
fastScroller?.measureRecyclerView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewRecycled(holder: ViewHolder) {
|
override fun onViewRecycled(holder: ViewHolder) {
|
||||||
@ -482,7 +488,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
|||||||
|
|
||||||
private fun setupView(view: View, fileDirItem: FileDirItem) {
|
private fun setupView(view: View, fileDirItem: FileDirItem) {
|
||||||
view.apply {
|
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_name.setTextColor(textColor)
|
||||||
item_details.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
|
val filtered = storedItems.filter { it.name.contains(text, true) } as ArrayList
|
||||||
filtered.sortBy { !it.name.startsWith(text, true) }
|
filtered.sortBy { !it.name.startsWith(text, true) }
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
(items_list.adapter as? ItemsAdapter)?.updateItems(filtered)
|
(items_list.adapter as? ItemsAdapter)?.updateItems(filtered, text)
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user