Added option to group messages by week

This commit is contained in:
M66B 2022-09-18 17:08:00 +02:00
parent 55cadb8dce
commit dabc89bc27
5 changed files with 46 additions and 6 deletions

View File

@ -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);

View File

@ -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",

View File

@ -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));

View File

@ -158,6 +158,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDate" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDateWeek"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_date_week"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDateHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDateFixed"
android:layout_width="0dp"
@ -167,7 +179,7 @@
android:text="@string/title_advanced_date_fixed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDateHint"
app:layout_constraintTop_toBottomOf="@id/swDateWeek"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

View File

@ -514,6 +514,7 @@
<string name="title_advanced_cards_shadow_highlight">Use highlight color instead of accent color</string>
<string name="title_advanced_tabular_dividers">Use divider lines when using tabular style</string>
<string name="title_advanced_date_header">Group by date</string>
<string name="title_advanced_date_week">Group by week instead of day</string>
<string name="title_advanced_date_fixed">Show fixed date header at the top</string>
<string name="title_advanced_date_bold">Show date in bold</string>
<string name="title_advanced_threading">Conversation threading</string>