From dabc89bc27eb8434f8c317d8624a8ce978403923 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 18 Sep 2022 17:08:00 +0200 Subject: [PATCH] Added option to group messages by week --- .../eu/faircode/email/FragmentMessages.java | 21 ++++++++++++++++--- .../eu/faircode/email/FragmentOptions.java | 2 +- .../email/FragmentOptionsDisplay.java | 14 ++++++++++++- .../res/layout/fragment_options_display.xml | 14 ++++++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 48a089564f..5cf4116347 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -341,6 +341,7 @@ public class FragmentMessages extends FragmentBase private boolean dividers; private boolean category; private boolean date; + private boolean date_week; private boolean date_fixed; private boolean date_bold; private boolean threading; @@ -481,6 +482,7 @@ public class FragmentMessages extends FragmentBase dividers = prefs.getBoolean("dividers", true); category = prefs.getBoolean("group_category", false); date = prefs.getBoolean("date", true); + date_week = prefs.getBoolean("date_week", false); date_fixed = (!date && prefs.getBoolean("date_fixed", false)); date_bold = prefs.getBoolean("date_bold", false); threading = (prefs.getBoolean("threading", true) || @@ -946,8 +948,8 @@ public class FragmentMessages extends FragmentBase cal1.setTimeInMillis(message.received); int year0 = cal0.get(Calendar.YEAR); int year1 = cal1.get(Calendar.YEAR); - int day0 = cal0.get(Calendar.DAY_OF_YEAR); - int day1 = cal1.get(Calendar.DAY_OF_YEAR); + int day0 = cal0.get(date_week ? Calendar.WEEK_OF_YEAR : Calendar.DAY_OF_YEAR); + int day1 = cal1.get(date_week ? Calendar.WEEK_OF_YEAR : Calendar.DAY_OF_YEAR); if (year0 == year1 && day0 == day1) dh = false; } @@ -980,7 +982,9 @@ public class FragmentMessages extends FragmentBase vSeparator.setVisibility(View.GONE); } - tvDate.setText(getRelativeDate(message.received, parent.getContext())); + tvDate.setText(date_week + ? getWeek(message.received, parent.getContext()) + : getRelativeDate(message.received, parent.getContext())); view.setContentDescription(tvDate.getText().toString()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) @@ -1016,6 +1020,17 @@ public class FragmentMessages extends FragmentBase DAY_IN_MILLIS, 0); return (rtime == null ? "" : rtime.toString()); } + + @NonNull + String getWeek(long time, Context context) { + StringBuilder sb = new StringBuilder(); + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(time); + sb.append(cal.get(Calendar.YEAR)).append('-').append(cal.get(Calendar.WEEK_OF_YEAR)); + cal.set(Calendar.DAY_OF_WEEK, 1); + sb.append(' ').append(Helper.getDateInstance(context).format(cal.getTimeInMillis())); + return sb.toString(); + } }; rvMessage.addItemDecoration(dateDecorator); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 8839f4e0d7..f5c9c8f1c5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -136,7 +136,7 @@ public class FragmentOptions extends FragmentBase { "portrait2", "portrait2c", "portrait_min_size", "landscape", "landscape_min_size", "column_width", "nav_categories", "nav_count", "nav_unseen_drafts", "nav_count_pinned", "navbar_colorize", - "indentation", "date", "date_fixed", "date_bold", "threading", "threading_unread", + "indentation", "date", "date_week", "date_fixed", "date_bold", "threading", "threading_unread", "highlight_unread", "highlight_color", "color_stripe", "color_stripe_wide", "avatars", "bimi", "favicons", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold", "authentication", "authentication_indicator", diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index af76b2f792..0432db0127 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -68,6 +68,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer private Button btnTheme; private Spinner spStartup; private SwitchCompat swDate; + private SwitchCompat swDateWeek; private SwitchCompat swDateFixed; private SwitchCompat swDateBold; private SwitchCompat swCategory; @@ -190,7 +191,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer private final static String[] RESET_OPTIONS = new String[]{ "theme", "startup", - "date", "date_fixed", "date_bold", "group_category", + "date", "date_week", "date_fixed", "date_bold", "group_category", "cards", "beige", "tabular_card_bg", "shadow_unread", "shadow_highlight", "dividers", "portrait2", "portrait2c", "landscape", "close_pane", "column_width", "nav_options", "nav_categories", "nav_count", "nav_unseen_drafts", "nav_count_pinned", "navbar_colorize", @@ -228,6 +229,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer btnTheme = view.findViewById(R.id.btnTheme); spStartup = view.findViewById(R.id.spStartup); swDate = view.findViewById(R.id.swDate); + swDateWeek = view.findViewById(R.id.swDateWeek); swDateFixed = view.findViewById(R.id.swDateFixed); swDateBold = view.findViewById(R.id.swDateBold); swCategory = view.findViewById(R.id.swCategory); @@ -401,11 +403,19 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("date", checked).apply(); + swDateWeek.setEnabled(checked); swDateFixed.setEnabled(!checked); swDateBold.setEnabled(checked || swDateFixed.isChecked()); } }); + swDateWeek.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("date_week", checked).apply(); + } + }); + swDateFixed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -1347,6 +1357,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } swDate.setChecked(prefs.getBoolean("date", true)); + swDateWeek.setChecked(prefs.getBoolean("date_week", false)); + swDateWeek.setEnabled(swDate.isChecked()); swDateFixed.setChecked(prefs.getBoolean("date_fixed", false)); swDateFixed.setEnabled(!swDate.isChecked()); swDateBold.setChecked(prefs.getBoolean("date_bold", false)); diff --git a/app/src/main/res/layout/fragment_options_display.xml b/app/src/main/res/layout/fragment_options_display.xml index 67f03dba60..95b35c3045 100644 --- a/app/src/main/res/layout/fragment_options_display.xml +++ b/app/src/main/res/layout/fragment_options_display.xml @@ -158,6 +158,18 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swDate" /> + + Use highlight color instead of accent color Use divider lines when using tabular style Group by date + Group by week instead of day Show fixed date header at the top Show date in bold Conversation threading