1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Trigger certificate chooser when check box checked

For convenience.  Implemented in onCheckChanged().

As a consequence, onCheckChanged() must not be triggered when the instance
state is restored (would occur if the check box state was checked when
saved), otherwise the certificate chooser would pop up once the state was
restored.  Therefore, all listeners have been moved into
initializeViewListeners() which is invoked after the state has been
restored.

Because onCheckChanged() is no longer triggered in
onRestoreInstanceState(), updateViewVisibility() was implemented to
restore the view visibility.
This commit is contained in:
Joe Steele 2014-07-27 00:59:28 -04:00
parent 301ac48a38
commit cf3561da5c

View File

@ -87,18 +87,19 @@ public class AccountSetupBasics extends K9Activity
mNextButton.setOnClickListener(this);
mManualSetupButton.setOnClickListener(this);
if (savedInstanceState == null) {
initializeViewListeners();
validateFields();
}
}
private void initializeViewListeners() {
mEmailView.addTextChangedListener(this);
mPasswordView.addTextChangedListener(this);
mClientCertificateCheckBox.setOnCheckedChangeListener(this);
mClientCertificateSpinner.setOnClientCertificateChangedListener(this);
}
@Override
public void onResume() {
super.onResume();
validateFields();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -125,6 +126,18 @@ public class AccountSetupBasics extends K9Activity
}
mCheckedIncoming = savedInstanceState.getBoolean(STATE_KEY_CHECKED_INCOMING);
updateViewVisibility(mClientCertificateCheckBox.isChecked());
/*
* We wait until now to initialize the listeners because we didn't want
* the OnCheckedChangeListener active while the
* mClientCertificateCheckBox state was being restored because it could
* trigger the pop-up of a ClientCertificateSpinner.chooseCertificate()
* dialog.
*/
initializeViewListeners();
validateFields();
}
public void afterTextChanged(Editable s) {
@ -147,7 +160,17 @@ public class AccountSetupBasics extends K9Activity
*/
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
updateViewVisibility(isChecked);
validateFields();
// Have the user select (or confirm) the client certificate
if (isChecked) {
mClientCertificateSpinner.chooseCertificate();
}
}
private void updateViewVisibility(boolean usingCertificates) {
if (usingCertificates) {
// hide password fields, show client certificate spinner
mPasswordView.setVisibility(View.GONE);
mClientCertificateSpinner.setVisibility(View.VISIBLE);
@ -156,7 +179,6 @@ public class AccountSetupBasics extends K9Activity
mPasswordView.setVisibility(View.VISIBLE);
mClientCertificateSpinner.setVisibility(View.GONE);
}
validateFields();
}
private void validateFields() {