From 1c4ebf15b70c5907a517663b61236eab0961036f Mon Sep 17 00:00:00 2001 From: Sander Bogaert Date: Fri, 11 Nov 2011 17:21:08 +0100 Subject: [PATCH] Added support for "Default account" setting in setup. --- res/layout/account_dialog_new.xml | 6 ++++++ res/layout/account_dialog_password.xml | 6 ++++++ .../activity/setup/AbstractSetupConfirmActivity.java | 3 +++ .../setup/AccountSetupAutoConfiguration.java | 12 ++++++++---- .../activity/setup/AccountSetupConfirmIncoming.java | 5 +++-- .../activity/setup/AccountSetupConfirmOutgoing.java | 10 +++++----- .../fsck/k9/activity/setup/AccountSetupIndex.java | 9 ++++++--- 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/res/layout/account_dialog_new.xml b/res/layout/account_dialog_new.xml index 5165bdd61..c4ec682e7 100644 --- a/res/layout/account_dialog_new.xml +++ b/res/layout/account_dialog_new.xml @@ -39,6 +39,12 @@ android:lines="1" android:text="@string/account_setup_basics_manual_setup_action"/> + + + + protocolAdapter = new ArrayAdapter(this, diff --git a/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java b/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java index 725f655e5..86345bf74 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java @@ -42,6 +42,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On private static final String EMAIL_ADDRESS = "account"; private static final String PASSWORD = "password"; + private static final String MAKEDEFAULT = "default"; // timeout for testing services availability ( in ms ) private static final int TIMEOUT = 5000; @@ -87,6 +88,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On private String mEmailAddress; private String mPassword; private String mLastMessage; + private boolean mMakeDefault; private AutoconfigInfo mAutoConfigInfo; private boolean bForceManual = false; private boolean bDoneSearching = false; @@ -97,10 +99,11 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On /* Start the auto-configuration activity */ - public static void actionAttemptConfiguration(Activity context, String email, String password) { + public static void actionAttemptConfiguration(Activity context, String email, String password, boolean makedefault) { Intent i = new Intent(context, AccountSetupAutoConfiguration.class); i.putExtra(EMAIL_ADDRESS, email); i.putExtra(PASSWORD, password); + i.putExtra(MAKEDEFAULT, makedefault); context.startActivity(i); } @@ -129,6 +132,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On // Getting our data to work with mEmailAddress = getIntent().getStringExtra(EMAIL_ADDRESS); mPassword = getIntent().getStringExtra(PASSWORD); + mMakeDefault = getIntent().getBooleanExtra(MAKEDEFAULT, false); // The real action, in a separate thread new Thread() { @@ -381,12 +385,12 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On // autoconfig failed, proceed by manual setup if( bForceManual ){ // TODO: get boolean from user - AccountSetupAccountType.actionStartManualConfiguration(this, mEmailAddress, mPassword, false); + AccountSetupAccountType.actionStartManualConfiguration(this, mEmailAddress, mPassword, mMakeDefault); finish(); // launch confirm activities }else{ AccountSetupConfirmIncoming.actionConfirmIncoming - (this, null, mEmailAddress, mPassword, mAutoConfigInfo); + (this, null, mEmailAddress, mPassword, mAutoConfigInfo,mMakeDefault); finish(); } break; @@ -447,7 +451,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On e.getMessage() == null ? "" : e.getMessage()), true); } // TODO: rework this so we just retry the last URL, DO NOT RESTART THE WHOLE ACTIVITY!! - AccountSetupAutoConfiguration.actionAttemptConfiguration(AccountSetupAutoConfiguration.this, mEmailAddress, mPassword); + AccountSetupAutoConfiguration.actionAttemptConfiguration(AccountSetupAutoConfiguration.this, mEmailAddress, mPassword, mMakeDefault); } }) .setNegativeButton( diff --git a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java index e45eac86a..3240b6112 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java @@ -24,7 +24,7 @@ import java.util.List; public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity { // account is allowed to be null - public static void actionConfirmIncoming(Context context, Account account, String email, String password, AutoconfigInfo info) { + public static void actionConfirmIncoming(Context context, Account account, String email, String password, AutoconfigInfo info, boolean makedefault) { Intent i = new Intent(context, AccountSetupConfirmIncoming.class); if( account != null ) i.putExtra(EXTRA_ACCOUNT, account.getUuid()); @@ -32,6 +32,7 @@ public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity { i.putExtra(EXTRA_EMAIL, email); i.putExtra(EXTRA_PASSWORD, password); i.putExtra(EXTRA_CONFIG_INFO, info); + i.putExtra(EXTRA_MAKEDEFAULT, makedefault); context.startActivity(i); } @@ -60,7 +61,7 @@ public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity { null,null,null); mAccount.setStoreUri(uri.toString()); - AccountSetupConfirmOutgoing.actionConfirmOutgoing(this, mAccount, mEmail, mPassword, mConfigInfo); + AccountSetupConfirmOutgoing.actionConfirmOutgoing(this, mAccount, mEmail, mPassword, mConfigInfo, mMakeDefault); } catch (UnsupportedEncodingException enc) {} catch (URISyntaxException use) { diff --git a/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java index a6bf30084..518ce115c 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java @@ -24,12 +24,13 @@ import java.util.List; public class AccountSetupConfirmOutgoing extends AbstractSetupConfirmActivity{ // account is allowed to be null - public static void actionConfirmOutgoing(Context context, Account account, String email, String password, AutoconfigInfo info) { + public static void actionConfirmOutgoing(Context context, Account account, String email, String password, AutoconfigInfo info, boolean makedefault) { Intent i = new Intent(context, AccountSetupConfirmOutgoing.class); i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_EMAIL, email); i.putExtra(EXTRA_PASSWORD, password); i.putExtra(EXTRA_CONFIG_INFO, info); + i.putExtra(EXTRA_MAKEDEFAULT, makedefault); context.startActivity(i); } @@ -84,14 +85,13 @@ public class AccountSetupConfirmOutgoing extends AbstractSetupConfirmActivity{ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (Intent.ACTION_EDIT.equals(getIntent().getAction())) { + // should verify but this normaly shouldn't happen, this activity is only used for initial setup, not edit mAccount.save(Preferences.getPreferences(this)); finish(); } else { - // have to pop up to ask if it should be default account now - // hard-coded now for test purposes - AccountSetupOptions.actionOptions(this, mAccount, true); + AccountSetupOptions.actionOptions(this, mAccount, mMakeDefault); finish(); } } } -} \ No newline at end of file +} diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIndex.java b/src/com/fsck/k9/activity/setup/AccountSetupIndex.java index 152ad83a5..389236e4c 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIndex.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIndex.java @@ -38,7 +38,7 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList public enum SuggestionType { DEVICE, BACKUP, NEW } // temp hard coded value ( since we don't ask if it should be default account for now ) - private boolean bTmpDefaultAccount = true; + private boolean bMakeDefault = true; private Account mAccount; private Button mNewAccountDialogButton; @@ -119,6 +119,7 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList final EditText emailField = ((EditText)dialog.findViewById(R.id.account_dialog_address_field)); final EditText passwordField = ((EditText)dialog.findViewById(R.id.account_dialog_password_field)); final CheckBox manualCheck = (CheckBox)dialog.findViewById(R.id.account_dialog_manual_box); + final CheckBox defaultCheck = (CheckBox)dialog.findViewById(R.id.account_dialog_default_box); mNewAccountDialogButton = ((Button)dialog.findViewById(R.id.account_dialog_next)); @@ -160,11 +161,13 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList final EditText passwordField = ((EditText) dialog.findViewById(R.id.account_dialog_password_field)); final CheckBox manualCheck = (CheckBox)dialog.findViewById(R.id.account_dialog_manual_box); + final CheckBox defaultCheck = (CheckBox)dialog.findViewById(R.id.account_dialog_default_box); mPasswordDialogButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { String email = args.get(BUNDLE_TYPE_SUGGESTION).toString(); String password = passwordField.getText().toString(); + bMakeDefault = defaultCheck.isChecked(); // TODO: replace this with a few listeners on the fields that activate/deactive the button on acceptable values if( password.isEmpty() ) return; @@ -180,12 +183,12 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList } private void onManualSetup(String email, String password) { - AccountSetupAccountType.actionStartManualConfiguration(this, email, password, bTmpDefaultAccount); + AccountSetupAccountType.actionStartManualConfiguration(this, email, password, bMakeDefault); finish(); } private void startSettingsDetection(String email, String password) { - AccountSetupAutoConfiguration.actionAttemptConfiguration(this, email, password); + AccountSetupAutoConfiguration.actionAttemptConfiguration(this, email, password, bMakeDefault); finish(); }