From 2225daeb5a126000c8a26b892961f4d089d0d9d2 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 25 Aug 2020 11:52:50 +0200 Subject: [PATCH] Refactoring --- .../eu/faircode/email/FragmentIdentity.java | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index 43f10bc762..28fb5cc1cf 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -1187,6 +1187,36 @@ public class FragmentIdentity extends FragmentBase { cbPrimary.setEnabled(cbSynchronize.isChecked()); + // Get providers + List providers = EmailProvider.loadProfiles(getContext()); + providers.add(0, new EmailProvider(getString(R.string.title_custom))); + + ArrayAdapter aaProfile = + new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, providers); + aaProfile.setDropDownViewResource(R.layout.spinner_item1_dropdown); + spProvider.setAdapter(aaProfile); + + if (savedInstanceState == null) { + spProvider.setTag(0); + spProvider.setSelection(0); + if (identity != null) + for (int pos = 1; pos < providers.size(); pos++) { + EmailProvider provider = providers.get(pos); + if (provider.smtp.host.equals(identity.host) && + provider.smtp.port == identity.port && + provider.smtp.starttls == (identity.encryption == EmailService.ENCRYPTION_STARTTLS)) { + spProvider.setTag(pos); + spProvider.setSelection(pos); + break; + } + } + } else { + int provider = savedInstanceState.getInt("fair:provider"); + spProvider.setTag(provider); + spProvider.setSelection(provider); + } + + // Get accounts new SimpleTask>() { @Override protected List onExecute(Context context, Bundle args) { @@ -1210,30 +1240,7 @@ public class FragmentIdentity extends FragmentBase { aaAccount.setDropDownViewResource(R.layout.spinner_item1_dropdown); spAccount.setAdapter(aaAccount); - // Get providers - List providers = EmailProvider.loadProfiles(getContext()); - providers.add(0, new EmailProvider(getString(R.string.title_custom))); - - ArrayAdapter aaProfile = - new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, providers); - aaProfile.setDropDownViewResource(R.layout.spinner_item1_dropdown); - spProvider.setAdapter(aaProfile); - if (savedInstanceState == null) { - spProvider.setTag(0); - spProvider.setSelection(0); - if (identity != null) - for (int pos = 1; pos < providers.size(); pos++) { - EmailProvider provider = providers.get(pos); - if (provider.smtp.host.equals(identity.host) && - provider.smtp.port == identity.port && - provider.smtp.starttls == (identity.encryption == EmailService.ENCRYPTION_STARTTLS)) { - spProvider.setTag(pos); - spProvider.setSelection(pos); - break; - } - } - spAccount.setTag(0); spAccount.setSelection(0); for (int pos = 0; pos < accounts.size(); pos++) { @@ -1246,10 +1253,6 @@ public class FragmentIdentity extends FragmentBase { } } } else { - int provider = savedInstanceState.getInt("fair:provider"); - spProvider.setTag(provider); - spProvider.setSelection(provider); - int account = savedInstanceState.getInt("fair:account"); spAccount.setTag(account); spAccount.setSelection(account);