better flow after returning from openkeychain for various actions

This commit is contained in:
Daniel Gultsch 2014-05-08 16:52:19 +02:00
parent 99a56a2bde
commit 7fa61564b8
3 changed files with 47 additions and 31 deletions

View File

@ -16,6 +16,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; 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_SEND_MESSAGE = 0x75441;
public static final int REQUEST_DECRYPT_PGP = 0x76783; 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_SEND_PGP_IMAGE = 0x53883;
private static final int REQUEST_ATTACH_FILE = 0x73824;
protected SlidingPaneLayout spl; protected SlidingPaneLayout spl;
@ -329,7 +331,7 @@ public class ConversationActivity extends XmppActivity {
attachFileIntent.setType("image/*"); attachFileIntent.setType("image/*");
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file)); 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 @Override
public void userInputRequried(PendingIntent pi) { public void userInputRequried(PendingIntent pi) {
ConversationActivity.this.runIntent(pi, REQUEST_SEND_PGP_IMAGE); ConversationActivity.this.runIntent(pi, REQUEST_ATTACH_FILE);
} }
@Override @Override
@ -448,7 +450,7 @@ public class ConversationActivity extends XmppActivity {
conversation.setNextEncryption(Message.ENCRYPTION_PGP); conversation.setNextEncryption(Message.ENCRYPTION_PGP);
item.setChecked(true); item.setChecked(true);
} else { } else {
announcePgp(conversation.getAccount()); announcePgp(conversation.getAccount(),conversation);
} }
} }
break; break;
@ -634,40 +636,50 @@ public class ConversationActivity extends XmppActivity {
if (selectedFragment != null) { if (selectedFragment != null) {
selectedFragment.hidePgpPassphraseBox(); selectedFragment.hidePgpPassphraseBox();
} }
} else if (requestCode == ATTACH_FILE) { } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
final Conversation conversation = getSelectedConversation(); final Conversation conversation = getSelectedConversation();
String presence = conversation.getNextPresence(); String presence = conversation.getNextPresence();
if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) { if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) {
xmppConnectionService.attachImageToConversation(conversation, presence, data.getData()); xmppConnectionService.attachImageToConversation(conversation, presence, data.getData());
} else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { } else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
pendingMessage = xmppConnectionService.attachEncryptedImageToConversation(conversation, presence, data.getData(), new OnPgpEngineResult() { attachPgpFile(conversation,data.getData());
@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());
}
});
} else { } else {
Log.d(LOGTAG,"unknown next message encryption: "+conversation.getNextEncryption()); 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() { public void updateConversationList() {
conversationList.clear(); conversationList.clear();

View File

@ -279,7 +279,7 @@ public class ManageAccountActivity extends XmppActivity {
} else if (item.getItemId()==R.id.mgmt_account_announce_pgp) { } else if (item.getItemId()==R.id.mgmt_account_announce_pgp) {
if (activity.hasPgp()) { if (activity.hasPgp()) {
mode.finish(); mode.finish();
announcePgp(selectedAccountForActionMode); announcePgp(selectedAccountForActionMode,null);
} }
} else if (item.getItemId() == R.id.mgmt_otr_key) { } else if (item.getItemId() == R.id.mgmt_otr_key) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
@ -458,8 +458,8 @@ public class ManageAccountActivity extends XmppActivity {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_ANNOUNCE_PGP) { if (requestCode == REQUEST_ANNOUNCE_PGP) {
announcePgp(selectedAccountForActionMode); announcePgp(selectedAccountForActionMode,null);
} }
} }
} }
} }

View File

@ -6,6 +6,7 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OnPgpEngineResult; import eu.siacs.conversations.crypto.OnPgpEngineResult;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
@ -162,7 +163,7 @@ public abstract class XmppActivity extends Activity {
startActivity(viewConversationIntent); startActivity(viewConversationIntent);
} }
protected void announcePgp(final Account account) { protected void announcePgp(final Account account, final Conversation conversation) {
xmppConnectionService.getPgpEngine().generateSignature(account, "online", new OnPgpEngineResult() { xmppConnectionService.getPgpEngine().generateSignature(account, "online", new OnPgpEngineResult() {
@Override @Override
@ -178,6 +179,9 @@ public abstract class XmppActivity extends Activity {
public void success() { public void success() {
xmppConnectionService.databaseBackend.updateAccount(account); xmppConnectionService.databaseBackend.updateAccount(account);
xmppConnectionService.sendPgpPresence(account, account.getPgpSignature()); xmppConnectionService.sendPgpPresence(account, account.getPgpSignature());
if (conversation!=null) {
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
}
} }
@Override @Override