summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/values/strings.xml23
-rw-r--r--src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java64
2 files changed, 69 insertions, 18 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a51e40910..001c5e176 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -214,14 +214,17 @@
<string name="best_rating_label">Best rating</string>
<string name="add_feed_label">Add feed</string>
<string name="miro_feed_added">Feed is being added</string>
-
+
<!-- Directory chooser -->
- <string name="selected_folder_label">Selected folder:</string>
- <string name="create_folder_label">Create folder</string>
- <string name="choose_data_directory">Choose data folder</string>
- <string name="create_folder_msg">Create new folder with name "%1$s"?</string>
- <string name="create_folder_success">Created new folder</string>
- <string name="create_folder_error_no_write_access">Cannot write to this folder</string>
- <string name="create_folder_error_already_exists">Folder already exists</string>
- <string name="create_folder_error">Could not create folder</string>
-</resources>
+ <string name="selected_folder_label">Selected folder:</string>
+ <string name="create_folder_label">Create folder</string>
+ <string name="choose_data_directory">Choose data folder</string>
+ <string name="create_folder_msg">Create new folder with name "%1$s"?</string>
+ <string name="create_folder_success">Created new folder</string>
+ <string name="create_folder_error_no_write_access">Cannot write to this folder</string>
+ <string name="create_folder_error_already_exists">Folder already exists</string>
+ <string name="create_folder_error">Could not create folder</string>
+ <string name="folder_not_empty_dialog_title">Folder is not empty</string>
+ <string name="folder_not_empty_dialog_msg">The folder you have selected is not empty. Media downloads and other data will be placed directly in this folder. Continue anyway?</string>
+
+</resources> \ No newline at end of file
diff --git a/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java b/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java
index 77efc0130..a83a77f28 100644
--- a/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java
+++ b/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java
@@ -5,8 +5,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import org.apache.commons.io.FileUtils;
+
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
@@ -76,14 +79,40 @@ public class DirectoryChooserActivity extends SherlockActivity {
@Override
public void onClick(View v) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Returning " + selectedDir.getAbsolutePath()
- + " as result");
- Intent resultData = new Intent();
- resultData.putExtra(RESULT_SELECTED_DIR,
- selectedDir.getAbsolutePath());
- setResult(RESULT_CODE_DIR_SELECTED, resultData);
- finish();
+ if (isValidFile(selectedDir)) {
+ if (selectedDir.list().length == 0) {
+ returnSelectedFolder();
+ } else {
+ showNonEmptyDirectoryWarning();
+ }
+ }
+ }
+
+ private void showNonEmptyDirectoryWarning() {
+ AlertDialog.Builder adb = new AlertDialog.Builder(
+ DirectoryChooserActivity.this);
+ adb.setTitle(R.string.folder_not_empty_dialog_title);
+ adb.setMessage(R.string.folder_not_empty_dialog_msg);
+ adb.setNegativeButton(R.string.cancel_label,
+ new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog,
+ int which) {
+ dialog.dismiss();
+ }
+ });
+ adb.setPositiveButton(R.string.confirm_label,
+ new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog,
+ int which) {
+ dialog.dismiss();
+ returnSelectedFolder();
+ }
+ });
+ adb.create().show();
}
});
@@ -129,6 +158,17 @@ public class DirectoryChooserActivity extends SherlockActivity {
changeDirectory(Environment.getExternalStorageDirectory());
}
+ /** Finishes the activity and returns the selected folder as a result. */
+ private void returnSelectedFolder() {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Returning " + selectedDir.getAbsolutePath()
+ + " as result");
+ Intent resultData = new Intent();
+ resultData.putExtra(RESULT_SELECTED_DIR, selectedDir.getAbsolutePath());
+ setResult(RESULT_CODE_DIR_SELECTED, resultData);
+ finish();
+ }
+
@Override
protected void onPause() {
super.onPause();
@@ -205,6 +245,7 @@ public class DirectoryChooserActivity extends SherlockActivity {
private void refreshButtonState() {
if (selectedDir != null) {
butConfirm.setEnabled(isValidFile(selectedDir));
+ supportInvalidateOptionsMenu();
}
}
@@ -236,6 +277,13 @@ public class DirectoryChooserActivity extends SherlockActivity {
}
@Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ menu.findItem(R.id.new_folder_item)
+ .setVisible(isValidFile(selectedDir));
+ return true;
+ }
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.directory_chooser, menu);