Fix cancel handling in account settings screens
- Don't loop on the confirmation dialog - Do a deep copy of the initial hostauth state - Save the initial hostauth state on configuration changes - Collect the user input before comparing the old state with the new b/14285245 Change-Id: Ibc033fac525be2a4cb03c6a0d1e92254a2236b4c
This commit is contained in:
parent
1ba8ba8033
commit
294593c5f5
@ -47,6 +47,8 @@ public abstract class AccountServerBaseFragment extends AccountSetupFragment
|
||||
private static final String BUNDLE_KEY_SETTINGS = "AccountServerBaseFragment.settings";
|
||||
private static final String BUNDLE_KEY_ACTIVITY_TITLE = "AccountServerBaseFragment.title";
|
||||
private static final String BUNDLE_KEY_SAVING = "AccountServerBaseFragment.saving";
|
||||
private static final String BUNDLE_KEY_SENDAUTH = "AccountServerBaseFragment.sendAuth";
|
||||
private static final String BUNDLE_KEY_RECVAUTH = "AccountServerBaseFragment.recvAuth";
|
||||
|
||||
protected Context mAppContext;
|
||||
/**
|
||||
@ -112,6 +114,8 @@ public abstract class AccountServerBaseFragment extends AccountSetupFragment
|
||||
if (savedInstanceState != null) {
|
||||
mSettingsMode = savedInstanceState.getBoolean(BUNDLE_KEY_SETTINGS);
|
||||
mSaving = savedInstanceState.getBoolean(BUNDLE_KEY_SAVING);
|
||||
mLoadedSendAuth = savedInstanceState.getParcelable(BUNDLE_KEY_SENDAUTH);
|
||||
mLoadedRecvAuth = savedInstanceState.getParcelable(BUNDLE_KEY_RECVAUTH);
|
||||
} else if (getArguments() != null) {
|
||||
mSettingsMode = getArguments().getBoolean(BUNDLE_KEY_SETTINGS);
|
||||
}
|
||||
@ -160,6 +164,8 @@ public abstract class AccountServerBaseFragment extends AccountSetupFragment
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(BUNDLE_KEY_ACTIVITY_TITLE, (String) getActivity().getTitle());
|
||||
outState.putBoolean(BUNDLE_KEY_SETTINGS, mSettingsMode);
|
||||
outState.putParcelable(BUNDLE_KEY_SENDAUTH, mLoadedSendAuth);
|
||||
outState.putParcelable(BUNDLE_KEY_RECVAUTH, mLoadedRecvAuth);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -178,6 +184,7 @@ public abstract class AccountServerBaseFragment extends AccountSetupFragment
|
||||
public void onClick(View v) {
|
||||
final int viewId = v.getId();
|
||||
if (viewId == R.id.cancel) {
|
||||
collectUserInputInternal();
|
||||
getActivity().onBackPressed();
|
||||
} else if (viewId == R.id.done) {
|
||||
collectUserInput();
|
||||
@ -280,5 +287,11 @@ public abstract class AccountServerBaseFragment extends AccountSetupFragment
|
||||
/**
|
||||
* Collect the user's input into the setup data object. Concrete classes must implement.
|
||||
*/
|
||||
public abstract void collectUserInput();
|
||||
public abstract int collectUserInputInternal();
|
||||
|
||||
public void collectUserInput() {
|
||||
final int phase = collectUserInputInternal();
|
||||
final Callback callback = (Callback) getActivity();
|
||||
callback.onAccountServerUIComplete(phase);
|
||||
}
|
||||
}
|
||||
|
@ -597,7 +597,7 @@ public class AccountSettings extends PreferenceActivity implements
|
||||
* Forcefully go backward in the stack. This may potentially discard unsaved settings.
|
||||
*/
|
||||
private void forceBack() {
|
||||
onBackPressed();
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,6 +22,7 @@ import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
@ -398,7 +399,13 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
||||
mClientCertificateSelector.setCertificate(recvAuth.mClientCertAlias);
|
||||
}
|
||||
|
||||
mLoadedRecvAuth = recvAuth;
|
||||
// Make a deep copy of the HostAuth to compare with later
|
||||
final Parcel parcel = Parcel.obtain();
|
||||
parcel.writeParcelable(recvAuth, recvAuth.describeContents());
|
||||
parcel.setDataPosition(0);
|
||||
mLoadedRecvAuth = parcel.readParcelable(HostAuth.class.getClassLoader());
|
||||
parcel.recycle();
|
||||
|
||||
mLoaded = true;
|
||||
validateFields();
|
||||
}
|
||||
@ -530,7 +537,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
||||
* Entry point from Activity, when "next" button is clicked
|
||||
*/
|
||||
@Override
|
||||
public void collectUserInput() {
|
||||
public int collectUserInputInternal() {
|
||||
final Account account = mSetupData.getAccount();
|
||||
|
||||
// Make sure delete policy is an valid option before using it; otherwise, the results are
|
||||
@ -568,8 +575,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
||||
}
|
||||
recvAuth.mClientCertAlias = mClientCertificateSelector.getCertificate();
|
||||
|
||||
final Callback callback = (Callback) getActivity();
|
||||
callback.onAccountServerUIComplete(SetupDataFragment.CHECK_INCOMING);
|
||||
return SetupDataFragment.CHECK_INCOMING;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
@ -256,7 +257,13 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
||||
updatePortFromSecurityType();
|
||||
}
|
||||
|
||||
mLoadedSendAuth = sendAuth;
|
||||
// Make a deep copy of the HostAuth to compare with later
|
||||
final Parcel parcel = Parcel.obtain();
|
||||
parcel.writeParcelable(sendAuth, sendAuth.describeContents());
|
||||
parcel.setDataPosition(0);
|
||||
mLoadedSendAuth = parcel.readParcelable(HostAuth.class.getClassLoader());
|
||||
parcel.recycle();
|
||||
|
||||
mLoaded = true;
|
||||
validateFields();
|
||||
}
|
||||
@ -362,7 +369,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
||||
* Entry point from Activity, when "next" button is clicked
|
||||
*/
|
||||
@Override
|
||||
public void collectUserInput() {
|
||||
public int collectUserInputInternal() {
|
||||
final Account account = mSetupData.getAccount();
|
||||
final HostAuth sendAuth = account.getOrCreateHostAuthSend(mAppContext);
|
||||
|
||||
@ -387,8 +394,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
||||
sendAuth.setConnection(mBaseScheme, serverAddress, serverPort, securityType);
|
||||
sendAuth.mDomain = null;
|
||||
|
||||
final Callback callback = (Callback) getActivity();
|
||||
callback.onAccountServerUIComplete(SetupDataFragment.CHECK_OUTGOING);
|
||||
return SetupDataFragment.CHECK_OUTGOING;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user