From 0ed29c1c77c065d73af5c9f1d7769c6c1a1a9c6f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 8 May 2014 14:23:09 +0200 Subject: more informative dialog if contact doesn't announce public key --- res/values/strings.xml | 2 + .../conversations/ui/ConversationActivity.java | 50 ++++++++++++++-------- .../conversations/ui/ConversationFragment.java | 41 ++++++++++-------- 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c3c7f658..61134d29 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -84,4 +84,6 @@ Restart Install offering… + No openPGP Key found + Conversations is unable to encrypt your messages because your contact is not announcing his or hers public key.\n\nPlease ask your contact to setup openPGP. diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 565d7ff4..7c87a0f6 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -341,26 +341,42 @@ public class ConversationActivity extends XmppActivity { } private void attachFile() { - if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_PGP) { + final Conversation conversation = getSelectedConversation(); + if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { if (hasPgp()) { - xmppConnectionService.getPgpEngine().hasKey(getSelectedConversation().getContact(), new OnPgpEngineResult() { - - @Override - public void userInputRequried(PendingIntent pi) { - ConversationActivity.this.runIntent(pi, REQUEST_SEND_PGP_IMAGE); - } - - @Override - public void success() { - attachFileDialog(); - } - - @Override - public void error(OpenPgpError openPgpError) { - // TODO Auto-generated method stub + if (conversation.getContact().getPgpKeyId()!=0) { + xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new OnPgpEngineResult() { + + @Override + public void userInputRequried(PendingIntent pi) { + ConversationActivity.this.runIntent(pi, REQUEST_SEND_PGP_IMAGE); + } + @Override + public void success() { + attachFileDialog(); + } + + @Override + public void error(OpenPgpError openPgpError) { + // TODO Auto-generated method stub + + } + }); + } else { + final ConversationFragment fragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (fragment != null) { + fragment.showNoPGPKeyDialog(new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + conversation.setNextEncryption(Message.ENCRYPTION_NONE); + attachFileDialog(); + } + }); } - }); + } } } else if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_NONE) { attachFileDialog(); diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 33aa5b5c..e370deb0 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -718,29 +718,32 @@ public class ConversationFragment extends Fragment { }); } else { - AlertDialog.Builder builder = new AlertDialog.Builder( - getActivity()); - builder.setTitle("No openPGP key found"); - builder.setIconAttribute(android.R.attr.alertDialogIcon); - builder.setMessage("There is no openPGP key associated with this contact"); - builder.setNegativeButton("Cancel", null); - builder.setPositiveButton("Send plain text", - new DialogInterface.OnClickListener() { + showNoPGPKeyDialog(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int which) { - conversation - .setNextEncryption(Message.ENCRYPTION_NONE); - message.setEncryption(Message.ENCRYPTION_NONE); - xmppService.sendMessage(message, null); - chatMsg.setText(""); - } - }); - builder.create().show(); + @Override + public void onClick(DialogInterface dialog, + int which) { + conversation + .setNextEncryption(Message.ENCRYPTION_NONE); + message.setEncryption(Message.ENCRYPTION_NONE); + xmppService.sendMessage(message, null); + chatMsg.setText(""); + } + }); } } } + + public void showNoPGPKeyDialog(DialogInterface.OnClickListener listener) { + AlertDialog.Builder builder = new AlertDialog.Builder( + getActivity()); + builder.setTitle(getString(R.string.no_pgp_key)); + builder.setIconAttribute(android.R.attr.alertDialogIcon); + builder.setMessage(getText(R.string.contact_has_no_pgp_key)); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.setPositiveButton(getString(R.string.send_unencrypted),listener); + builder.create().show(); + } protected void sendOtrMessage(final Message message) { ConversationActivity activity = (ConversationActivity) getActivity(); -- cgit v1.2.3