From 492d65feedda9a3445e109c5eed66def9df30f53 Mon Sep 17 00:00:00 2001 From: Art O Cathain Date: Wed, 18 Feb 2015 19:40:43 +0000 Subject: [PATCH 1/3] reduce duplication --- .../setup/AccountSetupAccountType.java | 109 +++++++----------- .../k9/activity/setup/AccountSetupBasics.java | 2 +- 2 files changed, 43 insertions(+), 68 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java index 5bc9f4130..54e8c24e7 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java @@ -14,6 +14,7 @@ import com.fsck.k9.Preferences; import com.fsck.k9.R; import com.fsck.k9.activity.K9Activity; import java.net.URI; +import java.net.URISyntaxException; /** * Prompts the user to select an account type. The account type, along with the @@ -49,83 +50,57 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); } - private void onPop() { - try { - URI uri = new URI(mAccount.getStoreUri()); - uri = new URI("pop3+ssl+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); - mAccount.setStoreUri(uri.toString()); - - uri = new URI(mAccount.getTransportUri()); - uri = new URI("smtp+tls+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); - mAccount.setTransportUri(uri.toString()); - - AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault); - finish(); - } catch (Exception use) { - failure(use); - } + private void setupStoreAndSmtpTransport(String schemePrefix) throws URISyntaxException { + URI uri = new URI(mAccount.getStoreUri()); + uri = new URI(schemePrefix, uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); + mAccount.setStoreUri(uri.toString()); + uri = new URI(mAccount.getTransportUri()); + uri = new URI("smtp+tls+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); + mAccount.setTransportUri(uri.toString()); } - private void onImap() { - try { - URI uri = new URI(mAccount.getStoreUri()); - uri = new URI("imap+ssl+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); - mAccount.setStoreUri(uri.toString()); + private void setupDav() throws URISyntaxException { + URI uri = new URI(mAccount.getStoreUri()); - uri = new URI(mAccount.getTransportUri()); - uri = new URI("smtp+tls+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); - mAccount.setTransportUri(uri.toString()); - - AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault); - finish(); - } catch (Exception use) { - failure(use); + /* + * The user info we have been given from + * AccountSetupBasics.onManualSetup() is encoded as an IMAP store + * URI: AuthType:UserName:Password (no fields should be empty). + * However, AuthType is not applicable to WebDAV nor to its store + * URI. Re-encode without it, using just the UserName and Password. + */ + String userPass = ""; + String[] userInfo = uri.getUserInfo().split(":"); + if (userInfo.length > 1) { + userPass = userInfo[1]; } - - } - - private void onWebDav() { - try { - URI uri = new URI(mAccount.getStoreUri()); - - /* - * The user info we have been given from - * AccountSetupBasics.onManualSetup() is encoded as an IMAP store - * URI: AuthType:UserName:Password (no fields should be empty). - * However, AuthType is not applicable to WebDAV nor to its store - * URI. Re-encode without it, using just the UserName and Password. - */ - String userPass = ""; - String[] userInfo = uri.getUserInfo().split(":"); - if (userInfo.length > 1) { - userPass = userInfo[1]; - } - if (userInfo.length > 2) { - userPass = userPass + ":" + userInfo[2]; - } - uri = new URI("webdav+ssl+", userPass, uri.getHost(), uri.getPort(), null, null, null); - mAccount.setStoreUri(uri.toString()); - AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault); - finish(); - } catch (Exception use) { - failure(use); + if (userInfo.length > 2) { + userPass = userPass + ":" + userInfo[2]; } - + uri = new URI("webdav+ssl+", userPass, uri.getHost(), uri.getPort(), null, null, null); + mAccount.setStoreUri(uri.toString()); } public void onClick(View v) { - switch (v.getId()) { - case R.id.pop: - onPop(); - break; - case R.id.imap: - onImap(); - break; - case R.id.webdav: - onWebDav(); - break; + try { + switch (v.getId()) { + case R.id.pop: + setupStoreAndSmtpTransport("pop3+ssl+"); + break; + case R.id.imap: + setupStoreAndSmtpTransport("imap+ssl+"); + break; + case R.id.webdav: + setupDav(); + break; + } + } catch (Exception ex) { + failure(ex); } + + AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault); + finish(); } private void failure(Exception use) { diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java index 91cd119ba..c9b8b345f 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java @@ -347,7 +347,7 @@ public class AccountSetupBasics extends K9Activity } } - protected void onNext() { + private void onNext() { if (mClientCertificateCheckBox.isChecked()) { // Auto-setup doesn't support client certificates. From d5d42469b030b4544ef80009cccac236fd6e76d1 Mon Sep 17 00:00:00 2001 From: Art O Cathain Date: Sun, 22 Feb 2015 16:03:58 +0000 Subject: [PATCH 2/3] Avoid confusing reuse of local variables --- .../setup/AccountSetupAccountType.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java index 54e8c24e7..1366c2563 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java @@ -51,17 +51,17 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen } private void setupStoreAndSmtpTransport(String schemePrefix) throws URISyntaxException { - URI uri = new URI(mAccount.getStoreUri()); - uri = new URI(schemePrefix, uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); - mAccount.setStoreUri(uri.toString()); + URI storeUriForDecode = new URI(mAccount.getStoreUri()); + URI storeUri = new URI(schemePrefix, storeUriForDecode.getUserInfo(), storeUriForDecode.getHost(), storeUriForDecode.getPort(), null, null, null); + mAccount.setStoreUri(storeUri.toString()); - uri = new URI(mAccount.getTransportUri()); - uri = new URI("smtp+tls+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); - mAccount.setTransportUri(uri.toString()); + URI transportUriForDecode = new URI(mAccount.getTransportUri()); + URI transportUri = new URI("smtp+tls+", transportUriForDecode.getUserInfo(), transportUriForDecode.getHost(), transportUriForDecode.getPort(), null, null, null); + mAccount.setTransportUri(transportUri.toString()); } private void setupDav() throws URISyntaxException { - URI uri = new URI(mAccount.getStoreUri()); + URI uriForDecode = new URI(mAccount.getStoreUri()); /* * The user info we have been given from @@ -71,14 +71,14 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen * URI. Re-encode without it, using just the UserName and Password. */ String userPass = ""; - String[] userInfo = uri.getUserInfo().split(":"); + String[] userInfo = uriForDecode.getUserInfo().split(":"); if (userInfo.length > 1) { userPass = userInfo[1]; } if (userInfo.length > 2) { userPass = userPass + ":" + userInfo[2]; } - uri = new URI("webdav+ssl+", userPass, uri.getHost(), uri.getPort(), null, null, null); + URI uri = new URI("webdav+ssl+", userPass, uriForDecode.getHost(), uriForDecode.getPort(), null, null, null); mAccount.setStoreUri(uri.toString()); } From 737e0d2ac8bf55fe72af806380bd15042262c900 Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 23 Feb 2015 03:36:34 +0100 Subject: [PATCH 3/3] Minor code style fixes --- .../activity/setup/AccountSetupAccountType.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java index 1366c2563..41d5ab552 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupAccountType.java @@ -23,11 +23,9 @@ import java.net.URISyntaxException; */ public class AccountSetupAccountType extends K9Activity implements OnClickListener { private static final String EXTRA_ACCOUNT = "account"; - private static final String EXTRA_MAKE_DEFAULT = "makeDefault"; private Account mAccount; - private boolean mMakeDefault; public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) { @@ -52,11 +50,13 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen private void setupStoreAndSmtpTransport(String schemePrefix) throws URISyntaxException { URI storeUriForDecode = new URI(mAccount.getStoreUri()); - URI storeUri = new URI(schemePrefix, storeUriForDecode.getUserInfo(), storeUriForDecode.getHost(), storeUriForDecode.getPort(), null, null, null); + URI storeUri = new URI(schemePrefix, storeUriForDecode.getUserInfo(), storeUriForDecode.getHost(), + storeUriForDecode.getPort(), null, null, null); mAccount.setStoreUri(storeUri.toString()); URI transportUriForDecode = new URI(mAccount.getTransportUri()); - URI transportUri = new URI("smtp+tls+", transportUriForDecode.getUserInfo(), transportUriForDecode.getHost(), transportUriForDecode.getPort(), null, null, null); + URI transportUri = new URI("smtp+tls+", transportUriForDecode.getUserInfo(), transportUriForDecode.getHost(), + transportUriForDecode.getPort(), null, null, null); mAccount.setTransportUri(transportUri.toString()); } @@ -85,15 +85,18 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen public void onClick(View v) { try { switch (v.getId()) { - case R.id.pop: + case R.id.pop: { setupStoreAndSmtpTransport("pop3+ssl+"); break; - case R.id.imap: + } + case R.id.imap: { setupStoreAndSmtpTransport("imap+ssl+"); break; - case R.id.webdav: + } + case R.id.webdav: { setupDav(); break; + } } } catch (Exception ex) { failure(ex);