diff --git a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java index 6473ac5355..95838c038b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java @@ -47,6 +47,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.Group; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.google.android.material.textfield.TextInputLayout; @@ -309,6 +310,7 @@ public class FragmentQuickSetup extends FragmentBase { account.last_connected = account.created; account.id = db.account().insertAccount(account); + args.putLong("account", account.id); EntityLog.log(context, "Quick added account=" + account.name); // Create folders @@ -343,6 +345,7 @@ public class FragmentQuickSetup extends FragmentBase { identity.primary = true; identity.id = db.identity().insertIdentity(identity); + args.putLong("identity", identity.id); EntityLog.log(context, "Quick added identity=" + identity.name + " email=" + identity.email); db.setTransactionSuccessful(); @@ -366,6 +369,7 @@ public class FragmentQuickSetup extends FragmentBase { grpSetup.setVisibility(result == null ? View.GONE : View.VISIBLE); } else { FragmentDialogDone fragment = new FragmentDialogDone(); + fragment.setArguments(args); fragment.setTargetFragment(FragmentQuickSetup.this, REQUEST_DONE); fragment.show(getFragmentManager(), "quick:done"); } @@ -429,9 +433,18 @@ public class FragmentQuickSetup extends FragmentBase { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { return new AlertDialog.Builder(getContext()) .setMessage(R.string.title_setup_quick_success) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + .setPositiveButton(R.string.title_review, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { + Bundle args = getArguments(); + long account = args.getLong("account"); + + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast( + new Intent(ActivitySetup.ACTION_EDIT_ACCOUNT) + .putExtra("id", account) + .putExtra("pop", false)); + sendResult(RESULT_OK); } }) diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index e37e50e92c..e8fc7c3c1c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -64,6 +64,7 @@ import androidx.preference.PreferenceManager; import com.google.android.material.snackbar.Snackbar; import java.io.IOException; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -551,12 +552,11 @@ public class FragmentSetup extends FragmentBase { String password = args.getString("password"); if (!user.contains("@")) - throw new IllegalArgumentException(user); + throw new IllegalArgumentException( + context.getString(R.string.title_email_invalid, user)); String domain = user.split("@")[1]; EmailProvider provider = EmailProvider.fromDomain(context, domain, EmailProvider.Discover.ALL); - if (provider == null) - throw new IllegalArgumentException(user); List folders; @@ -567,7 +567,8 @@ public class FragmentSetup extends FragmentBase { folders = iservice.getFolders(); if (folders == null) - throw new IllegalArgumentException(domain); + throw new IllegalArgumentException( + context.getString(R.string.title_setup_no_settings, domain)); } String iprotocol = provider.smtp.starttls ? "smtp" : "smtps"; @@ -600,6 +601,7 @@ public class FragmentSetup extends FragmentBase { account.last_connected = account.created; account.id = db.account().insertAccount(account); + args.putLong("account", account.id); EntityLog.log(context, "Gmail account=" + account.name); // Create folders @@ -646,6 +648,7 @@ public class FragmentSetup extends FragmentBase { identity.primary = true; identity.id = db.identity().insertIdentity(identity); + args.putLong("identity", identity.id); EntityLog.log(context, "Gmail identity=" + identity.name + " email=" + identity.email); db.setTransactionSuccessful(); @@ -661,12 +664,16 @@ public class FragmentSetup extends FragmentBase { @Override protected void onExecuted(Bundle args, Void data) { FragmentQuickSetup.FragmentDialogDone fragment = new FragmentQuickSetup.FragmentDialogDone(); + fragment.setArguments(args); fragment.show(getFragmentManager(), "gmail:done"); } @Override protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getFragmentManager(), ex); + if (ex instanceof IllegalArgumentException || ex instanceof UnknownHostException) + Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); + else + Snackbar.make(view, Helper.formatThrowable(ex, false), Snackbar.LENGTH_LONG).show(); } }.execute(this, args, "setup:gmail"); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ee0f3cb497..617effefed 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -420,6 +420,7 @@ OAuth is not supported Authorize Authorizing … + Review Synchronize now Synchronize all messages