From 4b74d3ae3938824edbbfc01d26dba60884dd6e53 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 4 Oct 2021 11:41:51 +0200 Subject: [PATCH] Added message categories --- .../java/eu/faircode/email/DaoMessage.java | 1 + .../eu/faircode/email/FragmentAccounts.java | 8 ++- .../eu/faircode/email/FragmentFolders.java | 19 +++-- .../eu/faircode/email/FragmentMessages.java | 69 ++++++++++++------- app/src/main/res/layout/fragment_messages.xml | 6 +- app/src/main/res/layout/item_category.xml | 27 -------- .../{item_message_date.xml => item_group.xml} | 16 ++++- 7 files changed, 82 insertions(+), 64 deletions(-) delete mode 100644 app/src/main/res/layout/item_category.xml rename app/src/main/res/layout/{item_message_date.xml => item_group.xml} (64%) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 159900ca73..f7e312d5a6 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -101,6 +101,7 @@ public interface DaoMessage { " AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_drafts + ")" + " AND (:filter_language IS NULL OR SUM(message.language = :filter_language) > 0)" + " ORDER BY -IFNULL(message.importance, 1)" + + ", account.category COLLATE NOCASE" + ", CASE" + " WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" + " WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" + diff --git a/app/src/main/java/eu/faircode/email/FragmentAccounts.java b/app/src/main/java/eu/faircode/email/FragmentAccounts.java index 001d960003..36e38deba9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccounts.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccounts.java @@ -191,15 +191,17 @@ public class FragmentAccounts extends FragmentBase { return null; } - View header = inflater.inflate(R.layout.item_category, parent, false); + View header = inflater.inflate(R.layout.item_group, parent, false); TextView tvCategory = header.findViewById(R.id.tvCategory); + TextView tvDate = header.findViewById(R.id.tvDate); if (cards) { - View vSeparatorCategory = header.findViewById(R.id.vSeparatorCategory); - vSeparatorCategory.setVisibility(View.GONE); + View vSeparator = header.findViewById(R.id.vSeparator); + vSeparator.setVisibility(View.GONE); } tvCategory.setText(account.category); + tvDate.setVisibility(View.GONE); header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index 8dbd166159..fda0e76302 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -202,7 +202,16 @@ public class FragmentFolders extends FragmentBase { rvFolder.setLayoutManager(llm); if (!cards) { - DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), llm.getOrientation()); + DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), llm.getOrientation()) { + @Override + public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { + View clItem = view.findViewById(R.id.clItem); + if (clItem == null || clItem.getVisibility() == View.GONE) + outRect.setEmpty(); + else + super.getItemOffsets(outRect, view, parent, state); + } + }; itemDecorator.setDrawable(getContext().getDrawable(R.drawable.divider)); rvFolder.addItemDecoration(itemDecorator); } @@ -255,15 +264,17 @@ public class FragmentFolders extends FragmentBase { return null; } - View header = inflater.inflate(R.layout.item_category, parent, false); + View header = inflater.inflate(R.layout.item_group, parent, false); TextView tvCategory = header.findViewById(R.id.tvCategory); + TextView tvDate = header.findViewById(R.id.tvDate); if (cards) { - View vSeparatorCategory = header.findViewById(R.id.vSeparatorCategory); - vSeparatorCategory.setVisibility(View.GONE); + View vSeparator = header.findViewById(R.id.vSeparator); + vSeparator.setVisibility(View.GONE); } tvCategory.setText(account.accountCategory); + tvDate.setVisibility(View.GONE); header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 69608a47b0..033d1e22a7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -107,7 +107,6 @@ import android.view.inputmethod.EditorInfo; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -667,14 +666,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. rvMessage.addItemDecoration(itemDecorator); } - View inDate = view.findViewById(R.id.inDate); - TextView tvFixedDate = inDate.findViewById(R.id.tvDate); - View vSeparatorDate = inDate.findViewById(R.id.vSeparatorDate); + View inGroup = view.findViewById(R.id.inGroup); + TextView tvFixedCategory = inGroup.findViewById(R.id.tvCategory); + TextView tvFixedDate = inGroup.findViewById(R.id.tvDate); + View vFixedSeparator = inGroup.findViewById(R.id.vSeparator); String sort = prefs.getString("sort", "time"); - inDate.setVisibility(date_fixed && "time".equals(sort) ? View.INVISIBLE : View.GONE); + inGroup.setVisibility(date_fixed && "time".equals(sort) ? View.INVISIBLE : View.GONE); + tvFixedCategory.setVisibility(View.GONE); if (cards) - vSeparatorDate.setVisibility(View.GONE); + vFixedSeparator.setVisibility(View.GONE); if (date_bold) tvFixedDate.setTypeface(Typeface.DEFAULT_BOLD); @@ -684,9 +685,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. int count = parent.getChildCount(); if (date_fixed) if ("time".equals(adapter.getSort())) - inDate.setVisibility(count > 0 ? View.VISIBLE : View.INVISIBLE); + inGroup.setVisibility(count > 0 ? View.VISIBLE : View.INVISIBLE); else - inDate.setVisibility(View.GONE); + inGroup.setVisibility(View.GONE); for (int i = 0; i < count; i++) { View view = parent.getChildAt(i); @@ -696,7 +697,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. TupleMessageEx top = adapter.getItemAtPosition(pos); tvFixedDate.setVisibility(top == null ? View.INVISIBLE : View.VISIBLE); if (!cards) - vSeparatorDate.setVisibility(top == null ? View.INVISIBLE : View.VISIBLE); + vFixedSeparator.setVisibility(top == null ? View.INVISIBLE : View.VISIBLE); tvFixedDate.setText(top == null ? null : getRelativeDate(top.received, parent.getContext())); } else { View header = getView(view, parent, pos); @@ -721,9 +722,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private View getView(View view, RecyclerView parent, int pos) { - if (!date || !SORT_DATE_HEADER.contains(adapter.getSort()) || date_fixed) - return null; - if (pos == NO_POSITION) return null; @@ -734,6 +732,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. if (message == null) return null; + boolean ch = (viewType == AdapterMessage.ViewType.UNIFIED && + (pos == 0 + ? message.accountCategory != null + : !Objects.equals(prev.accountCategory, message.accountCategory))); + boolean dh = (date && !date_fixed && SORT_DATE_HEADER.contains(adapter.getSort())); + + if (!ch && !dh) + return null; + if (pos > 0) { Calendar cal0 = Calendar.getInstance(); Calendar cal1 = Calendar.getInstance(); @@ -744,25 +751,37 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. int day0 = cal0.get(Calendar.DAY_OF_YEAR); int day1 = cal1.get(Calendar.DAY_OF_YEAR); if (year0 == year1 && day0 == day1) - return null; + dh = false; } - View header = inflater.inflate(R.layout.item_message_date, parent, false); + if (!ch && !dh) + return null; + + View header = inflater.inflate(R.layout.item_group, parent, false); + TextView tvCategory = header.findViewById(R.id.tvCategory); TextView tvDate = header.findViewById(R.id.tvDate); - tvDate.setTextSize(TypedValue.COMPLEX_UNIT_PX, Helper.getTextSize(parent.getContext(), adapter.getZoom())); - if (date_bold) - tvDate.setTypeface(Typeface.DEFAULT_BOLD); + tvCategory.setVisibility(ch ? View.VISIBLE : View.GONE); + tvDate.setVisibility(dh ? View.VISIBLE : View.GONE); - if (cards) { - View vSeparatorDate = header.findViewById(R.id.vSeparatorDate); - vSeparatorDate.setVisibility(View.GONE); - } + if (ch) + tvCategory.setText(message.accountCategory); + + if (dh) { + tvDate.setTextSize(TypedValue.COMPLEX_UNIT_PX, Helper.getTextSize(parent.getContext(), adapter.getZoom())); + if (date_bold) + tvDate.setTypeface(Typeface.DEFAULT_BOLD); - tvDate.setText(getRelativeDate(message.received, parent.getContext())); + if (cards) { + View vSeparator = header.findViewById(R.id.vSeparator); + vSeparator.setVisibility(View.GONE); + } + + tvDate.setText(getRelativeDate(message.received, parent.getContext())); - view.setContentDescription(tvDate.getText().toString()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) - view.setAccessibilityHeading(true); + view.setContentDescription(tvDate.getText().toString()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + view.setAccessibilityHeading(true); + } header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); diff --git a/app/src/main/res/layout/fragment_messages.xml b/app/src/main/res/layout/fragment_messages.xml index a1e1b17830..11ff91146b 100644 --- a/app/src/main/res/layout/fragment_messages.xml +++ b/app/src/main/res/layout/fragment_messages.xml @@ -136,8 +136,8 @@ app:layout_constraintTop_toBottomOf="@id/tvHintSelect" /> + app:layout_constraintTop_toBottomOf="@id/inGroup" /> - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_message_date.xml b/app/src/main/res/layout/item_group.xml similarity index 64% rename from app/src/main/res/layout/item_message_date.xml rename to app/src/main/res/layout/item_group.xml index ab02646e18..2b27298b9f 100644 --- a/app/src/main/res/layout/item_message_date.xml +++ b/app/src/main/res/layout/item_group.xml @@ -4,6 +4,18 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> + + + app:layout_constraintTop_toBottomOf="@+id/tvCategory" />