Added message categories

This commit is contained in:
M66B 2021-10-04 11:41:51 +02:00
parent 87d4855113
commit 4b74d3ae39
7 changed files with 83 additions and 65 deletions

View File

@ -101,6 +101,7 @@ public interface DaoMessage {
" AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_drafts + ")" + " 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)" + " AND (:filter_language IS NULL OR SUM(message.language = :filter_language) > 0)" +
" ORDER BY -IFNULL(message.importance, 1)" + " ORDER BY -IFNULL(message.importance, 1)" +
", account.category COLLATE NOCASE" +
", CASE" + ", CASE" +
" WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" + " WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" +
" WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" + " WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" +

View File

@ -191,15 +191,17 @@ public class FragmentAccounts extends FragmentBase {
return null; 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 tvCategory = header.findViewById(R.id.tvCategory);
TextView tvDate = header.findViewById(R.id.tvDate);
if (cards) { if (cards) {
View vSeparatorCategory = header.findViewById(R.id.vSeparatorCategory); View vSeparator = header.findViewById(R.id.vSeparator);
vSeparatorCategory.setVisibility(View.GONE); vSeparator.setVisibility(View.GONE);
} }
tvCategory.setText(account.category); tvCategory.setText(account.category);
tvDate.setVisibility(View.GONE);
header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY), header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

View File

@ -202,7 +202,16 @@ public class FragmentFolders extends FragmentBase {
rvFolder.setLayoutManager(llm); rvFolder.setLayoutManager(llm);
if (!cards) { 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)); itemDecorator.setDrawable(getContext().getDrawable(R.drawable.divider));
rvFolder.addItemDecoration(itemDecorator); rvFolder.addItemDecoration(itemDecorator);
} }
@ -255,15 +264,17 @@ public class FragmentFolders extends FragmentBase {
return null; 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 tvCategory = header.findViewById(R.id.tvCategory);
TextView tvDate = header.findViewById(R.id.tvDate);
if (cards) { if (cards) {
View vSeparatorCategory = header.findViewById(R.id.vSeparatorCategory); View vSeparator = header.findViewById(R.id.vSeparator);
vSeparatorCategory.setVisibility(View.GONE); vSeparator.setVisibility(View.GONE);
} }
tvCategory.setText(account.accountCategory); tvCategory.setText(account.accountCategory);
tvDate.setVisibility(View.GONE);
header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY), header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

View File

@ -107,7 +107,6 @@ import android.view.inputmethod.EditorInfo;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
@ -667,14 +666,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
rvMessage.addItemDecoration(itemDecorator); rvMessage.addItemDecoration(itemDecorator);
} }
View inDate = view.findViewById(R.id.inDate); View inGroup = view.findViewById(R.id.inGroup);
TextView tvFixedDate = inDate.findViewById(R.id.tvDate); TextView tvFixedCategory = inGroup.findViewById(R.id.tvCategory);
View vSeparatorDate = inDate.findViewById(R.id.vSeparatorDate); TextView tvFixedDate = inGroup.findViewById(R.id.tvDate);
View vFixedSeparator = inGroup.findViewById(R.id.vSeparator);
String sort = prefs.getString("sort", "time"); 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) if (cards)
vSeparatorDate.setVisibility(View.GONE); vFixedSeparator.setVisibility(View.GONE);
if (date_bold) if (date_bold)
tvFixedDate.setTypeface(Typeface.DEFAULT_BOLD); tvFixedDate.setTypeface(Typeface.DEFAULT_BOLD);
@ -684,9 +685,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
int count = parent.getChildCount(); int count = parent.getChildCount();
if (date_fixed) if (date_fixed)
if ("time".equals(adapter.getSort())) if ("time".equals(adapter.getSort()))
inDate.setVisibility(count > 0 ? View.VISIBLE : View.INVISIBLE); inGroup.setVisibility(count > 0 ? View.VISIBLE : View.INVISIBLE);
else else
inDate.setVisibility(View.GONE); inGroup.setVisibility(View.GONE);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
View view = parent.getChildAt(i); View view = parent.getChildAt(i);
@ -696,7 +697,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
TupleMessageEx top = adapter.getItemAtPosition(pos); TupleMessageEx top = adapter.getItemAtPosition(pos);
tvFixedDate.setVisibility(top == null ? View.INVISIBLE : View.VISIBLE); tvFixedDate.setVisibility(top == null ? View.INVISIBLE : View.VISIBLE);
if (!cards) 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())); tvFixedDate.setText(top == null ? null : getRelativeDate(top.received, parent.getContext()));
} else { } else {
View header = getView(view, parent, pos); 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) { 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) if (pos == NO_POSITION)
return null; return null;
@ -734,6 +732,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null) if (message == null)
return 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) { if (pos > 0) {
Calendar cal0 = Calendar.getInstance(); Calendar cal0 = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance(); Calendar cal1 = Calendar.getInstance();
@ -744,26 +751,38 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
int day0 = cal0.get(Calendar.DAY_OF_YEAR); int day0 = cal0.get(Calendar.DAY_OF_YEAR);
int day1 = cal1.get(Calendar.DAY_OF_YEAR); int day1 = cal1.get(Calendar.DAY_OF_YEAR);
if (year0 == year1 && day0 == day1) 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); TextView tvDate = header.findViewById(R.id.tvDate);
tvDate.setTextSize(TypedValue.COMPLEX_UNIT_PX, Helper.getTextSize(parent.getContext(), adapter.getZoom())); tvCategory.setVisibility(ch ? View.VISIBLE : View.GONE);
if (date_bold) tvDate.setVisibility(dh ? View.VISIBLE : View.GONE);
tvDate.setTypeface(Typeface.DEFAULT_BOLD);
if (cards) { if (ch)
View vSeparatorDate = header.findViewById(R.id.vSeparatorDate); tvCategory.setText(message.accountCategory);
vSeparatorDate.setVisibility(View.GONE);
if (dh) {
tvDate.setTextSize(TypedValue.COMPLEX_UNIT_PX, Helper.getTextSize(parent.getContext(), adapter.getZoom()));
if (date_bold)
tvDate.setTypeface(Typeface.DEFAULT_BOLD);
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);
} }
tvDate.setText(getRelativeDate(message.received, parent.getContext()));
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), header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());

View File

@ -136,8 +136,8 @@
app:layout_constraintTop_toBottomOf="@id/tvHintSelect" /> app:layout_constraintTop_toBottomOf="@id/tvHintSelect" />
<include <include
android:id="@+id/inDate" android:id="@+id/inGroup"
layout="@layout/item_message_date" layout="@layout/item_group"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -182,7 +182,7 @@
app:layout_constraintBottom_toTopOf="@+id/sbThread" app:layout_constraintBottom_toTopOf="@+id/sbThread"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/inDate" /> app:layout_constraintTop_toBottomOf="@id/inGroup" />
<View <View
android:id="@+id/vwAnchor" android:id="@+id/vwAnchor"

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<eu.faircode.email.FixedTextView
android:id="@+id/tvCategory"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="6dp"
android:text="Category"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/vSeparatorCategory"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCategory" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -4,6 +4,18 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<eu.faircode.email.FixedTextView
android:id="@+id/tvCategory"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="6dp"
android:text="Category"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvDate" android:id="@+id/tvDate"
android:layout_width="0dp" android:layout_width="0dp"
@ -14,10 +26,10 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toBottomOf="@+id/tvCategory" />
<View <View
android:id="@+id/vSeparatorDate" android:id="@+id/vSeparator"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="1dp" android:layout_height="1dp"
android:background="?attr/colorSeparator" android:background="?attr/colorSeparator"