made publish pgp work from conversation view

This commit is contained in:
Daniel Gultsch 2018-02-27 14:12:29 +01:00
parent 6b55f05e27
commit 5ed94d5ab0
2 changed files with 45 additions and 26 deletions

View File

@ -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<Intent> pendingViewIntent = new PendingItem<>();
private final PendingItem<ActivityResult> 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;
}
}
}

View File

@ -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<Uri> imageUris = AttachmentTool.extractUriFromIntent(data);
for (Iterator<Uri> 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() {