summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-12-30 21:45:55 +0100
committerdaniel oeh <daniel.oeh@gmail.com>2012-12-30 21:45:55 +0100
commit236e467657621d5073badda41eb69b718a576a09 (patch)
tree0394261e5a7ac8faed981bcdee2a1b9f889fb127 /src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java
parent6163ccbedb92cf11c5e638fb1dc462ea6bb38108 (diff)
downloadAntennaPod-236e467657621d5073badda41eb69b718a576a09.zip
Added 'empty directory' warning
Diffstat (limited to 'src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java')
-rw-r--r--src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java64
1 files changed, 56 insertions, 8 deletions
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);