Skip to content

Commit

Permalink
add highlight to the file name text view
Browse files Browse the repository at this point in the history
  • Loading branch information
seelchen committed Feb 5, 2024
1 parent 9d8aa44 commit 053e834
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
package com.amaze.filemanager.adapters

import android.content.Context
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -67,14 +70,22 @@ class SearchRecyclerViewAdapter :
override fun onBindViewHolder(holder: SearchRecyclerViewAdapter.ViewHolder, position: Int) {
val (file, matchResult) = getItem(position)

holder.fileNameTV.text = file.name
val colorPreference =
(AppConfig.getInstance().mainActivityContext as MainActivity).currentColorPreference

val fileName = SpannableString(file.name)
fileName.setSpan(
ForegroundColorSpan(colorPreference.accent),
matchResult.first,
matchResult.last + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

holder.fileNameTV.text = fileName
holder.filePathTV.text = file.path.substring(0, file.path.lastIndexOf("/"))

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

val colorPreference =
(AppConfig.getInstance().mainActivityContext as MainActivity).currentColorPreference

if (file.isDirectory) {
holder.colorView.setBackgroundColor(colorPreference.primaryFirstTab)
} else {
Expand Down

0 comments on commit 053e834

Please sign in to comment.