fixed crashes when activity got destroyed when selecting pgp key
This commit is contained in:
parent
d42c82abf2
commit
2cd43f7042
|
@ -17,6 +17,7 @@ import android.provider.MediaStore;
|
|||
import android.support.v4.widget.SlidingPaneLayout;
|
||||
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
|
@ -109,6 +110,7 @@ public class ConversationActivity extends XmppActivity
|
|||
|
||||
private boolean mActivityPaused = false;
|
||||
private AtomicBoolean mRedirected = new AtomicBoolean(false);
|
||||
private Pair<Integer, Intent> mPostponedActivityResult;
|
||||
|
||||
public Conversation getSelectedConversation() {
|
||||
return this.mSelectedConversation;
|
||||
|
@ -1101,6 +1103,7 @@ public class ConversationActivity extends XmppActivity
|
|||
mPendingFileUris.clear();
|
||||
mPendingGeoUri = null;
|
||||
setSelectedConversation(conversationList.get(0));
|
||||
mPostponedActivityResult = null;
|
||||
this.mConversationFragment.reInit(getSelectedConversation());
|
||||
} else {
|
||||
this.mConversationFragment.messageListAdapter.updatePreferences();
|
||||
|
@ -1108,6 +1111,10 @@ public class ConversationActivity extends XmppActivity
|
|||
this.mConversationFragment.setupIme();
|
||||
}
|
||||
|
||||
if (this.mPostponedActivityResult != null) {
|
||||
this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
|
||||
}
|
||||
|
||||
if(!forbidProcessingPendings) {
|
||||
for (Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
|
||||
Uri foo = i.next();
|
||||
|
@ -1208,14 +1215,24 @@ public class ConversationActivity extends XmppActivity
|
|||
if (requestCode == REQUEST_DECRYPT_PGP) {
|
||||
mConversationFragment.onActivityResult(requestCode, resultCode, data);
|
||||
} else if (requestCode == REQUEST_CHOOSE_PGP_ID) {
|
||||
if (xmppConnectionServiceBound) {
|
||||
if (data.getExtras().containsKey(OpenPgpApi.EXTRA_SIGN_KEY_ID)) {
|
||||
mSelectedConversation.getAccount().setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID));
|
||||
announcePgp(mSelectedConversation.getAccount(), null);
|
||||
} else {
|
||||
choosePgpSignId(mSelectedConversation.getAccount());
|
||||
}
|
||||
this.mPostponedActivityResult = null;
|
||||
} else {
|
||||
this.mPostponedActivityResult = new Pair<>(requestCode, data);
|
||||
}
|
||||
} else if (requestCode == REQUEST_ANNOUNCE_PGP) {
|
||||
if (xmppConnectionServiceBound) {
|
||||
announcePgp(mSelectedConversation.getAccount(), null);
|
||||
this.mPostponedActivityResult = null;
|
||||
} else {
|
||||
this.mPostponedActivityResult = new Pair<>(requestCode, data);
|
||||
}
|
||||
} else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
|
||||
mPendingImageUris.clear();
|
||||
mPendingImageUris.addAll(extractUriFromIntent(data));
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
import android.security.KeyChain;
|
||||
import android.security.KeyChainAliasCallback;
|
||||
import android.util.Pair;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.Menu;
|
||||
|
@ -30,17 +31,25 @@ import eu.siacs.conversations.entities.Account;
|
|||
import eu.siacs.conversations.services.XmppConnectionService;
|
||||
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
|
||||
import eu.siacs.conversations.ui.adapter.AccountAdapter;
|
||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
|
||||
public class ManageAccountActivity extends XmppActivity implements OnAccountUpdate, KeyChainAliasCallback, XmppConnectionService.OnAccountCreated {
|
||||
|
||||
private final String STATE_SELECTED_ACCOUNT = "selected_account";
|
||||
|
||||
protected Account selectedAccount = null;
|
||||
protected Jid selectedAccountJid = null;
|
||||
|
||||
protected final List<Account> accountList = new ArrayList<>();
|
||||
protected ListView accountListView;
|
||||
protected AccountAdapter mAccountAdapter;
|
||||
protected AtomicBoolean mInvokedAddAccount = new AtomicBoolean(false);
|
||||
|
||||
protected Pair<Integer, Intent> mPostponedActivityResult = null;
|
||||
|
||||
@Override
|
||||
public void onAccountUpdate() {
|
||||
refreshUi();
|
||||
|
@ -68,6 +77,17 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
|
||||
setContentView(R.layout.manage_accounts);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
String jid = savedInstanceState.getString(STATE_SELECTED_ACCOUNT);
|
||||
if (jid != null) {
|
||||
try {
|
||||
this.selectedAccountJid = Jid.fromString(jid);
|
||||
} catch (InvalidJidException e) {
|
||||
this.selectedAccountJid = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
accountListView = (ListView) findViewById(R.id.account_list);
|
||||
this.mAccountAdapter = new AccountAdapter(this, accountList);
|
||||
accountListView.setAdapter(this.mAccountAdapter);
|
||||
|
@ -83,12 +103,19 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo) {
|
||||
public void onSaveInstanceState(final Bundle savedInstanceState) {
|
||||
if (selectedAccount != null) {
|
||||
savedInstanceState.putString(STATE_SELECTED_ACCOUNT, selectedAccount.getJid().toBareJid().toString());
|
||||
}
|
||||
super.onSaveInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
ManageAccountActivity.this.getMenuInflater().inflate(
|
||||
R.menu.manageaccounts_context, menu);
|
||||
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
||||
AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
||||
this.selectedAccount = accountList.get(acmi.position);
|
||||
if (this.selectedAccount.isOptionSet(Account.OPTION_DISABLED)) {
|
||||
menu.findItem(R.id.mgmt_account_disable).setVisible(false);
|
||||
|
@ -103,7 +130,13 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
|
||||
@Override
|
||||
void onBackendConnected() {
|
||||
if (selectedAccountJid != null) {
|
||||
this.selectedAccount = xmppConnectionService.findAccountByJid(selectedAccountJid);
|
||||
}
|
||||
refreshUiReal();
|
||||
if (this.mPostponedActivityResult != null) {
|
||||
this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
|
||||
}
|
||||
if (Config.X509_VERIFICATION && this.accountList.size() == 0) {
|
||||
if (mInvokedAddAccount.compareAndSet(false, true)) {
|
||||
addAccountFromKey();
|
||||
|
@ -149,7 +182,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
deleteAccount(selectedAccount);
|
||||
return true;
|
||||
case R.id.mgmt_account_announce_pgp:
|
||||
choosePgpSignId(selectedAccount);
|
||||
publishOpenPGPPublicKey(selectedAccount);
|
||||
return true;
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
|
@ -284,7 +317,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
|
||||
private void publishOpenPGPPublicKey(Account account) {
|
||||
if (ManageAccountActivity.this.hasPgp()) {
|
||||
announcePgp(account, null);
|
||||
choosePgpSignId(selectedAccount);
|
||||
} else {
|
||||
this.showInstallPgpDialog();
|
||||
}
|
||||
|
@ -312,6 +345,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (xmppConnectionServiceBound) {
|
||||
if (requestCode == REQUEST_CHOOSE_PGP_ID) {
|
||||
if (data.getExtras().containsKey(OpenPgpApi.EXTRA_SIGN_KEY_ID)) {
|
||||
selectedAccount.setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID));
|
||||
|
@ -322,6 +356,10 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
} else if (requestCode == REQUEST_ANNOUNCE_PGP) {
|
||||
announcePgp(selectedAccount, null);
|
||||
}
|
||||
this.mPostponedActivityResult = null;
|
||||
} else {
|
||||
this.mPostponedActivityResult = new Pair<>(requestCode, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue