mirror of
https://github.com/nextcloud/android.git
synced 2024-12-01 03:43:43 +03:00
commit
14c586df7d
4 changed files with 37 additions and 60 deletions
|
@ -42,7 +42,7 @@ public class FileSortOrder {
|
|||
|
||||
public static final Map<String, FileSortOrder> sortOrders;
|
||||
static {
|
||||
sortOrders = new HashMap<String, FileSortOrder>();
|
||||
sortOrders = new HashMap<>();
|
||||
sortOrders.put(sort_a_to_z.mName, sort_a_to_z);
|
||||
sortOrders.put(sort_z_to_a.mName, sort_z_to_a);
|
||||
sortOrders.put(sort_old_to_new.mName, sort_old_to_new);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Sven R. Kunze
|
||||
|
@ -23,8 +23,6 @@ package com.owncloud.android.utils;
|
|||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
@ -63,22 +61,16 @@ public class FileSortOrderByDate extends FileSortOrder {
|
|||
/**
|
||||
* Sorts list by Date.
|
||||
*
|
||||
* @param filesArray list of files to sort
|
||||
* @param files list of files to sort
|
||||
*/
|
||||
public File[] sortLocalFiles(File[] filesArray) {
|
||||
public List<File> sortLocalFiles(List<File> files) {
|
||||
final int multiplier = mAscending ? 1 : -1;
|
||||
|
||||
List<File> files = new ArrayList<File>(Arrays.asList(filesArray));
|
||||
|
||||
Collections.sort(files, new Comparator<File>() {
|
||||
@SuppressFBWarnings(value = "Bx")
|
||||
public int compare(File o1, File o2) {
|
||||
Long obj1 = o1.lastModified();
|
||||
return multiplier * obj1.compareTo(o2.lastModified());
|
||||
}
|
||||
Collections.sort(files, (o1, o2) -> {
|
||||
Long obj1 = o1.lastModified();
|
||||
return multiplier * obj1.compareTo(o2.lastModified());
|
||||
});
|
||||
|
||||
File[] returnArray = new File[files.size()];
|
||||
return files.toArray(returnArray);
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Sven R. Kunze
|
||||
|
@ -23,8 +23,6 @@ package com.owncloud.android.utils;
|
|||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
@ -70,30 +68,25 @@ public class FileSortOrderByName extends FileSortOrder {
|
|||
/**
|
||||
* Sorts list by Name.
|
||||
*
|
||||
* @param filesArray files to sort
|
||||
* @param files files to sort
|
||||
*/
|
||||
public File[] sortLocalFiles(File[] filesArray) {
|
||||
public List<File> sortLocalFiles(List<File> files) {
|
||||
final int multiplier = mAscending ? 1 : -1;
|
||||
|
||||
List<File> files = new ArrayList<>(Arrays.asList(filesArray));
|
||||
|
||||
Collections.sort(files, new Comparator<File>() {
|
||||
public int compare(File o1, File o2) {
|
||||
if (o1.isDirectory() && o2.isDirectory()) {
|
||||
return multiplier * o1.getPath().toLowerCase(Locale.getDefault())
|
||||
.compareTo(o2.getPath().toLowerCase(Locale.getDefault()));
|
||||
} else if (o1.isDirectory()) {
|
||||
return -1;
|
||||
} else if (o2.isDirectory()) {
|
||||
return 1;
|
||||
}
|
||||
return multiplier * new AlphanumComparator().compare(o1.getPath()
|
||||
.toLowerCase(Locale.getDefault()),
|
||||
o2.getPath().toLowerCase(Locale.getDefault()));
|
||||
Collections.sort(files, (o1, o2) -> {
|
||||
if (o1.isDirectory() && o2.isDirectory()) {
|
||||
return multiplier * o1.getPath().toLowerCase(Locale.getDefault())
|
||||
.compareTo(o2.getPath().toLowerCase(Locale.getDefault()));
|
||||
} else if (o1.isDirectory()) {
|
||||
return -1;
|
||||
} else if (o2.isDirectory()) {
|
||||
return 1;
|
||||
}
|
||||
return multiplier * new AlphanumComparator().compare(o1.getPath()
|
||||
.toLowerCase(Locale.getDefault()),
|
||||
o2.getPath().toLowerCase(Locale.getDefault()));
|
||||
});
|
||||
|
||||
File[] returnArray = new File[files.size()];
|
||||
return files.toArray(returnArray);
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ package com.owncloud.android.utils;
|
|||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
@ -73,32 +71,26 @@ public class FileSortOrderBySize extends FileSortOrder {
|
|||
/**
|
||||
* Sorts list by Size.
|
||||
*
|
||||
* @param filesArray list of files to sort
|
||||
* @param files list of files to sort
|
||||
*/
|
||||
public File[] sortLocalFiles(File[] filesArray) {
|
||||
public List<File> sortLocalFiles(List<File> files) {
|
||||
final int multiplier = mAscending ? 1 : -1;
|
||||
|
||||
List<File> files = new ArrayList<>(Arrays.asList(filesArray));
|
||||
|
||||
Collections.sort(files, new Comparator<File>() {
|
||||
@SuppressFBWarnings(value = "Bx")
|
||||
public int compare(File o1, File o2) {
|
||||
if (o1.isDirectory() && o2.isDirectory()) {
|
||||
Long obj1 = FileStorageUtils.getFolderSize(o1);
|
||||
return multiplier * obj1.compareTo(FileStorageUtils.getFolderSize(o2));
|
||||
} else if (o1.isDirectory()) {
|
||||
return -1;
|
||||
} else if (o2.isDirectory()) {
|
||||
return 1;
|
||||
} else {
|
||||
Long obj1 = o1.length();
|
||||
return multiplier * obj1.compareTo(o2.length());
|
||||
}
|
||||
Collections.sort(files, (o1, o2) -> {
|
||||
if (o1.isDirectory() && o2.isDirectory()) {
|
||||
Long obj1 = FileStorageUtils.getFolderSize(o1);
|
||||
return multiplier * obj1.compareTo(FileStorageUtils.getFolderSize(o2));
|
||||
} else if (o1.isDirectory()) {
|
||||
return -1;
|
||||
} else if (o2.isDirectory()) {
|
||||
return 1;
|
||||
} else {
|
||||
Long obj1 = o1.length();
|
||||
return multiplier * obj1.compareTo(o2.length());
|
||||
}
|
||||
});
|
||||
|
||||
File[] returnArray = new File[files.size()];
|
||||
return files.toArray(returnArray);
|
||||
return files;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue