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