Tweak button ordering on the file received dialog

This commit is contained in:
Fredrik Fornwall
2016-04-16 23:02:20 +02:00
parent 2a056aeb2e
commit dc086a1e0b

View File

@@ -119,54 +119,54 @@ public class TermuxFileReceiverActivity extends Activity {
} }
void promptNameAndSave(final InputStream in, final String attachmentFileName) { void promptNameAndSave(final InputStream in, final String attachmentFileName) {
DialogUtils.textInput(this, R.string.file_received_title, attachmentFileName DialogUtils.textInput(this, R.string.file_received_title, attachmentFileName, R.string.file_received_edit_button, new DialogUtils.TextSetListener() {
, android.R.string.ok, new DialogUtils.TextSetListener() { @Override
@Override public void onTextSet(String text) {
public void onTextSet(final String text) { File outFile = saveStreamWithName(in, text);
if (saveStreamWithName(in, text) == null) return; if (outFile == null) return;
finish();
}
}, R.string.file_received_open_folder_button, new DialogUtils.TextSetListener() {
@Override
public void onTextSet(String text) {
if (saveStreamWithName(in, text) == null) return;
Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE); final File editorProgramFile = new File(EDITOR_PROGRAM);
executeIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, TERMUX_RECEIVEDIR); if (!editorProgramFile.isFile()) {
executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class); showErrorDialogAndQuit("The following file does not exist:\n$HOME/bin/termux-file-editor\n\n"
startService(executeIntent); + "Create this file as a script or a symlink - it will be called with the received file as only argument.");
finish(); return;
} }
}, R.string.file_received_edit_button, new DialogUtils.TextSetListener() {
@Override
public void onTextSet(String text) {
File outFile = saveStreamWithName(in, text);
if (outFile == null) return;
final File editorProgramFile = new File(EDITOR_PROGRAM); // Do this for the user if necessary:
if (!editorProgramFile.isFile()) { editorProgramFile.setExecutable(true);
showErrorDialogAndQuit("The following file does not exist:\n$HOME/bin/termux-file-editor\n\n"
+ "Create this file as a script or a symlink - it will be called with the received file as only argument."); final Uri scriptUri = new Uri.Builder().scheme("file").path(EDITOR_PROGRAM).build();
return;
Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE, scriptUri);
executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class);
executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{outFile.getAbsolutePath()});
startService(executeIntent);
finish();
} }
},
R.string.file_received_open_folder_button, new DialogUtils.TextSetListener() {
@Override
public void onTextSet(String text) {
if (saveStreamWithName(in, text) == null) return;
// Do this for the user if necessary: Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE);
editorProgramFile.setExecutable(true); executeIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, TERMUX_RECEIVEDIR);
executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class);
final Uri scriptUri = new Uri.Builder().scheme("file").path(EDITOR_PROGRAM).build(); startService(executeIntent);
finish();
Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE, scriptUri); }
executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class); },
executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{outFile.getAbsolutePath()}); android.R.string.cancel, new DialogUtils.TextSetListener() {
startService(executeIntent); @Override
finish(); public void onTextSet(final String text) {
} finish();
}, new DialogInterface.OnDismissListener() { }
@Override }, new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) { @Override
if (mFinishOnDismissNameDialog) finish(); public void onDismiss(DialogInterface dialog) {
} if (mFinishOnDismissNameDialog) finish();
}); }
});
} }
public File saveStreamWithName(InputStream in, String attachmentFileName) { public File saveStreamWithName(InputStream in, String attachmentFileName) {