diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-03-03 16:39:19 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-03-03 16:39:19 +0100 |
commit | 69af009c88c4ffa0ea3275c4b875a13e0ecdcddc (patch) | |
tree | 962db20530e3485340915d761cd00f291a1120cc /src | |
parent | c609eefefac5097c7c40a9f1b8741e9634da316f (diff) |
avoid some null pointers when pgp api is not installed
Diffstat (limited to 'src')
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationFragment.java | 50 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ManageAccountActivity.java | 16 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/XmppActivity.java | 15 |
3 files changed, 48 insertions, 33 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index a19cb18c2..434a35563 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -439,34 +439,32 @@ public class ConversationFragment extends Fragment { ConversationActivity activity = (ConversationActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; Contact contact = message.getConversation().getContact(); - if (contact.getPgpKeyId() != 0) { - xmppService.sendMessage(message, null); - chatMsg.setText(""); - } 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 assoziated with this contact"); - builder.setNegativeButton("Cancel", null); - builder.setPositiveButton("Send plain text", - new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - conversation.nextMessageEncryption = Message.ENCRYPTION_NONE; - message.setEncryption(Message.ENCRYPTION_NONE); - xmppService.sendMessage(message, null); - chatMsg.setText(""); - } - }); - builder.create().show(); + if (activity.hasPgp()) { + if (contact.getPgpKeyId() != 0) { + xmppService.sendMessage(message, null); + chatMsg.setText(""); + } 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 assoziated with this contact"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Send plain text", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + conversation.nextMessageEncryption = Message.ENCRYPTION_NONE; + message.setEncryption(Message.ENCRYPTION_NONE); + xmppService.sendMessage(message, null); + chatMsg.setText(""); + } + }); + builder.create().show(); + } } } - - public void resendPgpMessage(String msg) { - this.queuedPqpMessage = msg; - } - + protected void sendOtrMessage(final Message message) { ConversationActivity activity = (ConversationActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 22b82e77f..5d9c4059a 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -237,14 +237,16 @@ public class ManageAccountActivity extends XmppActivity implements ActionMode.Ca builder.setNegativeButton("Cancel",null); builder.create().show(); } else if (item.getItemId()==R.id.announce_pgp) { - mode.finish(); - try { - xmppConnectionService.generatePgpAnnouncement(selectedAccountForActionMode); - } catch (PgpEngine.UserInputRequiredException e) { + if (this.hasPgp()) { + mode.finish(); try { - startIntentSenderForResult(e.getPendingIntent().getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); - } catch (SendIntentException e1) { - Log.d("gultsch","sending intent failed"); + xmppConnectionService.generatePgpAnnouncement(selectedAccountForActionMode); + } catch (PgpEngine.UserInputRequiredException e) { + try { + startIntentSenderForResult(e.getPendingIntent().getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); + } catch (SendIntentException e1) { + Log.d("gultsch","sending intent failed"); + } } } } diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 569563c1a..6b1d12891 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -3,6 +3,8 @@ package eu.siacs.conversations.ui; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -63,5 +65,18 @@ public abstract class XmppActivity extends Activity { } } + public boolean hasPgp() { + if (xmppConnectionService.getPgpEngine()!=null) { + return true; + } else { + Builder builder = new AlertDialog.Builder(getApplicationContext()); + builder.setTitle("OpenKeychain not found"); + builder.setIconAttribute(android.R.attr.alertDialogIcon); + builder.setMessage("Please make sure you have installed OpenKeychain"); + builder.create().show(); + return false; + } + } + abstract void onBackendConnected(); } |