1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-17 21:32:26 -05:00

Save/Restore activity state

This assures that changes made to the port setting and to the chosen
client certificate are saved and restored.
This commit is contained in:
Joe Steele 2014-07-17 11:36:54 -04:00
parent 2e981e0c7d
commit acab554ee5
4 changed files with 58 additions and 24 deletions

View File

@ -2,12 +2,16 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android" > <merge xmlns:android="http://schemas.android.com/apk/res/android" >
<Button <Button
android:id="@+id/client_certificate_spinner_button"
style="?android:attr/spinnerStyle" style="?android:attr/spinnerStyle"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" /> android:layout_weight="1"
android:text="@string/client_certificate_spinner_empty"
android:freezesText="true" />
<ImageButton <ImageButton
android:id="@+id/client_certificate_spinner_delete"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"

View File

@ -278,19 +278,21 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mSubscribedFoldersOnly.setChecked(mAccount.subscribedFoldersOnly()); mSubscribedFoldersOnly.setChecked(mAccount.subscribedFoldersOnly());
if (savedInstanceState == null) {
initializeViewListeners(); initializeViewListeners();
validateFields(); validateFields();
}
} catch (Exception e) { } catch (Exception e) {
failure(e); failure(e);
} }
} }
/** /**
* Called at the end of {@code onCreate()}, after the views have been * Called at the end of either {@code onCreate()} or
* initialized, so that the listeners are not triggered during the view * {@code onRestoreInstanceState()}, after the views have been initialized,
* initialization. This avoids needless calls to {@code validateFields()} * so that the listeners are not triggered during the view initialization.
* which is called at the end of {@code onCreate()}. * This avoids needless calls to {@code validateFields()} which is called
* immediately after this is called.
*/ */
private void initializeViewListeners() { private void initializeViewListeners() {
@ -341,6 +343,19 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid()); outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
} }
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
/*
* We didn't want the listeners active while the state was being restored
* because they could overwrite the restored port with a default port when
* the security type was restored.
*/
initializeViewListeners();
validateFields();
}
/** /**
* Shows/hides password field and client certificate spinner * Shows/hides password field and client certificate spinner
*/ */

View File

@ -174,9 +174,10 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
} }
mCurrentPortViewSetting = mPortView.getText().toString(); mCurrentPortViewSetting = mPortView.getText().toString();
if (savedInstanceState == null) {
initializeViewListeners(); initializeViewListeners();
validateFields(); validateFields();
}
} catch (Exception e) { } catch (Exception e) {
/* /*
* We should always be able to parse our own settings. * We should always be able to parse our own settings.
@ -187,10 +188,11 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
} }
/** /**
* Called at the end of {@code onCreate()}, after the views have been * Called at the end of either {@code onCreate()} or
* initialized, so that the listeners are not triggered during the view * {@code onRestoreInstanceState()}, after the views have been initialized,
* initialization. This avoids needless calls to {@code validateFields()} * so that the listeners are not triggered during the view initialization.
* which is called at the end of {@code onCreate()}. * This avoids needless calls to {@code validateFields()} which is called
* immediately after this is called.
*/ */
private void initializeViewListeners() { private void initializeViewListeners() {
@ -242,6 +244,19 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid()); outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
} }
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
/*
* We didn't want the listeners active while the state was being restored
* because they could overwrite the restored port with a default port when
* the security type was restored.
*/
initializeViewListeners();
validateFields();
}
/** /**
* Shows/hides password field and client certificate spinner * Shows/hides password field and client certificate spinner
*/ */

View File

@ -47,8 +47,7 @@ public class ClientCertificateSpinner extends LinearLayout {
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.client_certificate_spinner, this, true); inflater.inflate(R.layout.client_certificate_spinner, this, true);
mSelection = (Button) getChildAt(0); mSelection = (Button) findViewById(R.id.client_certificate_spinner_button);
updateView();
mSelection.setOnClickListener(new OnClickListener() { mSelection.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -56,7 +55,7 @@ public class ClientCertificateSpinner extends LinearLayout {
} }
}); });
mDeleteButton = (ImageButton) getChildAt(1); mDeleteButton = (ImageButton) findViewById(R.id.client_certificate_spinner_delete);
mDeleteButton.setOnClickListener(new OnClickListener() { mDeleteButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -65,10 +64,6 @@ public class ClientCertificateSpinner extends LinearLayout {
}); });
} }
public ClientCertificateSpinner(Context context) {
this(context, null);
}
public void setAlias(String alias) { public void setAlias(String alias) {
// Note: KeyChainAliasCallback gives back "" on cancel // Note: KeyChainAliasCallback gives back "" on cancel
if (alias != null && alias.equals("")) { if (alias != null && alias.equals("")) {
@ -80,16 +75,21 @@ public class ClientCertificateSpinner extends LinearLayout {
mActivity.runOnUiThread(new Runnable() { mActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
updateView();
if (mListener != null) { if (mListener != null) {
mListener.onClientCertificateChanged(mAlias); mListener.onClientCertificateChanged(mAlias);
} }
updateView();
} }
}); });
} }
public String getAlias() { public String getAlias() {
return mAlias; String alias = mSelection.getText().toString();
if (alias.equals(mActivity.getString(R.string.client_certificate_spinner_empty))) {
return null;
} else {
return alias;
}
} }
private void onDelete() { private void onDelete() {