aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/files/SimpleDirChooser.java23
1 files changed, 13 insertions, 10 deletions
diff --git a/main/src/cgeo/geocaching/files/SimpleDirChooser.java b/main/src/cgeo/geocaching/files/SimpleDirChooser.java
index 9e99aec..c59b0cb 100644
--- a/main/src/cgeo/geocaching/files/SimpleDirChooser.java
+++ b/main/src/cgeo/geocaching/files/SimpleDirChooser.java
@@ -42,16 +42,7 @@ public class SimpleDirChooser extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Bundle extras = getIntent().getExtras();
- String startDir = "";
- if (extras != null) {
- startDir = extras.getString(START_DIR);
- }
- if (StringUtils.isBlank(startDir)) {
- startDir = Environment.getExternalStorageDirectory().getPath();
- } else {
- startDir = startDir.substring(0, startDir.lastIndexOf(File.separatorChar));
- }
- currentDir = new File(startDir);
+ currentDir = dirContaining(extras.getString(START_DIR));
ActivityMixin.setTheme(this);
setContentView(R.layout.simple_dir_chooser);
@@ -84,6 +75,18 @@ public class SimpleDirChooser extends ListActivity {
});
}
+ /**
+ * Return the directory containing a given path, or a sensible default.
+ *
+ * @param path the path to get the enclosing directory from, can be null or empty
+ * @return the directory containing <code>path</code>, or a sensible default if none
+ */
+ private static File dirContaining(final String path) {
+ return StringUtils.contains(path, File.separatorChar) ?
+ new File(StringUtils.substringBeforeLast(path, Character.toString(File.separatorChar))) :
+ Environment.getExternalStorageDirectory();
+ }
+
private void fill(File dir) {
EditText path = (EditText) findViewById(R.id.simple_dir_chooser_path);
path.setText(this.getResources().getString(R.string.simple_dir_chooser_current_path) + " " + dir.getAbsolutePath());