mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
allow encrypting to clipboard in EncryptFileFragment
This commit is contained in:
parent
f6bc1dcca3
commit
d11b7b58f1
@ -49,6 +49,7 @@ import android.widget.TextView;
|
|||||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
|
||||||
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpConstants;
|
import org.sufficientlysecure.keychain.pgp.PgpConstants;
|
||||||
@ -85,7 +86,10 @@ public class EncryptFilesFragment
|
|||||||
private boolean mEncryptFilenames;
|
private boolean mEncryptFilenames;
|
||||||
private boolean mHiddenRecipients = false;
|
private boolean mHiddenRecipients = false;
|
||||||
|
|
||||||
private boolean mShareAfterEncrypt;
|
private AfterEncryptAction mAfterEncryptAction;
|
||||||
|
private enum AfterEncryptAction {
|
||||||
|
SAVE, SHARE, COPY;
|
||||||
|
}
|
||||||
|
|
||||||
private ArrayList<Uri> mOutputUris;
|
private ArrayList<Uri> mOutputUris;
|
||||||
|
|
||||||
@ -268,12 +272,17 @@ public class EncryptFilesFragment
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.encrypt_save: {
|
case R.id.encrypt_save: {
|
||||||
mShareAfterEncrypt = false;
|
mAfterEncryptAction = AfterEncryptAction.SAVE;
|
||||||
cryptoOperation();
|
cryptoOperation();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.encrypt_share: {
|
case R.id.encrypt_share: {
|
||||||
mShareAfterEncrypt = true;
|
mAfterEncryptAction = AfterEncryptAction.SHARE;
|
||||||
|
cryptoOperation();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case R.id.encrypt_copy: {
|
||||||
|
mAfterEncryptAction = AfterEncryptAction.COPY;
|
||||||
cryptoOperation();
|
cryptoOperation();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -376,13 +385,14 @@ public class EncryptFilesFragment
|
|||||||
protected void onCryptoOperationSuccess(final SignEncryptResult result) {
|
protected void onCryptoOperationSuccess(final SignEncryptResult result) {
|
||||||
|
|
||||||
if (mDeleteAfterEncrypt) {
|
if (mDeleteAfterEncrypt) {
|
||||||
|
// TODO make behavior coherent here
|
||||||
DeleteFileDialogFragment deleteFileDialog =
|
DeleteFileDialogFragment deleteFileDialog =
|
||||||
DeleteFileDialogFragment.newInstance(mFilesAdapter.getAsArrayList());
|
DeleteFileDialogFragment.newInstance(mFilesAdapter.getAsArrayList());
|
||||||
deleteFileDialog.setOnDeletedListener(new DeleteFileDialogFragment.OnDeletedListener() {
|
deleteFileDialog.setOnDeletedListener(new DeleteFileDialogFragment.OnDeletedListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeleted() {
|
public void onDeleted() {
|
||||||
if (mShareAfterEncrypt) {
|
if (mAfterEncryptAction == AfterEncryptAction.SHARE) {
|
||||||
// Share encrypted message/file
|
// Share encrypted message/file
|
||||||
startActivity(sendWithChooserExcludingEncrypt());
|
startActivity(sendWithChooserExcludingEncrypt());
|
||||||
} else {
|
} else {
|
||||||
@ -394,12 +404,24 @@ public class EncryptFilesFragment
|
|||||||
});
|
});
|
||||||
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
|
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
|
||||||
} else {
|
} else {
|
||||||
if (mShareAfterEncrypt) {
|
|
||||||
// Share encrypted message/file
|
switch (mAfterEncryptAction) {
|
||||||
startActivity(sendWithChooserExcludingEncrypt());
|
|
||||||
} else {
|
case SHARE:
|
||||||
// Save encrypted file
|
// Share encrypted message/file
|
||||||
result.createNotify(getActivity()).show();
|
startActivity(sendWithChooserExcludingEncrypt());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case COPY:
|
||||||
|
byte[] resultBytes = result.getResultBytes();
|
||||||
|
ClipboardReflection.copyToClipboard(getActivity(), new String(resultBytes));
|
||||||
|
result.createNotify(getActivity()).show();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SAVE:
|
||||||
|
// Encrypted file was saved already, just show notification
|
||||||
|
result.createNotify(getActivity()).show();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,19 +430,19 @@ public class EncryptFilesFragment
|
|||||||
// prepares mOutputUris, either directly and returns false, or indirectly
|
// prepares mOutputUris, either directly and returns false, or indirectly
|
||||||
// which returns true and will call cryptoOperation after mOutputUris has
|
// which returns true and will call cryptoOperation after mOutputUris has
|
||||||
// been set at a later point.
|
// been set at a later point.
|
||||||
private boolean prepareOutputStreams(boolean share) {
|
private boolean prepareOutputStreams() {
|
||||||
|
|
||||||
if (mFilesModels.isEmpty()) {
|
if (mFilesModels.isEmpty()) {
|
||||||
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show(this);
|
||||||
return true;
|
return true;
|
||||||
} else if (mFilesModels.size() > 1 && !mShareAfterEncrypt) {
|
} else if (mFilesModels.size() > 1 && mAfterEncryptAction != AfterEncryptAction.SHARE) {
|
||||||
Log.e(Constants.TAG, "Aborting: mInputUris.size() > 1 && !mShareAfterEncrypt");
|
Log.e(Constants.TAG, "Aborting: mInputUris.size() > 1 && !afterEncryptAction");
|
||||||
// This should be impossible...
|
// This should be impossible...
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (share) {
|
if (mAfterEncryptAction == AfterEncryptAction.SHARE) {
|
||||||
mOutputUris = new ArrayList<>();
|
mOutputUris = new ArrayList<>();
|
||||||
int filenameCounter = 1;
|
int filenameCounter = 1;
|
||||||
for (FilesAdapter.ViewModel model : mFilesModels) {
|
for (FilesAdapter.ViewModel model : mFilesModels) {
|
||||||
@ -467,7 +489,7 @@ public class EncryptFilesFragment
|
|||||||
// if this is still null, prepare output streams again
|
// if this is still null, prepare output streams again
|
||||||
if (mOutputUris == null) {
|
if (mOutputUris == null) {
|
||||||
// this may interrupt the flow, and call us again from onActivityResult
|
// this may interrupt the flow, and call us again from onActivityResult
|
||||||
if (prepareOutputStreams(mShareAfterEncrypt)) {
|
if (prepareOutputStreams()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -600,7 +622,8 @@ public class EncryptFilesFragment
|
|||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
mOutputUris = new ArrayList<>(1);
|
mOutputUris = new ArrayList<>(1);
|
||||||
mOutputUris.add(data.getData());
|
mOutputUris.add(data.getData());
|
||||||
mShareAfterEncrypt = false;
|
// make sure this is correct!
|
||||||
|
mAfterEncryptAction = AfterEncryptAction.SAVE;
|
||||||
cryptoOperation();
|
cryptoOperation();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -14,6 +14,11 @@
|
|||||||
android:icon="@drawable/ic_action_encrypt_share_24dp"
|
android:icon="@drawable/ic_action_encrypt_share_24dp"
|
||||||
app:showAsAction="always" />
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/encrypt_copy"
|
||||||
|
android:title="@string/btn_copy_encrypted_signed"
|
||||||
|
android:icon="@drawable/ic_action_encrypt_copy_24dp" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/check_delete_after_encrypt"
|
android:id="@+id/check_delete_after_encrypt"
|
||||||
android:title="@string/label_delete_after_encryption"
|
android:title="@string/label_delete_after_encryption"
|
||||||
|
Loading…
Reference in New Issue
Block a user