mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-13 13:05:03 -05:00
Moved the initialisation of a new account to the AccountSetupAccountType class. This is used when a manual configuration run is started. Doing this will allow to avoid duplicated code later on ( not having to do the initialisation in each class of the setup that could possibly initiate a manual configuration run ).
This commit is contained in:
parent
8be8f62fb8
commit
b30e67c270
@ -14,7 +14,12 @@ import com.fsck.k9.K9;
|
|||||||
import com.fsck.k9.Preferences;
|
import com.fsck.k9.Preferences;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.activity.K9Activity;
|
import com.fsck.k9.activity.K9Activity;
|
||||||
|
import com.fsck.k9.helper.Contacts;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompts the user to select an account type. The account type, along with the
|
* Prompts the user to select an account type. The account type, along with the
|
||||||
@ -22,12 +27,14 @@ import java.net.URI;
|
|||||||
* AccountSetupIncoming activity.
|
* AccountSetupIncoming activity.
|
||||||
*/
|
*/
|
||||||
public class AccountSetupAccountType extends K9Activity implements OnClickListener {
|
public class AccountSetupAccountType extends K9Activity implements OnClickListener {
|
||||||
private static final String EXTRA_ACCOUNT = "account";
|
|
||||||
|
|
||||||
|
private static final String EXTRA_IS_MANUAL = "mManual";
|
||||||
|
private static final String EXTRA_EMAIL = "email";
|
||||||
|
private static final String EXTRA_PASSWORD = "password";
|
||||||
|
private static final String EXTRA_ACCOUNT = "account";
|
||||||
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
|
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
|
||||||
|
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
|
|
||||||
private boolean mMakeDefault;
|
private boolean mMakeDefault;
|
||||||
|
|
||||||
public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) {
|
public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) {
|
||||||
@ -37,6 +44,93 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
|
|||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void actionStartManualConfiguration(Context context, String email, String password, boolean makeDefault) {
|
||||||
|
Intent i = new Intent(context, AccountSetupAccountType.class);
|
||||||
|
i.putExtra(EXTRA_IS_MANUAL, true);
|
||||||
|
i.putExtra(EXTRA_EMAIL, email);
|
||||||
|
i.putExtra(EXTRA_PASSWORD, password);
|
||||||
|
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
|
||||||
|
context.startActivity(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Initialises a new account blank.
|
||||||
|
*/
|
||||||
|
private void initialiseAccount(String email, String password) {
|
||||||
|
String[] emailParts = splitEmail(email);
|
||||||
|
String user = emailParts[0];
|
||||||
|
String domain = emailParts[1];
|
||||||
|
|
||||||
|
mAccount = Preferences.getPreferences(this).newAccount();
|
||||||
|
mAccount.setName(getOwnerName());
|
||||||
|
mAccount.setEmail(email);
|
||||||
|
try {
|
||||||
|
String userEnc = URLEncoder.encode(user, "UTF-8");
|
||||||
|
String passwordEnc = URLEncoder.encode(password, "UTF-8");
|
||||||
|
|
||||||
|
URI uri = new URI("placeholder", userEnc + ":" + passwordEnc, "mail." + domain, -1, null,
|
||||||
|
null, null);
|
||||||
|
mAccount.setStoreUri(uri.toString());
|
||||||
|
mAccount.setTransportUri(uri.toString());
|
||||||
|
} catch (UnsupportedEncodingException enc) {
|
||||||
|
// This really shouldn't happen since the encoding is hardcoded to UTF-8
|
||||||
|
Log.e(K9.LOG_TAG, "Couldn't urlencode username or password.", enc);
|
||||||
|
} catch (URISyntaxException use) {
|
||||||
|
/*
|
||||||
|
* If we can't set up the URL we just continue. It's only for
|
||||||
|
* convenience.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts));
|
||||||
|
mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash));
|
||||||
|
mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Helper methods for the above, these could be in a static class in the helper package. But since
|
||||||
|
this is the only place they are used for now I'll leave them here.
|
||||||
|
*/
|
||||||
|
private String[] splitEmail(String email) {
|
||||||
|
String[] retParts = new String[2];
|
||||||
|
String[] emailParts = email.split("@");
|
||||||
|
retParts[0] = (emailParts.length > 0) ? emailParts[0] : "";
|
||||||
|
retParts[1] = (emailParts.length > 1) ? emailParts[1] : "";
|
||||||
|
return retParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getOwnerName() {
|
||||||
|
String name = null;
|
||||||
|
try {
|
||||||
|
name = Contacts.getInstance(this).getOwnerName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(K9.LOG_TAG, "Could not get owner name, using default account name", e);
|
||||||
|
}
|
||||||
|
if (name == null || name.length() == 0) {
|
||||||
|
try {
|
||||||
|
name = getDefaultAccountName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(K9.LOG_TAG, "Could not get default account name", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name == null) {
|
||||||
|
name = "";
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDefaultAccountName() {
|
||||||
|
String name = null;
|
||||||
|
Account account = Preferences.getPreferences(this).getDefaultAccount();
|
||||||
|
if (account != null) {
|
||||||
|
name = account.getName();
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
'Constructor'
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -45,9 +139,14 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
|
|||||||
((Button)findViewById(R.id.imap)).setOnClickListener(this);
|
((Button)findViewById(R.id.imap)).setOnClickListener(this);
|
||||||
((Button)findViewById(R.id.webdav)).setOnClickListener(this);
|
((Button)findViewById(R.id.webdav)).setOnClickListener(this);
|
||||||
|
|
||||||
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
|
if( getIntent().getStringExtra(EXTRA_IS_MANUAL) != null){
|
||||||
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
initialiseAccount(getIntent().getStringExtra(EXTRA_EMAIL),
|
||||||
mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
|
getIntent().getStringExtra(EXTRA_PASSWORD));
|
||||||
|
}else{
|
||||||
|
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
|
||||||
|
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
||||||
|
mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPop() {
|
private void onPop() {
|
||||||
|
@ -180,35 +180,7 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onManualSetup(String email, String password) {
|
private void onManualSetup(String email, String password) {
|
||||||
String[] emailParts = splitEmail(email);
|
AccountSetupAccountType.actionStartManualConfiguration(this, email, password, bTmpDefaultAccount);
|
||||||
String user = emailParts[0];
|
|
||||||
String domain = emailParts[1];
|
|
||||||
|
|
||||||
mAccount = Preferences.getPreferences(this).newAccount();
|
|
||||||
mAccount.setName(getOwnerName());
|
|
||||||
mAccount.setEmail(email);
|
|
||||||
try {
|
|
||||||
String userEnc = URLEncoder.encode(user, "UTF-8");
|
|
||||||
String passwordEnc = URLEncoder.encode(password, "UTF-8");
|
|
||||||
|
|
||||||
URI uri = new URI("placeholder", userEnc + ":" + passwordEnc, "mail." + domain, -1, null,
|
|
||||||
null, null);
|
|
||||||
mAccount.setStoreUri(uri.toString());
|
|
||||||
mAccount.setTransportUri(uri.toString());
|
|
||||||
} catch (UnsupportedEncodingException enc) {
|
|
||||||
// This really shouldn't happen since the encoding is hardcoded to UTF-8
|
|
||||||
Log.e(K9.LOG_TAG, "Couldn't urlencode username or password.", enc);
|
|
||||||
} catch (URISyntaxException use) {
|
|
||||||
/*
|
|
||||||
* If we can't set up the URL we just continue. It's only for
|
|
||||||
* convenience.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts));
|
|
||||||
mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash));
|
|
||||||
mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent));
|
|
||||||
|
|
||||||
AccountSetupAccountType.actionSelectAccountType(this, mAccount, bTmpDefaultAccount);
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,46 +219,6 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Some helpers copy pasted from previous setup. Need a review.
|
|
||||||
*/
|
|
||||||
private String[] splitEmail(String email) {
|
|
||||||
String[] retParts = new String[2];
|
|
||||||
String[] emailParts = email.split("@");
|
|
||||||
retParts[0] = (emailParts.length > 0) ? emailParts[0] : "";
|
|
||||||
retParts[1] = (emailParts.length > 1) ? emailParts[1] : "";
|
|
||||||
return retParts;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getOwnerName() {
|
|
||||||
String name = null;
|
|
||||||
try {
|
|
||||||
name = Contacts.getInstance(this).getOwnerName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(K9.LOG_TAG, "Could not get owner name, using default account name", e);
|
|
||||||
}
|
|
||||||
if (name == null || name.length() == 0) {
|
|
||||||
try {
|
|
||||||
name = getDefaultAccountName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(K9.LOG_TAG, "Could not get default account name", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (name == null) {
|
|
||||||
name = "";
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getDefaultAccountName() {
|
|
||||||
String name = null;
|
|
||||||
Account account = Preferences.getPreferences(this).getDefaultAccount();
|
|
||||||
if (account != null) {
|
|
||||||
name = account.getName();
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Simple class to wrap account suggestion data
|
Simple class to wrap account suggestion data
|
||||||
*/
|
*/
|
||||||
|
@ -252,6 +252,7 @@ public class ConfigurationXMLHandler extends DefaultHandler {
|
|||||||
Dealing with unpredictable input like this we better make sure we don't crash k-9.
|
Dealing with unpredictable input like this we better make sure we don't crash k-9.
|
||||||
*/
|
*/
|
||||||
private void validateServer(Server mServerInProgress) throws SAXException{
|
private void validateServer(Server mServerInProgress) throws SAXException{
|
||||||
|
// TODO: check if basic information is provided
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user