aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-05-12 14:59:46 +0200
committerDaniel Gultsch <daniel@gultsch.de>2014-05-12 14:59:46 +0200
commit3455d10a4a87916bfe5da52ca9c401dafa8d5155 (patch)
treee7b6cc4520ad0dd64e348d2e9a27ffe7a81db696 /src/eu/siacs/conversations/ui
parent4d0bf7971ec321a55f180b833b033ceaa6635fdf (diff)
Better error handling if attach file doesnt work (on permission denied)
and unified encrypted and unencrypted file attachment
Diffstat (limited to 'src/eu/siacs/conversations/ui')
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java54
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java15
-rw-r--r--src/eu/siacs/conversations/ui/ManageAccountActivity.java1
-rw-r--r--src/eu/siacs/conversations/ui/UiCallback.java9
-rw-r--r--src/eu/siacs/conversations/ui/XmppActivity.java26
5 files changed, 69 insertions, 36 deletions
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();
}
});
+
}
}