21
21
package com.amaze.filemanager.adapters
22
22
23
23
import android.content.Context
24
+ import android.text.Spannable
25
+ import android.text.SpannableString
26
+ import android.text.style.ForegroundColorSpan
24
27
import android.view.LayoutInflater
25
28
import android.view.View
26
29
import android.view.ViewGroup
@@ -31,27 +34,30 @@ import androidx.recyclerview.widget.ListAdapter
31
34
import androidx.recyclerview.widget.RecyclerView
32
35
import com.amaze.filemanager.R
33
36
import com.amaze.filemanager.application.AppConfig
34
- import com.amaze.filemanager.filesystem.HybridFileParcelable
37
+ import com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem.SearchResult
35
38
import com.amaze.filemanager.ui.activities.MainActivity
36
39
import com.amaze.filemanager.ui.colors.ColorPreference
37
40
import java.util.Random
38
41
39
42
class SearchRecyclerViewAdapter :
40
- ListAdapter <HybridFileParcelable , SearchRecyclerViewAdapter .ViewHolder >(
43
+ ListAdapter <SearchResult , SearchRecyclerViewAdapter .ViewHolder >(
41
44
42
- object : DiffUtil .ItemCallback <HybridFileParcelable >() {
45
+ object : DiffUtil .ItemCallback <SearchResult >() {
43
46
override fun areItemsTheSame (
44
- oldItem : HybridFileParcelable ,
45
- newItem : HybridFileParcelable
47
+ oldItem : SearchResult ,
48
+ newItem : SearchResult
46
49
): Boolean {
47
- return oldItem.path == newItem.path && oldItem.name == newItem.name
50
+ return oldItem.file.path == newItem.file.path &&
51
+ oldItem.file.name == newItem.file.name
48
52
}
49
53
50
54
override fun areContentsTheSame (
51
- oldItem : HybridFileParcelable ,
52
- newItem : HybridFileParcelable
55
+ oldItem : SearchResult ,
56
+ newItem : SearchResult
53
57
): Boolean {
54
- return oldItem.path == newItem.path && oldItem.name == newItem.name
58
+ return oldItem.file.path == newItem.file.path &&
59
+ oldItem.file.name == newItem.file.name &&
60
+ oldItem.matchRange == newItem.matchRange
55
61
}
56
62
}
57
63
) {
@@ -62,17 +68,25 @@ class SearchRecyclerViewAdapter :
62
68
}
63
69
64
70
override fun onBindViewHolder (holder : SearchRecyclerViewAdapter .ViewHolder , position : Int ) {
65
- val item = getItem(position)
66
-
67
- holder.fileNameTV.text = item.name
68
- holder.filePathTV.text = item.path.substring(0 , item.path.lastIndexOf(" /" ))
69
-
70
- holder.colorView.setBackgroundColor(getRandomColor(holder.colorView.context))
71
+ val (file, matchResult) = getItem(position)
71
72
72
73
val colorPreference =
73
74
(AppConfig .getInstance().mainActivityContext as MainActivity ).currentColorPreference
74
75
75
- if (item.isDirectory) {
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
85
+ holder.filePathTV.text = file.path.substring(0 , file.path.lastIndexOf(" /" ))
86
+
87
+ holder.colorView.setBackgroundColor(getRandomColor(holder.colorView.context))
88
+
89
+ if (file.isDirectory) {
76
90
holder.colorView.setBackgroundColor(colorPreference.primaryFirstTab)
77
91
} else {
78
92
holder.colorView.setBackgroundColor(colorPreference.accent)
@@ -93,16 +107,16 @@ class SearchRecyclerViewAdapter :
93
107
94
108
view.setOnClickListener {
95
109
96
- val item = getItem(adapterPosition)
110
+ val (file, _) = getItem(adapterPosition)
97
111
98
- if (! item .isDirectory) {
99
- item .openFile(
112
+ if (! file .isDirectory) {
113
+ file .openFile(
100
114
AppConfig .getInstance().mainActivityContext as MainActivity ? ,
101
115
false
102
116
)
103
117
} else {
104
118
(AppConfig .getInstance().mainActivityContext as MainActivity ? )
105
- ?.goToMain(item .path)
119
+ ?.goToMain(file .path)
106
120
}
107
121
108
122
(AppConfig .getInstance().mainActivityContext as MainActivity ? )
0 commit comments