mirror of
https://github.com/nextcloud/android.git
synced 2024-11-21 20:55:31 +03:00
Merge pull request #3067 from nextcloud/fixDoubleSorting
LocalFileListAdapter: fix double sorting
This commit is contained in:
commit
3b9e6fa210
2 changed files with 5 additions and 123 deletions
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* Copyright (C) 2016 Tobias Kaminsky
|
||||
|
@ -20,8 +20,6 @@
|
|||
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
import android.widget.ListAdapter;
|
||||
|
||||
public interface FilterableListAdapter extends ListAdapter {
|
||||
public interface FilterableListAdapter {
|
||||
void filter(String text);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ package com.owncloud.android.ui.adapter;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.database.DataSetObserver;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -30,10 +29,8 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
|
@ -49,8 +46,6 @@ import com.owncloud.android.utils.ThemeUtils;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -84,42 +79,11 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
checkedFiles = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
// footer is not enabled
|
||||
return position < getItemCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDataSetObserver(DataSetObserver observer) {
|
||||
// not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterDataSetObserver(DataSetObserver observer) {
|
||||
// not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mFiles.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mFiles.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getItem(int position) {
|
||||
return mFiles.get(position);
|
||||
}
|
||||
|
||||
public boolean isCheckedFile(File file) {
|
||||
return checkedFiles.contains(file);
|
||||
}
|
||||
|
@ -310,69 +274,6 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
File file = null;
|
||||
|
||||
boolean isGridView = true;
|
||||
|
||||
ImageView checkBoxV = view.findViewById(R.id.custom_checkbox);
|
||||
TextView fileSizeV = view.findViewById(R.id.file_size);
|
||||
TextView fileSizeSeparatorV = view.findViewById(R.id.file_separator);
|
||||
if (!isGridView) {
|
||||
TextView lastModV = view.findViewById(R.id.last_mod);
|
||||
lastModV.setVisibility(View.VISIBLE);
|
||||
lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.lastModified()));
|
||||
view.findViewById(R.id.overflow_menu).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (!file.isDirectory()) {
|
||||
if (!isGridView) {
|
||||
fileSizeSeparatorV.setVisibility(View.VISIBLE);
|
||||
fileSizeV.setVisibility(View.VISIBLE);
|
||||
fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
|
||||
}
|
||||
|
||||
AbsListView parentList = (AbsListView) parent;
|
||||
if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
|
||||
checkBoxV.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (parentList.isItemChecked(position)) {
|
||||
checkBoxV.setImageResource(R.drawable.ic_checkbox_marked);
|
||||
} else {
|
||||
checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline);
|
||||
}
|
||||
checkBoxV.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
if (!isGridView) {
|
||||
fileSizeSeparatorV.setVisibility(View.GONE);
|
||||
fileSizeV.setVisibility(View.GONE);
|
||||
}
|
||||
checkBoxV.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// not GONE; the alignment changes; ugly way to keep it
|
||||
view.findViewById(R.id.localFileIndicator).setVisibility(View.INVISIBLE);
|
||||
view.findViewById(R.id.keptOfflineIcon).setVisibility(View.GONE);
|
||||
view.findViewById(R.id.favorite_action).setVisibility(View.GONE);
|
||||
|
||||
view.findViewById(R.id.sharedIcon).setVisibility(View.GONE);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return mFiles.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the adapted directory for a new one
|
||||
*
|
||||
|
@ -393,23 +294,6 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
}
|
||||
}
|
||||
|
||||
Collections.sort(mFiles, new Comparator<File>() {
|
||||
@Override
|
||||
public int compare(File lhs, File rhs) {
|
||||
if (lhs.isDirectory() && !rhs.isDirectory()) {
|
||||
return -1;
|
||||
} else if (!lhs.isDirectory() && rhs.isDirectory()) {
|
||||
return 1;
|
||||
}
|
||||
return compareNames(lhs, rhs);
|
||||
}
|
||||
|
||||
private int compareNames(File lhs, File rhs) {
|
||||
return lhs.getName().toLowerCase(Locale.getDefault()).compareTo(
|
||||
rhs.getName().toLowerCase(Locale.getDefault()));
|
||||
}
|
||||
});
|
||||
|
||||
FileSortOrder sortOrder = PreferenceManager.getSortOrder(mContext, null);
|
||||
mFiles = sortOrder.sortLocalFiles(mFiles);
|
||||
|
||||
|
@ -473,7 +357,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
* @param files ArrayList of files to filter
|
||||
* @return Non-hidden files
|
||||
*/
|
||||
public List<File> filterHiddenFiles(List<File> files) {
|
||||
private List<File> filterHiddenFiles(List<File> files) {
|
||||
List<File> ret = new ArrayList<>();
|
||||
|
||||
for (File file : files) {
|
||||
|
@ -523,7 +407,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
this.gridView = gridView;
|
||||
}
|
||||
|
||||
static class LocalFileListItemViewHolder extends LocalFileListGridViewHolder {
|
||||
private static class LocalFileListItemViewHolder extends LocalFileListGridViewHolder {
|
||||
private final TextView fileSize;
|
||||
private final TextView lastModification;
|
||||
private final TextView fileSeparator;
|
||||
|
@ -560,7 +444,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
}
|
||||
}
|
||||
|
||||
static class LocalFileListFooterViewHolder extends RecyclerView.ViewHolder {
|
||||
private static class LocalFileListFooterViewHolder extends RecyclerView.ViewHolder {
|
||||
private final TextView footerText;
|
||||
|
||||
private LocalFileListFooterViewHolder(View itemView) {
|
||||
|
|
Loading…
Reference in a new issue