avoid some null pointers when pgp api is not installed

This commit is contained in:
Daniel Gultsch 2014-03-03 16:39:19 +01:00
parent c609eefefa
commit 69af009c88
3 changed files with 48 additions and 33 deletions

View File

@ -439,6 +439,7 @@ public class ConversationFragment extends Fragment {
ConversationActivity activity = (ConversationActivity) getActivity(); ConversationActivity activity = (ConversationActivity) getActivity();
final XmppConnectionService xmppService = activity.xmppConnectionService; final XmppConnectionService xmppService = activity.xmppConnectionService;
Contact contact = message.getConversation().getContact(); Contact contact = message.getConversation().getContact();
if (activity.hasPgp()) {
if (contact.getPgpKeyId() != 0) { if (contact.getPgpKeyId() != 0) {
xmppService.sendMessage(message, null); xmppService.sendMessage(message, null);
chatMsg.setText(""); chatMsg.setText("");
@ -462,9 +463,6 @@ public class ConversationFragment extends Fragment {
builder.create().show(); builder.create().show();
} }
} }
public void resendPgpMessage(String msg) {
this.queuedPqpMessage = msg;
} }
protected void sendOtrMessage(final Message message) { protected void sendOtrMessage(final Message message) {

View File

@ -237,6 +237,7 @@ public class ManageAccountActivity extends XmppActivity implements ActionMode.Ca
builder.setNegativeButton("Cancel",null); builder.setNegativeButton("Cancel",null);
builder.create().show(); builder.create().show();
} else if (item.getItemId()==R.id.announce_pgp) { } else if (item.getItemId()==R.id.announce_pgp) {
if (this.hasPgp()) {
mode.finish(); mode.finish();
try { try {
xmppConnectionService.generatePgpAnnouncement(selectedAccountForActionMode); xmppConnectionService.generatePgpAnnouncement(selectedAccountForActionMode);
@ -248,6 +249,7 @@ public class ManageAccountActivity extends XmppActivity implements ActionMode.Ca
} }
} }
} }
}
return true; return true;
} }

View File

@ -3,6 +3,8 @@ package eu.siacs.conversations.ui;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; 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(); abstract void onBackendConnected();
} }