mirror of
https://github.com/TeamAmaze/AmazeFileManager.git
synced 2026-10-22 08:26:55 +08:00
change SearchRecyclerViewAdapter to work with SearchResult
This commit is contained in:
@@ -31,27 +31,30 @@ import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.amaze.filemanager.R
|
||||
import com.amaze.filemanager.application.AppConfig
|
||||
import com.amaze.filemanager.filesystem.HybridFileParcelable
|
||||
import com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem.SearchResult
|
||||
import com.amaze.filemanager.ui.activities.MainActivity
|
||||
import com.amaze.filemanager.ui.colors.ColorPreference
|
||||
import java.util.Random
|
||||
|
||||
class SearchRecyclerViewAdapter :
|
||||
ListAdapter<HybridFileParcelable, SearchRecyclerViewAdapter.ViewHolder>(
|
||||
ListAdapter<SearchResult, SearchRecyclerViewAdapter.ViewHolder>(
|
||||
|
||||
object : DiffUtil.ItemCallback<HybridFileParcelable>() {
|
||||
object : DiffUtil.ItemCallback<SearchResult>() {
|
||||
override fun areItemsTheSame(
|
||||
oldItem: HybridFileParcelable,
|
||||
newItem: HybridFileParcelable
|
||||
oldItem: SearchResult,
|
||||
newItem: SearchResult
|
||||
): Boolean {
|
||||
return oldItem.path == newItem.path && oldItem.name == newItem.name
|
||||
return oldItem.file.path == newItem.file.path &&
|
||||
oldItem.file.name == newItem.file.name
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(
|
||||
oldItem: HybridFileParcelable,
|
||||
newItem: HybridFileParcelable
|
||||
oldItem: SearchResult,
|
||||
newItem: SearchResult
|
||||
): Boolean {
|
||||
return oldItem.path == newItem.path && oldItem.name == newItem.name
|
||||
return oldItem.file.path == newItem.file.path &&
|
||||
oldItem.file.name == newItem.file.name &&
|
||||
oldItem.matchRange == newItem.matchRange
|
||||
}
|
||||
}
|
||||
) {
|
||||
@@ -62,17 +65,17 @@ class SearchRecyclerViewAdapter :
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SearchRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
val (file, matchResult) = getItem(position)
|
||||
|
||||
holder.fileNameTV.text = item.name
|
||||
holder.filePathTV.text = item.path.substring(0, item.path.lastIndexOf("/"))
|
||||
holder.fileNameTV.text = file.name
|
||||
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 (item.isDirectory) {
|
||||
if (file.isDirectory) {
|
||||
holder.colorView.setBackgroundColor(colorPreference.primaryFirstTab)
|
||||
} else {
|
||||
holder.colorView.setBackgroundColor(colorPreference.accent)
|
||||
@@ -93,16 +96,16 @@ class SearchRecyclerViewAdapter :
|
||||
|
||||
view.setOnClickListener {
|
||||
|
||||
val item = getItem(adapterPosition)
|
||||
val (file, _) = getItem(adapterPosition)
|
||||
|
||||
if (!item.isDirectory) {
|
||||
item.openFile(
|
||||
if (!file.isDirectory) {
|
||||
file.openFile(
|
||||
AppConfig.getInstance().mainActivityContext as MainActivity?,
|
||||
false
|
||||
)
|
||||
} else {
|
||||
(AppConfig.getInstance().mainActivityContext as MainActivity?)
|
||||
?.goToMain(item.path)
|
||||
?.goToMain(file.path)
|
||||
}
|
||||
|
||||
(AppConfig.getInstance().mainActivityContext as MainActivity?)
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.amaze.filemanager.R;
|
||||
import com.amaze.filemanager.adapters.SearchRecyclerViewAdapter;
|
||||
import com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem.SearchResult;
|
||||
import com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem.SearchResultListSorter;
|
||||
import com.amaze.filemanager.filesystem.HybridFileParcelable;
|
||||
import com.amaze.filemanager.filesystem.files.sort.DirSortBy;
|
||||
import com.amaze.filemanager.filesystem.files.sort.SortBy;
|
||||
import com.amaze.filemanager.filesystem.files.sort.SortOrder;
|
||||
@@ -376,11 +375,7 @@ public class SearchView {
|
||||
ArrayList<SearchResult> items = new ArrayList<>(newResults);
|
||||
Collections.sort(
|
||||
items, new SearchResultListSorter(DirSortBy.NONE_ON_TOP, sortType, searchTerm));
|
||||
ArrayList<HybridFileParcelable> files = new ArrayList<>();
|
||||
for (SearchResult searchResult : items) {
|
||||
files.add(searchResult.getFile());
|
||||
}
|
||||
searchRecyclerViewAdapter.submitList(files);
|
||||
searchRecyclerViewAdapter.submitList(items);
|
||||
searchRecyclerViewAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user