fixed onActivityResult handling for pgp
This commit is contained in:
parent
b0bec2c390
commit
3b75161113
|
@ -60,6 +60,8 @@ import eu.siacs.conversations.ui.service.EmojiService;
|
|||
import eu.siacs.conversations.ui.util.PendingItem;
|
||||
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
||||
|
||||
import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
|
||||
|
||||
public class ConversationActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
|
||||
|
||||
public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
|
||||
|
@ -194,6 +196,40 @@ public class ConversationActivity extends XmppActivity implements OnConversation
|
|||
return true;
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.net.Uri;
|
|||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.PendingIntent;
|
||||
|
@ -639,9 +640,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 = this.binding.textinput.getText().toString();
|
||||
Message message = new Message(conversation, body, conversation.getNextEncryption());
|
||||
|
@ -697,10 +695,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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2276,7 +2271,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 {
|
||||
|
@ -2284,6 +2283,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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue