Use switch... and effectively sorts before listing.
Change-Id: Ia7eb2c53dc8a69b3d65e56afc7a27f0548c63d07
This commit is contained in:
@@ -10,11 +10,14 @@ package org.libreoffice.ui;
|
|||||||
|
|
||||||
import org.libreoffice.R;
|
import org.libreoffice.R;
|
||||||
|
|
||||||
|
import org.libreoffice.storage.IFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Arrays;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -198,55 +201,52 @@ public class FileUtilities {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sortFiles(File[] files, int sortMode) {
|
static void sortFiles(List<IFile> files, int sortMode) {
|
||||||
// Should really change all this to a switch statement...
|
switch (sortMode) {
|
||||||
if (sortMode == SORT_AZ) {
|
case SORT_AZ:
|
||||||
Arrays.sort(files , new Comparator<File>() {
|
Collections.sort(files , new Comparator<IFile>() {
|
||||||
public int compare(File lhs, File rhs) {
|
public int compare(IFile lhs, IFile rhs) {
|
||||||
return lhs.getName().compareTo(rhs.getName());
|
return lhs.getName().compareTo(rhs.getName());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
break;
|
||||||
}
|
case SORT_ZA:
|
||||||
if (sortMode == SORT_ZA) {
|
Collections.sort(files , new Comparator<IFile>() {
|
||||||
Arrays.sort(files , new Comparator<File>() {
|
public int compare(IFile lhs, IFile rhs) {
|
||||||
public int compare(File lhs, File rhs) {
|
return rhs.getName().compareTo(lhs.getName());
|
||||||
return rhs.getName().compareTo(lhs.getName());
|
}
|
||||||
}
|
});
|
||||||
});
|
break;
|
||||||
return;
|
case SORT_OLDEST:
|
||||||
}
|
Collections.sort(files , new Comparator<IFile>() {
|
||||||
if (sortMode == SORT_OLDEST) {
|
public int compare(IFile lhs, IFile rhs) {
|
||||||
Arrays.sort(files , new Comparator<File>() {
|
return lhs.getLastModified().compareTo(rhs.getLastModified());
|
||||||
public int compare(File lhs, File rhs) {
|
}
|
||||||
return Long.valueOf(lhs.lastModified()).compareTo(rhs.lastModified());
|
});
|
||||||
}
|
break;
|
||||||
});
|
case SORT_NEWEST:
|
||||||
return;
|
Collections.sort(files , new Comparator<IFile>() {
|
||||||
}
|
public int compare(IFile lhs, IFile rhs) {
|
||||||
if (sortMode == SORT_NEWEST) {
|
return rhs.getLastModified().compareTo(lhs.getLastModified());
|
||||||
Arrays.sort(files , new Comparator<File>() {
|
}
|
||||||
public int compare(File lhs, File rhs) {
|
});
|
||||||
return Long.valueOf(rhs.lastModified()).compareTo(lhs.lastModified());
|
break;
|
||||||
}
|
case SORT_LARGEST:
|
||||||
});
|
Collections.sort(files , new Comparator<IFile>() {
|
||||||
return;
|
public int compare(IFile lhs, IFile rhs) {
|
||||||
}
|
return Long.valueOf(rhs.getSize()).compareTo(lhs.getSize());
|
||||||
if (sortMode == SORT_LARGEST) {
|
}
|
||||||
Arrays.sort(files , new Comparator<File>() {
|
});
|
||||||
public int compare(File lhs, File rhs) {
|
break;
|
||||||
return Long.valueOf(rhs.length()).compareTo(lhs.length());
|
case SORT_SMALLEST:
|
||||||
}
|
Collections.sort(files , new Comparator<IFile>() {
|
||||||
});
|
public int compare(IFile lhs, IFile rhs) {
|
||||||
return;
|
return Long.valueOf(lhs.getSize()).compareTo(rhs.getSize());
|
||||||
}
|
}
|
||||||
if (sortMode == SORT_SMALLEST) {
|
});
|
||||||
Arrays.sort(files , new Comparator<File>() {
|
break;
|
||||||
public int compare(File lhs, File rhs) {
|
default:
|
||||||
return Long.valueOf(lhs.length()).compareTo(rhs.length());
|
Log.e(LOGTAG, "uncatched sortMode: " + sortMode);
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -177,6 +177,8 @@ public class LibreOfficeUIActivity extends ActionBarActivity implements ActionBa
|
|||||||
} else {
|
} else {
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileUtilities.sortFiles(filePaths, sortMode);
|
||||||
// refresh view
|
// refresh view
|
||||||
if (viewMode == GRID_VIEW) {
|
if (viewMode == GRID_VIEW) {
|
||||||
gv.setAdapter(new GridItemAdapter(getApplicationContext(),
|
gv.setAdapter(new GridItemAdapter(getApplicationContext(),
|
||||||
|
Reference in New Issue
Block a user