diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 3ed99ce13e..4b902ca67d 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -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) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index 5876c6418f..e51429a146 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -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); diff --git a/app/src/main/res/layout/fragment_options_notifications.xml b/app/src/main/res/layout/fragment_options_notifications.xml index 0b86bcb8bc..caf99860af 100644 --- a/app/src/main/res/layout/fragment_options_notifications.xml +++ b/app/src/main/res/layout/fragment_options_notifications.xml @@ -115,6 +115,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btnManageService" /> + + Manage notifications Default channel Receive channel + Show newest notifications first Use background service to synchronize messages A background service can be stopped by Android at any time, but doesn\'t require a status bar notification