Show number of drafts in navigation menu

This commit is contained in:
M66B 2019-11-08 14:48:20 +01:00
parent 79611bb034
commit 1f4d0c1243
6 changed files with 44 additions and 27 deletions

View File

@ -413,9 +413,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}
});
db.folder().liveUnified().observe(this, new Observer<List<EntityFolderUnified>>() {
db.folder().liveUnified().observe(this, new Observer<List<TupleFolderUnified>>() {
@Override
public void onChanged(List<EntityFolderUnified> folders) {
public void onChanged(List<TupleFolderUnified> folders) {
if (folders == null)
folders = new ArrayList<>();
ibExpanderUnified.setVisibility(folders.size() > 0 ? View.VISIBLE : View.GONE);

View File

@ -112,7 +112,13 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
ivItem.setColorFilter(folder.color);
}
int count = (EntityFolder.OUTBOX.equals(folder.type) ? folder.snoozed + folder.operations : folder.unseen);
int count;
if (EntityFolder.OUTBOX.equals(folder.type))
count = folder.snoozed + folder.operations;
else if (EntityFolder.DRAFTS.equals(folder.type))
count = folder.messages;
else
count = folder.unseen;
if (count == 0)
tvItem.setText(folder.getDisplayName(context));
@ -235,6 +241,7 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
Objects.equals(f1.state, f2.state) &&
Objects.equals(f1.sync_state, f2.sync_state) &&
Objects.equals(f1.last_sync, f2.last_sync) &&
f1.messages == f2.messages &&
f1.unseen == f2.unseen &&
f1.snoozed == f2.snoozed &&
f1.operations == f2.operations &&

View File

@ -51,7 +51,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
private int colorUnread;
private int textColorSecondary;
private List<EntityFolderUnified> items = new ArrayList<>();
private List<TupleFolderUnified> items = new ArrayList<>();
private NumberFormat NF = NumberFormat.getNumberInstance();
@ -82,17 +82,23 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
view.setOnClickListener(null);
}
private void bindTo(EntityFolderUnified folder) {
private void bindTo(TupleFolderUnified folder) {
ivItem.setImageResource(EntityFolder.getIcon(folder.type));
if (folder.unseen == 0)
long count;
if (EntityFolder.DRAFTS.equals(folder.type))
count = folder.messages;
else
count = folder.unseen;
if (count == 0)
tvItem.setText(Helper.localizeFolderType(context, folder.type));
else
tvItem.setText(context.getString(R.string.title_name_count,
Helper.localizeFolderType(context, folder.type), NF.format(folder.unseen)));
Helper.localizeFolderType(context, folder.type), NF.format(count)));
tvItem.setTextColor(folder.unseen == 0 ? textColorSecondary : colorUnread);
tvItem.setTypeface(folder.unseen == 0 ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
tvItem.setTextColor(count == 0 ? textColorSecondary : colorUnread);
tvItem.setTypeface(count == 0 ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
tvItemExtra.setVisibility(View.GONE);
ivExternal.setVisibility(View.GONE);
@ -105,7 +111,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
if (pos == RecyclerView.NO_POSITION)
return;
EntityFolderUnified folder = items.get(pos);
TupleFolderUnified folder = items.get(pos);
if (folder == null || folder.type == null)
return;
@ -127,12 +133,12 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
}
public void set(@NonNull List<EntityFolderUnified> types) {
public void set(@NonNull List<TupleFolderUnified> types) {
Log.i("Set nav unified=" + types.size());
Collections.sort(types, new Comparator<EntityFolderUnified>() {
Collections.sort(types, new Comparator<TupleFolderUnified>() {
@Override
public int compare(EntityFolderUnified f1, EntityFolderUnified f2) {
public int compare(TupleFolderUnified f1, TupleFolderUnified f2) {
int i1 = EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type);
int i2 = EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type);
return Integer.compare(i1, i2);
@ -168,10 +174,10 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
}
private class DiffCallback extends DiffUtil.Callback {
private List<EntityFolderUnified> prev = new ArrayList<>();
private List<EntityFolderUnified> next = new ArrayList<>();
private List<TupleFolderUnified> prev = new ArrayList<>();
private List<TupleFolderUnified> next = new ArrayList<>();
DiffCallback(List<EntityFolderUnified> prev, List<EntityFolderUnified> next) {
DiffCallback(List<TupleFolderUnified> prev, List<TupleFolderUnified> next) {
this.prev.addAll(prev);
this.next.addAll(next);
}
@ -188,16 +194,16 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
EntityFolderUnified f1 = prev.get(oldItemPosition);
EntityFolderUnified f2 = next.get(newItemPosition);
TupleFolderUnified f1 = prev.get(oldItemPosition);
TupleFolderUnified f2 = next.get(newItemPosition);
return f1.type.equals(f2.type);
}
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
EntityFolderUnified f1 = prev.get(oldItemPosition);
EntityFolderUnified f2 = next.get(newItemPosition);
return (f1.unseen == f2.unseen);
TupleFolderUnified f1 = prev.get(oldItemPosition);
TupleFolderUnified f2 = next.get(newItemPosition);
return (f1.messages == f2.messages && f1.unseen == f2.unseen);
}
}
@ -215,7 +221,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.unwire();
EntityFolderUnified folder = items.get(position);
TupleFolderUnified folder = items.get(position);
holder.bindTo(folder);
holder.wire();
}

View File

@ -111,6 +111,7 @@ public interface DaoFolder {
@Query("SELECT folder.*" +
", account.`order` AS accountOrder, account.name AS accountName" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN NOT message.ui_seen THEN 1 ELSE 0 END) AS unseen" +
", SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) AS snoozed" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id) AS operations" +
@ -153,8 +154,9 @@ public interface DaoFolder {
" AND type <> '" + EntityFolder.USER + "'")
List<EntityFolder> getSystemFolders(long account);
@Query("SELECT folder.type," +
" SUM(CASE WHEN NOT message.ui_seen AND NOT message.ui_hide THEN 1 ELSE 0 END) AS unseen" +
@Query("SELECT folder.type" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN NOT message.ui_seen AND NOT message.ui_hide THEN 1 ELSE 0 END) AS unseen" +
" FROM folder" +
" JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id" +
@ -162,7 +164,7 @@ public interface DaoFolder {
" AND folder.type <> '" + EntityFolder.SYSTEM + "'" +
" AND folder.type <> '" + EntityFolder.USER + "'" +
" GROUP BY folder.type")
LiveData<List<EntityFolderUnified>> liveUnified();
LiveData<List<TupleFolderUnified>> liveUnified();
@Query("SELECT * FROM folder WHERE id = :id")
EntityFolder getFolder(Long id);

View File

@ -29,6 +29,7 @@ import java.util.Locale;
public class TupleFolderNav extends EntityFolder implements Serializable {
public Integer accountOrder;
public String accountName;
public int messages;
public int unseen;
public int snoozed;
public int operations;

View File

@ -19,7 +19,8 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
public class EntityFolderUnified {
public class TupleFolderUnified {
public String type;
public long unseen;
public int messages;
public int unseen;
}