aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog
diff options
context:
space:
mode:
authormar-v-in <github@rvin.mooo.com>2014-06-22 16:31:28 +0200
committermar-v-in <github@rvin.mooo.com>2014-06-22 16:31:28 +0200
commit79fb23b095fba273d77066204ee44d2b8d1edf8d (patch)
tree69aa452c547cb6bc6b882abf6d8e22836bfb2303 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog
parent313e571a61e22a7152e32366d747114233d25b6e (diff)
downloadopen-keychain-79fb23b095fba273d77066204ee44d2b8d1edf8d.tar.gz
open-keychain-79fb23b095fba273d77066204ee44d2b8d1edf8d.tar.bz2
open-keychain-79fb23b095fba273d77066204ee44d2b8d1edf8d.zip
Improve file more, Part 1
- Use Uris where it makes sense, Use File class to clarify it's a file (and not whatever else a string could be) - Show sdcard in side menu in storage API #665 - Propose filename with gpg ending when storing it using the storage API #665 - Don't show output dialog on Android 4.4 #665 - Only show filename on Android < 4.4 #665 TODO: - File deletion for Android < 4.4 - Testing (especially with Android < 4.4) - Batch-encryption - UI - Temporary content provider (see #665 discussion)
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java38
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java87
2 files changed, 43 insertions, 82 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java
index cae6cf043..f9111d885 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java
@@ -18,43 +18,23 @@
package org.sufficientlysecure.keychain.ui.dialog;
import android.app.Dialog;
-import android.app.ProgressDialog;
import android.content.DialogInterface;
-import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Message;
-import android.os.Messenger;
import android.provider.DocumentsContract;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
-import android.widget.Toast;
+import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.service.KeychainIntentService;
-import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
+import org.sufficientlysecure.keychain.helper.FileHelper;
public class DeleteFileDialogFragment extends DialogFragment {
- private static final String ARG_DELETE_FILE = "delete_file";
private static final String ARG_DELETE_URI = "delete_uri";
/**
* Creates new instance of this delete file dialog fragment
*/
- public static DeleteFileDialogFragment newInstance(String deleteFile) {
- DeleteFileDialogFragment frag = new DeleteFileDialogFragment();
- Bundle args = new Bundle();
-
- args.putString(ARG_DELETE_FILE, deleteFile);
-
- frag.setArguments(args);
-
- return frag;
- }
-
- /**
- * Creates new instance of this delete file dialog fragment
- */
public static DeleteFileDialogFragment newInstance(Uri deleteUri) {
DeleteFileDialogFragment frag = new DeleteFileDialogFragment();
Bundle args = new Bundle();
@@ -74,14 +54,14 @@ public class DeleteFileDialogFragment extends DialogFragment {
final FragmentActivity activity = getActivity();
final Uri deleteUri = getArguments().containsKey(ARG_DELETE_URI) ? getArguments().<Uri>getParcelable(ARG_DELETE_URI) : null;
- final String deleteFile = getArguments().getString(ARG_DELETE_FILE);
+ String deleteFilename = FileHelper.getFilename(getActivity(), deleteUri);
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);
alert.setIcon(R.drawable.ic_dialog_alert_holo_light);
alert.setTitle(R.string.warning);
- alert.setMessage(this.getString(R.string.file_delete_confirmation, deleteFile));
+ alert.setMessage(this.getString(R.string.file_delete_confirmation, deleteFilename));
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@@ -89,12 +69,14 @@ public class DeleteFileDialogFragment extends DialogFragment {
public void onClick(DialogInterface dialog, int id) {
dismiss();
- if (deleteUri != null) {
+ if (Constants.KITKAT) {
// We can not securely delete Documents, so just use usual delete on them
- DocumentsContract.deleteDocument(getActivity().getContentResolver(), deleteUri);
- return;
+ if (DocumentsContract.deleteDocument(getActivity().getContentResolver(), deleteUri)) return;
}
+ // TODO!!! We can't delete files from Uri without trying to find it's real path
+
+ /*
// Send all information needed to service to edit key in other thread
Intent intent = new Intent(activity, KeychainIntentService.class);
@@ -102,7 +84,6 @@ public class DeleteFileDialogFragment extends DialogFragment {
Bundle data = new Bundle();
intent.setAction(KeychainIntentService.ACTION_DELETE_FILE_SECURELY);
- data.putString(KeychainIntentService.DELETE_FILE, deleteFile);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
ProgressDialogFragment deletingDialog = ProgressDialogFragment.newInstance(
@@ -134,6 +115,7 @@ public class DeleteFileDialogFragment extends DialogFragment {
// start service with intent
activity.startService(intent);
+ */
}
});
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java
index 10a24ddf0..c02c37055 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FileDialogFragment.java
@@ -23,13 +23,11 @@ import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
-import android.provider.OpenableColumns;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
@@ -39,11 +37,17 @@ import android.widget.TextView;
import com.beardedhen.androidbootstrap.BootstrapButton;
+import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.util.Log;
+import java.io.File;
+
+/**
+ * This is a file chooser dialog no longer used with KitKat
+ */
public class FileDialogFragment extends DialogFragment {
private static final String ARG_MESSENGER = "messenger";
private static final String ARG_TITLE = "title";
@@ -53,8 +57,7 @@ public class FileDialogFragment extends DialogFragment {
public static final int MESSAGE_OKAY = 1;
- public static final String MESSAGE_DATA_URI = "uri";
- public static final String MESSAGE_DATA_FILENAME = "filename";
+ public static final String MESSAGE_DATA_FILE = "file";
public static final String MESSAGE_DATA_CHECKED = "checked";
private Messenger mMessenger;
@@ -64,8 +67,7 @@ public class FileDialogFragment extends DialogFragment {
private CheckBox mCheckBox;
private TextView mMessageTextView;
- private String mOutputFilename;
- private Uri mOutputUri;
+ private File mFile;
private static final int REQUEST_CODE = 0x00007004;
@@ -73,14 +75,14 @@ public class FileDialogFragment extends DialogFragment {
* Creates new instance of this file dialog fragment
*/
public static FileDialogFragment newInstance(Messenger messenger, String title, String message,
- String defaultFile, String checkboxText) {
+ File defaultFile, String checkboxText) {
FileDialogFragment frag = new FileDialogFragment();
Bundle args = new Bundle();
args.putParcelable(ARG_MESSENGER, messenger);
args.putString(ARG_TITLE, title);
args.putString(ARG_MESSAGE, message);
- args.putString(ARG_DEFAULT_FILE, defaultFile);
+ args.putString(ARG_DEFAULT_FILE, defaultFile.getAbsolutePath());
args.putString(ARG_CHECKBOX_TEXT, checkboxText);
frag.setArguments(args);
@@ -99,7 +101,11 @@ public class FileDialogFragment extends DialogFragment {
String title = getArguments().getString(ARG_TITLE);
String message = getArguments().getString(ARG_MESSAGE);
- mOutputFilename = getArguments().getString(ARG_DEFAULT_FILE);
+ mFile = new File(getArguments().getString(ARG_DEFAULT_FILE));
+ if (!mFile.isAbsolute()) {
+ // We use OK dir by default
+ mFile = new File(Constants.Path.APP_DIR.getAbsolutePath(), mFile.getName());
+ }
String checkboxText = getArguments().getString(ARG_CHECKBOX_TEXT);
LayoutInflater inflater = (LayoutInflater) activity
@@ -113,18 +119,14 @@ public class FileDialogFragment extends DialogFragment {
mMessageTextView.setText(message);
mFilename = (EditText) view.findViewById(R.id.input);
- mFilename.setText(mOutputFilename);
+ mFilename.setText(mFile.getName());
mBrowse = (BootstrapButton) view.findViewById(R.id.btn_browse);
mBrowse.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// only .asc or .gpg files
// setting it to text/plain prevents Cynaogenmod's file manager from selecting asc
// or gpg types!
- if (Constants.KITKAT) {
- FileHelper.saveDocument(FileDialogFragment.this, mOutputUri, "*/*", REQUEST_CODE);
- } else {
- FileHelper.openFile(FileDialogFragment.this, mOutputFilename, "*/*", REQUEST_CODE);
- }
+ FileHelper.openFile(FileDialogFragment.this, Uri.fromFile(mFile), "*/*", REQUEST_CODE);
}
});
@@ -147,19 +149,23 @@ public class FileDialogFragment extends DialogFragment {
dismiss();
String currentFilename = mFilename.getText().toString();
- if (mOutputFilename == null || !mOutputFilename.equals(currentFilename)) {
- mOutputUri = null;
- mOutputFilename = mFilename.getText().toString();
+ if (currentFilename == null || currentFilename.isEmpty()) {
+ // No file is like pressing cancel, UI: maybe disable positive button in this case?
+ return;
+ }
+
+ if (mFile == null || currentFilename.startsWith("/")) {
+ mFile = new File(currentFilename);
+ } else if (!mFile.getName().equals(currentFilename)) {
+ // We update our File object if user changed name!
+ mFile = new File(mFile.getParentFile(), currentFilename);
}
boolean checked = mCheckBox.isEnabled() && mCheckBox.isChecked();
// return resulting data back to activity
Bundle data = new Bundle();
- if (mOutputUri != null) {
- data.putParcelable(MESSAGE_DATA_URI, mOutputUri);
- }
- data.putString(MESSAGE_DATA_FILENAME, mFilename.getText().toString());
+ data.putString(MESSAGE_DATA_FILE, mFile.getAbsolutePath());
data.putBoolean(MESSAGE_DATA_CHECKED, checked);
sendMessageToHandler(MESSAGE_OKAY, data);
@@ -176,44 +182,17 @@ public class FileDialogFragment extends DialogFragment {
return alert.show();
}
- /**
- * Updates filename in dialog, normally called in onActivityResult in activity using the
- * FileDialog
- */
- private void setFilename(String filename) {
- AlertDialog dialog = (AlertDialog) getDialog();
- EditText filenameEditText = (EditText) dialog.findViewById(R.id.input);
-
- if (filenameEditText != null) {
- filenameEditText.setText(filename);
- }
- }
-
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode & 0xFFFF) {
case REQUEST_CODE: {
if (resultCode == Activity.RESULT_OK && data != null) {
- if (Constants.KITKAT) {
- mOutputUri = data.getData();
- Cursor cursor = getActivity().getContentResolver().query(mOutputUri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null);
- if (cursor != null) {
- if (cursor.moveToNext()) {
- mOutputFilename = cursor.getString(0);
- mFilename.setText(mOutputFilename);
- }
- cursor.close();
- }
+ File file = new File(data.getData().getPath());
+ if (file.getParentFile().exists()) {
+ mFile = file;
+ mFilename.setText(mFile.getName());
} else {
- try {
- String path = data.getData().getPath();
- Log.d(Constants.TAG, "path=" + path);
-
- // set filename used in export/import dialogs
- setFilename(path);
- } catch (NullPointerException e) {
- Log.e(Constants.TAG, "Nullpointer while retrieving path!", e);
- }
+ AppMsg.makeText(getActivity(), R.string.no_file_selected, AppMsg.STYLE_ALERT).show();
}
}