Added flagging from notification

pull/156/head
M66B 6 years ago
parent a128036d11
commit 4dbb17facc

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

@ -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"

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

@ -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<EntityMessage> 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 {

@ -91,6 +91,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbNotifyActionArchive" />
<CheckBox
android:id="@+id/cbNotifyActionFlag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_advanced_notify_action_flag"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbNotifyActionReply" />
<CheckBox
android:id="@+id/cbNotifyActionSeen"
android:layout_width="wrap_content"
@ -98,7 +107,7 @@
android:layout_marginTop="6dp"
android:text="@string/title_advanced_notify_action_seen"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbNotifyActionReply" />
app:layout_constraintTop_toBottomOf="@id/cbNotifyActionFlag" />
<TextView
android:id="@+id/tvNotifyActionsHint"

@ -203,6 +203,7 @@
<string name="title_advanced_notify_action_trash">Trash</string>
<string name="title_advanced_notify_action_archive">Archive</string>
<string name="title_advanced_notify_action_reply">Reply</string>
<string name="title_advanced_notify_action_flag">Star</string>
<string name="title_advanced_notify_action_seen">Read</string>
<string name="title_advanced_notify_action_hint">At most three actions will be shown</string>
<string name="title_advanced_light">Use notification light</string>

Loading…
Cancel
Save