From b58e4bca85dca96f771c4ed1a23bfe1002187922 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 1 Mar 2020 11:04:31 +0100 Subject: [PATCH] Removed message action bar --- .../eu/faircode/email/AdapterMessage.java | 348 +++--------------- .../java/eu/faircode/email/DaoAnswer.java | 2 +- .../eu/faircode/email/FragmentMessages.java | 236 ++++++++---- .../res/layout/include_message_navigation.xml | 74 ++-- app/src/main/res/menu/action_message.xml | 28 -- app/src/main/res/menu/popup_message_more.xml | 8 + app/src/main/res/values/strings.xml | 2 + 7 files changed, 252 insertions(+), 446 deletions(-) delete mode 100644 app/src/main/res/menu/action_message.xml diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 55c60eb4bc..30c449f459 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -127,8 +127,6 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.StaggeredGridLayoutManager; import com.github.chrisbanes.photoview.PhotoView; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.android.material.bottomnavigation.LabelVisibilityMode; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; @@ -231,7 +229,6 @@ public class AdapterMessage extends RecyclerView.Adapter>() { - @Override - protected List onExecute(Context context, Bundle args) { - TupleMessageEx message = (TupleMessageEx) args.getSerializable("message"); - if (message == null) - return null; - - DB db = DB.getInstance(context); - return db.identity().getComposableIdentities(message.account); - } - - @Override - protected void onExecuted(Bundle args, List identities) { - TupleMessageEx message = (TupleMessageEx) args.getSerializable("message"); - - TupleMessageEx amessage = getMessage(); - if (amessage == null || !amessage.id.equals(message.id)) - return; - - final Address[] to = - message.replySelf(identities, message.account) - ? message.to - : (message.reply == null || message.reply.length == 0 ? message.from : message.reply); - - Address[] recipients = message.getAllRecipients(identities, message.account); - - View anchor = bnvActions.findViewById(R.id.action_reply); - PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor); - popupMenu.inflate(R.menu.popup_reply); - popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(recipients.length > 0); - popupMenu.getMenu().findItem(R.id.menu_reply_list).setVisible(message.list_post != null); - popupMenu.getMenu().findItem(R.id.menu_reply_receipt).setVisible(message.receipt_to != null); - popupMenu.getMenu().findItem(R.id.menu_new_message).setVisible(to != null && to.length > 0); - popupMenu.getMenu().findItem(R.id.menu_reply_answer).setVisible(answers != 0 || !ActivityBilling.isPro(context)); - - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem target) { - switch (target.getItemId()) { - case R.id.menu_reply_to_sender: - onMenuReply(message, "reply"); - return true; - case R.id.menu_reply_to_all: - onMenuReply(message, "reply_all"); - return true; - case R.id.menu_reply_list: - onMenuReply(message, "list"); - return true; - case R.id.menu_reply_receipt: - onMenuReply(message, "receipt"); - return true; - case R.id.menu_forward: - onMenuReply(message, "forward"); - return true; - case R.id.menu_editasnew: - onMenuEditAsNew(message); - return true; - case R.id.menu_new_message: - onMenuNew(message, to); - return true; - case R.id.menu_reply_answer: - onMenuAnswer(message); - return true; - default: - return false; - } - } - }); - popupMenu.show(); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); - } - }.execute(context, owner, args, "message:reply"); - } - - private void onMenuReply(TupleMessageEx message, String action) { - Intent reply = new Intent(context, ActivityCompose.class) - .putExtra("action", action) - .putExtra("reference", message.id); - context.startActivity(reply); - } - - private void onMenuEditAsNew(final TupleMessageEx message) { - Intent asnew = new Intent(context, ActivityCompose.class) - .putExtra("action", "editasnew") - .putExtra("reference", message.id); - context.startActivity(asnew); - } - - private void onMenuNew(TupleMessageEx message, Address[] to) { - Intent reply = new Intent(context, ActivityCompose.class) - .putExtra("action", "new") - .putExtra("to", MessageHelper.formatAddresses(to, true, true)); - context.startActivity(reply); - } - - private void onMenuAnswer(TupleMessageEx message) { - new SimpleTask>() { - @Override - protected List onExecute(Context context, Bundle args) { - return DB.getInstance(context).answer().getAnswers(false); - } - - @Override - protected void onExecuted(Bundle args, List answers) { - if (answers == null || answers.size() == 0) { - Snackbar snackbar = Snackbar.make( - parentFragment.getView(), - context.getString(R.string.title_no_answers), - Snackbar.LENGTH_LONG); - snackbar.setAction(R.string.title_fix, new View.OnClickListener() { - @Override - public void onClick(View v) { - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); - lbm.sendBroadcast(new Intent(ActivityView.ACTION_EDIT_ANSWERS)); - } - }); - snackbar.show(); - } else { - View anchor = bnvActions.findViewById(R.id.action_reply); - PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor); - - int order = 0; - for (EntityAnswer answer : answers) - popupMenu.getMenu().add(Menu.NONE, answer.id.intValue(), order++, answer.toString()); - - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem target) { - if (!ActivityBilling.isPro(context)) { - context.startActivity(new Intent(context, ActivityBilling.class)); - return true; - } - - context.startActivity(new Intent(context, ActivityCompose.class) - .putExtra("action", "reply") - .putExtra("reference", message.id) - .putExtra("answer", (long) target.getItemId())); - return true; - } - }); - - popupMenu.show(); - } - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); - } - }.execute(context, owner, new Bundle(), "message:answer"); - } - - private void onActionArchive(TupleMessageEx message) { - properties.move(message.id, EntityFolder.ARCHIVE); - } - private void onActionMove(TupleMessageEx message, final boolean copy) { Bundle args = new Bundle(); args.putString("title", context.getString(copy ? R.string.title_copy_to : R.string.title_move_to_folder)); @@ -3229,7 +2999,7 @@ public class AdapterMessage extends RecyclerView.Adapter liveAnswerCount(); + Integer getAnswerCount(); @Insert long insertAnswer(EntityAnswer answer); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 9024684334..b29aa4df69 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -891,75 +891,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. fabReply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - 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 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; - } - } - }); - popupMenu.show(); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(getParentFragmentManager(), ex); - } - }.execute(FragmentMessages.this, args, "messages:reply"); - } - } - }); - - fabReply.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - return onReply("reply_all"); + onReply(); } }); @@ -2035,7 +1967,164 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }; - private boolean onReply(String action) { + private void onReply() { + if (values.containsKey("expanded") && values.get("expanded").size() > 0) { + long id = values.get("expanded").get(0); + int pos = adapter.getPositionForKey(id); + TupleMessageEx message = adapter.getItemAtPosition(pos); + + Bundle args = new Bundle(); + args.putLong("id", id); + + new SimpleTask>() { + @Override + protected List 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; + + args.putInt("answers", db.answer().getAnswerCount()); + + return db.identity().getComposableIdentities(message.account); + } + + @Override + protected void onExecuted(Bundle args, List identities) { + if (identities == null) + identities = new ArrayList<>(); + + final Address[] to = + message.replySelf(identities, message.account) + ? message.to + : (message.reply == null || message.reply.length == 0 ? message.from : message.reply); + + Address[] recipients = message.getAllRecipients(identities, message.account); + + int answers = args.getInt("answers"); + + PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply); + popupMenu.inflate(R.menu.popup_reply); + popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(recipients.length > 0); + popupMenu.getMenu().findItem(R.id.menu_reply_list).setVisible(message.list_post != null); + popupMenu.getMenu().findItem(R.id.menu_reply_receipt).setVisible(message.receipt_to != null); + popupMenu.getMenu().findItem(R.id.menu_new_message).setVisible(to != null && to.length > 0); + popupMenu.getMenu().findItem(R.id.menu_reply_answer).setVisible(answers != 0 || !ActivityBilling.isPro(getContext())); + + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem target) { + switch (target.getItemId()) { + case R.id.menu_reply_to_sender: + onMenuReply(message, "reply"); + return true; + case R.id.menu_reply_to_all: + onMenuReply(message, "reply_all"); + return true; + case R.id.menu_reply_list: + onMenuReply(message, "list"); + return true; + case R.id.menu_reply_receipt: + onMenuReply(message, "receipt"); + return true; + case R.id.menu_forward: + onMenuReply(message, "forward"); + return true; + case R.id.menu_editasnew: + onMenuReply(message, "editasnew"); + return true; + case R.id.menu_new_message: + onMenuNew(message, to); + return true; + case R.id.menu_reply_answer: + onMenuAnswer(message); + return true; + default: + return false; + } + } + }); + popupMenu.show(); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentMessages.this, args, "messages:reply"); + } + } + + private void onMenuReply(TupleMessageEx message, String action) { + Intent reply = new Intent(getContext(), ActivityCompose.class) + .putExtra("action", action) + .putExtra("reference", message.id); + startActivity(reply); + } + + private void onMenuNew(TupleMessageEx message, Address[] to) { + Intent reply = new Intent(getContext(), ActivityCompose.class) + .putExtra("action", "new") + .putExtra("to", MessageHelper.formatAddresses(to, true, true)); + startActivity(reply); + } + + private void onMenuAnswer(TupleMessageEx message) { + new SimpleTask>() { + @Override + protected List onExecute(Context context, Bundle args) { + return DB.getInstance(context).answer().getAnswers(false); + } + + @Override + protected void onExecuted(Bundle args, List answers) { + if (answers == null || answers.size() == 0) { + Snackbar snackbar = Snackbar.make(view, R.string.title_no_answers, Snackbar.LENGTH_LONG); + snackbar.setAction(R.string.title_fix, new View.OnClickListener() { + @Override + public void onClick(View v) { + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast(new Intent(ActivityView.ACTION_EDIT_ANSWERS)); + } + }); + snackbar.show(); + } else { + PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply); + + int order = 0; + for (EntityAnswer answer : answers) + popupMenu.getMenu().add(Menu.NONE, answer.id.intValue(), order++, answer.toString()); + + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem target) { + if (!ActivityBilling.isPro(getContext())) { + startActivity(new Intent(getContext(), ActivityBilling.class)); + return true; + } + + startActivity(new Intent(getContext(), ActivityCompose.class) + .putExtra("action", "reply") + .putExtra("reference", message.id) + .putExtra("answer", (long) target.getItemId())); + return true; + } + }); + + popupMenu.show(); + } + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(getContext(), getViewLifecycleOwner(), new Bundle(), "message:answer"); + } + + private boolean _onReply(String action) { if (values.containsKey("expanded") && values.get("expanded").size() > 0) { Context context = getContext(); if (context == null) @@ -2803,13 +2892,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }); - db.answer().liveAnswerCount().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(Integer count) { - adapter.setAnswerCount(count == null ? -1 : count); - } - }); - // Folder switch (viewType) { case UNIFIED: diff --git a/app/src/main/res/layout/include_message_navigation.xml b/app/src/main/res/layout/include_message_navigation.xml index 15938ea27f..819348ad59 100644 --- a/app/src/main/res/layout/include_message_navigation.xml +++ b/app/src/main/res/layout/include_message_navigation.xml @@ -5,7 +5,7 @@ android:layout_height="wrap_content"> - - - + app:layout_constraintTop_toBottomOf="@id/vSeparator" + app:srcCompat="@drawable/baseline_more_vert_24" /> + + - - diff --git a/app/src/main/res/menu/action_message.xml b/app/src/main/res/menu/action_message.xml deleted file mode 100644 index cd2f8e3132..0000000000 --- a/app/src/main/res/menu/action_message.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/popup_message_more.xml b/app/src/main/res/menu/popup_message_more.xml index 26b28dfce1..a806e212ab 100644 --- a/app/src/main/res/menu/popup_message_more.xml +++ b/app/src/main/res/menu/popup_message_more.xml @@ -32,6 +32,14 @@ + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c903fee7d..77d0a85603 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -677,6 +677,8 @@ More Spam Move + Not spam + Move to … Move to … Move to %1$s … Snooze …