diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 85de6c55a2..6023ecdd86 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1702,9 +1702,11 @@ class Core { boolean pro = Helper.isPro(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean flags = prefs.getBoolean("flags", true); boolean notify_trash = prefs.getBoolean("notify_trash", true); boolean notify_archive = prefs.getBoolean("notify_archive", true); boolean notify_reply = prefs.getBoolean("notify_reply", false); + boolean notify_flag = prefs.getBoolean("notify_flag", false); boolean notify_seen = prefs.getBoolean("notify_seen", true); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); @@ -1864,6 +1866,16 @@ class Core { mbuilder.addAction(actionReply.build()); } + if (notify_flag && flags) { + Intent flag = new Intent(context, ServiceUI.class).setAction("flag:" + message.id); + PendingIntent piFlag = PendingIntent.getService(context, ServiceUI.PI_FLAG, flag, PendingIntent.FLAG_UPDATE_CURRENT); + NotificationCompat.Action.Builder actionFlag = new NotificationCompat.Action.Builder( + R.drawable.baseline_star_24, + context.getString(R.string.title_advanced_notify_action_flag), + piFlag); + mbuilder.addAction(actionFlag.build()); + } + if (notify_seen) { Intent seen = new Intent(context, ServiceUI.class).setAction("seen:" + message.id); PendingIntent piSeen = PendingIntent.getService(context, ServiceUI.PI_SEEN, seen, PendingIntent.FLAG_UPDATE_CURRENT); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 596279f79e..8b423fb204 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -55,7 +55,7 @@ public class FragmentOptions extends FragmentBase { "addresses", "monospaced", "autohtml", "autoimages", "actionbar", "pull", "autoscroll", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove", "autoresize", "resize", "prefix_once", "autosend", - "notify_trash", "notify_archive", "notify_reply", "notify_seen", "notify_preview", "light", "sound", + "notify_trash", "notify_archive", "notify_reply", "notify_flag", "notify_seen", "notify_preview", "light", "sound", "badge", "subscriptions", "search_local", "english", "authentication", "paranoid", "updates", "debug", "first", "why", "last_update_check", "app_support", "message_swipe", "message_select", "folder_actions", "folder_sync", "edit_ref_confirmed", "show_html_confirmed", "show_images_confirmed", "print_html_confirmed", "show_organization", "style_toolbar" diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index 13a8396b82..d6c508eb67 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -44,8 +44,9 @@ public class FragmentOptionsNotifications extends FragmentBase { private SwitchCompat swNotifyPreview; private CheckBox cbNotifyActionTrash; private CheckBox cbNotifyActionArchive; - private CheckBox cbNotifyActionSeen; private CheckBox cbNotifyActionReply; + private CheckBox cbNotifyActionFlag; + private CheckBox cbNotifyActionSeen; private SwitchCompat swLight; private Button btnSound; @@ -64,6 +65,7 @@ public class FragmentOptionsNotifications extends FragmentBase { cbNotifyActionTrash = view.findViewById(R.id.cbNotifyActionTrash); cbNotifyActionArchive = view.findViewById(R.id.cbNotifyActionArchive); cbNotifyActionReply = view.findViewById(R.id.cbNotifyActionReply); + cbNotifyActionFlag = view.findViewById(R.id.cbNotifyActionFlag); cbNotifyActionSeen = view.findViewById(R.id.cbNotifyActionSeen); swLight = view.findViewById(R.id.swLight); btnSound = view.findViewById(R.id.btnSound); @@ -104,6 +106,13 @@ public class FragmentOptionsNotifications extends FragmentBase { } }); + cbNotifyActionFlag.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean checked) { + prefs.edit().putBoolean("notify_flag", checked).apply(); + } + }); + cbNotifyActionSeen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean checked) { @@ -143,6 +152,7 @@ public class FragmentOptionsNotifications extends FragmentBase { cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true)); cbNotifyActionArchive.setChecked(prefs.getBoolean("notify_archive", true)); cbNotifyActionReply.setChecked(prefs.getBoolean("notify_reply", false)); + cbNotifyActionFlag.setChecked(prefs.getBoolean("notify_flag", false)); cbNotifyActionSeen.setChecked(prefs.getBoolean("notify_seen", true)); swLight.setChecked(prefs.getBoolean("light", false)); diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index 0344f7ba8f..45cd9a7c66 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -21,17 +21,22 @@ package eu.faircode.email; import android.app.IntentService; import android.content.Intent; +import android.content.SharedPreferences; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; + +import java.util.List; 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 = 4; - static final int PI_SEEN = 5; - static final int PI_IGNORED = 6; - static final int PI_SNOOZED = 7; + static final int PI_FLAG = 6; + static final int PI_SEEN = 6; + static final int PI_IGNORED = 7; + static final int PI_SNOOZED = 8; public ServiceUI() { this(ServiceUI.class.getName()); @@ -83,6 +88,9 @@ public class ServiceUI extends IntentService { case "reply": onReply(id); break; + case "flag": + onFlag(id); + break; case "seen": onSeen(id); break; @@ -154,6 +162,30 @@ public class ServiceUI extends IntentService { startActivity(reply); } + private void onFlag(long id) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + boolean threading = prefs.getBoolean("threading", true); + + DB db = DB.getInstance(this); + try { + db.beginTransaction(); + + EntityMessage message = db.message().getMessage(id); + if (message != null) { + List messages = db.message().getMessageByThread( + message.account, message.thread, threading ? null : id, null); + for (EntityMessage threaded : messages) { + EntityOperation.queue(this, db, threaded, EntityOperation.FLAG, true); + EntityOperation.queue(this, db, threaded, EntityOperation.SEEN, true); + } + } + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + private void onSeen(long id) { DB db = DB.getInstance(this); try { diff --git a/app/src/main/res/layout/fragment_options_notifications.xml b/app/src/main/res/layout/fragment_options_notifications.xml index e76eecffd7..b342cbd0e4 100644 --- a/app/src/main/res/layout/fragment_options_notifications.xml +++ b/app/src/main/res/layout/fragment_options_notifications.xml @@ -91,6 +91,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cbNotifyActionArchive" /> + + + app:layout_constraintTop_toBottomOf="@id/cbNotifyActionFlag" /> Trash Archive Reply + Star Read At most three actions will be shown Use notification light