Show operation errors in nav menu

This commit is contained in:
M66B 2019-05-04 22:38:11 +02:00
parent 496ce0ae9e
commit f473703299
4 changed files with 38 additions and 5 deletions

View File

@ -378,10 +378,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}
});
db.operation().liveCount().observe(this, new Observer<Integer>() {
db.operation().liveStats().observe(this, new Observer<TupleOperationStats>() {
@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();
}
});

View File

@ -65,8 +65,10 @@ public interface DaoOperation {
@Query(GET_OPS_FOLDER)
LiveData<List<EntityOperation>> liveOperations(long folder);
@Query("SELECT COUNT(operation.id) FROM operation")
LiveData<Integer> 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<TupleOperationStats> liveStats();
@Query("SELECT COUNT(operation.id) FROM operation" +
" WHERE operation.name = '" + EntityOperation.SEND + "'")

View File

@ -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;

View File

@ -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 <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
public class TupleOperationStats {
public Integer pending;
public Integer errors;
}