Skip to content

Commit 053e834

Browse files
committed
add highlight to the file name text view
1 parent 9d8aa44 commit 053e834

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

app/src/main/java/com/amaze/filemanager/adapters/SearchRecyclerViewAdapter.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
package com.amaze.filemanager.adapters
2222

2323
import android.content.Context
24+
import android.text.Spannable
25+
import android.text.SpannableString
26+
import android.text.style.ForegroundColorSpan
2427
import android.view.LayoutInflater
2528
import android.view.View
2629
import android.view.ViewGroup
@@ -67,14 +70,22 @@ class SearchRecyclerViewAdapter :
6770
override fun onBindViewHolder(holder: SearchRecyclerViewAdapter.ViewHolder, position: Int) {
6871
val (file, matchResult) = getItem(position)
6972

70-
holder.fileNameTV.text = file.name
73+
val colorPreference =
74+
(AppConfig.getInstance().mainActivityContext as MainActivity).currentColorPreference
75+
76+
val fileName = SpannableString(file.name)
77+
fileName.setSpan(
78+
ForegroundColorSpan(colorPreference.accent),
79+
matchResult.first,
80+
matchResult.last + 1,
81+
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
82+
)
83+
84+
holder.fileNameTV.text = fileName
7185
holder.filePathTV.text = file.path.substring(0, file.path.lastIndexOf("/"))
7286

7387
holder.colorView.setBackgroundColor(getRandomColor(holder.colorView.context))
7488

75-
val colorPreference =
76-
(AppConfig.getInstance().mainActivityContext as MainActivity).currentColorPreference
77-
7889
if (file.isDirectory) {
7990
holder.colorView.setBackgroundColor(colorPreference.primaryFirstTab)
8091
} else {

0 commit comments

Comments
 (0)