From f473703299979d33e772bd2ced3235e94f4b95aa Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 4 May 2019 22:38:11 +0200 Subject: [PATCH] Show operation errors in nav menu --- .../java/eu/faircode/email/ActivityView.java | 8 +++--- .../java/eu/faircode/email/DaoOperation.java | 6 +++-- .../java/eu/faircode/email/NavMenuItem.java | 4 +++ .../faircode/email/TupleOperationStats.java | 25 +++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/TupleOperationStats.java diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 71a1607c12..3d6304a9cb 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -378,10 +378,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } }); - db.operation().liveCount().observe(this, new Observer() { + db.operation().liveStats().observe(this, new Observer() { @Override - public void onChanged(Integer count) { - navOperations.setCount(count); + public void onChanged(TupleOperationStats stats) { + navOperations.setIcon(stats == null || stats.errors == null || stats.errors == 0 + ? R.drawable.baseline_list_24 : R.drawable.baseline_warning_24); + navOperations.setCount(stats == null ? 0 : stats.pending); madapter.notifyDataSetChanged(); } }); diff --git a/app/src/main/java/eu/faircode/email/DaoOperation.java b/app/src/main/java/eu/faircode/email/DaoOperation.java index 25d9cff5dc..ce568a6652 100644 --- a/app/src/main/java/eu/faircode/email/DaoOperation.java +++ b/app/src/main/java/eu/faircode/email/DaoOperation.java @@ -65,8 +65,10 @@ public interface DaoOperation { @Query(GET_OPS_FOLDER) LiveData> liveOperations(long folder); - @Query("SELECT COUNT(operation.id) FROM operation") - LiveData liveCount(); + @Query("SELECT COUNT(operation.id) AS pending" + + ", SUM(CASE WHEN operation.error IS NULL THEN 0 ELSE 1 END) AS errors" + + " FROM operation") + LiveData liveStats(); @Query("SELECT COUNT(operation.id) FROM operation" + " WHERE operation.name = '" + EntityOperation.SEND + "'") diff --git a/app/src/main/java/eu/faircode/email/NavMenuItem.java b/app/src/main/java/eu/faircode/email/NavMenuItem.java index aa11de352b..2aec550d7c 100644 --- a/app/src/main/java/eu/faircode/email/NavMenuItem.java +++ b/app/src/main/java/eu/faircode/email/NavMenuItem.java @@ -21,6 +21,10 @@ public class NavMenuItem { this.longClick = longClick; } + void setIcon(int icon) { + this.icon = icon; + } + void setCount(Integer count) { if (count != null && count == 0) count = null; diff --git a/app/src/main/java/eu/faircode/email/TupleOperationStats.java b/app/src/main/java/eu/faircode/email/TupleOperationStats.java new file mode 100644 index 0000000000..b309698917 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/TupleOperationStats.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-2019 by Marcel Bokhorst (M66B) +*/ + +public class TupleOperationStats { + public Integer pending; + public Integer errors; +}