aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-06-07 13:25:27 +0200
committeriNPUTmice <daniel@gultsch.de>2014-06-07 13:25:27 +0200
commitea8f3a26758ef4e65b3a41d1241fadba626b83e9 (patch)
tree8f222332e1d6ace1cc7bb68c780fe65dd503b41b /src/eu/siacs/conversations/ui
parentdf7f7c5c4e133d7b055a3c146e1c8bc577178939 (diff)
possible fix to be able to images and encrypted messages at a faster rate
Diffstat (limited to 'src/eu/siacs/conversations/ui')
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java63
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java23
-rw-r--r--src/eu/siacs/conversations/ui/UiCallback.java8
-rw-r--r--src/eu/siacs/conversations/ui/XmppActivity.java10
4 files changed, 47 insertions, 57 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 55c538d6..0c9c154f 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -85,8 +85,6 @@ public class ConversationActivity extends XmppActivity {
private boolean showLastseen = false;
private ArrayAdapter<Conversation> listAdapter;
- public Message pendingMessage = null;
-
private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() {
@Override
@@ -399,21 +397,23 @@ public class ConversationActivity extends XmppActivity {
if (hasPgp()) {
if (conversation.getContact().getPgpKeyId() != 0) {
xmppConnectionService.getPgpEngine().hasKey(
- conversation.getContact(), new UiCallback() {
+ conversation.getContact(),
+ new UiCallback<Contact>() {
@Override
- public void userInputRequried(PendingIntent pi) {
+ public void userInputRequried(PendingIntent pi,
+ Contact contact) {
ConversationActivity.this.runIntent(pi,
attachmentChoice);
}
@Override
- public void success() {
+ public void success(Contact contact) {
selectPresenceToAttachFile(attachmentChoice);
}
@Override
- public void error(int error) {
+ public void error(int error, Contact contact) {
displayErrorDialog(error);
}
});
@@ -794,7 +794,7 @@ public class ConversationActivity extends XmppActivity {
announcePgp(getSelectedConversation().getAccount(),
getSelectedConversation());
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
- encryptTextMessage();
+ // encryptTextMessage();
} else if (requestCode == REQUEST_IMAGE_CAPTURE) {
attachImageToConversation(getSelectedConversation(), null);
} else if (requestCode == REQUEST_RECORD_AUDIO) {
@@ -815,26 +815,30 @@ public class ConversationActivity extends XmppActivity {
prepareImageToast = Toast.makeText(getApplicationContext(),
getText(R.string.preparing_image), Toast.LENGTH_LONG);
prepareImageToast.show();
- pendingMessage = xmppConnectionService.attachImageToConversation(
- conversation, uri, new UiCallback() {
+ xmppConnectionService.attachImageToConversation(conversation, uri,
+ new UiCallback<Message>() {
@Override
- public void userInputRequried(PendingIntent pi) {
+ public void userInputRequried(PendingIntent pi,
+ Message object) {
hidePrepareImageToast();
ConversationActivity.this.runIntent(pi,
ConversationActivity.REQUEST_SEND_PGP_IMAGE);
}
@Override
- public void success() {
- sendPendingImageMessage();
- hidePrepareImageToast();
+ public void success(Message message) {
+ message.getConversation().getMessages().add(message);
+ xmppConnectionService.databaseBackend
+ .createMessage(message);
+ xmppConnectionService.sendMessage(message, null);
+ xmppConnectionService.updateUi(
+ message.getConversation(), false);
}
@Override
- public void error(int error) {
+ public void error(int error, Message message) {
hidePrepareImageToast();
- pendingMessage = null;
displayErrorDialog(error);
}
});
@@ -852,14 +856,6 @@ public class ConversationActivity extends XmppActivity {
}
}
- 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());
@@ -1084,29 +1080,24 @@ public class ConversationActivity extends XmppActivity {
}
}
- public void encryptTextMessage() {
- xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage,
- new UiCallback() {
+ public void encryptTextMessage(Message message) {
+ xmppConnectionService.getPgpEngine().encrypt(message,
+ new UiCallback<Message>() {
@Override
- public void userInputRequried(PendingIntent pi) {
+ public void userInputRequried(PendingIntent pi,
+ Message message) {
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();
- }
+ public void success(Message message) {
+ xmppConnectionService.sendMessage(message, null);
}
@Override
- public void error(int error) {
+ public void error(int error, Message message) {
}
});
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 29033891..e976d799 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -621,26 +621,26 @@ public class ConversationFragment extends Fragment {
}
}
- private void decryptMessage(final Message message) {
+ private void decryptMessage(Message message) {
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
if (engine != null) {
- engine.decrypt(message, new UiCallback() {
+ engine.decrypt(message, new UiCallback<Message>() {
@Override
- public void userInputRequried(PendingIntent pi) {
+ public void userInputRequried(PendingIntent pi, Message message) {
askForPassphraseIntent = pi.getIntentSender();
pgpInfo.setVisibility(View.VISIBLE);
}
@Override
- public void success() {
+ public void success(Message message) {
activity.xmppConnectionService.databaseBackend
.updateMessage(message);
updateMessages();
}
@Override
- public void error(int error) {
+ public void error(int error, Message message) {
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
// updateMessages();
}
@@ -752,7 +752,6 @@ 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();
@@ -760,22 +759,22 @@ public class ConversationFragment extends Fragment {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
if (contact.getPgpKeyId() != 0) {
xmppService.getPgpEngine().hasKey(contact,
- new UiCallback() {
+ new UiCallback<Contact>() {
@Override
- public void userInputRequried(PendingIntent pi) {
+ public void userInputRequried(PendingIntent pi,Contact contact) {
activity.runIntent(
pi,
ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
}
@Override
- public void success() {
- activity.encryptTextMessage();
+ public void success(Contact contact) {
+ activity.encryptTextMessage(message);
}
@Override
- public void error(int error) {
+ public void error(int error, Contact contact) {
}
});
@@ -805,7 +804,7 @@ public class ConversationFragment extends Fragment {
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
warning.show();
}
- activity.encryptTextMessage();
+ activity.encryptTextMessage(message);
} else {
showNoPGPKeyDialog(true,
new DialogInterface.OnClickListener() {
diff --git a/src/eu/siacs/conversations/ui/UiCallback.java b/src/eu/siacs/conversations/ui/UiCallback.java
index f9273b96..05a869f7 100644
--- a/src/eu/siacs/conversations/ui/UiCallback.java
+++ b/src/eu/siacs/conversations/ui/UiCallback.java
@@ -2,8 +2,8 @@ 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);
+public interface UiCallback<T> {
+ public void success(T object);
+ public void error(int errorCode, T object);
+ public void userInputRequried(PendingIntent pi, T object);
}
diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java
index 81092b22..ca9ee490 100644
--- a/src/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/eu/siacs/conversations/ui/XmppActivity.java
@@ -166,11 +166,11 @@ public abstract class XmppActivity extends Activity {
startActivity(viewConversationIntent);
}
- protected void announcePgp(final Account account, final Conversation conversation) {
- xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback() {
+ protected void announcePgp(Account account, final Conversation conversation) {
+ xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback<Account>() {
@Override
- public void userInputRequried(PendingIntent pi) {
+ public void userInputRequried(PendingIntent pi, Account account) {
try {
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
} catch (SendIntentException e) {
@@ -179,7 +179,7 @@ public abstract class XmppActivity extends Activity {
}
@Override
- public void success() {
+ public void success(Account account) {
xmppConnectionService.databaseBackend.updateAccount(account);
xmppConnectionService.sendPresence(account);
if (conversation!=null) {
@@ -188,7 +188,7 @@ public abstract class XmppActivity extends Activity {
}
@Override
- public void error(int error) {
+ public void error(int error, Account account) {
displayErrorDialog(error);
}
});