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" >
<Button
android:id="@+id/client_certificate_spinner_button"
style="?android:attr/spinnerStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" />
android:layout_weight="1"
android:text="@string/client_certificate_spinner_empty"
android:freezesText="true" />
<ImageButton
android:id="@+id/client_certificate_spinner_delete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"

View File

@ -278,19 +278,21 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mSubscribedFoldersOnly.setChecked(mAccount.subscribedFoldersOnly());
if (savedInstanceState == null) {
initializeViewListeners();
validateFields();
}
} catch (Exception e) {
failure(e);
}
}
/**
* Called at the end of {@code onCreate()}, after the views have been
* initialized, so that the listeners are not triggered during the view
* initialization. This avoids needless calls to {@code validateFields()}
* which is called at the end of {@code onCreate()}.
* Called at the end of either {@code onCreate()} or
* {@code onRestoreInstanceState()}, after the views have been initialized,
* so that the listeners are not triggered during the view initialization.
* This avoids needless calls to {@code validateFields()} which is called
* immediately after this is called.
*/
private void initializeViewListeners() {
@ -341,6 +343,19 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
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
*/

View File

@ -174,9 +174,10 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
}
mCurrentPortViewSetting = mPortView.getText().toString();
if (savedInstanceState == null) {
initializeViewListeners();
validateFields();
}
} catch (Exception e) {
/*
* 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
* initialized, so that the listeners are not triggered during the view
* initialization. This avoids needless calls to {@code validateFields()}
* which is called at the end of {@code onCreate()}.
* Called at the end of either {@code onCreate()} or
* {@code onRestoreInstanceState()}, after the views have been initialized,
* so that the listeners are not triggered during the view initialization.
* This avoids needless calls to {@code validateFields()} which is called
* immediately after this is called.
*/
private void initializeViewListeners() {
@ -242,6 +244,19 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
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
*/

View File

@ -47,8 +47,7 @@ public class ClientCertificateSpinner extends LinearLayout {
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.client_certificate_spinner, this, true);
mSelection = (Button) getChildAt(0);
updateView();
mSelection = (Button) findViewById(R.id.client_certificate_spinner_button);
mSelection.setOnClickListener(new OnClickListener() {
@Override
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() {
@Override
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) {
// Note: KeyChainAliasCallback gives back "" on cancel
if (alias != null && alias.equals("")) {
@ -80,16 +75,21 @@ public class ClientCertificateSpinner extends LinearLayout {
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateView();
if (mListener != null) {
mListener.onClientCertificateChanged(mAlias);
}
updateView();
}
});
}
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() {