diff options
author | Siqi Liu <me@siqi.fr> | 2015-04-23 15:18:23 +0200 |
---|---|---|
committer | Siqi Liu <me@siqi.fr> | 2015-04-23 15:31:16 +0200 |
commit | 0848e70b0f13d025076ab3536b9378375e3d1cf0 (patch) | |
tree | 42f41a107da711ce6dc83b9ced48347e52165e6c /android | |
parent | dde1964a2c291aad5b3df76c1ddfbcb7a983a6ed (diff) |
Use switch... and effectively sorts before listing.
Change-Id: Ia7eb2c53dc8a69b3d65e56afc7a27f0548c63d07
Diffstat (limited to 'android')
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java | 100 | ||||
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 2 |
2 files changed, 52 insertions, 50 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java index 9c5875019169..b8bb7e922111 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java @@ -10,11 +10,14 @@ package org.libreoffice.ui; import org.libreoffice.R; +import org.libreoffice.storage.IFile; + import java.io.File; import java.io.FileFilter; import java.io.FilenameFilter; import java.util.Map; -import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.HashMap; import java.util.Comparator; import android.util.Log; @@ -198,55 +201,52 @@ public class FileUtilities { }; } - static void sortFiles(File[] files, int sortMode) { - // Should really change all this to a switch statement... - if (sortMode == SORT_AZ) { - Arrays.sort(files , new Comparator<File>() { - public int compare(File lhs, File rhs) { - return lhs.getName().compareTo(rhs.getName()); - } - }); - return; - } - if (sortMode == SORT_ZA) { - Arrays.sort(files , new Comparator<File>() { - public int compare(File lhs, File rhs) { - return rhs.getName().compareTo(lhs.getName()); - } - }); - return; - } - if (sortMode == SORT_OLDEST) { - Arrays.sort(files , new Comparator<File>() { - public int compare(File lhs, File rhs) { - return Long.valueOf(lhs.lastModified()).compareTo(rhs.lastModified()); - } - }); - return; - } - if (sortMode == SORT_NEWEST) { - Arrays.sort(files , new Comparator<File>() { - public int compare(File lhs, File rhs) { - return Long.valueOf(rhs.lastModified()).compareTo(lhs.lastModified()); - } - }); - return; - } - if (sortMode == SORT_LARGEST) { - Arrays.sort(files , new Comparator<File>() { - public int compare(File lhs, File rhs) { - return Long.valueOf(rhs.length()).compareTo(lhs.length()); - } - }); - return; - } - if (sortMode == SORT_SMALLEST) { - Arrays.sort(files , new Comparator<File>() { - public int compare(File lhs, File rhs) { - return Long.valueOf(lhs.length()).compareTo(rhs.length()); - } - }); - return; + static void sortFiles(List<IFile> files, int sortMode) { + switch (sortMode) { + case SORT_AZ: + Collections.sort(files , new Comparator<IFile>() { + public int compare(IFile lhs, IFile rhs) { + return lhs.getName().compareTo(rhs.getName()); + } + }); + break; + case SORT_ZA: + Collections.sort(files , new Comparator<IFile>() { + public int compare(IFile lhs, IFile rhs) { + return rhs.getName().compareTo(lhs.getName()); + } + }); + break; + case SORT_OLDEST: + Collections.sort(files , new Comparator<IFile>() { + public int compare(IFile lhs, IFile rhs) { + return lhs.getLastModified().compareTo(rhs.getLastModified()); + } + }); + break; + case SORT_NEWEST: + Collections.sort(files , new Comparator<IFile>() { + public int compare(IFile lhs, IFile rhs) { + return rhs.getLastModified().compareTo(lhs.getLastModified()); + } + }); + break; + case SORT_LARGEST: + Collections.sort(files , new Comparator<IFile>() { + public int compare(IFile lhs, IFile rhs) { + return Long.valueOf(rhs.getSize()).compareTo(lhs.getSize()); + } + }); + break; + case SORT_SMALLEST: + Collections.sort(files , new Comparator<IFile>() { + public int compare(IFile lhs, IFile rhs) { + return Long.valueOf(lhs.getSize()).compareTo(rhs.getSize()); + } + }); + break; + default: + Log.e(LOGTAG, "uncatched sortMode: " + sortMode); } return; } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 229c6190b572..3c269bf83d89 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -177,6 +177,8 @@ public class LibreOfficeUIActivity extends ActionBarActivity implements ActionBa } else { getSupportActionBar().setDisplayHomeAsUpEnabled(false); } + + FileUtilities.sortFiles(filePaths, sortMode); // refresh view if (viewMode == GRID_VIEW) { gv.setAdapter(new GridItemAdapter(getApplicationContext(), |