@@ -31,27 +31,30 @@ import androidx.recyclerview.widget.ListAdapter
31
31
import androidx.recyclerview.widget.RecyclerView
32
32
import com.amaze.filemanager.R
33
33
import com.amaze.filemanager.application.AppConfig
34
- import com.amaze.filemanager.filesystem.HybridFileParcelable
34
+ import com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem.SearchResult
35
35
import com.amaze.filemanager.ui.activities.MainActivity
36
36
import com.amaze.filemanager.ui.colors.ColorPreference
37
37
import java.util.Random
38
38
39
39
class SearchRecyclerViewAdapter :
40
- ListAdapter <HybridFileParcelable , SearchRecyclerViewAdapter .ViewHolder >(
40
+ ListAdapter <SearchResult , SearchRecyclerViewAdapter .ViewHolder >(
41
41
42
- object : DiffUtil .ItemCallback <HybridFileParcelable >() {
42
+ object : DiffUtil .ItemCallback <SearchResult >() {
43
43
override fun areItemsTheSame (
44
- oldItem : HybridFileParcelable ,
45
- newItem : HybridFileParcelable
44
+ oldItem : SearchResult ,
45
+ newItem : SearchResult
46
46
): Boolean {
47
- return oldItem.path == newItem.path && oldItem.name == newItem.name
47
+ return oldItem.file.path == newItem.file.path &&
48
+ oldItem.file.name == newItem.file.name
48
49
}
49
50
50
51
override fun areContentsTheSame (
51
- oldItem : HybridFileParcelable ,
52
- newItem : HybridFileParcelable
52
+ oldItem : SearchResult ,
53
+ newItem : SearchResult
53
54
): Boolean {
54
- return oldItem.path == newItem.path && oldItem.name == newItem.name
55
+ return oldItem.file.path == newItem.file.path &&
56
+ oldItem.file.name == newItem.file.name &&
57
+ oldItem.matchRange == newItem.matchRange
55
58
}
56
59
}
57
60
) {
@@ -62,17 +65,17 @@ class SearchRecyclerViewAdapter :
62
65
}
63
66
64
67
override fun onBindViewHolder (holder : SearchRecyclerViewAdapter .ViewHolder , position : Int ) {
65
- val item = getItem(position)
68
+ val (file, matchResult) = getItem(position)
66
69
67
- holder.fileNameTV.text = item .name
68
- holder.filePathTV.text = item .path.substring(0 , item .path.lastIndexOf(" /" ))
70
+ holder.fileNameTV.text = file .name
71
+ holder.filePathTV.text = file .path.substring(0 , file .path.lastIndexOf(" /" ))
69
72
70
73
holder.colorView.setBackgroundColor(getRandomColor(holder.colorView.context))
71
74
72
75
val colorPreference =
73
76
(AppConfig .getInstance().mainActivityContext as MainActivity ).currentColorPreference
74
77
75
- if (item .isDirectory) {
78
+ if (file .isDirectory) {
76
79
holder.colorView.setBackgroundColor(colorPreference.primaryFirstTab)
77
80
} else {
78
81
holder.colorView.setBackgroundColor(colorPreference.accent)
@@ -93,16 +96,16 @@ class SearchRecyclerViewAdapter :
93
96
94
97
view.setOnClickListener {
95
98
96
- val item = getItem(adapterPosition)
99
+ val (file, _) = getItem(adapterPosition)
97
100
98
- if (! item .isDirectory) {
99
- item .openFile(
101
+ if (! file .isDirectory) {
102
+ file .openFile(
100
103
AppConfig .getInstance().mainActivityContext as MainActivity ? ,
101
104
false
102
105
)
103
106
} else {
104
107
(AppConfig .getInstance().mainActivityContext as MainActivity ? )
105
- ?.goToMain(item .path)
108
+ ?.goToMain(file .path)
106
109
}
107
110
108
111
(AppConfig .getInstance().mainActivityContext as MainActivity ? )
0 commit comments