From e90392ee6cc1b258350af5822f53b4ada9f71443 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 15 Sep 2023 21:32:44 +0200 Subject: [PATCH] Select identity: add --- .../eu/faircode/email/FragmentCompose.java | 14 +++++++++++++- .../email/FragmentDialogSelectIdentity.java | 19 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 11c9e1057e..e8c7df8c53 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2481,8 +2481,11 @@ public class FragmentCompose extends FragmentBase { } private void onMenuIdentitySelect() { + Bundle args = new Bundle(); + args.putBoolean("add", true); + FragmentDialogSelectIdentity fragment = new FragmentDialogSelectIdentity(); - fragment.setArguments(new Bundle()); + fragment.setArguments(args); fragment.setTargetFragment(this, REQUEST_SELECT_IDENTITY); fragment.show(getParentFragmentManager(), "select:identity"); } @@ -4795,6 +4798,15 @@ public class FragmentCompose extends FragmentBase { } private void onSelectIdentity(Bundle args) { + long id = args.getLong("id"); + if (id < 0) { + getContext().startActivity(new Intent(getContext(), ActivitySetup.class) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK) + .putExtra("manual", true) + .putExtra("scroll", true)); + return; + } + new SimpleTask() { @Override protected EntityIdentity onExecute(Context context, Bundle args) throws Throwable { diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogSelectIdentity.java b/app/src/main/java/eu/faircode/email/FragmentDialogSelectIdentity.java index 9925dcf692..799198c2d7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogSelectIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogSelectIdentity.java @@ -23,6 +23,7 @@ import static android.app.Activity.RESULT_OK; import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; import android.text.TextUtils; @@ -46,6 +47,8 @@ public class FragmentDialogSelectIdentity extends FragmentDialogBase { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { final Context context = getContext(); + final Bundle args = getArguments(); + final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_account_select, null); RecyclerView rvSelect = dview.findViewById(R.id.rvSelect); final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait); @@ -54,12 +57,22 @@ public class FragmentDialogSelectIdentity extends FragmentDialogBase { rvSelect.setHasFixedSize(false); rvSelect.setLayoutManager(new LinearLayoutManager(context)); - Dialog dialog = new AlertDialog.Builder(context) + AlertDialog.Builder builder = new AlertDialog.Builder(context) .setIcon(R.drawable.twotone_person_24) .setTitle(R.string.title_list_identities) .setView(dview) - .setNegativeButton(android.R.string.cancel, null) - .create(); + .setNegativeButton(android.R.string.cancel, null); + + if (args != null && args.getBoolean("add")) + builder.setNeutralButton(R.string.title_add, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + args.putLong("id", -1L); + sendResult(RESULT_OK); + } + }); + + Dialog dialog = builder.create(); new SimpleTask>() { @Override