From 5ed94d5ab089f743ad60b97dc9f8f5976292a9c6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 27 Feb 2018 14:12:29 +0100 Subject: [PATCH] made publish pgp work from conversation view --- .../ui/ConversationActivity.java | 55 +++++++++++++++---- .../ui/ConversationFragment.java | 16 ------ 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 6be671e02..c367b84a4 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -31,6 +31,7 @@ package eu.siacs.conversations.ui; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; @@ -43,6 +44,7 @@ import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.support.annotation.IdRes; +import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; import android.util.Log; @@ -50,6 +52,8 @@ import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; +import org.openintents.openpgp.util.OpenPgpApi; + import java.util.concurrent.atomic.AtomicBoolean; import eu.siacs.conversations.Config; @@ -63,6 +67,7 @@ import eu.siacs.conversations.ui.interfaces.OnConversationRead; import eu.siacs.conversations.ui.interfaces.OnConversationSelected; import eu.siacs.conversations.ui.interfaces.OnConversationsListItemUpdated; import eu.siacs.conversations.ui.service.EmojiService; +import eu.siacs.conversations.ui.util.ActivityResult; import eu.siacs.conversations.ui.util.PendingItem; import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.xmpp.OnUpdateBlocklist; @@ -83,6 +88,7 @@ public class ConversationActivity extends XmppActivity implements OnConversation private static final @IdRes int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment}; private final PendingItem pendingViewIntent = new PendingItem<>(); + private final PendingItem postponedActivityResult = new PendingItem<>(); private ActivityConversationsBinding binding; private boolean mActivityPaused = true; private AtomicBoolean mRedirectInProcess = new AtomicBoolean(false); @@ -124,6 +130,12 @@ public class ConversationActivity extends XmppActivity implements OnConversation for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) { notifyFragmentOfBackendConnected(id); } + + ActivityResult activityResult = postponedActivityResult.pop(); + if (activityResult != null) { + handleActivityResult(activityResult); + } + invalidateActionBarTitle(); if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) { Conversation conversation = ConversationsOverviewFragment.getSuggestion(this); @@ -267,23 +279,33 @@ public class ConversationActivity extends XmppActivity implements OnConversation } @Override - public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { + public void onRequestPermissionsResult(int requestCode,@NonNull String permissions[], @NonNull int[] grantResults) { UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults); } @Override public void onActivityResult(int requestCode, int resultCode, final Intent data) { - if (resultCode == RESULT_OK) { - handlePositiveActivityResult(requestCode, data); + super.onActivityResult(requestCode, resultCode, data); + ActivityResult activityResult = ActivityResult.of(requestCode, resultCode, data); + if (xmppConnectionService != null) { + handleActivityResult(activityResult); } else { - handleNegativeActivityResult(requestCode); + this.postponedActivityResult.push(activityResult); + } + } + + private void handleActivityResult(ActivityResult activityResult) { + if (activityResult.resultCode == Activity.RESULT_OK) { + handlePositiveActivityResult(activityResult.requestCode, activityResult.data); + } else { + handleNegativeActivityResult(activityResult.requestCode); } } private void handleNegativeActivityResult(int requestCode) { + Conversation conversation = ConversationFragment.getConversationReliable(this); switch (requestCode) { case REQUEST_DECRYPT_PGP: - Conversation conversation = ConversationFragment.getConversationReliable(this); if (conversation == null) { break; } @@ -296,14 +318,28 @@ public class ConversationActivity extends XmppActivity implements OnConversation } private void handlePositiveActivityResult(int requestCode, final Intent data) { + Log.d(Config.LOGTAG,"positive activity result"); + Conversation conversation = ConversationFragment.getConversationReliable(this); + if (conversation == null) { + Log.d(Config.LOGTAG,"conversation not found"); + return; + } switch (requestCode) { case REQUEST_DECRYPT_PGP: - Conversation conversation = ConversationFragment.getConversationReliable(this); - if (conversation == null) { - break; - } conversation.getAccount().getPgpDecryptionService().continueDecryption(data); break; + case REQUEST_CHOOSE_PGP_ID: + long id = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0); + if (id != 0) { + conversation.getAccount().setPgpSignId(id); + announcePgp(conversation.getAccount(), null, null, onOpenPGPKeyPublished); + } else { + choosePgpSignId(conversation.getAccount()); + } + break; + case REQUEST_ANNOUNCE_PGP: + announcePgp(conversation.getAccount(), conversation, data, onOpenPGPKeyPublished); + break; } } @@ -512,7 +548,6 @@ public class ConversationActivity extends XmppActivity implements OnConversation Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation); if (suggestion != null) { openConversation(suggestion, null); - return; } } } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 015360c88..831970d41 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -686,18 +686,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke int choice = data.getIntExtra("choice", ATTACHMENT_CHOICE_INVALID); selectPresenceToAttachFile(choice); break; - case REQUEST_CHOOSE_PGP_ID: - long id = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0); - if (id != 0) { - conversation.getAccount().setPgpSignId(id); - activity.announcePgp(conversation.getAccount(), null, null, activity.onOpenPGPKeyPublished); - } else { - activity.choosePgpSignId(conversation.getAccount()); - } - break; - case REQUEST_ANNOUNCE_PGP: - activity.announcePgp(conversation.getAccount(), conversation, data, activity.onOpenPGPKeyPublished); - break; case ATTACHMENT_CHOICE_CHOOSE_IMAGE: List imageUris = AttachmentTool.extractUriFromIntent(data); for (Iterator i = imageUris.iterator(); i.hasNext(); i.remove()) { @@ -2359,10 +2347,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke setScrollPosition(scrollState); } } - ActivityResult activityResult = postponedActivityResult.pop(); - if (activityResult != null) { - handleActivityResult(activityResult); - } } public void clearPending() {