mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Merge pull request #561
Reduce code duplication in AccountSetupAccountType
This commit is contained in:
commit
dd20ff5aa3
@ -14,6 +14,7 @@ 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 java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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,11 +23,9 @@ import java.net.URI;
|
|||||||
*/
|
*/
|
||||||
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_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) {
|
||||||
@ -49,45 +48,20 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
|
|||||||
mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
|
mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPop() {
|
private void setupStoreAndSmtpTransport(String schemePrefix) throws URISyntaxException {
|
||||||
try {
|
URI storeUriForDecode = new URI(mAccount.getStoreUri());
|
||||||
URI uri = new URI(mAccount.getStoreUri());
|
URI storeUri = new URI(schemePrefix, storeUriForDecode.getUserInfo(), storeUriForDecode.getHost(),
|
||||||
uri = new URI("pop3+ssl+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
storeUriForDecode.getPort(), null, null, null);
|
||||||
mAccount.setStoreUri(uri.toString());
|
mAccount.setStoreUri(storeUri.toString());
|
||||||
|
|
||||||
uri = new URI(mAccount.getTransportUri());
|
URI transportUriForDecode = new URI(mAccount.getTransportUri());
|
||||||
uri = new URI("smtp+tls+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
URI transportUri = new URI("smtp+tls+", transportUriForDecode.getUserInfo(), transportUriForDecode.getHost(),
|
||||||
mAccount.setTransportUri(uri.toString());
|
transportUriForDecode.getPort(), null, null, null);
|
||||||
|
mAccount.setTransportUri(transportUri.toString());
|
||||||
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
|
|
||||||
finish();
|
|
||||||
} catch (Exception use) {
|
|
||||||
failure(use);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
private void setupDav() throws URISyntaxException {
|
||||||
|
URI uriForDecode = new URI(mAccount.getStoreUri());
|
||||||
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());
|
|
||||||
|
|
||||||
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 onWebDav() {
|
|
||||||
try {
|
|
||||||
URI uri = new URI(mAccount.getStoreUri());
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The user info we have been given from
|
* The user info we have been given from
|
||||||
@ -97,35 +71,39 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
|
|||||||
* URI. Re-encode without it, using just the UserName and Password.
|
* URI. Re-encode without it, using just the UserName and Password.
|
||||||
*/
|
*/
|
||||||
String userPass = "";
|
String userPass = "";
|
||||||
String[] userInfo = uri.getUserInfo().split(":");
|
String[] userInfo = uriForDecode.getUserInfo().split(":");
|
||||||
if (userInfo.length > 1) {
|
if (userInfo.length > 1) {
|
||||||
userPass = userInfo[1];
|
userPass = userInfo[1];
|
||||||
}
|
}
|
||||||
if (userInfo.length > 2) {
|
if (userInfo.length > 2) {
|
||||||
userPass = userPass + ":" + userInfo[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());
|
mAccount.setStoreUri(uri.toString());
|
||||||
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
|
|
||||||
finish();
|
|
||||||
} catch (Exception use) {
|
|
||||||
failure(use);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
try {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.pop:
|
case R.id.pop: {
|
||||||
onPop();
|
setupStoreAndSmtpTransport("pop3+ssl+");
|
||||||
break;
|
|
||||||
case R.id.imap:
|
|
||||||
onImap();
|
|
||||||
break;
|
|
||||||
case R.id.webdav:
|
|
||||||
onWebDav();
|
|
||||||
break;
|
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) {
|
private void failure(Exception use) {
|
||||||
|
@ -347,7 +347,7 @@ public class AccountSetupBasics extends K9Activity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onNext() {
|
private void onNext() {
|
||||||
if (mClientCertificateCheckBox.isChecked()) {
|
if (mClientCertificateCheckBox.isChecked()) {
|
||||||
|
|
||||||
// Auto-setup doesn't support client certificates.
|
// Auto-setup doesn't support client certificates.
|
||||||
|
Loading…
Reference in New Issue
Block a user