diff options
| author | rsudev <rasch@munin-soft.de> | 2012-10-27 00:17:31 +0200 |
|---|---|---|
| committer | rsudev <rasch@munin-soft.de> | 2012-11-03 23:24:18 +0100 |
| commit | f5343eac8a433b198d47057a112e4c92486906b3 (patch) | |
| tree | f4eda41be808315c30768ffc362689dec62fda72 /main/src/cgeo/geocaching/files/FileList.java | |
| parent | c942e65f13579e96ef528f8a7641f3571ce963dd (diff) | |
| download | cgeo-f5343eac8a433b198d47057a112e4c92486906b3.zip cgeo-f5343eac8a433b198d47057a112e4c92486906b3.tar.gz cgeo-f5343eac8a433b198d47057a112e4c92486906b3.tar.bz2 | |
Implements #1676, custom themes
- Adds the selection of a base folder for map themes to settings
- Reworks the map menu to allow selection of a custom theme
- Implements a reusable version of listDir to get a list of files
Diffstat (limited to 'main/src/cgeo/geocaching/files/FileList.java')
| -rw-r--r-- | main/src/cgeo/geocaching/files/FileList.java | 69 |
1 files changed, 28 insertions, 41 deletions
diff --git a/main/src/cgeo/geocaching/files/FileList.java b/main/src/cgeo/geocaching/files/FileList.java index f3622f9..e7bd807 100644 --- a/main/src/cgeo/geocaching/files/FileList.java +++ b/main/src/cgeo/geocaching/files/FileList.java @@ -3,10 +3,10 @@ package cgeo.geocaching.files; import cgeo.geocaching.R; import cgeo.geocaching.StoredList; import cgeo.geocaching.activity.AbstractListActivity; +import cgeo.geocaching.utils.FileUtils; import cgeo.geocaching.utils.Log; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import android.app.ProgressDialog; @@ -151,8 +151,11 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis protected abstract void setTitle(); private class SearchFilesThread extends Thread { + + private final FileListSelector selector = new FileListSelector(); + public void notifyEnd() { - endSearching = true; + selector.setShouldEnd(true); } @Override @@ -165,7 +168,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis for (final File dir : getBaseFolders()) { if (dir.exists() && dir.isDirectory()) { - listDir(list, dir); + FileUtils.listDir(list, dir,selector,changeWaitDialogHandler); if (!list.isEmpty()) { loaded = true; break; @@ -174,7 +177,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis } if (!loaded) { changeWaitDialogHandler.sendMessage(Message.obtain(changeWaitDialogHandler, MSG_SEARCH_WHOLE_SD_CARD, Environment.getExternalStorageDirectory().getName())); - listDirs(list, getStorages()); + listDirs(list, getStorages(), selector, changeWaitDialogHandler); } } else { Log.w("No external media mounted."); @@ -198,44 +201,9 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis } } - private void listDirs(List<File> list, List<File> directories) { + private void listDirs(List<File> list, List<File> directories, FileListSelector selector, Handler feedbackHandler) { for (final File dir : directories) { - listDir(list, dir); - } - } - - private void listDir(List<File> result, File directory) { - if (directory == null || !directory.isDirectory() || !directory.canRead()) { - return; - } - - final File[] files = directory.listFiles(); - - if (ArrayUtils.isNotEmpty(files)) { - for (File file : files) { - if (endSearching) { - return; - } - if (!file.canRead()) { - continue; - } - String name = file.getName(); - if (file.isFile()) { - if (filenameBelongsToList(name)) { - result.add(file); // add file to list - } - } else if (file.isDirectory()) { - if (name.charAt(0) == '.') { - continue; // skip hidden directories - } - if (name.length() > 16) { - name = name.substring(0, 14) + '…'; - } - changeWaitDialogHandler.sendMessage(Message.obtain(changeWaitDialogHandler, 0, name)); - - listDir(result, file); // go deeper - } - } + FileUtils.listDir(list, dir, selector, feedbackHandler); } } @@ -322,4 +290,23 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis } } } + + private class FileListSelector extends FileUtils.FileSelector { + + boolean _shouldEnd = false; + + @Override + public boolean isSelected(File file) { + return filenameBelongsToList(file.getName()); + } + + @Override + public boolean shouldEnd() { + return _shouldEnd; + } + + public void setShouldEnd(boolean shouldEnd) { + _shouldEnd = shouldEnd; + } + } } |
