diff options
Diffstat (limited to 'src/eu/siacs/conversations/ui')
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationActivity.java | 103 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationFragment.java | 47 |
2 files changed, 78 insertions, 72 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 85025108..fbe2752a 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -320,7 +320,55 @@ public class ConversationActivity extends XmppActivity { } return true; } + + private void attachFileDialog() { + selectPresence(getSelectedConversation(), new OnPresenceSelected() { + + @Override + public void onPresenceSelected(boolean success, String presence) { + if (success) { + Intent attachFileIntent = new Intent(); + attachFileIntent.setType("image/*"); + attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); + Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file)); + startActivityForResult(chooser, ATTACH_FILE); + } + } + + @Override + public void onSendPlainTextInstead() { + + } + },"file"); + } + private void attachFile() { + if (getSelectedConversation().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 + + } + }); + } + } else if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_NONE) { + attachFileDialog(); + } + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -328,25 +376,7 @@ public class ConversationActivity extends XmppActivity { spl.openPane(); break; case R.id.action_attach_file: - selectPresence(getSelectedConversation(), new OnPresenceSelected() { - - @Override - public void onPresenceSelected(boolean success, String presence) { - if (success) { - Intent attachFileIntent = new Intent(); - attachFileIntent.setType("image/*"); - attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); - Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file)); - startActivityForResult(chooser, ATTACH_FILE); - } - } - - @Override - public void onSendPlainTextInstead() { - // TODO Auto-generated method stub - - } - },"file"); + attachFile(); break; case R.id.action_add: startActivity(new Intent(this, ContactsActivity.class)); @@ -391,19 +421,19 @@ public class ConversationActivity extends XmppActivity { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.encryption_choice_none: - selConv.nextMessageEncryption = Message.ENCRYPTION_NONE; + selConv.setNextEncryption(Message.ENCRYPTION_NONE); item.setChecked(true); break; case R.id.encryption_choice_otr: - selConv.nextMessageEncryption = Message.ENCRYPTION_OTR; + selConv.setNextEncryption(Message.ENCRYPTION_OTR); item.setChecked(true); break; case R.id.encryption_choice_pgp: - selConv.nextMessageEncryption = Message.ENCRYPTION_PGP; + selConv.setNextEncryption(Message.ENCRYPTION_PGP); item.setChecked(true); break; default: - selConv.nextMessageEncryption = Message.ENCRYPTION_NONE; + selConv.setNextEncryption(Message.ENCRYPTION_NONE); break; } fragment.updateChatMsgHint(); @@ -411,7 +441,7 @@ public class ConversationActivity extends XmppActivity { } }); popup.inflate(R.menu.encryption_choices); - switch (selConv.nextMessageEncryption) { + switch (selConv.getNextEncryption()) { case Message.ENCRYPTION_NONE: popup.getMenu().findItem(R.id.encryption_choice_none) .setChecked(true); @@ -591,21 +621,14 @@ public class ConversationActivity extends XmppActivity { } else if (requestCode == ATTACH_FILE) { final Conversation conversation = getSelectedConversation(); String presence = conversation.getNextPresence(); - if (conversation.nextMessageEncryption == Message.ENCRYPTION_NONE) { + if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) { xmppConnectionService.attachImageToConversation(conversation, presence, data.getData()); - } else if (conversation.nextMessageEncryption == Message.ENCRYPTION_PGP) { + } else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, data.getData(), new OnPgpEngineResult() { @Override public void userInputRequried(PendingIntent pi) { - Log.d(LOGTAG,"user input requried"); - try { - startIntentSenderForResult(pi.getIntentSender(), - ConversationActivity.REQUEST_SEND_PGP_IMAGE, null, 0, - 0, 0); - } catch (SendIntentException e1) { - Log.d("xmppService","failed to start intent to send message"); - } + ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_PGP_IMAGE); } @Override @@ -615,6 +638,7 @@ public class ConversationActivity extends XmppActivity { xmppConnectionService.databaseBackend.createMessage(pendingMessage); xmppConnectionService.sendMessage(pendingMessage, null); xmppConnectionService.updateUi(conversation, false); + pendingMessage = null; } @Override @@ -623,7 +647,7 @@ public class ConversationActivity extends XmppActivity { } }); } else { - Log.d(LOGTAG,"unknown next message encryption: "+conversation.nextMessageEncryption); + Log.d(LOGTAG,"unknown next message encryption: "+conversation.getNextEncryption()); } } } @@ -730,6 +754,15 @@ public class ConversationActivity extends XmppActivity { builder.create().show(); } + public void runIntent(PendingIntent pi, int requestCode) { + try { + this.startIntentSenderForResult(pi.getIntentSender(),requestCode, null, 0, + 0, 0); + } catch (SendIntentException e1) { + Log.d("xmppService","failed to start intent to send message"); + } + } + class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { private final WeakReference<ImageView> imageViewReference; diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index dab03552..af722edc 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -79,10 +79,10 @@ public class ConversationFragment extends Fragment { if (chatMsg.getText().length() < 1) return; Message message = new Message(conversation, chatMsg.getText() - .toString(), conversation.nextMessageEncryption); - if (conversation.nextMessageEncryption == Message.ENCRYPTION_OTR) { + .toString(), conversation.getNextEncryption()); + if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) { sendOtrMessage(message); - } else if (conversation.nextMessageEncryption == Message.ENCRYPTION_PGP) { + } else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { sendPgpMessage(message); } else { sendPlainTextMessage(message); @@ -129,7 +129,7 @@ public class ConversationFragment extends Fragment { if (conversation.getMode() == Conversation.MODE_MULTI) { chatMsg.setHint(getString(R.string.send_message_to_conference)); } else { - switch (conversation.nextMessageEncryption) { + switch (conversation.getNextEncryption()) { case Message.ENCRYPTION_NONE: chatMsg.setHint(getString(R.string.send_plain_text_message)); break; @@ -139,9 +139,6 @@ public class ConversationFragment extends Fragment { case Message.ENCRYPTION_PGP: chatMsg.setHint(getString(R.string.send_pgp_message)); break; - case Message.ENCRYPTION_DECRYPTED: - chatMsg.setHint(getString(R.string.send_pgp_message)); - break; default: break; } @@ -441,12 +438,6 @@ public class ConversationFragment extends Fragment { } } - if (queuedPqpMessage != null) { - this.conversation.nextMessageEncryption = Message.ENCRYPTION_PGP; - Message message = new Message(conversation, queuedPqpMessage, - Message.ENCRYPTION_PGP); - sendPgpMessage(message); - } if (conversation.getMode() == Conversation.MODE_MULTI) { activity.xmppConnectionService .setOnRenameListener(new OnRenameListener() { @@ -520,14 +511,8 @@ public class ConversationFragment extends Fragment { this.messageListAdapter.notifyDataSetChanged(); if (conversation.getMode() == Conversation.MODE_SINGLE) { if (messageList.size() >= 1) { - int latestEncryption = this.conversation.getLatestMessage() - .getEncryption(); - if ((latestEncryption == Message.ENCRYPTION_DECRYPTED)||(latestEncryption == Message.ENCRYPTION_DECRYPTION_FAILED)) { - conversation.nextMessageEncryption = Message.ENCRYPTION_PGP; - } else { - conversation.nextMessageEncryption = latestEncryption; - } - makeFingerprintWarning(latestEncryption); + conversation.setNextEncryption(conversation.getLatestEncryption()); + makeFingerprintWarning(conversation.getLatestEncryption()); } } else { if (conversation.getMucOptions().getError() != 0) { @@ -600,17 +585,11 @@ public class ConversationFragment extends Fragment { final Account account = message.getConversation().getAccount(); if (activity.hasPgp()) { if (contact.getPgpKeyId() != 0) { - xmppService.getPgpEngine().hasKey(account,contact.getPgpKeyId(), new OnPgpEngineResult() { + xmppService.getPgpEngine().hasKey(contact, new OnPgpEngineResult() { @Override public void userInputRequried(PendingIntent pi) { - try { - getActivity().startIntentSenderForResult(pi.getIntentSender(), - ConversationActivity.REQUEST_SEND_MESSAGE, null, 0, - 0, 0); - } catch (SendIntentException e1) { - Log.d("xmppService","failed to start intent to send message"); - } + activity.runIntent(pi, ConversationActivity.REQUEST_SEND_MESSAGE); } @Override @@ -619,13 +598,7 @@ public class ConversationFragment extends Fragment { @Override public void userInputRequried(PendingIntent pi) { - try { - activity.startIntentSenderForResult(pi.getIntentSender(), - ConversationActivity.REQUEST_SEND_MESSAGE, null, 0, - 0, 0); - } catch (SendIntentException e1) { - Log.d("xmppService","failed to start intent to send message"); - } + activity.runIntent(pi, ConversationActivity.REQUEST_SEND_MESSAGE); } @Override @@ -664,7 +637,7 @@ public class ConversationFragment extends Fragment { @Override public void onClick(DialogInterface dialog, int which) { - conversation.nextMessageEncryption = Message.ENCRYPTION_NONE; + conversation.setNextEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE); xmppService.sendMessage(message, null); chatMsg.setText(""); |