From b920cf056ee0b6a4d39ff01d9bdf6c68643af76f Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 10 Oct 2021 19:54:16 +0200 Subject: [PATCH] Added quick save quick setup wizard --- .../eu/faircode/email/FragmentQuickSetup.java | 119 +++++++++++------- .../main/res/layout/fragment_quick_setup.xml | 26 +++- 2 files changed, 99 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java index 9712b6ae19..8b6317b1d6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java @@ -81,6 +81,7 @@ public class FragmentQuickSetup extends FragmentBase { private Button btnHelp; private Button btnSupport; + private TextView tvUser; private TextView tvImap; private TextView tvSmtp; @@ -96,8 +97,18 @@ public class FragmentQuickSetup extends FragmentBase { private Group grpCertificate; private Group grpError; + private EmailProvider bestProvider = null; + private Bundle bestArgs = null; + private static final String PRIVACY_URI = "https://www.mozilla.org/privacy/"; + @Override + public void onSaveInstanceState(Bundle outState) { + outState.putString("fair:password", tilPassword.getEditText().getText().toString()); + outState.putParcelable("fair:best", bestProvider); + outState.putParcelable("fair:args", bestArgs); + } + @Override @Nullable public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -123,6 +134,7 @@ public class FragmentQuickSetup extends FragmentBase { btnHelp = view.findViewById(R.id.btnHelp); btnSupport = view.findViewById(R.id.btnSupport); + tvUser = view.findViewById(R.id.tvUser); tvImap = view.findViewById(R.id.tvImap); tvSmtp = view.findViewById(R.id.tvSmtp); @@ -227,6 +239,13 @@ public class FragmentQuickSetup extends FragmentBase { grpCertificate.setVisibility(View.GONE); grpError.setVisibility(View.GONE); + if (savedInstanceState != null) { + tilPassword.getEditText().setText(savedInstanceState.getString("fair:password")); + bestProvider = savedInstanceState.getParcelable("fair:best"); + bestArgs = savedInstanceState.getParcelable("fair:args"); + showResult(bestProvider, bestArgs); + } + return view; } @@ -236,6 +255,7 @@ public class FragmentQuickSetup extends FragmentBase { args.putString("email", etEmail.getText().toString().trim()); args.putString("password", tilPassword.getEditText().getText().toString()); args.putBoolean("check", check); + args.putParcelable("best", bestProvider); new SimpleTask() { @Override @@ -269,6 +289,7 @@ public class FragmentQuickSetup extends FragmentBase { String email = args.getString("email"); String password = args.getString("password"); boolean check = args.getBoolean("check"); + EmailProvider best = args.getParcelable("best"); if (TextUtils.isEmpty(name)) throw new IllegalArgumentException(context.getString(R.string.title_no_name)); @@ -288,7 +309,11 @@ public class FragmentQuickSetup extends FragmentBase { throw new IllegalArgumentException(context.getString(R.string.title_no_internet)); Throwable fail = null; - List providers = EmailProvider.fromEmail(context, email, EmailProvider.Discover.ALL); + List providers; + if (best == null) + providers = EmailProvider.fromEmail(context, email, EmailProvider.Discover.ALL); + else + providers = Arrays.asList(best); for (EmailProvider provider : providers) try { EntityLog.log(context, "Checking" + @@ -484,8 +509,8 @@ public class FragmentQuickSetup extends FragmentBase { db.endTransaction(); } - fail = null; - break; + ServiceSynchronize.eval(context, "quick setup"); + return provider; } catch (Throwable ex) { Log.w(ex); if (fail == null) @@ -495,8 +520,6 @@ public class FragmentQuickSetup extends FragmentBase { if (fail != null) throw fail; - ServiceSynchronize.eval(context, "quick setup"); - return null; } @@ -506,11 +529,9 @@ public class FragmentQuickSetup extends FragmentBase { boolean check = args.getBoolean("check"); if (check) { - tvImap.setText(result == null ? null : result.imap.toString()); - tvSmtp.setText(result == null ? null : result.smtp.toString()); - grpSetup.setVisibility(result == null ? View.GONE : View.VISIBLE); - showCertInfo(result, args); - btnSave.setVisibility(result == null ? View.GONE : View.VISIBLE); + bestProvider = result; + bestArgs = args; + showResult(bestProvider, bestArgs); } else { FragmentDialogAccount fragment = new FragmentDialogAccount(); fragment.setArguments(args); @@ -566,6 +587,7 @@ public class FragmentQuickSetup extends FragmentBase { if (provider != null && provider.imap != null && provider.smtp != null) { + tvUser.setText("-"); tvImap.setText(provider.imap.toString()); tvSmtp.setText(provider.smtp.toString()); grpSetup.setVisibility(View.VISIBLE); @@ -583,40 +605,6 @@ public class FragmentQuickSetup extends FragmentBase { } } - private void showCertInfo(EmailProvider provider, Bundle args) { - X509Certificate imap_certificate = - (X509Certificate) args.getSerializable("imap_certificate"); - X509Certificate smtp_certificate = - (X509Certificate) args.getSerializable("smtp_certificate"); - - List imapNames = new ArrayList<>(); - if (imap_certificate != null) - try { - imapNames = EntityCertificate.getDnsNames(imap_certificate); - } catch (Throwable ignored) { - } - boolean imapMatches = EntityCertificate.matches(provider.imap.host, imapNames); - - List smtpNames = new ArrayList<>(); - if (smtp_certificate != null) - try { - smtpNames = EntityCertificate.getDnsNames(smtp_certificate); - } catch (Throwable ignored) { - } - boolean smtpMatches = EntityCertificate.matches(provider.imap.host, smtpNames); - - tvImapFingerprint.setText(EntityCertificate.getKeyFingerprint(imap_certificate)); - tvImapDnsNames.setText(TextUtils.join(", ", imapNames)); - tvImapDnsNames.setTypeface(imapMatches ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD); - tvSmtpFingerprint.setText(EntityCertificate.getKeyFingerprint(smtp_certificate)); - tvSmtpDnsNames.setText(TextUtils.join(", ", smtpNames)); - tvSmtpDnsNames.setTypeface(smtpMatches ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD); - - grpCertificate.setVisibility( - imap_certificate == null && smtp_certificate == null - ? View.GONE : View.VISIBLE); - } - private void setManual(boolean manual) { FragmentActivity activity = getActivity(); if (activity == null) @@ -631,6 +619,49 @@ public class FragmentQuickSetup extends FragmentBase { }.execute(this, args, "setup:quick"); } + private void showResult(EmailProvider provider, Bundle args) { + X509Certificate imap_certificate = + (X509Certificate) args.getSerializable("imap_certificate"); + X509Certificate smtp_certificate = + (X509Certificate) args.getSerializable("smtp_certificate"); + + List imapNames = new ArrayList<>(); + if (imap_certificate != null) + try { + imapNames = EntityCertificate.getDnsNames(imap_certificate); + } catch (Throwable ignored) { + } + boolean imapMatches = (provider != null && + EntityCertificate.matches(provider.imap.host, imapNames)); + + List smtpNames = new ArrayList<>(); + if (smtp_certificate != null) + try { + smtpNames = EntityCertificate.getDnsNames(smtp_certificate); + } catch (Throwable ignored) { + } + boolean smtpMatches = (provider != null && + EntityCertificate.matches(provider.imap.host, smtpNames)); + + tvUser.setText(provider == null ? null : provider.username); + tvImap.setText(provider == null ? null : provider.imap.toString()); + tvSmtp.setText(provider == null ? null : provider.smtp.toString()); + grpSetup.setVisibility(provider == null ? View.GONE : View.VISIBLE); + + tvImapFingerprint.setText(EntityCertificate.getKeyFingerprint(imap_certificate)); + tvImapDnsNames.setText(TextUtils.join(", ", imapNames)); + tvImapDnsNames.setTypeface(imapMatches ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD); + tvSmtpFingerprint.setText(EntityCertificate.getKeyFingerprint(smtp_certificate)); + tvSmtpDnsNames.setText(TextUtils.join(", ", smtpNames)); + tvSmtpDnsNames.setTypeface(smtpMatches ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD); + + grpCertificate.setVisibility( + imap_certificate == null && smtp_certificate == null + ? View.GONE : View.VISIBLE); + + btnSave.setVisibility(provider == null ? View.GONE : View.VISIBLE); + } + @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/app/src/main/res/layout/fragment_quick_setup.xml b/app/src/main/res/layout/fragment_quick_setup.xml index 43efe357c9..da1bb66c34 100644 --- a/app/src/main/res/layout/fragment_quick_setup.xml +++ b/app/src/main/res/layout/fragment_quick_setup.xml @@ -233,15 +233,36 @@ app:layout_constraintTop_toBottomOf="@id/tvInstructions" /> + + + +