aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui/ConversationActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java104
1 files changed, 77 insertions, 27 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 99af97e2..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;
@@ -16,6 +17,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 +65,10 @@ 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;
+ public static final int REQUEST_ENCRYPT_MESSAGE = 0x378018;
protected SlidingPaneLayout spl;
@@ -329,7 +333,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 +353,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 +452,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 +638,54 @@ 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());
+ } else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
+ encryptTextMessage();
+ } else {
+ Log.d(LOGTAG,"unknown result code:"+requestCode);
}
}
}
+
+ 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();
@@ -872,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
+
+ }
+ });
+ }
}