From a936ca5286e1ab45340e0a7bde1a0adf905205bb Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 27 Feb 2020 18:55:22 +0100 Subject: [PATCH] Added FAB reply menu --- .../eu/faircode/email/FragmentMessages.java | 72 +++++++++++++++---- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index c62c54f4a0..813bf67e09 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -891,20 +891,68 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. fabReply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - boolean reply_hint = prefs.getBoolean("reply_hint", false); - if (reply_hint) - onReply("reply"); - else - new AlertDialog.Builder(getContext()) - .setMessage(R.string.title_reply_hint) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + if (values.containsKey("expanded") && values.get("expanded").size() > 0) { + Bundle args = new Bundle(); + args.putLong("id", values.get("expanded").get(0)); + + new SimpleTask() { + @Override + protected Integer onExecute(Context context, Bundle args) { + long id = args.getLong("id"); + + DB db = DB.getInstance(context); + EntityMessage message = db.message().getMessage(id); + if (message == null) + return null; + + List identities = db.identity().getComposableIdentities(message.account); + if (identities == null) + return null; + + Address[] recipients = message.getAllRecipients(identities, message.account); + return recipients.length; + } + + @Override + protected void onExecuted(Bundle args, Integer recipients) { + if (recipients == null) + return; + + PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply); + popupMenu.inflate(R.menu.popup_reply); + for (int i = 0; i < popupMenu.getMenu().size(); i++) + popupMenu.getMenu().getItem(i).setVisible(false); + popupMenu.getMenu().findItem(R.id.menu_reply_to_sender).setVisible(true); + popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(recipients > 1); + popupMenu.getMenu().findItem(R.id.menu_forward).setVisible(true); + + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - prefs.edit().putBoolean("reply_hint", true).apply(); - onReply("reply"); + public boolean onMenuItemClick(MenuItem target) { + switch (target.getItemId()) { + case R.id.menu_reply_to_sender: + onReply("reply"); + return true; + case R.id.menu_reply_to_all: + onReply("reply_all"); + return true; + case R.id.menu_forward: + onReply("forward"); + return true; + default: + return false; + } } - }) - .show(); + }); + popupMenu.show(); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentMessages.this, args, "messages:reply"); + } } });