aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-03-30 22:14:41 +0200
committerChristian Schneppe <christian@pix-art.de>2018-03-30 22:14:41 +0200
commit20f74141e480fdbe774c66f17b94654ff55fcc38 (patch)
tree60598741c6bfcfa45734c71f81ab0d8f48a782a1
parent47a6f6f5371842c68505acbf0a71dde935e7ee19 (diff)
fixed onActivityResult handling for pgp
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java35
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java23
2 files changed, 50 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index 501a70961..32689ca7b 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -63,6 +63,7 @@ import de.pixart.messenger.ui.interfaces.OnConversationsListItemUpdated;
import de.pixart.messenger.ui.util.PendingItem;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
+import static de.pixart.messenger.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS;
public class ConversationActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
@@ -199,6 +200,40 @@ public class ConversationActivity extends XmppActivity implements OnConversation
}
@Override
+ public void onActivityResult(int requestCode, int resultCode, final Intent data) {
+ Log.d(Config.LOGTAG, "on activity result");
+ if (resultCode == RESULT_OK) {
+ handlePositiveActivityResult(requestCode, data);
+ } else {
+ handleNegativeActivityResult(requestCode);
+ }
+ }
+
+ private void handleNegativeActivityResult(int requestCode) {
+ switch (requestCode) {
+ case REQUEST_DECRYPT_PGP:
+ Conversation conversation = ConversationFragment.getConversationReliable(this);
+ if (conversation == null) {
+ break;
+ }
+ conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption();
+ break;
+ }
+ }
+
+ private void handlePositiveActivityResult(int requestCode, final Intent data) {
+ switch (requestCode) {
+ case REQUEST_DECRYPT_PGP:
+ Conversation conversation = ConversationFragment.getConversationReliable(this);
+ if (conversation == null) {
+ break;
+ }
+ conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
+ break;
+ }
+ }
+
+ @Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new EmojiService(this).init(useBundledEmoji());
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 718b0d8b9..5db052b10 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -21,6 +21,7 @@ import android.os.Handler;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
+import android.support.annotation.IdRes;
import android.support.media.ExifInterface;
import android.support.v13.view.inputmethod.InputConnectionCompat;
import android.support.v13.view.inputmethod.InputContentInfoCompat;
@@ -882,9 +883,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private void handlePositiveActivityResult(int requestCode, final Intent data) {
switch (requestCode) {
- case REQUEST_DECRYPT_PGP:
- conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
- break;
case REQUEST_TRUST_KEYS_TEXT:
final String body = binding.textinput.getText().toString();
Message message = new Message(conversation, body, conversation.getNextEncryption());
@@ -946,10 +944,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private void handleNegativeActivityResult(int requestCode) {
switch (requestCode) {
- case REQUEST_DECRYPT_PGP:
- // discard the message to prevent decryption being blocked
- conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption();
- break;
+ //nothing to do for now
}
}
@@ -2642,7 +2637,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
public static Conversation getConversation(Activity activity) {
- Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.secondary_fragment);
+ return getConversation(activity, R.id.secondary_fragment);
+ }
+
+ private static Conversation getConversation(Activity activity, @IdRes int res) {
+ final Fragment fragment = activity.getFragmentManager().findFragmentById(res);
if (fragment != null && fragment instanceof ConversationFragment) {
return ((ConversationFragment) fragment).getConversation();
} else {
@@ -2650,6 +2649,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
+ public static Conversation getConversationReliable(Activity activity) {
+ final Conversation conversation = getConversation(activity, R.id.secondary_fragment);
+ if (conversation != null) {
+ return conversation;
+ }
+ return getConversation(activity, R.id.main_fragment);
+ }
+
public Conversation getConversation() {
return conversation;
}