From 97ec6f0bbfdee6405e001f801e1dc285cb15c4f9 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 3 Jul 2021 18:26:32 +0200 Subject: [PATCH] Show manual setup after quick setup failure --- .../eu/faircode/email/FragmentQuickSetup.java | 16 +++++++++ .../java/eu/faircode/email/FragmentSetup.java | 35 +++++++++++-------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java index d39df7ba69..a887b7e716 100644 --- a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java @@ -43,6 +43,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.Group; +import androidx.fragment.app.FragmentActivity; import com.google.android.material.textfield.TextInputLayout; @@ -440,6 +441,8 @@ public class FragmentQuickSetup extends FragmentBase { @Override protected void onExecuted(Bundle args, EmailProvider result) { + setManual(false); + boolean check = args.getBoolean("check"); if (check) { tvImap.setText(result == null ? null : result.imap.toString()); @@ -459,6 +462,7 @@ public class FragmentQuickSetup extends FragmentBase { @Override protected void onException(final Bundle args, Throwable ex) { Log.e(ex); + setManual(true); EmailProvider provider = args.getParcelable("provider"); if (ex instanceof AuthenticationFailedException) { @@ -514,6 +518,18 @@ public class FragmentQuickSetup extends FragmentBase { }); } } + + private void setManual(boolean manual) { + FragmentActivity activity = getActivity(); + if (activity == null) + return; + + Intent intent = activity.getIntent(); + if (intent == null) + return; + + intent.putExtra("manual", manual); + } }.execute(this, args, "setup:quick"); } diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index da2ff5ed18..68535ee5d6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -109,17 +109,7 @@ public class FragmentSetup extends FragmentBase { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { setSubtitle(R.string.title_setup); - if (savedInstanceState == null) { - FragmentActivity activity = getActivity(); - if (activity != null) { - Intent intent = activity.getIntent(); - if (intent.hasExtra("manual")) { - manual = intent.getBooleanExtra("manual", false); - intent.removeExtra("manual"); - activity.setIntent(intent); - } - } - } else + if (savedInstanceState != null) manual = savedInstanceState.getBoolean("fair:manual"); textColorPrimary = Helper.resolveColor(getContext(), android.R.attr.textColorPrimary); @@ -298,8 +288,7 @@ public class FragmentSetup extends FragmentBase { @Override public void onClick(View v) { manual = !manual; - ibManual.setImageLevel(manual ? 0 /* less */ : 1 /* more */); - grpManual.setVisibility(manual ? View.VISIBLE : View.GONE); + updateManual(); } }); @@ -312,8 +301,7 @@ public class FragmentSetup extends FragmentBase { } }); - ibManual.setImageLevel(manual ? 0 /* less */ : 1 /* more */); - grpManual.setVisibility(manual ? View.VISIBLE : View.GONE); + updateManual(); btnAccount.setOnClickListener(new View.OnClickListener() { @Override @@ -534,6 +522,8 @@ public class FragmentSetup extends FragmentBase { public void onResume() { super.onResume(); + updateManual(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); cm.registerDefaultNetworkCallback(networkCallback); @@ -579,6 +569,21 @@ public class FragmentSetup extends FragmentBase { } } + private void updateManual() { + FragmentActivity activity = getActivity(); + if (activity != null) { + Intent intent = activity.getIntent(); + if (intent.hasExtra("manual")) { + manual = intent.getBooleanExtra("manual", false); + intent.removeExtra("manual"); + activity.setIntent(intent); + } + } + + ibManual.setImageLevel(manual ? 0 /* less */ : 1 /* more */); + grpManual.setVisibility(manual ? View.VISIBLE : View.GONE); + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { for (int i = 0; i < permissions.length; i++)