mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-22 06:43:45 +01:00
Added 'empty directory' warning
This commit is contained in:
parent
6163ccbedb
commit
236e467657
@ -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>
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user