Added notify action junk

This commit is contained in:
M66B
2019-09-26 21:28:05 +02:00
parent aa3f5e01ab
commit bfe383594c
5 changed files with 55 additions and 34 deletions

View File

@@ -2475,6 +2475,7 @@ class Core {
boolean flags = prefs.getBoolean("flags", true);
boolean notify_preview = prefs.getBoolean("notify_preview", true);
boolean notify_trash = (prefs.getBoolean("notify_trash", true) || !pro);
boolean notify_junk = (prefs.getBoolean("notify_junk", true) && pro);
boolean notify_archive = (prefs.getBoolean("notify_archive", true) || !pro);
boolean notify_reply = (prefs.getBoolean("notify_reply", false) && pro);
boolean notify_reply_direct = (prefs.getBoolean("notify_reply_direct", false) && pro);
@@ -2671,6 +2672,19 @@ class Core {
mbuilder.addAction(actionTrash.build());
}
if (notify_junk &&
db.folder().getFolderByType(message.account, EntityFolder.JUNK) != null) {
Intent junk = new Intent(context, ServiceUI.class)
.setAction("junk:" + message.id)
.putExtra("group", group);
PendingIntent piJunk = PendingIntent.getService(context, ServiceUI.PI_JUNK, junk, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action.Builder actionJunk = new NotificationCompat.Action.Builder(
R.drawable.baseline_flag_24,
context.getString(R.string.title_advanced_notify_action_junk),
piJunk);
mbuilder.addAction(actionJunk.build());
}
if (notify_archive &&
db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE) != null) {
Intent archive = new Intent(context, ServiceUI.class)

View File

@@ -58,6 +58,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private SwitchCompat swUnseenIgnored;
private SwitchCompat swNotifyPreview;
private CheckBox cbNotifyActionTrash;
private CheckBox cbNotifyActionJunk;
private CheckBox cbNotifyActionArchive;
private CheckBox cbNotifyActionReply;
private CheckBox cbNotifyActionReplyDirect;
@@ -79,7 +80,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private final static String[] RESET_OPTIONS = new String[]{
"badge", "unseen_ignored",
"notify_preview", "notify_trash", "notify_archive", "notify_reply", "notify_reply_direct", "notify_flag",
"notify_preview", "notify_trash", "notify_junk", "notify_archive", "notify_reply", "notify_reply_direct", "notify_flag",
"notify_seen", "notify_snooze", "notify_snooze_duration", "notify_remove",
"biometrics_notify",
"light", "sound", "alert_once"
@@ -99,6 +100,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swUnseenIgnored = view.findViewById(R.id.swUnseenIgnored);
swNotifyPreview = view.findViewById(R.id.swNotifyPreview);
cbNotifyActionTrash = view.findViewById(R.id.cbNotifyActionTrash);
cbNotifyActionJunk = view.findViewById(R.id.cbNotifyActionJunk);
cbNotifyActionArchive = view.findViewById(R.id.cbNotifyActionArchive);
cbNotifyActionReply = view.findViewById(R.id.cbNotifyActionReply);
cbNotifyActionReplyDirect = view.findViewById(R.id.cbNotifyActionReplyDirect);
@@ -155,6 +157,13 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
}
});
cbNotifyActionJunk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_junk", checked).apply();
}
});
cbNotifyActionArchive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
@@ -338,6 +347,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true));
cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true) || !pro);
cbNotifyActionJunk.setChecked(prefs.getBoolean("notify_junk", false) && pro);
cbNotifyActionArchive.setChecked(prefs.getBoolean("notify_archive", true) || !pro);
cbNotifyActionReply.setChecked(prefs.getBoolean("notify_reply", false) && pro);
cbNotifyActionReplyDirect.setChecked(prefs.getBoolean("notify_reply_direct", false) && pro);
@@ -347,8 +357,10 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
etNotifyActionSnooze.setText(Integer.toString(prefs.getInt("notify_snooze_duration", 60)));
cbNotifyActionTrash.setEnabled(pro);
cbNotifyActionJunk.setEnabled(pro);
cbNotifyActionArchive.setEnabled(pro);
cbNotifyActionReply.setEnabled(pro);
cbNotifyActionReplyDirect.setEnabled(pro);
cbNotifyActionFlag.setEnabled(pro);
cbNotifyActionSeen.setEnabled(pro);
cbNotifyActionSnooze.setEnabled(pro);

View File

@@ -42,13 +42,14 @@ import javax.mail.internet.InternetAddress;
public class ServiceUI extends IntentService {
static final int PI_CLEAR = 1;
static final int PI_TRASH = 2;
static final int PI_ARCHIVE = 3;
static final int PI_REPLY_DIRECT = 4;
static final int PI_FLAG = 5;
static final int PI_SEEN = 6;
static final int PI_SNOOZE = 7;
static final int PI_IGNORED = 8;
static final int PI_WAKEUP = 9;
static final int PI_JUNK = 3;
static final int PI_ARCHIVE = 4;
static final int PI_REPLY_DIRECT = 5;
static final int PI_FLAG = 6;
static final int PI_SEEN = 7;
static final int PI_SNOOZE = 8;
static final int PI_IGNORED = 9;
static final int PI_WAKEUP = 10;
public ServiceUI() {
this(ServiceUI.class.getName());
@@ -97,12 +98,17 @@ public class ServiceUI extends IntentService {
case "trash":
cancel(group, id);
onTrash(id);
onMove(id, EntityFolder.TRASH);
break;
case "junk":
cancel(group, id);
onMove(id, EntityFolder.JUNK);
break;
case "archive":
cancel(group, id);
onArchive(id);
onMove(id, EntityFolder.ARCHIVE);
break;
case "reply":
@@ -158,7 +164,7 @@ public class ServiceUI extends IntentService {
nm.cancel(tag, 1);
}
private void onTrash(long id) {
private void onMove(long id, String folderType) {
DB db = DB.getInstance(this);
try {
db.beginTransaction();
@@ -167,7 +173,7 @@ public class ServiceUI extends IntentService {
if (message == null)
return;
EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
EntityFolder trash = db.folder().getFolderByType(message.account, folderType);
if (trash != null)
EntityOperation.queue(this, message, EntityOperation.MOVE, trash.id);
@@ -177,27 +183,6 @@ public class ServiceUI extends IntentService {
}
}
private void onArchive(long id) {
DB db = DB.getInstance(this);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return;
EntityFolder archive = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE);
if (archive == null)
archive = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
if (archive != null)
EntityOperation.queue(this, message, EntityOperation.MOVE, archive.id);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
private void onReplyDirect(long id, Intent intent) throws IOException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean prefix_once = prefs.getBoolean("prefix_once", true);