From 66ff193d84ccc3a59d8266f3f3f8339d9156ffe4 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 4 Feb 2021 13:56:01 +0100 Subject: [PATCH] Skip identity selection if one --- .../eu/faircode/email/FragmentMessages.java | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 6ef4d2f41f..b8937fc2a4 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -2607,21 +2607,39 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private void onCompose() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean identities_asked = prefs.getBoolean("identities_asked", false); - if (identities_asked) - startActivity(new Intent(getContext(), ActivityCompose.class) - .putExtra("action", "new") - .putExtra("account", account) - ); - else { - Bundle args = new Bundle(); - args.putLong("account", account); + Bundle args = new Bundle(); + args.putLong("account", account); - FragmentDialogIdentity fragment = new FragmentDialogIdentity(); - fragment.setArguments(args); - fragment.show(getParentFragmentManager(), "messages:identities"); - } + new SimpleTask() { + @Override + protected Boolean onExecute(Context context, Bundle args) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean identities_asked = prefs.getBoolean("identities_asked", false); + if (identities_asked) + return false; + + DB db = DB.getInstance(context); + List identities = db.identity().getComposableIdentities(null); + return (identities != null && identities.size() > 1); + } + + @Override + protected void onExecuted(Bundle args, Boolean ask) { + if (ask) { + FragmentDialogIdentity fragment = new FragmentDialogIdentity(); + fragment.setArguments(args); + fragment.show(getParentFragmentManager(), "messages:identities"); + } else + startActivity(new Intent(getContext(), ActivityCompose.class) + .putExtra("action", "new") + .putExtra("account", account)); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(this, args, "message:compose"); } private void onMore() {