From db2128dcd3c6e6bb299f7ed1d3f00afff1868641 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 3 Jul 2021 15:13:20 +0200 Subject: [PATCH] Show send errors in message lists --- .../java/eu/faircode/email/DaoMessage.java | 7 +++-- .../eu/faircode/email/FragmentMessages.java | 28 ++++++++++++++----- .../eu/faircode/email/TupleOutboxStats.java | 25 +++++++++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/TupleOutboxStats.java diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index a4594a9206..93b357c3ca 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -245,11 +245,12 @@ public interface DaoMessage { boolean filter_archive, boolean ascending, boolean debug); - @Query("SELECT COUNT(*) FROM message" + + @Query("SELECT COUNT(*) AS pending, SUM(message.error IS NOT NULL) AS errors" + + " FROM message" + " JOIN folder_view AS folder ON folder.id = message.folder" + " WHERE " + is_outbox + - " AND NOT ui_snoozed IS NULL") - LiveData liveOutboxPending(); + " AND (NOT message.ui_snoozed IS NULL OR message.error IS NOT NULL)") + LiveData liveOutboxPending(); @Query("SELECT account.name AS accountName" + ", COUNT(message.id) AS count" + diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 1566baaa40..737cdb4a45 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -314,6 +314,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private int colorPrimary; private int colorAccent; + private int colorSeparator; + private int colorWarning; private long primary; private boolean connected; @@ -431,6 +433,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. colorPrimary = Helper.resolveColor(getContext(), R.attr.colorPrimary); colorAccent = Helper.resolveColor(getContext(), R.attr.colorAccent); + colorSeparator = Helper.resolveColor(getContext(), R.attr.colorSeparator); + colorWarning = Helper.resolveColor(getContext(), R.attr.colorWarning); if (criteria == null) if (thread == null) { @@ -3998,16 +4002,26 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. break; } - if (send_pending && - (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER)) - db.message().liveOutboxPending().observe(getViewLifecycleOwner(), new Observer() { + if (!EntityFolder.OUTBOX.equals(type) && + (viewType == AdapterMessage.ViewType.UNIFIED || + viewType == AdapterMessage.ViewType.FOLDER)) + db.message().liveOutboxPending().observe(getViewLifecycleOwner(), new Observer() { @Override - public void onChanged(Integer pending) { - if (pending != null && pending > 10) + public void onChanged(TupleOutboxStats stats) { + int pending = (stats == null || stats.pending == null ? 0 : stats.pending); + int errors = (stats == null || stats.errors == null ? 0 : stats.errors); + + int count = (send_pending ? pending : errors); + if (count > 10) tvOutboxCount.setText("+"); else - tvOutboxCount.setText(pending == null || pending == 0 ? null : NF.format(pending)); - grpOutbox.setVisibility(pending == null || pending == 0 ? View.GONE : View.VISIBLE); + tvOutboxCount.setText(count == 0 ? null : NF.format(count)); + + int color = (errors == 0 ? colorSeparator : colorWarning); + ibOutbox.setImageTintList(ColorStateList.valueOf(color)); + tvOutboxCount.setTextColor(color); + + grpOutbox.setVisibility(count == 0 ? View.GONE : View.VISIBLE); } }); diff --git a/app/src/main/java/eu/faircode/email/TupleOutboxStats.java b/app/src/main/java/eu/faircode/email/TupleOutboxStats.java new file mode 100644 index 0000000000..e23e4e1d6a --- /dev/null +++ b/app/src/main/java/eu/faircode/email/TupleOutboxStats.java @@ -0,0 +1,25 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2021 by Marcel Bokhorst (M66B) +*/ + +public class TupleOutboxStats { + Integer pending; + Integer errors; +}