mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 14:41:08 +00:00
Optionally show unified inbox in nav menu
This commit is contained in:
parent
62fcc7da21
commit
4b57d527b7
3 changed files with 70 additions and 13 deletions
|
@ -42,7 +42,10 @@ import java.text.NumberFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.ViewHolder> {
|
||||
private Context context;
|
||||
|
@ -92,7 +95,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
|
|||
}
|
||||
|
||||
private void bindTo(TupleFolderUnified folder) {
|
||||
if (EntityFolder.INBOX.equals(folder.type))
|
||||
if (EntityFolder.INBOX.equals(folder.type) || folder.type == null)
|
||||
ivItem.setImageResource(folder.folders > 1
|
||||
? R.drawable.twotone_all_inbox_24
|
||||
: R.drawable.twotone_move_to_inbox_24);
|
||||
|
@ -121,11 +124,14 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
|
|||
tvCount.setText(Helper.formatNumber(count, 99, NF));
|
||||
tvCount.setVisibility(count == 0 || expanded || !nav_count_pinned ? View.GONE : View.VISIBLE);
|
||||
|
||||
String name = (folder.type == null
|
||||
? context.getString(R.string.title_folder_unified)
|
||||
: EntityFolder.localizeType(context, folder.type));
|
||||
|
||||
if (count == 0)
|
||||
tvItem.setText(EntityFolder.localizeType(context, folder.type));
|
||||
tvItem.setText(name);
|
||||
else
|
||||
tvItem.setText(context.getString(R.string.title_name_count,
|
||||
EntityFolder.localizeType(context, folder.type), NF.format(count)));
|
||||
tvItem.setText(context.getString(R.string.title_name_count, name, NF.format(count)));
|
||||
|
||||
tvItem.setTextColor(count == 0 ? textColorSecondary : colorUnread);
|
||||
tvItem.setTypeface(count == 0 ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
|
||||
|
@ -145,13 +151,17 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
|
|||
return;
|
||||
|
||||
TupleFolderUnified folder = items.get(pos);
|
||||
if (folder == null || folder.type == null)
|
||||
if (folder == null)
|
||||
return;
|
||||
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
if (EntityFolder.OUTBOX.equals(folder.type))
|
||||
lbm.sendBroadcast(new Intent(ActivityView.ACTION_VIEW_OUTBOX));
|
||||
else if (folder.folders > 1)
|
||||
if (folder.type == null) {
|
||||
Intent view = new Intent(context, ActivityView.class);
|
||||
view.setAction("unified");
|
||||
context.startActivity(view);
|
||||
} else if (folder.folders > 1)
|
||||
lbm.sendBroadcast(
|
||||
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
|
||||
.putExtra("type", folder.type));
|
||||
|
@ -210,8 +220,52 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
|
|||
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
|
||||
}
|
||||
|
||||
public void set(@NonNull List<TupleFolderUnified> types, boolean expanded) {
|
||||
Log.i("Set nav unified=" + types.size());
|
||||
public void set(@NonNull List<TupleFolderUnified> folders, boolean expanded) {
|
||||
Log.i("Set nav unified=" + folders.size());
|
||||
|
||||
boolean show = false;
|
||||
Map<String, TupleFolderUnified> map = new HashMap<>();
|
||||
TupleFolderUnified unified = new TupleFolderUnified();
|
||||
for (TupleFolderUnified type : new ArrayList<>(folders)) {
|
||||
TupleFolderUnified f = map.get(type.type);
|
||||
if (f == null)
|
||||
map.put(type.type, type);
|
||||
else {
|
||||
f.folders += type.folders;
|
||||
f.messages += type.messages;
|
||||
f.unseen += type.unseen;
|
||||
|
||||
if (Objects.equals(f.color, type.color) ||
|
||||
(f.color == null && f.folders == type.folders)) {
|
||||
f.color = type.color;
|
||||
f.colorCount += type.colorCount;
|
||||
} else
|
||||
f.colorCount++;
|
||||
}
|
||||
|
||||
if (type.unified) {
|
||||
unified.folders += type.folders;
|
||||
unified.messages += type.messages;
|
||||
unified.unseen += type.unseen;
|
||||
|
||||
if (Objects.equals(unified.color, type.color) ||
|
||||
(unified.color == null && unified.folders == type.folders)) {
|
||||
unified.color = type.color;
|
||||
unified.colorCount += type.colorCount;
|
||||
} else
|
||||
unified.colorCount++;
|
||||
}
|
||||
|
||||
if ((EntityFolder.INBOX.equals(type.type) && !type.unified) ||
|
||||
(!EntityFolder.INBOX.equals(type.type) && type.unified))
|
||||
show = true;
|
||||
}
|
||||
|
||||
List<TupleFolderUnified> types = new ArrayList<>();
|
||||
for (String type : map.keySet())
|
||||
types.add(map.get(type));
|
||||
if (unified.folders > 0 && show)
|
||||
types.add(unified);
|
||||
|
||||
Collections.sort(types, new Comparator<TupleFolderUnified>() {
|
||||
@Override
|
||||
|
@ -284,7 +338,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
|
|||
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
||||
TupleFolderUnified f1 = prev.get(oldItemPosition);
|
||||
TupleFolderUnified f2 = next.get(newItemPosition);
|
||||
return f1.type.equals(f2.type);
|
||||
return (Objects.equals(f1.type, f2.type) && f1.unified == f2.unified);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -180,7 +180,7 @@ public interface DaoFolder {
|
|||
" ORDER BY name COLLATE NOCASE")
|
||||
List<EntityFolder> getChildFolders(long parent);
|
||||
|
||||
@Query("SELECT folder.type" +
|
||||
@Query("SELECT folder.type, folder.unified" +
|
||||
", COUNT(DISTINCT folder.id) AS folders" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN NOT message.ui_seen THEN 1 ELSE 0 END) AS unseen" +
|
||||
|
@ -190,9 +190,10 @@ public interface DaoFolder {
|
|||
" LEFT JOIN account ON account.id = folder.account" +
|
||||
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
|
||||
" WHERE (account.id IS NULL OR account.synchronize)" +
|
||||
" AND folder.type <> '" + EntityFolder.SYSTEM + "'" +
|
||||
" AND folder.type <> '" + EntityFolder.USER + "'" +
|
||||
" GROUP BY folder.type")
|
||||
" AND ((folder.type <> '" + EntityFolder.SYSTEM + "'" +
|
||||
" AND folder.type <> '" + EntityFolder.USER + "')" +
|
||||
" OR folder.unified)" +
|
||||
" GROUP BY folder.type, folder.unified")
|
||||
LiveData<List<TupleFolderUnified>> liveUnified();
|
||||
|
||||
@Query("SELECT * FROM folder" +
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Objects;
|
|||
|
||||
public class TupleFolderUnified {
|
||||
public String type;
|
||||
public boolean unified;
|
||||
public int folders;
|
||||
public int messages;
|
||||
public int unseen;
|
||||
|
@ -35,6 +36,7 @@ public class TupleFolderUnified {
|
|||
if (obj instanceof TupleFolderUnified) {
|
||||
TupleFolderUnified other = (TupleFolderUnified) obj;
|
||||
return (Objects.equals(this.type, other.type) &&
|
||||
this.unified == other.unified &&
|
||||
this.folders == other.folders &&
|
||||
this.messages == other.messages &&
|
||||
this.unseen == other.unseen &&
|
||||
|
|
Loading…
Reference in a new issue