From 7fa61564b83b4a9e3403974b291750286a32d451 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 8 May 2014 16:52:19 +0200 Subject: better flow after returning from openkeychain for various actions --- .../conversations/ui/ConversationActivity.java | 66 +++++++++++++--------- .../conversations/ui/ManageAccountActivity.java | 6 +- src/eu/siacs/conversations/ui/XmppActivity.java | 6 +- 3 files changed, 47 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 99af97e2..a6d1be4e 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -16,6 +16,7 @@ import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.UIHelper; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; @@ -63,8 +64,9 @@ public class ConversationActivity extends XmppActivity { public static final int REQUEST_SEND_MESSAGE = 0x75441; public static final int REQUEST_DECRYPT_PGP = 0x76783; - private static final int ATTACH_FILE = 0x48502; + private static final int REQUEST_ATTACH_FILE_DIALOG = 0x48502; private static final int REQUEST_SEND_PGP_IMAGE = 0x53883; + private static final int REQUEST_ATTACH_FILE = 0x73824; protected SlidingPaneLayout spl; @@ -329,7 +331,7 @@ public class ConversationActivity extends XmppActivity { attachFileIntent.setType("image/*"); attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file)); - startActivityForResult(chooser, ATTACH_FILE); + startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG); } } @@ -349,7 +351,7 @@ public class ConversationActivity extends XmppActivity { @Override public void userInputRequried(PendingIntent pi) { - ConversationActivity.this.runIntent(pi, REQUEST_SEND_PGP_IMAGE); + ConversationActivity.this.runIntent(pi, REQUEST_ATTACH_FILE); } @Override @@ -448,7 +450,7 @@ public class ConversationActivity extends XmppActivity { conversation.setNextEncryption(Message.ENCRYPTION_PGP); item.setChecked(true); } else { - announcePgp(conversation.getAccount()); + announcePgp(conversation.getAccount(),conversation); } } break; @@ -634,40 +636,50 @@ public class ConversationActivity extends XmppActivity { if (selectedFragment != null) { selectedFragment.hidePgpPassphraseBox(); } - } else if (requestCode == ATTACH_FILE) { + } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { final Conversation conversation = getSelectedConversation(); String presence = conversation.getNextPresence(); if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) { xmppConnectionService.attachImageToConversation(conversation, presence, data.getData()); } else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { - pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, data.getData(), new OnPgpEngineResult() { - - @Override - public void userInputRequried(PendingIntent pi) { - ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_PGP_IMAGE); - } - - @Override - public void success() { - conversation.getMessages().add(pendingMessage); - pendingMessage.setStatus(Message.STATUS_OFFERED); - xmppConnectionService.databaseBackend.createMessage(pendingMessage); - xmppConnectionService.sendMessage(pendingMessage, null); - xmppConnectionService.updateUi(conversation, false); - pendingMessage = null; - } - - @Override - public void error(OpenPgpError openPgpError) { - Log.d(LOGTAG,"pgp error"+openPgpError.getMessage()); - } - }); + attachPgpFile(conversation,data.getData()); } else { Log.d(LOGTAG,"unknown next message encryption: "+conversation.getNextEncryption()); } + } else if (requestCode == REQUEST_SEND_PGP_IMAGE) { + + } else if (requestCode == REQUEST_ATTACH_FILE) { + attachFile(); + } else if (requestCode == REQUEST_ANNOUNCE_PGP) { + announcePgp(getSelectedConversation().getAccount(),getSelectedConversation()); } } } + + private void attachPgpFile(Conversation conversation, Uri uri) { + String presence = conversation.getNextPresence(); + pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, uri, new OnPgpEngineResult() { + + @Override + public void userInputRequried(PendingIntent pi) { + ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_PGP_IMAGE); + } + + @Override + public void success() { + pendingMessage.getConversation().getMessages().add(pendingMessage); + xmppConnectionService.databaseBackend.createMessage(pendingMessage); + xmppConnectionService.sendMessage(pendingMessage, null); + xmppConnectionService.updateUi(pendingMessage.getConversation(), false); + pendingMessage = null; + } + + @Override + public void error(OpenPgpError openPgpError) { + Log.d(LOGTAG,"pgp error"+openPgpError.getMessage()); + } + }); + } public void updateConversationList() { conversationList.clear(); diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 8f4d9b9f..8fefa272 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -279,7 +279,7 @@ public class ManageAccountActivity extends XmppActivity { } else if (item.getItemId()==R.id.mgmt_account_announce_pgp) { if (activity.hasPgp()) { mode.finish(); - announcePgp(selectedAccountForActionMode); + announcePgp(selectedAccountForActionMode,null); } } else if (item.getItemId() == R.id.mgmt_otr_key) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); @@ -458,8 +458,8 @@ public class ManageAccountActivity extends XmppActivity { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == REQUEST_ANNOUNCE_PGP) { - announcePgp(selectedAccountForActionMode); - } + announcePgp(selectedAccountForActionMode,null); + } } } } diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 70b2e24e..55dcecc9 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -6,6 +6,7 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.OnPgpEngineResult; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.utils.ExceptionHelper; @@ -162,7 +163,7 @@ public abstract class XmppActivity extends Activity { startActivity(viewConversationIntent); } - protected void announcePgp(final Account account) { + protected void announcePgp(final Account account, final Conversation conversation) { xmppConnectionService.getPgpEngine().generateSignature(account, "online", new OnPgpEngineResult() { @Override @@ -178,6 +179,9 @@ public abstract class XmppActivity extends Activity { public void success() { xmppConnectionService.databaseBackend.updateAccount(account); xmppConnectionService.sendPgpPresence(account, account.getPgpSignature()); + if (conversation!=null) { + conversation.setNextEncryption(Message.ENCRYPTION_PGP); + } } @Override -- cgit v1.2.3 From c555a9d03c25407be43b114d74edd6f2c1587300 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 8 May 2014 17:31:53 +0200 Subject: sending text message after returing from pending intent --- src/eu/siacs/conversations/crypto/PgpEngine.java | 97 ++++++++++------------ .../conversations/ui/ConversationActivity.java | 38 +++++++++ .../conversations/ui/ConversationFragment.java | 35 ++------ 3 files changed, 90 insertions(+), 80 deletions(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 5a51a1e8..0e0b33d1 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -114,59 +114,18 @@ public class PgpEngine { } } - public void encrypt(Account account, final Message message, - final OnPgpEngineResult callback) { + public void encrypt(final Message message,final OnPgpEngineResult callback) { long[] keys = { message.getConversation().getContact().getPgpKeyId() }; Intent params = new Intent(); params.setAction(OpenPgpApi.ACTION_ENCRYPT); params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys); - params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); - params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, account.getJid()); - - InputStream is = new ByteArrayInputStream(message.getBody().getBytes()); - final OutputStream os = new ByteArrayOutputStream(); - api.executeApiAsync(params, is, os, new IOpenPgpCallback() { - - @Override - public void onReturn(Intent result) { - switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, - OpenPgpApi.RESULT_CODE_ERROR)) { - case OpenPgpApi.RESULT_CODE_SUCCESS: - StringBuilder encryptedMessageBody = new StringBuilder(); - String[] lines = os.toString().split("\n"); - for (int i = 3; i < lines.length - 1; ++i) { - encryptedMessageBody.append(lines[i].trim()); - } - message.setEncryptedBody(encryptedMessageBody.toString()); - callback.success(); - break; - case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: - callback.userInputRequried((PendingIntent) result - .getParcelableExtra(OpenPgpApi.RESULT_INTENT)); - break; - case OpenPgpApi.RESULT_CODE_ERROR: - callback.error((OpenPgpError) result - .getParcelableExtra(OpenPgpApi.RESULT_ERROR)); - break; - } - } - }); + params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid()); - } + if (message.getType() == Message.TYPE_TEXT) { + params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); - public void encrypt(final Message message, final OnPgpEngineResult callback) { - try { - Log.d("xmppService","calling to encrypt file"); - JingleFile inputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, true); - JingleFile outputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, false); - outputFile.createNewFile(); - long[] keys = { message.getConversation().getContact().getPgpKeyId() }; - Intent params = new Intent(); - params.setAction(OpenPgpApi.ACTION_ENCRYPT); - params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys); - params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid()); - InputStream is = new FileInputStream(inputFile); - OutputStream os = new FileOutputStream(outputFile); + InputStream is = new ByteArrayInputStream(message.getBody().getBytes()); + final OutputStream os = new ByteArrayOutputStream(); api.executeApiAsync(params, is, os, new IOpenPgpCallback() { @Override @@ -174,6 +133,12 @@ public class PgpEngine { switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { case OpenPgpApi.RESULT_CODE_SUCCESS: + StringBuilder encryptedMessageBody = new StringBuilder(); + String[] lines = os.toString().split("\n"); + for (int i = 3; i < lines.length - 1; ++i) { + encryptedMessageBody.append(lines[i].trim()); + } + message.setEncryptedBody(encryptedMessageBody.toString()); callback.success(); break; case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: @@ -187,13 +152,41 @@ public class PgpEngine { } } }); - } catch (FileNotFoundException e) { - Log.d("xmppService","file not found: "+e.getMessage()); - } catch (IOException e) { - Log.d("xmppService","io exception during file encrypt"); + } else if (message.getType() == Message.TYPE_IMAGE) { + try { + JingleFile inputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, true); + JingleFile outputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, false); + outputFile.createNewFile(); + InputStream is = new FileInputStream(inputFile); + OutputStream os = new FileOutputStream(outputFile); + api.executeApiAsync(params, is, os, new IOpenPgpCallback() { + + @Override + public void onReturn(Intent result) { + switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, + OpenPgpApi.RESULT_CODE_ERROR)) { + case OpenPgpApi.RESULT_CODE_SUCCESS: + callback.success(); + break; + case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: + callback.userInputRequried((PendingIntent) result + .getParcelableExtra(OpenPgpApi.RESULT_INTENT)); + break; + case OpenPgpApi.RESULT_CODE_ERROR: + callback.error((OpenPgpError) result + .getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + break; + } + } + }); + } catch (FileNotFoundException e) { + Log.d("xmppService","file not found: "+e.getMessage()); + } catch (IOException e) { + Log.d("xmppService","io exception during file encrypt"); + } } } - + public long fetchKeyId(Account account, String status, String signature) { if ((signature == null) || (api == null)) { return 0; diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index a6d1be4e..646eb3c0 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.ui; import java.io.FileNotFoundException; import java.lang.ref.WeakReference; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -67,6 +68,7 @@ public class ConversationActivity extends XmppActivity { private static final int REQUEST_ATTACH_FILE_DIALOG = 0x48502; private static final int REQUEST_SEND_PGP_IMAGE = 0x53883; private static final int REQUEST_ATTACH_FILE = 0x73824; + public static final int REQUEST_ENCRYPT_MESSAGE = 0x378018; protected SlidingPaneLayout spl; @@ -652,6 +654,10 @@ public class ConversationActivity extends XmppActivity { attachFile(); } else if (requestCode == REQUEST_ANNOUNCE_PGP) { announcePgp(getSelectedConversation().getAccount(),getSelectedConversation()); + } else if (requestCode == REQUEST_ENCRYPT_MESSAGE) { + encryptTextMessage(); + } else { + Log.d(LOGTAG,"unknown result code:"+requestCode); } } } @@ -884,4 +890,36 @@ public class ConversationActivity extends XmppActivity { return bitmapWorkerTaskReference.get(); } } + + public void encryptTextMessage() { + xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage, new OnPgpEngineResult() { + + @Override + public void userInputRequried( + PendingIntent pi) { + activity.runIntent( + pi, + ConversationActivity.REQUEST_SEND_MESSAGE); + } + + @Override + public void success() { + xmppConnectionService.sendMessage(pendingMessage, null); + pendingMessage = null; + ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (selectedFragment != null) { + selectedFragment.clearInputField(); + } + } + + @Override + public void error( + OpenPgpError openPgpError) { + // TODO Auto-generated method + // stub + + } + }); + } } diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index e370deb0..e06c9eeb 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -664,10 +664,10 @@ public class ConversationFragment extends Fragment { } protected void sendPgpMessage(final Message message) { + activity.pendingMessage = message; final ConversationActivity activity = (ConversationActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; final Contact contact = message.getConversation().getContact(); - final Account account = message.getConversation().getAccount(); if (activity.hasPgp()) { if (contact.getPgpKeyId() != 0) { xmppService.getPgpEngine().hasKey(contact, @@ -677,37 +677,12 @@ public class ConversationFragment extends Fragment { public void userInputRequried(PendingIntent pi) { activity.runIntent( pi, - ConversationActivity.REQUEST_SEND_MESSAGE); + ConversationActivity.REQUEST_ENCRYPT_MESSAGE); } @Override public void success() { - xmppService.getPgpEngine().encrypt(account, - message, new OnPgpEngineResult() { - - @Override - public void userInputRequried( - PendingIntent pi) { - activity.runIntent( - pi, - ConversationActivity.REQUEST_SEND_MESSAGE); - } - - @Override - public void success() { - xmppService.sendMessage( - message, null); - chatMsg.setText(""); - } - - @Override - public void error( - OpenPgpError openPgpError) { - // TODO Auto-generated method - // stub - - } - }); + activity.encryptTextMessage(); } @Override @@ -809,4 +784,8 @@ public class ConversationFragment extends Fragment { public void setText(String text) { this.pastedText = text; } + + public void clearInputField() { + this.chatMsg.setText(""); + } } -- cgit v1.2.3 From 8a2da100d5fd673e2f5160920f15ac2fffaa8e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 8 May 2014 19:03:32 +0200 Subject: Improve OTR fingerprint dialog and fix german sentence --- src/eu/siacs/conversations/ui/ManageAccountActivity.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 8fefa272..0a1cb5cd 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -288,7 +288,10 @@ public class ManageAccountActivity extends XmppActivity { View view = (View) getLayoutInflater().inflate(R.layout.otr_fingerprint, null); if (fingerprintTxt!=null) { TextView fingerprint = (TextView) view.findViewById(R.id.otr_fingerprint); + TextView noFingerprintView = (TextView) view.findViewById(R.id.otr_no_fingerprint); fingerprint.setText(fingerprintTxt); + fingerprint.setVisibility(View.VISIBLE); + noFingerprintView.setVisibility(View.GONE); } builder.setView(view); builder.setPositiveButton("Done", null); -- cgit v1.2.3 From a14a28973ada020234c60680a51cdff2f9129de9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 9 May 2014 20:46:43 +0200 Subject: nicer descriptions in notificaton for images and encrypted messages --- src/eu/siacs/conversations/entities/Message.java | 16 ++++++++++++++++ src/eu/siacs/conversations/ui/ConversationActivity.java | 11 ++++++++++- src/eu/siacs/conversations/ui/ConversationFragment.java | 4 +++- src/eu/siacs/conversations/utils/UIHelper.java | 8 ++++---- 4 files changed, 33 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java index a17d552f..33f7a8d4 100644 --- a/src/eu/siacs/conversations/entities/Message.java +++ b/src/eu/siacs/conversations/entities/Message.java @@ -1,7 +1,9 @@ package eu.siacs.conversations.entities; +import eu.siacs.conversations.R; import eu.siacs.conversations.xmpp.jingle.JingleConnection; import android.content.ContentValues; +import android.content.Context; import android.database.Cursor; public class Message extends AbstractEntity { @@ -103,6 +105,20 @@ public class Message extends AbstractEntity { public String getBody() { return body; } + + public String getReadableBody(Context context) { + if ((encryption == ENCRYPTION_PGP)&&(type == TYPE_TEXT)) { + return ""+context.getText(R.string.encrypted_message_received); + } else if ((encryption == ENCRYPTION_OTR)&&(type == TYPE_IMAGE)) { + return ""+context.getText(R.string.encrypted_image_received); + } else if (encryption == ENCRYPTION_DECRYPTION_FAILED) { + return ""+context.getText(R.string.decryption_failed); + } else if (type == TYPE_IMAGE) { + return ""+context.getText(R.string.image_file); + } else { + return body.trim(); + } + } public long getTimeSent() { return timeSent; diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 646eb3c0..d3e3737f 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -55,6 +55,7 @@ import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.TextView; import android.widget.ImageView; +import android.widget.Toast; public class ConversationActivity extends XmppActivity { @@ -112,6 +113,7 @@ public class ConversationActivity extends XmppActivity { protected ConversationActivity activity = this; private DisplayMetrics metrics; + private Toast prepareImageToast; public List getConversationList() { return this.conversationList; @@ -178,7 +180,11 @@ public class ConversationActivity extends XmppActivity { Message latestMessage = conv.getLatestMessage(); if (latestMessage.getType() == Message.TYPE_TEXT) { - convLastMsg.setText(conv.getLatestMessage().getBody()); + if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)&&(latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) { + convLastMsg.setText(conv.getLatestMessage().getBody()); + } else { + convLastMsg.setText(getText(R.string.encrypted_message_received)); + } convLastMsg.setVisibility(View.VISIBLE); imagePreview.setVisibility(View.GONE); } else if (latestMessage.getType() == Message.TYPE_IMAGE) { @@ -639,11 +645,14 @@ public class ConversationActivity extends XmppActivity { selectedFragment.hidePgpPassphraseBox(); } } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { + prepareImageToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); final Conversation conversation = getSelectedConversation(); String presence = conversation.getNextPresence(); if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) { + prepareImageToast.show(); xmppConnectionService.attachImageToConversation(conversation, presence, data.getData()); } else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { + prepareImageToast.show(); attachPgpFile(conversation,data.getData()); } else { Log.d(LOGTAG,"unknown next message encryption: "+conversation.getNextEncryption()); diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index e06c9eeb..6850ac54 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -492,7 +492,9 @@ public class ConversationFragment extends Fragment { @Override public void onStop() { super.onStop(); - this.conversation.setNextMessage(chatMsg.getText().toString()); + if (this.conversation!=null) { + this.conversation.setNextMessage(chatMsg.getText().toString()); + } } public void onBackendConnected() { diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index 1c52ff0b..8baa3c25 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -389,7 +389,7 @@ public class UIHelper { context, true)); mBuilder.setContentTitle(conversation.getName(useSubject)); if (notify) { - mBuilder.setTicker(conversation.getLatestMessage().getBody().trim()); + mBuilder.setTicker(conversation.getLatestMessage().getReadableBody(context)); } StringBuilder bigText = new StringBuilder(); List messages = conversation.getMessages(); @@ -397,10 +397,10 @@ public class UIHelper { for (int i = messages.size() - 1; i >= 0; --i) { if (!messages.get(i).isRead()) { if (i == messages.size() - 1) { - firstLine = messages.get(i).getBody().trim(); + firstLine = messages.get(i).getReadableBody(context); bigText.append(firstLine); } else { - firstLine = messages.get(i).getBody().trim(); + firstLine = messages.get(i).getReadableBody(context); bigText.insert(0, firstLine + "\n"); } } else { @@ -422,7 +422,7 @@ public class UIHelper { names.append(unread.get(i).getName(useSubject)); } style.addLine(Html.fromHtml("" + unread.get(i).getName(useSubject) - + " " + unread.get(i).getLatestMessage().getBody().trim())); + + " " + unread.get(i).getLatestMessage().getReadableBody(context))); } mBuilder.setContentTitle(unread.size() + " unread Conversations"); mBuilder.setContentText(names.toString()); -- cgit v1.2.3 From 3b8446e6d519d09d6e116faf661470d2e95abfb3 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 9 May 2014 20:47:03 +0200 Subject: link to openkeychain from contact details --- src/eu/siacs/conversations/crypto/PgpEngine.java | 13 +++++++--- .../conversations/ui/ContactDetailsActivity.java | 29 +++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 0e0b33d1..229b4300 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -274,9 +274,7 @@ public class PgpEngine { params.setAction(OpenPgpApi.ACTION_GET_KEY); params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId()); params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, contact.getAccount().getJid()); - InputStream is = new ByteArrayInputStream(new byte[0]); - OutputStream os = new ByteArrayOutputStream(); - api.executeApiAsync(params, is, os, new IOpenPgpCallback() { + api.executeApiAsync(params, null, null, new IOpenPgpCallback() { @Override public void onReturn(Intent result) { @@ -296,4 +294,13 @@ public class PgpEngine { } }); } + + public PendingIntent getIntentForKey(Contact contact) { + Intent params = new Intent(); + params.setAction(OpenPgpApi.ACTION_GET_KEY); + params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId()); + params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, contact.getAccount().getJid()); + Intent result = api.executeApi(params, null, null); + return (PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT); + } } diff --git a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java index 1ed3fa13..eaa9b8ee 100644 --- a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -4,10 +4,14 @@ import java.math.BigInteger; import java.util.Iterator; import java.util.Locale; +import org.openintents.openpgp.util.OpenPgpUtils; + import android.app.AlertDialog; +import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.IntentSender.SendIntentException; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract.CommonDataKinds; @@ -26,6 +30,7 @@ import android.widget.QuickContactBadge; import android.widget.TextView; import android.widget.Toast; import eu.siacs.conversations.R; +import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Presences; import eu.siacs.conversations.utils.UIHelper; @@ -252,17 +257,29 @@ public class ContactDetailsActivity extends XmppActivity { key.setText(otrFingerprint); keys.addView(view); } - Log.d("gultsch", "pgp key id " + contact.getPgpKeyId()); if (contact.getPgpKeyId() != 0) { View view = (View) inflater.inflate(R.layout.contact_key, null); TextView key = (TextView) view.findViewById(R.id.key); TextView keyType = (TextView) view.findViewById(R.id.key_type); keyType.setText("PGP Key ID"); - BigInteger bi = new BigInteger("" + contact.getPgpKeyId()); - StringBuilder builder = new StringBuilder(bi.toString(16) - .toUpperCase(Locale.US)); - builder.insert(8, " "); - key.setText(builder.toString()); + key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId())); + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + PgpEngine pgp = activity.xmppConnectionService.getPgpEngine(); + if (pgp!=null) { + PendingIntent intent = pgp.getIntentForKey(contact); + if (intent!=null) { + try { + startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0); + } catch (SendIntentException e) { + + } + } + } + } + }); keys.addView(view); } } -- cgit v1.2.3 From ef0bc6714a71555b05ca3dea10c274a40605810c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 9 May 2014 21:20:34 +0200 Subject: added dialog for otr file transfer --- .../conversations/ui/ConversationActivity.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index d3e3737f..234730fc 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -2,7 +2,6 @@ package eu.siacs.conversations.ui; import java.io.FileNotFoundException; import java.lang.ref.WeakReference; -import java.math.BigInteger; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -390,6 +389,31 @@ public class ConversationActivity extends XmppActivity { } } else if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_NONE) { attachFileDialog(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.otr_file_transfer)); + builder.setMessage(getString(R.string.otr_file_transfer_msg)); + builder.setNegativeButton(getString(R.string.cancel), null); + if (conversation.getContact().getPgpKeyId()==0) { + builder.setPositiveButton(getString(R.string.send_unencrypted), new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + conversation.setNextEncryption(Message.ENCRYPTION_NONE); + attachFile(); + } + }); + } else { + builder.setPositiveButton(getString(R.string.use_pgp_encryption), new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + conversation.setNextEncryption(Message.ENCRYPTION_PGP); + attachFile(); + } + }); + } + builder.create().show(); } } -- cgit v1.2.3 From 8632954e61c11bfa32cc192f0dcd4d3b2a72c7f0 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 10 May 2014 11:03:32 +0200 Subject: fixed possible npe and possible exception --- src/eu/siacs/conversations/ui/ConversationFragment.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 6850ac54..06bbc3a5 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -198,8 +198,12 @@ public class ConversationFragment extends Fragment { boolean error = false; if (message.getType() == Message.TYPE_IMAGE) { String[] fileParams = message.getBody().split(","); - long size = Long.parseLong(fileParams[0]); - filesize = size / 1024 + " KB"; + try { + long size = Long.parseLong(fileParams[0]); + filesize = size / 1024 + " KB"; + } catch (NumberFormatException e) { + filesize = "0 KB"; + } } switch (message.getStatus()) { case Message.STATUS_UNSEND: @@ -585,6 +589,9 @@ public class ConversationFragment extends Fragment { } public void updateMessages() { + if (getView()==null) { + return; + } ConversationActivity activity = (ConversationActivity) getActivity(); if (this.conversation != null) { for (Message message : this.conversation.getMessages()) { -- cgit v1.2.3 From 3455d10a4a87916bfe5da52ca9c401dafa8d5155 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 12 May 2014 14:59:46 +0200 Subject: Better error handling if attach file doesnt work (on permission denied) and unified encrypted and unencrypted file attachment --- .../conversations/crypto/OnPgpEngineResult.java | 11 ----- src/eu/siacs/conversations/crypto/PgpEngine.java | 33 ++++++------- .../conversations/persistance/FileBackend.java | 12 ++--- .../services/XmppConnectionService.java | 48 ++++++++----------- .../conversations/ui/ConversationActivity.java | 54 ++++++++++++++-------- .../conversations/ui/ConversationFragment.java | 15 ++---- .../conversations/ui/ManageAccountActivity.java | 1 - src/eu/siacs/conversations/ui/UiCallback.java | 9 ++++ src/eu/siacs/conversations/ui/XmppActivity.java | 26 ++++++++--- 9 files changed, 107 insertions(+), 102 deletions(-) delete mode 100644 src/eu/siacs/conversations/crypto/OnPgpEngineResult.java create mode 100644 src/eu/siacs/conversations/ui/UiCallback.java (limited to 'src') diff --git a/src/eu/siacs/conversations/crypto/OnPgpEngineResult.java b/src/eu/siacs/conversations/crypto/OnPgpEngineResult.java deleted file mode 100644 index 8e115839..00000000 --- a/src/eu/siacs/conversations/crypto/OnPgpEngineResult.java +++ /dev/null @@ -1,11 +0,0 @@ -package eu.siacs.conversations.crypto; - -import org.openintents.openpgp.OpenPgpError; - -import android.app.PendingIntent; - -public interface OnPgpEngineResult { - public void success(); - public void error(OpenPgpError openPgpError); - public void userInputRequried(PendingIntent pi); -} diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 229b4300..48750e24 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -14,12 +14,13 @@ import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback; +import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.ui.UiCallback; import eu.siacs.conversations.xmpp.jingle.JingleFile; - import android.app.PendingIntent; import android.content.Intent; import android.graphics.BitmapFactory; @@ -34,7 +35,7 @@ public class PgpEngine { this.mXmppConnectionService = service; } - public void decrypt(final Message message, final OnPgpEngineResult callback) { + public void decrypt(final Message message, final UiCallback callback) { Log.d("xmppService","decrypting message "+message.getUuid()); Intent params = new Intent(); params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); @@ -59,8 +60,7 @@ public class PgpEngine { .getParcelableExtra(OpenPgpApi.RESULT_INTENT)); return; case OpenPgpApi.RESULT_CODE_ERROR: - callback.error((OpenPgpError) result - .getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + callback.error(R.string.openpgp_error); return; default: return; @@ -97,8 +97,7 @@ public class PgpEngine { .getParcelableExtra(OpenPgpApi.RESULT_INTENT)); return; case OpenPgpApi.RESULT_CODE_ERROR: - callback.error((OpenPgpError) result - .getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + callback.error(R.string.openpgp_error); return; default: return; @@ -106,15 +105,15 @@ public class PgpEngine { } }); } catch (FileNotFoundException e) { - callback.error(new OpenPgpError(0, "file not found: "+e.getMessage())); + callback.error(R.string.error_decrypting_file); } catch (IOException e) { - callback.error(new OpenPgpError(0, "io exception: "+e.getMessage())); + callback.error(R.string.error_decrypting_file); } } } - public void encrypt(final Message message,final OnPgpEngineResult callback) { + public void encrypt(final Message message,final UiCallback callback) { long[] keys = { message.getConversation().getContact().getPgpKeyId() }; Intent params = new Intent(); params.setAction(OpenPgpApi.ACTION_ENCRYPT); @@ -146,8 +145,7 @@ public class PgpEngine { .getParcelableExtra(OpenPgpApi.RESULT_INTENT)); break; case OpenPgpApi.RESULT_CODE_ERROR: - callback.error((OpenPgpError) result - .getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + callback.error(R.string.openpgp_error); break; } } @@ -173,8 +171,7 @@ public class PgpEngine { .getParcelableExtra(OpenPgpApi.RESULT_INTENT)); break; case OpenPgpApi.RESULT_CODE_ERROR: - callback.error((OpenPgpError) result - .getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + callback.error(R.string.openpgp_error); break; } } @@ -235,7 +232,7 @@ public class PgpEngine { } public void generateSignature(final Account account, String status, - final OnPgpEngineResult callback) { + final UiCallback callback) { Intent params = new Intent(); params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); params.setAction(OpenPgpApi.ACTION_SIGN); @@ -261,15 +258,14 @@ public class PgpEngine { .getParcelableExtra(OpenPgpApi.RESULT_INTENT)); return; case OpenPgpApi.RESULT_CODE_ERROR: - callback.error((OpenPgpError) result - .getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + callback.error(R.string.openpgp_error); return; } } }); } - public void hasKey(Contact contact, final OnPgpEngineResult callback) { + public void hasKey(Contact contact, final UiCallback callback) { Intent params = new Intent(); params.setAction(OpenPgpApi.ACTION_GET_KEY); params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId()); @@ -287,8 +283,7 @@ public class PgpEngine { .getParcelableExtra(OpenPgpApi.RESULT_INTENT)); return; case OpenPgpApi.RESULT_CODE_ERROR: - callback.error((OpenPgpError) result - .getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + callback.error(R.string.openpgp_error); return; } } diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 868e2398..becb1ee3 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -102,7 +102,7 @@ public class FileBackend { boolean success = scalledBitmap.compress( Bitmap.CompressFormat.WEBP, 75, os); if (!success) { - // Log.d("xmppService", "couldnt compress"); + return null; } os.flush(); os.close(); @@ -112,14 +112,12 @@ public class FileBackend { message.setBody(""+size+","+width+","+height); return file; } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + return null; } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + return null; + } catch (SecurityException e) { + return null; } - - return null; } public Bitmap getImageFromMessage(Message message) { diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 3581d189..d2742997 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -17,8 +17,7 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection; import net.java.otr4j.OtrException; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionStatus; - -import eu.siacs.conversations.crypto.OnPgpEngineResult; +import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; @@ -33,6 +32,7 @@ import eu.siacs.conversations.persistance.OnPhoneContactsMerged; import eu.siacs.conversations.ui.OnAccountListChangedListener; import eu.siacs.conversations.ui.OnConversationListChangedListener; import eu.siacs.conversations.ui.OnRosterFetchedListener; +import eu.siacs.conversations.ui.UiCallback; import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.MessageParser; import eu.siacs.conversations.utils.OnPhoneContactsLoadedListener; @@ -446,45 +446,35 @@ public class XmppConnectionService extends Service { return this.fileBackend; } - public Message attachImageToConversation(final Conversation conversation, - final String presence, final Uri uri) { - final Message message = new Message(conversation, "",Message.ENCRYPTION_NONE); - message.setPresence(presence); + public Message attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback callback) { + final Message message; + if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { + message = new Message(conversation, "",Message.ENCRYPTION_DECRYPTED); + } else { + message = new Message(conversation, "", Message.ENCRYPTION_NONE); + } + message.setPresence(conversation.getNextPresence()); message.setType(Message.TYPE_IMAGE); message.setStatus(Message.STATUS_OFFERED); new Thread(new Runnable() { @Override public void run() { - getFileBackend().copyImageToPrivateStorage(message, uri); - databaseBackend.createMessage(message); - conversation.getMessages().add(message); - if (convChangedListener != null) { - convChangedListener.onConversationListChanged(); + JingleFile file = getFileBackend().copyImageToPrivateStorage(message, uri); + if (file==null) { + callback.error(R.string.error_copying_image_file); + } else { + if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { + getPgpEngine().encrypt(message, callback); + } else { + callback.success(); + } } - sendMessage(message, null); } }).start(); return message; } - public Message attachEncryptedImageToConversation(final Conversation conversation, final String presence, final Uri uri, final OnPgpEngineResult callback) { - Log.d(LOGTAG,"attach encrypted image"); - final Message message = new Message(conversation, "",Message.ENCRYPTION_DECRYPTED); - message.setPresence(presence); - message.setType(Message.TYPE_IMAGE); - message.setStatus(Message.STATUS_OFFERED); - new Thread(new Runnable() { - - @Override - public void run() { - getFileBackend().copyImageToPrivateStorage(message, uri); - getPgpEngine().encrypt(message, callback); - } - }).start(); - return message; - } - protected Conversation findMuc(String name, Account account) { for (Conversation conversation : this.conversations) { if (conversation.getContactJid().split("/")[0].equals(name) diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 234730fc..88728245 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -9,7 +9,6 @@ import java.util.List; import org.openintents.openpgp.OpenPgpError; import eu.siacs.conversations.R; -import eu.siacs.conversations.crypto.OnPgpEngineResult; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; @@ -354,7 +353,7 @@ public class ConversationActivity extends XmppActivity { if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { if (hasPgp()) { if (conversation.getContact().getPgpKeyId()!=0) { - xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new OnPgpEngineResult() { + xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new UiCallback() { @Override public void userInputRequried(PendingIntent pi) { @@ -367,7 +366,7 @@ public class ConversationActivity extends XmppActivity { } @Override - public void error(OpenPgpError openPgpError) { + public void error(int error) { // TODO Auto-generated method stub } @@ -671,10 +670,26 @@ public class ConversationActivity extends XmppActivity { } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { prepareImageToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); final Conversation conversation = getSelectedConversation(); - String presence = conversation.getNextPresence(); if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) { prepareImageToast.show(); - xmppConnectionService.attachImageToConversation(conversation, presence, data.getData()); + this.pendingMessage = xmppConnectionService.attachImageToConversation(conversation, data.getData(),new UiCallback() { + + @Override + public void userInputRequried(PendingIntent pi) { + + } + + @Override + public void success() { + sendPendingImageMessage(); + } + + @Override + public void error(int error) { + pendingMessage = null; + displayErrorDialog(error); + } + }); } else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { prepareImageToast.show(); attachPgpFile(conversation,data.getData()); @@ -696,8 +711,7 @@ public class ConversationActivity extends XmppActivity { } private void attachPgpFile(Conversation conversation, Uri uri) { - String presence = conversation.getNextPresence(); - pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, uri, new OnPgpEngineResult() { + pendingMessage = xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback() { @Override public void userInputRequried(PendingIntent pi) { @@ -706,20 +720,25 @@ public class ConversationActivity extends XmppActivity { @Override public void success() { - pendingMessage.getConversation().getMessages().add(pendingMessage); - xmppConnectionService.databaseBackend.createMessage(pendingMessage); - xmppConnectionService.sendMessage(pendingMessage, null); - xmppConnectionService.updateUi(pendingMessage.getConversation(), false); - pendingMessage = null; + sendPendingImageMessage(); } @Override - public void error(OpenPgpError openPgpError) { - Log.d(LOGTAG,"pgp error"+openPgpError.getMessage()); + public void error(int error) { + pendingMessage = null; + displayErrorDialog(error); } }); } + private void sendPendingImageMessage() { + pendingMessage.getConversation().getMessages().add(pendingMessage); + xmppConnectionService.databaseBackend.createMessage(pendingMessage); + xmppConnectionService.sendMessage(pendingMessage, null); + xmppConnectionService.updateUi(pendingMessage.getConversation(), false); + pendingMessage = null; + } + public void updateConversationList() { conversationList.clear(); conversationList.addAll(xmppConnectionService.getConversations()); @@ -925,7 +944,7 @@ public class ConversationActivity extends XmppActivity { } public void encryptTextMessage() { - xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage, new OnPgpEngineResult() { + xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage, new UiCallback() { @Override public void userInputRequried( @@ -947,10 +966,7 @@ public class ConversationActivity extends XmppActivity { } @Override - public void error( - OpenPgpError openPgpError) { - // TODO Auto-generated method - // stub + public void error(int error) { } }); diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 06bbc3a5..91a39ecc 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -8,9 +8,7 @@ import java.util.Set; import org.openintents.openpgp.OpenPgpError; import net.java.otr4j.session.SessionStatus; - import eu.siacs.conversations.R; -import eu.siacs.conversations.crypto.OnPgpEngineResult; import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; @@ -560,7 +558,7 @@ public class ConversationFragment extends Fragment { private void decryptMessage(final Message message) { PgpEngine engine = activity.xmppConnectionService.getPgpEngine(); if (engine != null) { - engine.decrypt(message, new OnPgpEngineResult() { + engine.decrypt(message, new UiCallback() { @Override public void userInputRequried(PendingIntent pi) { @@ -576,9 +574,7 @@ public class ConversationFragment extends Fragment { } @Override - public void error(OpenPgpError openPgpError) { - Log.d("xmppService", - "decryption error" + openPgpError.getMessage()); + public void error(int error) { message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED); // updateMessages(); } @@ -680,7 +676,7 @@ public class ConversationFragment extends Fragment { if (activity.hasPgp()) { if (contact.getPgpKeyId() != 0) { xmppService.getPgpEngine().hasKey(contact, - new OnPgpEngineResult() { + new UiCallback() { @Override public void userInputRequried(PendingIntent pi) { @@ -695,9 +691,8 @@ public class ConversationFragment extends Fragment { } @Override - public void error(OpenPgpError openPgpError) { - Log.d("xmppService", "openpgp error" - + openPgpError.getMessage()); + public void error(int error) { + } }); diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 0a1cb5cd..0b7dac58 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -6,7 +6,6 @@ import java.util.List; import org.openintents.openpgp.OpenPgpError; import eu.siacs.conversations.R; -import eu.siacs.conversations.crypto.OnPgpEngineResult; import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.ui.EditAccount.EditAccountListener; diff --git a/src/eu/siacs/conversations/ui/UiCallback.java b/src/eu/siacs/conversations/ui/UiCallback.java new file mode 100644 index 00000000..f9273b96 --- /dev/null +++ b/src/eu/siacs/conversations/ui/UiCallback.java @@ -0,0 +1,9 @@ +package eu.siacs.conversations.ui; + +import android.app.PendingIntent; + +public interface UiCallback { + public void success(); + public void error(int errorCode); + public void userInputRequried(PendingIntent pi); +} diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 55dcecc9..dc894ad5 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -1,9 +1,8 @@ package eu.siacs.conversations.ui; -import org.openintents.openpgp.OpenPgpError; +import java.nio.channels.AlreadyConnectedException; import eu.siacs.conversations.R; -import eu.siacs.conversations.crypto.OnPgpEngineResult; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; @@ -164,7 +163,7 @@ public abstract class XmppActivity extends Activity { } protected void announcePgp(final Account account, final Conversation conversation) { - xmppConnectionService.getPgpEngine().generateSignature(account, "online", new OnPgpEngineResult() { + xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback() { @Override public void userInputRequried(PendingIntent pi) { @@ -185,10 +184,25 @@ public abstract class XmppActivity extends Activity { } @Override - public void error(OpenPgpError openPgpError) { - // TODO Auto-generated method stub - + public void error(int error) { + displayErrorDialog(error); + } + }); + } + + protected void displayErrorDialog(final int errorCode) { + runOnUiThread(new Runnable() { + + @Override + public void run() { + AlertDialog.Builder builder = new AlertDialog.Builder(XmppActivity.this); + builder.setIconAttribute(android.R.attr.alertDialogIcon); + builder.setTitle(getString(R.string.error)); + builder.setMessage(errorCode); + builder.setNeutralButton(R.string.accept, null); + builder.create().show(); } }); + } } -- cgit v1.2.3