mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-08 18:13:24 +02:00
Optionally show unified inbox in nav menu
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user