1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

tidy method

This commit is contained in:
Art O Cathain 2015-02-22 16:58:46 +00:00
parent ebef8eccb9
commit a656a61c65

View File

@ -24,6 +24,7 @@ import com.fsck.k9.fragment.ConfirmationDialogFragment;
import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
import com.fsck.k9.mail.AuthenticationFailedException; import com.fsck.k9.mail.AuthenticationFailedException;
import com.fsck.k9.mail.CertificateValidationException; import com.fsck.k9.mail.CertificateValidationException;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.Transport;
import com.fsck.k9.mail.store.webdav.WebDavStore; import com.fsck.k9.mail.store.webdav.WebDavStore;
@ -391,10 +392,10 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
} }
} }
class CheckAccountTask extends AsyncTask<CheckDirection, Integer, Void> { private class CheckAccountTask extends AsyncTask<CheckDirection, Integer, Void> {
private final Account account; private final Account account;
CheckAccountTask(Account account) { private CheckAccountTask(Account account) {
this.account = account; this.account = account;
} }
@ -402,58 +403,36 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
protected Void doInBackground(CheckDirection... params) { protected Void doInBackground(CheckDirection... params) {
final CheckDirection direction = params[0]; final CheckDirection direction = params[0];
try { try {
if (mDestroyed) { /*
* This task could be interrupted at any point, but network operations can block,
* so relying on InterruptedException is not enough. Instead, check after
* each potentially long-running operation.
*/
if (cancelled()) {
return null; return null;
} } else {
if (mCanceled) { final MessagingController ctrl = MessagingController.getInstance(getApplication());
finish(); ctrl.clearCertificateErrorNotifications(AccountSetupCheckSettings.this,
return null; account, direction);
}
final MessagingController ctrl = MessagingController.getInstance(getApplication());
ctrl.clearCertificateErrorNotifications(AccountSetupCheckSettings.this,
account, direction);
if (direction == CheckDirection.INCOMING) { if (direction == CheckDirection.INCOMING) {
Store store = account.getRemoteStore(); checkIncoming();
if (store instanceof WebDavStore) {
publishProgress(R.string.account_setup_check_settings_authenticate);
} else {
publishProgress(R.string.account_setup_check_settings_check_incoming_msg);
} }
store.checkSettings(); }
if (store instanceof WebDavStore) { if (cancelled()) {
publishProgress(R.string.account_setup_check_settings_fetch);
}
MessagingController.getInstance(getApplication()).listFoldersSynchronous(account, true, null);
MessagingController.getInstance(getApplication())
.synchronizeMailbox(account, account.getInboxFolderName(), null, null);
}
if (mDestroyed) {
return null; return null;
} else if (direction == CheckDirection.OUTGOING) {
checkOutgoing();
} }
if (mCanceled) {
if (cancelled()) {
return null;
} else {
setResult(RESULT_OK);
finish(); finish();
return null;
} }
if (direction == CheckDirection.OUTGOING) {
if (!(account.getRemoteStore() instanceof WebDavStore)) {
publishProgress(R.string.account_setup_check_settings_check_outgoing_msg);
}
Transport transport = Transport.getInstance(K9.app, account);
transport.close();
transport.open();
transport.close();
}
if (mDestroyed) {
return null;
}
if (mCanceled) {
finish();
return null;
}
setResult(RESULT_OK);
finish();
} catch (AuthenticationFailedException afe) { } catch (AuthenticationFailedException afe) {
Log.e(K9.LOG_TAG, "Error while testing settings", afe); Log.e(K9.LOG_TAG, "Error while testing settings", afe);
showErrorDialog( showErrorDialog(
@ -470,6 +449,44 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
return null; return null;
} }
private boolean cancelled() {
if (mDestroyed) {
return true;
}
if (mCanceled) {
finish();
return true;
}
return false;
}
private void checkOutgoing() throws MessagingException {
if (!(account.getRemoteStore() instanceof WebDavStore)) {
publishProgress(R.string.account_setup_check_settings_check_outgoing_msg);
}
Transport transport = Transport.getInstance(K9.app, account);
transport.close();
transport.open();
transport.close();
}
private void checkIncoming() throws MessagingException {
Store store = account.getRemoteStore();
if (store instanceof WebDavStore) {
publishProgress(R.string.account_setup_check_settings_authenticate);
} else {
publishProgress(R.string.account_setup_check_settings_check_incoming_msg);
}
store.checkSettings();
if (store instanceof WebDavStore) {
publishProgress(R.string.account_setup_check_settings_fetch);
}
MessagingController.getInstance(getApplication()).listFoldersSynchronous(account, true, null);
MessagingController.getInstance(getApplication())
.synchronizeMailbox(account, account.getInboxFolderName(), null, null);
}
@Override @Override
protected void onProgressUpdate(Integer... values) { protected void onProgressUpdate(Integer... values) {
setMessage(values[0]); setMessage(values[0]);