Made notification actions configurable

This commit is contained in:
M66B
2019-05-05 22:28:07 +02:00
parent e506834104
commit 76e41329b4
7 changed files with 375 additions and 159 deletions

View File

@@ -1702,6 +1702,11 @@ class Core {
boolean pro = Helper.isPro(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
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_seen = prefs.getBoolean("notify_seen", true);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Get contact info
@@ -1710,12 +1715,10 @@ class Core {
messageContact.put(message, ContactInfo.get(context, message.from, false));
// Build pending intents
Intent summary = new Intent(context, ActivityView.class);
summary.setAction("unified");
Intent summary = new Intent(context, ActivityView.class).setAction("unified");
PendingIntent piSummary = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, summary, PendingIntent.FLAG_UPDATE_CURRENT);
Intent clear = new Intent(context, ServiceUI.class);
clear.setAction("clear");
Intent clear = new Intent(context, ServiceUI.class).setAction("clear");
PendingIntent piClear = PendingIntent.getService(context, ServiceUI.PI_CLEAR, clear, PendingIntent.FLAG_UPDATE_CURRENT);
// Build title
@@ -1793,37 +1796,8 @@ class Core {
PendingIntent piContent = PendingIntent.getActivity(
context, ActivityView.REQUEST_THREAD, thread, PendingIntent.FLAG_UPDATE_CURRENT);
Intent ignored = new Intent(context, ServiceUI.class);
ignored.setAction("ignore:" + message.id);
PendingIntent piDelete = PendingIntent.getService(context, ServiceUI.PI_IGNORED, ignored, PendingIntent.FLAG_UPDATE_CURRENT);
Intent seen = new Intent(context, ServiceUI.class);
seen.setAction("seen:" + message.id);
PendingIntent piSeen = PendingIntent.getService(context, ServiceUI.PI_SEEN, seen, PendingIntent.FLAG_UPDATE_CURRENT);
Intent archive = new Intent(context, ServiceUI.class);
archive.setAction("archive:" + message.id);
PendingIntent piArchive = PendingIntent.getService(context, ServiceUI.PI_ARCHIVE, archive, PendingIntent.FLAG_UPDATE_CURRENT);
Intent trash = new Intent(context, ServiceUI.class);
trash.setAction("trash:" + message.id);
PendingIntent piTrash = PendingIntent.getService(context, ServiceUI.PI_TRASH, trash, PendingIntent.FLAG_UPDATE_CURRENT);
// Build actions
NotificationCompat.Action.Builder actionSeen = new NotificationCompat.Action.Builder(
R.drawable.baseline_visibility_24,
context.getString(R.string.title_action_seen),
piSeen);
NotificationCompat.Action.Builder actionArchive = new NotificationCompat.Action.Builder(
R.drawable.baseline_archive_24,
context.getString(R.string.title_action_archive),
piArchive);
NotificationCompat.Action.Builder actionTrash = new NotificationCompat.Action.Builder(
R.drawable.baseline_delete_24,
context.getString(R.string.title_action_trash),
piTrash);
Intent ignore = new Intent(context, ServiceUI.class).setAction("ignore:" + message.id);
PendingIntent piIgnore = PendingIntent.getService(context, ServiceUI.PI_IGNORED, ignore, PendingIntent.FLAG_UPDATE_CURRENT);
// Get channel name
String channelName = null;
@@ -1852,16 +1826,53 @@ class Core {
.setSubText(message.accountName + " · " + folderName)
.setContentIntent(piContent)
.setWhen(message.received)
.setDeleteIntent(piDelete)
.setDeleteIntent(piIgnore)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.setGroup(group)
.setGroupSummary(false)
.setOnlyAlertOnce(true)
.addAction(actionSeen.build())
.addAction(actionArchive.build())
.addAction(actionTrash.build());
.setOnlyAlertOnce(true);
if (notify_trash) {
Intent trash = new Intent(context, ServiceUI.class).setAction("trash:" + message.id);
PendingIntent piTrash = PendingIntent.getService(context, ServiceUI.PI_TRASH, trash, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action.Builder actionTrash = new NotificationCompat.Action.Builder(
R.drawable.baseline_delete_24,
context.getString(R.string.title_advanced_notify_action_trash),
piTrash);
mbuilder.addAction(actionTrash.build());
}
if (notify_archive) {
Intent archive = new Intent(context, ServiceUI.class).setAction("archive:" + message.id);
PendingIntent piArchive = PendingIntent.getService(context, ServiceUI.PI_ARCHIVE, archive, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action.Builder actionArchive = new NotificationCompat.Action.Builder(
R.drawable.baseline_archive_24,
context.getString(R.string.title_advanced_notify_action_archive),
piArchive);
mbuilder.addAction(actionArchive.build());
}
if (notify_reply) {
Intent reply = new Intent(context, ServiceUI.class).setAction("reply:" + message.id);
PendingIntent piReply = PendingIntent.getService(context, ServiceUI.PI_REPLY, reply, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action.Builder actionReply = new NotificationCompat.Action.Builder(
R.drawable.baseline_reply_24,
context.getString(R.string.title_advanced_notify_action_reply),
piReply);
mbuilder.addAction(actionReply.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);
NotificationCompat.Action.Builder actionSeen = new NotificationCompat.Action.Builder(
R.drawable.baseline_visibility_24,
context.getString(R.string.title_advanced_notify_action_seen),
piSeen);
mbuilder.addAction(actionSeen.build());
}
if (pro) {
if (!TextUtils.isEmpty(message.subject))

View File

@@ -41,6 +41,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.TextView;
@@ -105,19 +106,25 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private SwitchCompat swPrefixOnce;
private SwitchCompat swAutoSend;
private SwitchCompat swBadge;
private SwitchCompat swSubscriptions;
private SwitchCompat swNotifyPreview;
private SwitchCompat swSearchLocal;
private CheckBox cbNotifyActionTrash;
private CheckBox cbNotifyActionArchive;
private CheckBox cbNotifyActionSeen;
private CheckBox cbNotifyActionReply;
private SwitchCompat swLight;
private Button btnSound;
private SwitchCompat swBadge;
private SwitchCompat swSubscriptions;
private SwitchCompat swSearchLocal;
private SwitchCompat swAuthentication;
private SwitchCompat swParanoid;
private TextView tvParanoidHint;
private SwitchCompat swEnglish;
private SwitchCompat swUpdates;
private SwitchCompat swDebug;
private TextView tvLastCleanup;
private Group grpSearchLocal;
@@ -138,8 +145,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
"addresses", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "autoscroll", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove",
"autoresize", "resize", "prefix_once", "autosend",
"badge", "subscriptions", "notify_preview", "search_local", "light", "sound",
"authentication", "paranoid", "english", "updates", "debug",
"notify_trash", "notify_archive", "notify_reply", "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"
};
@@ -196,19 +203,24 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swPrefixOnce = view.findViewById(R.id.swPrefixOnce);
swAutoSend = view.findViewById(R.id.swAutoSend);
swBadge = view.findViewById(R.id.swBadge);
swSubscriptions = view.findViewById(R.id.swSubscriptions);
swNotifyPreview = view.findViewById(R.id.swNotifyPreview);
swSearchLocal = view.findViewById(R.id.swSearchLocal);
cbNotifyActionTrash = view.findViewById(R.id.cbNotifyActionTrash);
cbNotifyActionArchive = view.findViewById(R.id.cbNotifyActionArchive);
cbNotifyActionReply = view.findViewById(R.id.cbNotifyActionReply);
cbNotifyActionSeen = view.findViewById(R.id.cbNotifyActionSeen);
swLight = view.findViewById(R.id.swLight);
btnSound = view.findViewById(R.id.btnSound);
swBadge = view.findViewById(R.id.swBadge);
swSubscriptions = view.findViewById(R.id.swSubscriptions);
swSearchLocal = view.findViewById(R.id.swSearchLocal);
swEnglish = view.findViewById(R.id.swEnglish);
swAuthentication = view.findViewById(R.id.swAuthentication);
swParanoid = view.findViewById(R.id.swParanoid);
tvParanoidHint = view.findViewById(R.id.tvParanoidHint);
swEnglish = view.findViewById(R.id.swEnglish);
swUpdates = view.findViewById(R.id.swUpdates);
swDebug = view.findViewById(R.id.swDebug);
tvLastCleanup = view.findViewById(R.id.tvLastCleanup);
grpSearchLocal = view.findViewById(R.id.grpSearchLocal);
@@ -220,6 +232,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
setOptions();
// General
swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -295,6 +309,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
// Connection
swMetered.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -324,6 +340,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
// Display
spStartup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
@@ -438,6 +456,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
// Behavior
swPull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -538,20 +558,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swBadge.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("badge", checked).apply();
ServiceSynchronize.reload(getContext(), "badge");
}
});
swSubscriptions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("subscriptions", checked).apply();
}
});
// Notifications
swNotifyPreview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
@@ -560,10 +567,31 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swSearchLocal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
cbNotifyActionTrash.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("search_local", checked).apply();
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_trash", checked).apply();
}
});
cbNotifyActionArchive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_archive", checked).apply();
}
});
cbNotifyActionReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_reply", checked).apply();
}
});
cbNotifyActionSeen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_seen", checked).apply();
}
});
@@ -588,20 +616,31 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swAuthentication.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
// Misc
swBadge.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("authentication", checked).apply();
prefs.edit().putBoolean("badge", checked).apply();
ServiceSynchronize.reload(getContext(), "badge");
}
});
swParanoid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
swSubscriptions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("paranoid", checked).apply();
prefs.edit().putBoolean("subscriptions", checked).apply();
}
});
swSearchLocal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("search_local", checked).apply();
}
});
final Intent faq = new Intent(Intent.ACTION_VIEW);
faq.setData(Uri.parse(Helper.FAQ_URI + "#user-content-faq86"));
faq.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -627,6 +666,20 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swAuthentication.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("authentication", checked).apply();
}
});
swParanoid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("paranoid", checked).apply();
}
});
swUpdates.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -707,6 +760,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private void setOptions() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
// General
swEnabled.setChecked(prefs.getBoolean("enabled", true));
spPollInterval.setEnabled(swEnabled.isChecked());
swSchedule.setEnabled(swEnabled.isChecked());
@@ -724,6 +779,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
tvScheduleStart.setText(formatHour(getContext(), prefs.getInt("schedule_start", 0)));
tvScheduleEnd.setText(formatHour(getContext(), prefs.getInt("schedule_end", 0)));
// Connection
swMetered.setChecked(prefs.getBoolean("metered", true));
int download = prefs.getInt("download", MessageHelper.DEFAULT_ATTACHMENT_DOWNLOAD_SIZE);
@@ -736,6 +793,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swRoaming.setChecked(prefs.getBoolean("roaming", true));
// Display
boolean compact = prefs.getBoolean("compact", false);
String startup = prefs.getString("startup", "unified");
@@ -761,6 +820,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swImages.setChecked(prefs.getBoolean("autoimages", false));
swActionbar.setChecked(prefs.getBoolean("actionbar", true));
// Behavior
swPull.setChecked(prefs.getBoolean("pull", true));
swAutoScroll.setChecked(prefs.getBoolean("autoscroll", false));
swSwipeNav.setChecked(prefs.getBoolean("swipenav", true));
@@ -786,21 +847,31 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", false));
swAutoSend.setChecked(!prefs.getBoolean("autosend", false));
swBadge.setChecked(prefs.getBoolean("badge", true));
swSubscriptions.setChecked(prefs.getBoolean("subscriptions", false));
// Notifications
swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true));
swNotifyPreview.setEnabled(Helper.isPro(getContext()));
swSearchLocal.setChecked(prefs.getBoolean("search_local", false));
cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true));
cbNotifyActionArchive.setChecked(prefs.getBoolean("notify_archive", true));
cbNotifyActionReply.setChecked(prefs.getBoolean("notify_reply", false));
cbNotifyActionSeen.setChecked(prefs.getBoolean("notify_seen", true));
swLight.setChecked(prefs.getBoolean("light", false));
grpNotification.setVisibility(Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
// Misc
swBadge.setChecked(prefs.getBoolean("badge", true));
swSubscriptions.setChecked(prefs.getBoolean("subscriptions", false));
swEnglish.setChecked(prefs.getBoolean("english", false));
swSearchLocal.setChecked(prefs.getBoolean("search_local", false));
swAuthentication.setChecked(prefs.getBoolean("authentication", false));
swParanoid.setChecked(prefs.getBoolean("paranoid", true));
swEnglish.setChecked(prefs.getBoolean("english", false));
swUpdates.setChecked(prefs.getBoolean("updates", true));
swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE);
swDebug.setChecked(prefs.getBoolean("debug", false));
grpSearchLocal.setVisibility(Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M ? View.GONE : View.VISIBLE);
grpNotification.setVisibility(Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
}
private String formatHour(Context context, int minutes) {

View File

@@ -26,11 +26,12 @@ import androidx.annotation.Nullable;
public class ServiceUI extends IntentService {
static final int PI_CLEAR = 1;
static final int PI_SEEN = 2;
static final int PI_TRASH = 2;
static final int PI_ARCHIVE = 3;
static final int PI_TRASH = 4;
static final int PI_IGNORED = 5;
static final int PI_SNOOZED = 6;
static final int PI_REPLY = 4;
static final int PI_SEEN = 5;
static final int PI_IGNORED = 6;
static final int PI_SNOOZED = 7;
public ServiceUI() {
this(ServiceUI.class.getName());
@@ -73,14 +74,17 @@ public class ServiceUI extends IntentService {
case "clear":
onClear();
break;
case "seen":
onSeen(id);
case "trash":
onTrash(id);
break;
case "archive":
onArchive(id);
break;
case "trash":
onTrash(id);
case "reply":
onReply(id);
break;
case "seen":
onSeen(id);
break;
case "ignore":
onIgnore(id);
@@ -101,14 +105,17 @@ public class ServiceUI extends IntentService {
DB.getInstance(this).message().ignoreAll();
}
private void onSeen(long id) {
private void onTrash(long id) {
DB db = DB.getInstance(this);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message != null)
EntityOperation.queue(this, db, message, EntityOperation.SEEN, true);
if (message != null) {
EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
if (trash != null)
EntityOperation.queue(this, db, message, EntityOperation.MOVE, trash.id);
}
db.setTransactionSuccessful();
} finally {
@@ -136,17 +143,25 @@ public class ServiceUI extends IntentService {
}
}
private void onTrash(long id) {
private void onReply(long id) {
onSeen(id);
// No check for attachments
Intent reply = new Intent(this, ActivityCompose.class)
.putExtra("action", "reply")
.putExtra("reference", id);
reply.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(reply);
}
private void onSeen(long id) {
DB db = DB.getInstance(this);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message != null) {
EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
if (trash != null)
EntityOperation.queue(this, db, message, EntityOperation.MOVE, trash.id);
}
if (message != null)
EntityOperation.queue(this, db, message, EntityOperation.SEEN, true);
db.setTransactionSuccessful();
} finally {