survive rotation in editaccount

This commit is contained in:
Daniel Gultsch 2016-08-26 09:10:59 +02:00
parent e98ab37c9d
commit 9e0145a8f6
2 changed files with 53 additions and 18 deletions

View File

@ -1136,7 +1136,9 @@ public class ConversationActivity extends XmppActivity
} else if (Config.MAGIC_CREATE_DOMAIN != null) { } else if (Config.MAGIC_CREATE_DOMAIN != null) {
startActivity(new Intent(this, WelcomeActivity.class)); startActivity(new Intent(this, WelcomeActivity.class));
} else { } else {
startActivity(new Intent(this, EditAccountActivity.class)); Intent editAccount = new Intent(this, EditAccountActivity.class);
editAccount.putExtra("init",true);
startActivity(editAccount);
} }
finish(); finish();
} }

View File

@ -1,5 +1,6 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.app.ActionBar;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -241,6 +242,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
}; };
private Toast mFetchingMamPrefsToast; private Toast mFetchingMamPrefsToast;
private TableRow mPushRow; private TableRow mPushRow;
private String mSavedInstanceAccount;
private boolean mSavedInstanceInit = false;
public void refreshUiReal() { public void refreshUiReal() {
invalidateOptionsMenu(); invalidateOptionsMenu();
@ -449,6 +452,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
this.mSavedInstanceAccount = savedInstanceState.getString("account");
this.mSavedInstanceInit = savedInstanceState.getBoolean("initMode", false);
}
setContentView(R.layout.activity_edit_account); setContentView(R.layout.activity_edit_account);
this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid); this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
this.mAccountJid.addTextChangedListener(this.mTextWatcher); this.mAccountJid.addTextChangedListener(this.mTextWatcher);
@ -581,7 +588,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} catch (final InvalidJidException | NullPointerException ignored) { } catch (final InvalidJidException | NullPointerException ignored) {
this.jidToEdit = null; this.jidToEdit = null;
} }
this.mInitMode = getIntent().getBooleanExtra("init", false) || this.jidToEdit == null; boolean init = getIntent().getBooleanExtra("init", false);
this.mInitMode = init || this.jidToEdit == null;
this.messageFingerprint = getIntent().getStringExtra("fingerprint"); this.messageFingerprint = getIntent().getStringExtra("fingerprint");
if (!mInitMode) { if (!mInitMode) {
this.mRegisterNew.setVisibility(View.GONE); this.mRegisterNew.setVisibility(View.GONE);
@ -590,8 +598,13 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
} else { } else {
this.mAvatar.setVisibility(View.GONE); this.mAvatar.setVisibility(View.GONE);
if (getActionBar() != null) { ActionBar ab = getActionBar();
getActionBar().setTitle(R.string.action_add_account); if (ab != null) {
if (init && Config.MAGIC_CREATE_DOMAIN == null) {
ab.setDisplayShowHomeEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
}
ab.setTitle(R.string.action_add_account);
} }
} }
} }
@ -602,11 +615,30 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE); this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
} }
@Override
public void onSaveInstanceState(final Bundle savedInstanceState) {
if (mAccount != null) {
savedInstanceState.putString("account", mAccount.getJid().toBareJid().toString());
savedInstanceState.putBoolean("initMode", mInitMode);
}
super.onSaveInstanceState(savedInstanceState);
}
@Override @Override
protected void onBackendConnected() { protected void onBackendConnected() {
if (this.jidToEdit != null) { if (mSavedInstanceAccount != null) {
try {
this.mAccount = xmppConnectionService.findAccountByJid(Jid.fromString(mSavedInstanceAccount));
this.mInitMode = mSavedInstanceInit;
} catch (InvalidJidException e) {
this.mAccount = null;
}
} else if (this.jidToEdit != null) {
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit); this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
if (this.mAccount != null) { }
if (mAccount != null) {
this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER); this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER);
this.mUsernameMode |= mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && mAccount.isOptionSet(Account.OPTION_REGISTER); this.mUsernameMode |= mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && mAccount.isOptionSet(Account.OPTION_REGISTER);
if (this.mAccount.getPrivateKeyAlias() != null) { if (this.mAccount.getPrivateKeyAlias() != null) {
@ -617,7 +649,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
updateAccountInformation(true); updateAccountInformation(true);
} }
}
if (Config.MAGIC_CREATE_DOMAIN == null && this.xmppConnectionService.getAccounts().size() == 0) { if (Config.MAGIC_CREATE_DOMAIN == null && this.xmppConnectionService.getAccounts().size() == 0) {
this.mCancelButton.setEnabled(false); this.mCancelButton.setEnabled(false);
this.mCancelButton.setTextColor(getSecondaryTextColor()); this.mCancelButton.setTextColor(getSecondaryTextColor());