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 @@
Best rating
Add feed
Feed is being added
-
+
- Selected folder:
- Create folder
- Choose data folder
- Create new folder with name "%1$s"?
- Created new folder
- Cannot write to this folder
- Folder already exists
- Could not create folder
-
+ Selected folder:
+ Create folder
+ Choose data folder
+ Create new folder with name "%1$s"?
+ Created new folder
+ Cannot write to this folder
+ Folder already exists
+ Could not create folder
+ Folder is not empty
+ The folder you have selected is not empty. Media downloads and other data will be placed directly in this folder. Continue anyway?
+
+
\ 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();
}
}
@@ -235,6 +276,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);