Added option to show newest notification first

This commit is contained in:
M66B 2020-10-23 17:17:48 +02:00
parent 5c7a1cade1
commit 9e261b7e3f
4 changed files with 33 additions and 2 deletions

View File

@ -94,6 +94,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
@ -3523,7 +3524,8 @@ class Core {
" id=" + id + " group=" + notification.getGroup() +
(Build.VERSION.SDK_INT < Build.VERSION_CODES.O
? " sdk=" + Build.VERSION.SDK_INT
: " channel=" + notification.getChannelId()));
: " channel=" + notification.getChannelId()) +
" sort=" + notification.getSortKey());
try {
nm.notify(tag, 1, notification);
} catch (Throwable ex) {
@ -3556,6 +3558,7 @@ class Core {
boolean pro = ActivityBilling.isPro(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean notify_newest_first = prefs.getBoolean("notify_newest_first", false);
boolean name_email = prefs.getBoolean("name_email", false);
boolean prefer_contact = prefs.getBoolean("prefer_contact", false);
boolean flags = prefs.getBoolean("flags", true);
@ -3761,6 +3764,9 @@ class Core {
channelName = channel.getId();
}
String sortKey = String.format(Locale.ROOT, "%13d",
notify_newest_first ? (10000000000000L - message.received) : message.received);
NotificationCompat.Builder mbuilder =
new NotificationCompat.Builder(context, channelName)
.addExtras(args)
@ -3768,6 +3774,7 @@ class Core {
.setContentIntent(piContent)
.setWhen(message.received)
.setShowWhen(true)
.setSortKey(sortKey)
.setDeleteIntent(piIgnore)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setCategory(NotificationCompat.CATEGORY_EMAIL)

View File

@ -58,6 +58,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private ImageView ivChannelDefault;
private Button btnManageService;
private ImageView ivChannelService;
private SwitchCompat swNewestFirst;
private SwitchCompat swBackground;
private CheckBox cbNotifyActionTrash;
@ -95,6 +96,8 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private Group grpNotification;
private final static String[] RESET_OPTIONS = new String[]{
"notify_newest_first",
"background_service",
"notify_trash", "notify_junk", "notify_block_sender", "notify_archive", "notify_move",
"notify_reply", "notify_reply_direct",
"notify_flag", "notify_seen", "notify_snooze",
@ -121,6 +124,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
ivChannelDefault = view.findViewById(R.id.ivChannelDefault);
btnManageService = view.findViewById(R.id.btnManageService);
ivChannelService = view.findViewById(R.id.ivChannelService);
swNewestFirst = view.findViewById(R.id.swNewestFirst);
swBackground = view.findViewById(R.id.swBackground);
cbNotifyActionTrash = view.findViewById(R.id.cbNotifyActionTrash);
@ -205,6 +209,13 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
ivChannelService.setVisibility(View.GONE);
swNewestFirst.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_newest_first", checked).apply();
}
});
swBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -484,6 +495,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
boolean pro = ActivityBilling.isPro(getContext());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swNewestFirst.setChecked(prefs.getBoolean("notify_newest_first", false));
swBackground.setChecked(prefs.getBoolean("background_service", false));
cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true) || !pro);

View File

@ -115,6 +115,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnManageService" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNewestFirst"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_notifications_newest_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvManageServiceHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swBackground"
android:layout_width="0dp"
@ -123,7 +134,7 @@
android:text="@string/title_advanced_notifications_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvManageServiceHint"
app:layout_constraintTop_toBottomOf="@id/swNewestFirst"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

View File

@ -427,6 +427,7 @@
<string name="title_advanced_notifications">Manage notifications</string>
<string name="title_advanced_notifications_default">Default channel</string>
<string name="title_advanced_notifications_service">Receive channel</string>
<string name="title_advanced_notifications_newest_first">Show newest notifications first</string>
<string name="title_advanced_notifications_background">Use background service to synchronize messages</string>
<string name="title_advanced_notifications_background_hint">A background service can be stopped by Android at any time, but doesn\'t require a status bar notification</string>