|
@@ -84,10 +84,13 @@ import com.owncloud.android.utils.MimeTypeUtil;
|
|
import com.owncloud.android.utils.theme.CapabilityUtils;
|
|
import com.owncloud.android.utils.theme.CapabilityUtils;
|
|
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
|
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
|
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
|
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
|
|
|
+import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
+import java.util.Date;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
@@ -104,7 +107,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|
* This Adapter populates a RecyclerView with all files and folders in a Nextcloud instance.
|
|
* This Adapter populates a RecyclerView with all files and folders in a Nextcloud instance.
|
|
*/
|
|
*/
|
|
public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
- implements DisplayUtils.AvatarGenerationListener {
|
|
|
|
|
|
+ implements DisplayUtils.AvatarGenerationListener, FastScrollRecyclerView.SectionedAdapter {
|
|
|
|
|
|
private static final int showFilenameColumnThreshold = 4;
|
|
private static final int showFilenameColumnThreshold = 4;
|
|
private final ComponentsGetter transferServiceGetter;
|
|
private final ComponentsGetter transferServiceGetter;
|
|
@@ -138,6 +141,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|
private OCFile highlightedItem;
|
|
private OCFile highlightedItem;
|
|
private boolean showMetadata = true;
|
|
private boolean showMetadata = true;
|
|
|
|
|
|
|
|
+ private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy", Locale.getDefault());
|
|
|
|
+
|
|
public OCFileListAdapter(
|
|
public OCFileListAdapter(
|
|
Activity activity,
|
|
Activity activity,
|
|
User user,
|
|
User user,
|
|
@@ -770,13 +775,18 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|
return output;
|
|
return output;
|
|
}
|
|
}
|
|
|
|
|
|
- public OCFile getItem(int position) {
|
|
|
|
|
|
+ public @Nullable
|
|
|
|
+ OCFile getItem(int position) {
|
|
int newPosition = position;
|
|
int newPosition = position;
|
|
|
|
|
|
if (shouldShowHeader() && position > 0) {
|
|
if (shouldShowHeader() && position > 0) {
|
|
newPosition = position - 1;
|
|
newPosition = position - 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (newPosition >= mFiles.size()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
return mFiles.get(newPosition);
|
|
return mFiles.get(newPosition);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1209,6 +1219,35 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|
showMetadata = bool;
|
|
showMetadata = bool;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @NonNull
|
|
|
|
+ @Override
|
|
|
|
+ public String getSectionName(int position) {
|
|
|
|
+ // sort
|
|
|
|
+ Enum<FileSortOrder.SortType> sortOrderType;
|
|
|
|
+ if (ocFileListFragmentInterface.isGalleryFragment()) {
|
|
|
|
+ sortOrderType = FileSortOrder.SortType.DATE;
|
|
|
|
+ } else {
|
|
|
|
+ sortOrderType = preferences.getSortOrderByFolder(currentDirectory).getType();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ OCFile file = getItem(position);
|
|
|
|
+
|
|
|
|
+ if (file == null) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (sortOrderType == FileSortOrder.SortType.ALPHABET) {
|
|
|
|
+ return String.valueOf(file.getFileName().charAt(0));
|
|
|
|
+ } else if (sortOrderType == FileSortOrder.SortType.DATE) {
|
|
|
|
+ long milliseconds = file.getModificationTimestamp();
|
|
|
|
+ Date date = new Date(milliseconds);
|
|
|
|
+ return dateFormat.format(date);
|
|
|
|
+ } else {
|
|
|
|
+ // Size
|
|
|
|
+ return DisplayUtils.bytesToHumanReadable(file.getFileLength());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
public void setShowShareAvatar(boolean bool) {
|
|
public void setShowShareAvatar(boolean bool) {
|
|
showShareAvatar = bool;
|
|
showShareAvatar = bool;
|