possible fix to be able to images and encrypted messages at a faster rate
This commit is contained in:
parent
df7f7c5c4e
commit
ea8f3a2675
|
@ -36,14 +36,16 @@ public class PgpEngine {
|
||||||
this.mXmppConnectionService = service;
|
this.mXmppConnectionService = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decrypt(final Message message, final UiCallback callback) {
|
public void decrypt(final Message message,
|
||||||
Log.d("xmppService","decrypting message "+message.getUuid());
|
final UiCallback<Message> callback) {
|
||||||
|
Log.d("xmppService", "decrypting message " + message.getUuid());
|
||||||
Intent params = new Intent();
|
Intent params = new Intent();
|
||||||
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
|
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
|
||||||
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message
|
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message
|
||||||
.getConversation().getAccount().getJid());
|
.getConversation().getAccount().getJid());
|
||||||
if (message.getType() == Message.TYPE_TEXT) {
|
if (message.getType() == Message.TYPE_TEXT) {
|
||||||
InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
|
InputStream is = new ByteArrayInputStream(message.getBody()
|
||||||
|
.getBytes());
|
||||||
final OutputStream os = new ByteArrayOutputStream();
|
final OutputStream os = new ByteArrayOutputStream();
|
||||||
api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
|
api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
|
||||||
|
|
||||||
|
@ -54,14 +56,15 @@ public class PgpEngine {
|
||||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||||
message.setBody(os.toString());
|
message.setBody(os.toString());
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||||
callback.success();
|
callback.success(message);
|
||||||
return;
|
return;
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||||
callback.userInputRequried((PendingIntent) result
|
callback.userInputRequried((PendingIntent) result
|
||||||
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
|
.getParcelableExtra(OpenPgpApi.RESULT_INTENT),
|
||||||
|
message);
|
||||||
return;
|
return;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
callback.error(R.string.openpgp_error);
|
callback.error(R.string.openpgp_error, message);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
@ -70,8 +73,10 @@ public class PgpEngine {
|
||||||
});
|
});
|
||||||
} else if (message.getType() == Message.TYPE_IMAGE) {
|
} else if (message.getType() == Message.TYPE_IMAGE) {
|
||||||
try {
|
try {
|
||||||
final JingleFile inputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, false);
|
final JingleFile inputFile = this.mXmppConnectionService
|
||||||
final JingleFile outputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message,true);
|
.getFileBackend().getJingleFile(message, false);
|
||||||
|
final JingleFile outputFile = this.mXmppConnectionService
|
||||||
|
.getFileBackend().getJingleFile(message, true);
|
||||||
outputFile.createNewFile();
|
outputFile.createNewFile();
|
||||||
InputStream is = new FileInputStream(inputFile);
|
InputStream is = new FileInputStream(inputFile);
|
||||||
OutputStream os = new FileOutputStream(outputFile);
|
OutputStream os = new FileOutputStream(outputFile);
|
||||||
|
@ -84,21 +89,27 @@ public class PgpEngine {
|
||||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
BitmapFactory.decodeFile(outputFile.getAbsolutePath(),options);
|
BitmapFactory.decodeFile(
|
||||||
|
outputFile.getAbsolutePath(), options);
|
||||||
int imageHeight = options.outHeight;
|
int imageHeight = options.outHeight;
|
||||||
int imageWidth = options.outWidth;
|
int imageWidth = options.outWidth;
|
||||||
message.setBody(""+outputFile.getSize()+","+imageWidth+","+imageHeight);
|
message.setBody("" + outputFile.getSize() + ","
|
||||||
|
+ imageWidth + "," + imageHeight);
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||||
PgpEngine.this.mXmppConnectionService.updateMessage(message);
|
PgpEngine.this.mXmppConnectionService
|
||||||
PgpEngine.this.mXmppConnectionService.updateUi(message.getConversation(), false);
|
.updateMessage(message);
|
||||||
callback.success();
|
PgpEngine.this.mXmppConnectionService.updateUi(
|
||||||
|
message.getConversation(), false);
|
||||||
|
callback.success(message);
|
||||||
return;
|
return;
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||||
callback.userInputRequried((PendingIntent) result
|
callback.userInputRequried(
|
||||||
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
|
(PendingIntent) result
|
||||||
|
.getParcelableExtra(OpenPgpApi.RESULT_INTENT),
|
||||||
|
message);
|
||||||
return;
|
return;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
callback.error(R.string.openpgp_error);
|
callback.error(R.string.openpgp_error, message);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
@ -106,30 +117,35 @@ public class PgpEngine {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
callback.error(R.string.error_decrypting_file);
|
callback.error(R.string.error_decrypting_file, message);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
callback.error(R.string.error_decrypting_file);
|
callback.error(R.string.error_decrypting_file, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encrypt(final Message message,final UiCallback callback) {
|
public void encrypt(final Message message,
|
||||||
|
final UiCallback<Message> callback) {
|
||||||
|
|
||||||
Intent params = new Intent();
|
Intent params = new Intent();
|
||||||
params.setAction(OpenPgpApi.ACTION_ENCRYPT);
|
params.setAction(OpenPgpApi.ACTION_ENCRYPT);
|
||||||
if (message.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
if (message.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
||||||
long[] keys = { message.getConversation().getContact().getPgpKeyId() };
|
long[] keys = { message.getConversation().getContact()
|
||||||
|
.getPgpKeyId() };
|
||||||
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys);
|
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys);
|
||||||
} else {
|
} else {
|
||||||
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, message.getConversation().getMucOptions().getPgpKeyIds());
|
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, message.getConversation()
|
||||||
|
.getMucOptions().getPgpKeyIds());
|
||||||
}
|
}
|
||||||
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid());
|
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message
|
||||||
|
.getConversation().getAccount().getJid());
|
||||||
|
|
||||||
if (message.getType() == Message.TYPE_TEXT) {
|
if (message.getType() == Message.TYPE_TEXT) {
|
||||||
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||||
|
|
||||||
InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
|
InputStream is = new ByteArrayInputStream(message.getBody()
|
||||||
|
.getBytes());
|
||||||
final OutputStream os = new ByteArrayOutputStream();
|
final OutputStream os = new ByteArrayOutputStream();
|
||||||
api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
|
api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
|
||||||
|
|
||||||
|
@ -143,23 +159,28 @@ public class PgpEngine {
|
||||||
for (int i = 3; i < lines.length - 1; ++i) {
|
for (int i = 3; i < lines.length - 1; ++i) {
|
||||||
encryptedMessageBody.append(lines[i].trim());
|
encryptedMessageBody.append(lines[i].trim());
|
||||||
}
|
}
|
||||||
message.setEncryptedBody(encryptedMessageBody.toString());
|
message.setEncryptedBody(encryptedMessageBody
|
||||||
callback.success();
|
.toString());
|
||||||
|
message.ready = true;
|
||||||
|
callback.success(message);
|
||||||
break;
|
break;
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||||
callback.userInputRequried((PendingIntent) result
|
callback.userInputRequried((PendingIntent) result
|
||||||
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
|
.getParcelableExtra(OpenPgpApi.RESULT_INTENT),
|
||||||
|
message);
|
||||||
break;
|
break;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
callback.error(R.string.openpgp_error);
|
callback.error(R.string.openpgp_error, message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (message.getType() == Message.TYPE_IMAGE) {
|
} else if (message.getType() == Message.TYPE_IMAGE) {
|
||||||
try {
|
try {
|
||||||
JingleFile inputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, true);
|
JingleFile inputFile = this.mXmppConnectionService
|
||||||
JingleFile outputFile = this.mXmppConnectionService.getFileBackend().getJingleFile(message, false);
|
.getFileBackend().getJingleFile(message, true);
|
||||||
|
JingleFile outputFile = this.mXmppConnectionService
|
||||||
|
.getFileBackend().getJingleFile(message, false);
|
||||||
outputFile.createNewFile();
|
outputFile.createNewFile();
|
||||||
InputStream is = new FileInputStream(inputFile);
|
InputStream is = new FileInputStream(inputFile);
|
||||||
OutputStream os = new FileOutputStream(outputFile);
|
OutputStream os = new FileOutputStream(outputFile);
|
||||||
|
@ -170,22 +191,25 @@ public class PgpEngine {
|
||||||
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
|
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
|
||||||
OpenPgpApi.RESULT_CODE_ERROR)) {
|
OpenPgpApi.RESULT_CODE_ERROR)) {
|
||||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||||
callback.success();
|
message.ready = true;
|
||||||
|
callback.success(message);
|
||||||
break;
|
break;
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||||
callback.userInputRequried((PendingIntent) result
|
callback.userInputRequried(
|
||||||
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
|
(PendingIntent) result
|
||||||
|
.getParcelableExtra(OpenPgpApi.RESULT_INTENT),
|
||||||
|
message);
|
||||||
break;
|
break;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
callback.error(R.string.openpgp_error);
|
callback.error(R.string.openpgp_error, message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.d("xmppService","file not found: "+e.getMessage());
|
Log.d("xmppService", "file not found: " + e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d("xmppService","io exception during file encrypt");
|
Log.d("xmppService", "io exception during file encrypt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,15 +253,18 @@ public class PgpEngine {
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||||
return 0;
|
return 0;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
Log.d("xmppService","openpgp error: "+((OpenPgpError) result
|
Log.d("xmppService",
|
||||||
.getParcelableExtra(OpenPgpApi.RESULT_ERROR)).getMessage());
|
"openpgp error: "
|
||||||
|
+ ((OpenPgpError) result
|
||||||
|
.getParcelableExtra(OpenPgpApi.RESULT_ERROR))
|
||||||
|
.getMessage());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateSignature(final Account account, String status,
|
public void generateSignature(final Account account, String status,
|
||||||
final UiCallback callback) {
|
final UiCallback<Account> callback) {
|
||||||
Intent params = new Intent();
|
Intent params = new Intent();
|
||||||
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||||
params.setAction(OpenPgpApi.ACTION_SIGN);
|
params.setAction(OpenPgpApi.ACTION_SIGN);
|
||||||
|
@ -256,39 +283,42 @@ public class PgpEngine {
|
||||||
signatureBuilder.append(lines[i].trim());
|
signatureBuilder.append(lines[i].trim());
|
||||||
}
|
}
|
||||||
account.setKey("pgp_signature", signatureBuilder.toString());
|
account.setKey("pgp_signature", signatureBuilder.toString());
|
||||||
callback.success();
|
callback.success(account);
|
||||||
return;
|
return;
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||||
callback.userInputRequried((PendingIntent) result
|
callback.userInputRequried((PendingIntent) result
|
||||||
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
|
.getParcelableExtra(OpenPgpApi.RESULT_INTENT),
|
||||||
|
account);
|
||||||
return;
|
return;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
callback.error(R.string.openpgp_error);
|
callback.error(R.string.openpgp_error, account);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hasKey(Contact contact, final UiCallback callback) {
|
public void hasKey(final Contact contact, final UiCallback<Contact> callback) {
|
||||||
Intent params = new Intent();
|
Intent params = new Intent();
|
||||||
params.setAction(OpenPgpApi.ACTION_GET_KEY);
|
params.setAction(OpenPgpApi.ACTION_GET_KEY);
|
||||||
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId());
|
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId());
|
||||||
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, contact.getAccount().getJid());
|
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, contact.getAccount()
|
||||||
|
.getJid());
|
||||||
api.executeApiAsync(params, null, null, new IOpenPgpCallback() {
|
api.executeApiAsync(params, null, null, new IOpenPgpCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReturn(Intent result) {
|
public void onReturn(Intent result) {
|
||||||
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) {
|
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) {
|
||||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||||
callback.success();
|
callback.success(contact);
|
||||||
return;
|
return;
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||||
callback.userInputRequried((PendingIntent) result
|
callback.userInputRequried((PendingIntent) result
|
||||||
.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
|
.getParcelableExtra(OpenPgpApi.RESULT_INTENT),
|
||||||
|
contact);
|
||||||
return;
|
return;
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
callback.error(R.string.openpgp_error);
|
callback.error(R.string.openpgp_error, contact);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,9 +329,11 @@ public class PgpEngine {
|
||||||
Intent params = new Intent();
|
Intent params = new Intent();
|
||||||
params.setAction(OpenPgpApi.ACTION_GET_KEY);
|
params.setAction(OpenPgpApi.ACTION_GET_KEY);
|
||||||
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId());
|
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId());
|
||||||
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, contact.getAccount().getJid());
|
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, contact.getAccount()
|
||||||
|
.getJid());
|
||||||
Intent result = api.executeApi(params, null, null);
|
Intent result = api.executeApi(params, null, null);
|
||||||
return (PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
return (PendingIntent) result
|
||||||
|
.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PendingIntent getIntentForKey(Account account, long pgpKeyId) {
|
public PendingIntent getIntentForKey(Account account, long pgpKeyId) {
|
||||||
|
@ -310,6 +342,7 @@ public class PgpEngine {
|
||||||
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, pgpKeyId);
|
params.putExtra(OpenPgpApi.EXTRA_KEY_ID, pgpKeyId);
|
||||||
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, account.getJid());
|
params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, account.getJid());
|
||||||
Intent result = api.executeApi(params, null, null);
|
Intent result = api.executeApi(params, null, null);
|
||||||
return (PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
return (PendingIntent) result
|
||||||
|
.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,8 @@ public class Message extends AbstractEntity {
|
||||||
|
|
||||||
protected transient JingleConnection jingleConnection = null;
|
protected transient JingleConnection jingleConnection = null;
|
||||||
|
|
||||||
|
public boolean ready = true;
|
||||||
|
|
||||||
private Message() {
|
private Message() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,7 +356,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message attachImageToConversation(final Conversation conversation,
|
public Message attachImageToConversation(final Conversation conversation,
|
||||||
final Uri uri, final UiCallback callback) {
|
final Uri uri, final UiCallback<Message> callback) {
|
||||||
final Message message;
|
final Message message;
|
||||||
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
message = new Message(conversation, "",
|
message = new Message(conversation, "",
|
||||||
|
@ -376,10 +376,11 @@ public class XmppConnectionService extends Service {
|
||||||
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
getPgpEngine().encrypt(message, callback);
|
getPgpEngine().encrypt(message, callback);
|
||||||
} else {
|
} else {
|
||||||
callback.success();
|
message.ready = true;
|
||||||
|
callback.success(message);
|
||||||
}
|
}
|
||||||
} catch (FileBackend.ImageCopyException e) {
|
} catch (FileBackend.ImageCopyException e) {
|
||||||
callback.error(e.getResId());
|
callback.error(e.getResId(),message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
|
@ -85,8 +85,6 @@ public class ConversationActivity extends XmppActivity {
|
||||||
private boolean showLastseen = false;
|
private boolean showLastseen = false;
|
||||||
private ArrayAdapter<Conversation> listAdapter;
|
private ArrayAdapter<Conversation> listAdapter;
|
||||||
|
|
||||||
public Message pendingMessage = null;
|
|
||||||
|
|
||||||
private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() {
|
private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -399,21 +397,23 @@ public class ConversationActivity extends XmppActivity {
|
||||||
if (hasPgp()) {
|
if (hasPgp()) {
|
||||||
if (conversation.getContact().getPgpKeyId() != 0) {
|
if (conversation.getContact().getPgpKeyId() != 0) {
|
||||||
xmppConnectionService.getPgpEngine().hasKey(
|
xmppConnectionService.getPgpEngine().hasKey(
|
||||||
conversation.getContact(), new UiCallback() {
|
conversation.getContact(),
|
||||||
|
new UiCallback<Contact>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userInputRequried(PendingIntent pi) {
|
public void userInputRequried(PendingIntent pi,
|
||||||
|
Contact contact) {
|
||||||
ConversationActivity.this.runIntent(pi,
|
ConversationActivity.this.runIntent(pi,
|
||||||
attachmentChoice);
|
attachmentChoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success(Contact contact) {
|
||||||
selectPresenceToAttachFile(attachmentChoice);
|
selectPresenceToAttachFile(attachmentChoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int error) {
|
public void error(int error, Contact contact) {
|
||||||
displayErrorDialog(error);
|
displayErrorDialog(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -794,7 +794,7 @@ public class ConversationActivity extends XmppActivity {
|
||||||
announcePgp(getSelectedConversation().getAccount(),
|
announcePgp(getSelectedConversation().getAccount(),
|
||||||
getSelectedConversation());
|
getSelectedConversation());
|
||||||
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
|
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
|
||||||
encryptTextMessage();
|
// encryptTextMessage();
|
||||||
} else if (requestCode == REQUEST_IMAGE_CAPTURE) {
|
} else if (requestCode == REQUEST_IMAGE_CAPTURE) {
|
||||||
attachImageToConversation(getSelectedConversation(), null);
|
attachImageToConversation(getSelectedConversation(), null);
|
||||||
} else if (requestCode == REQUEST_RECORD_AUDIO) {
|
} else if (requestCode == REQUEST_RECORD_AUDIO) {
|
||||||
|
@ -815,26 +815,30 @@ public class ConversationActivity extends XmppActivity {
|
||||||
prepareImageToast = Toast.makeText(getApplicationContext(),
|
prepareImageToast = Toast.makeText(getApplicationContext(),
|
||||||
getText(R.string.preparing_image), Toast.LENGTH_LONG);
|
getText(R.string.preparing_image), Toast.LENGTH_LONG);
|
||||||
prepareImageToast.show();
|
prepareImageToast.show();
|
||||||
pendingMessage = xmppConnectionService.attachImageToConversation(
|
xmppConnectionService.attachImageToConversation(conversation, uri,
|
||||||
conversation, uri, new UiCallback() {
|
new UiCallback<Message>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userInputRequried(PendingIntent pi) {
|
public void userInputRequried(PendingIntent pi,
|
||||||
|
Message object) {
|
||||||
hidePrepareImageToast();
|
hidePrepareImageToast();
|
||||||
ConversationActivity.this.runIntent(pi,
|
ConversationActivity.this.runIntent(pi,
|
||||||
ConversationActivity.REQUEST_SEND_PGP_IMAGE);
|
ConversationActivity.REQUEST_SEND_PGP_IMAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success(Message message) {
|
||||||
sendPendingImageMessage();
|
message.getConversation().getMessages().add(message);
|
||||||
hidePrepareImageToast();
|
xmppConnectionService.databaseBackend
|
||||||
|
.createMessage(message);
|
||||||
|
xmppConnectionService.sendMessage(message, null);
|
||||||
|
xmppConnectionService.updateUi(
|
||||||
|
message.getConversation(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int error) {
|
public void error(int error, Message message) {
|
||||||
hidePrepareImageToast();
|
hidePrepareImageToast();
|
||||||
pendingMessage = null;
|
|
||||||
displayErrorDialog(error);
|
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() {
|
public void updateConversationList() {
|
||||||
conversationList.clear();
|
conversationList.clear();
|
||||||
conversationList.addAll(xmppConnectionService.getConversations());
|
conversationList.addAll(xmppConnectionService.getConversations());
|
||||||
|
@ -1084,29 +1080,24 @@ public class ConversationActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encryptTextMessage() {
|
public void encryptTextMessage(Message message) {
|
||||||
xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage,
|
xmppConnectionService.getPgpEngine().encrypt(message,
|
||||||
new UiCallback() {
|
new UiCallback<Message>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userInputRequried(PendingIntent pi) {
|
public void userInputRequried(PendingIntent pi,
|
||||||
|
Message message) {
|
||||||
activity.runIntent(pi,
|
activity.runIntent(pi,
|
||||||
ConversationActivity.REQUEST_SEND_MESSAGE);
|
ConversationActivity.REQUEST_SEND_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success(Message message) {
|
||||||
xmppConnectionService.sendMessage(pendingMessage, null);
|
xmppConnectionService.sendMessage(message, null);
|
||||||
pendingMessage = null;
|
|
||||||
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
|
|
||||||
.findFragmentByTag("conversation");
|
|
||||||
if (selectedFragment != null) {
|
|
||||||
selectedFragment.clearInputField();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int error) {
|
public void error(int error, Message message) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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();
|
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
|
||||||
if (engine != null) {
|
if (engine != null) {
|
||||||
engine.decrypt(message, new UiCallback() {
|
engine.decrypt(message, new UiCallback<Message>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userInputRequried(PendingIntent pi) {
|
public void userInputRequried(PendingIntent pi, Message message) {
|
||||||
askForPassphraseIntent = pi.getIntentSender();
|
askForPassphraseIntent = pi.getIntentSender();
|
||||||
pgpInfo.setVisibility(View.VISIBLE);
|
pgpInfo.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success(Message message) {
|
||||||
activity.xmppConnectionService.databaseBackend
|
activity.xmppConnectionService.databaseBackend
|
||||||
.updateMessage(message);
|
.updateMessage(message);
|
||||||
updateMessages();
|
updateMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int error) {
|
public void error(int error, Message message) {
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
|
||||||
// updateMessages();
|
// updateMessages();
|
||||||
}
|
}
|
||||||
|
@ -752,7 +752,6 @@ public class ConversationFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendPgpMessage(final Message message) {
|
protected void sendPgpMessage(final Message message) {
|
||||||
activity.pendingMessage = message;
|
|
||||||
final ConversationActivity activity = (ConversationActivity) getActivity();
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
||||||
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
||||||
final Contact contact = message.getConversation().getContact();
|
final Contact contact = message.getConversation().getContact();
|
||||||
|
@ -760,22 +759,22 @@ public class ConversationFragment extends Fragment {
|
||||||
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||||
if (contact.getPgpKeyId() != 0) {
|
if (contact.getPgpKeyId() != 0) {
|
||||||
xmppService.getPgpEngine().hasKey(contact,
|
xmppService.getPgpEngine().hasKey(contact,
|
||||||
new UiCallback() {
|
new UiCallback<Contact>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userInputRequried(PendingIntent pi) {
|
public void userInputRequried(PendingIntent pi,Contact contact) {
|
||||||
activity.runIntent(
|
activity.runIntent(
|
||||||
pi,
|
pi,
|
||||||
ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
|
ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success(Contact contact) {
|
||||||
activity.encryptTextMessage();
|
activity.encryptTextMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
|
||||||
warning.show();
|
warning.show();
|
||||||
}
|
}
|
||||||
activity.encryptTextMessage();
|
activity.encryptTextMessage(message);
|
||||||
} else {
|
} else {
|
||||||
showNoPGPKeyDialog(true,
|
showNoPGPKeyDialog(true,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
|
|
|
@ -2,8 +2,8 @@ package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
|
||||||
public interface UiCallback {
|
public interface UiCallback<T> {
|
||||||
public void success();
|
public void success(T object);
|
||||||
public void error(int errorCode);
|
public void error(int errorCode, T object);
|
||||||
public void userInputRequried(PendingIntent pi);
|
public void userInputRequried(PendingIntent pi, T object);
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,11 +166,11 @@ public abstract class XmppActivity extends Activity {
|
||||||
startActivity(viewConversationIntent);
|
startActivity(viewConversationIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void announcePgp(final Account account, final Conversation conversation) {
|
protected void announcePgp(Account account, final Conversation conversation) {
|
||||||
xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback() {
|
xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback<Account>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userInputRequried(PendingIntent pi) {
|
public void userInputRequried(PendingIntent pi, Account account) {
|
||||||
try {
|
try {
|
||||||
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
|
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
|
||||||
} catch (SendIntentException e) {
|
} catch (SendIntentException e) {
|
||||||
|
@ -179,7 +179,7 @@ public abstract class XmppActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success(Account account) {
|
||||||
xmppConnectionService.databaseBackend.updateAccount(account);
|
xmppConnectionService.databaseBackend.updateAccount(account);
|
||||||
xmppConnectionService.sendPresence(account);
|
xmppConnectionService.sendPresence(account);
|
||||||
if (conversation!=null) {
|
if (conversation!=null) {
|
||||||
|
@ -188,7 +188,7 @@ public abstract class XmppActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int error) {
|
public void error(int error, Account account) {
|
||||||
displayErrorDialog(error);
|
displayErrorDialog(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue