|
|
@ -1715,8 +1715,12 @@ class Core {
|
|
|
|
return notifications;
|
|
|
|
return notifications;
|
|
|
|
|
|
|
|
|
|
|
|
boolean pro = Helper.isPro(context);
|
|
|
|
boolean pro = Helper.isPro(context);
|
|
|
|
|
|
|
|
boolean canGroup = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N);
|
|
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
boolean flags = prefs.getBoolean("flags", true);
|
|
|
|
boolean flags = prefs.getBoolean("flags", true);
|
|
|
|
|
|
|
|
boolean notify_group = (prefs.getBoolean("notify_group", true) && canGroup);
|
|
|
|
|
|
|
|
boolean notify_preview = prefs.getBoolean("notify_preview", true);
|
|
|
|
boolean notify_trash = prefs.getBoolean("notify_trash", true);
|
|
|
|
boolean notify_trash = prefs.getBoolean("notify_trash", true);
|
|
|
|
boolean notify_archive = prefs.getBoolean("notify_archive", true);
|
|
|
|
boolean notify_archive = prefs.getBoolean("notify_archive", true);
|
|
|
|
boolean notify_reply = prefs.getBoolean("notify_reply", false);
|
|
|
|
boolean notify_reply = prefs.getBoolean("notify_reply", false);
|
|
|
@ -1730,70 +1734,62 @@ class Core {
|
|
|
|
for (TupleMessageEx message : messages)
|
|
|
|
for (TupleMessageEx message : messages)
|
|
|
|
messageContact.put(message, ContactInfo.get(context, message.from, false));
|
|
|
|
messageContact.put(message, ContactInfo.get(context, message.from, false));
|
|
|
|
|
|
|
|
|
|
|
|
// Build pending intents
|
|
|
|
if (notify_group) {
|
|
|
|
Intent summary = new Intent(context, ActivityView.class).setAction("unified");
|
|
|
|
// Build pending intents
|
|
|
|
PendingIntent piSummary = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, summary, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
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).setAction("clear");
|
|
|
|
Intent clear = new Intent(context, ServiceUI.class).setAction("clear");
|
|
|
|
PendingIntent piClear = PendingIntent.getService(context, ServiceUI.PI_CLEAR, clear, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
PendingIntent piClear = PendingIntent.getService(context, ServiceUI.PI_CLEAR, clear, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
|
|
// Build title
|
|
|
|
// Build title
|
|
|
|
String title = context.getResources().getQuantityString(
|
|
|
|
String title = context.getResources().getQuantityString(
|
|
|
|
R.plurals.title_notification_unseen, messages.size(), messages.size());
|
|
|
|
R.plurals.title_notification_unseen, messages.size(), messages.size());
|
|
|
|
|
|
|
|
|
|
|
|
// Build notification
|
|
|
|
// Build notification
|
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "notification");
|
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "notification");
|
|
|
|
builder
|
|
|
|
builder
|
|
|
|
.setSmallIcon(R.drawable.baseline_email_white_24)
|
|
|
|
.setSmallIcon(R.drawable.baseline_email_white_24)
|
|
|
|
.setContentTitle(title)
|
|
|
|
.setContentTitle(title)
|
|
|
|
.setContentIntent(piSummary)
|
|
|
|
.setContentIntent(piSummary)
|
|
|
|
.setNumber(messages.size())
|
|
|
|
.setNumber(messages.size())
|
|
|
|
.setShowWhen(false)
|
|
|
|
.setShowWhen(false)
|
|
|
|
.setDeleteIntent(piClear)
|
|
|
|
.setDeleteIntent(piClear)
|
|
|
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
|
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
|
|
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
|
|
|
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
|
|
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
|
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
|
|
.setGroup(group)
|
|
|
|
.setGroup(group)
|
|
|
|
.setGroupSummary(true);
|
|
|
|
.setGroupSummary(true);
|
|
|
|
|
|
|
|
|
|
|
|
Notification pub = builder.build();
|
|
|
|
|
|
|
|
builder
|
|
|
|
|
|
|
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
|
|
|
|
|
|
|
.setPublicVersion(pub);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
|
|
|
|
|
|
boolean light = prefs.getBoolean("light", false);
|
|
|
|
|
|
|
|
String sound = prefs.getString("sound", null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (light)
|
|
|
|
Notification pub = builder.build();
|
|
|
|
builder.setLights(Color.GREEN, 1000, 1000);
|
|
|
|
builder
|
|
|
|
|
|
|
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
|
|
|
|
|
|
|
.setPublicVersion(pub);
|
|
|
|
|
|
|
|
|
|
|
|
Uri uri = (sound == null ? null : Uri.parse(sound));
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
|
|
if (uri == null || "file".equals(uri.getScheme()))
|
|
|
|
setNotificationSoundAndLight(context, builder);
|
|
|
|
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
|
|
builder.setOnlyAlertOnce(true);
|
|
|
|
builder.setSound(uri);
|
|
|
|
} else
|
|
|
|
|
|
|
|
builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
for (EntityMessage message : messages) {
|
|
|
|
|
|
|
|
sb.append("<strong>").append(messageContact.get(message).getDisplayName(true)).append("</strong>");
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(message.subject))
|
|
|
|
|
|
|
|
sb.append(": ").append(message.subject);
|
|
|
|
|
|
|
|
sb.append(" ").append(df.format(message.received));
|
|
|
|
|
|
|
|
sb.append("<br>");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
builder.setOnlyAlertOnce(true);
|
|
|
|
builder.setStyle(new NotificationCompat.BigTextStyle()
|
|
|
|
} else
|
|
|
|
.bigText(HtmlHelper.fromHtml(sb.toString()))
|
|
|
|
builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
|
|
|
|
.setSummaryText(title));
|
|
|
|
|
|
|
|
|
|
|
|
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
|
|
|
|
notifications.add(builder.build());
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
for (EntityMessage message : messages) {
|
|
|
|
|
|
|
|
sb.append("<strong>").append(messageContact.get(message).getDisplayName(true)).append("</strong>");
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(message.subject))
|
|
|
|
|
|
|
|
sb.append(": ").append(message.subject);
|
|
|
|
|
|
|
|
sb.append(" ").append(df.format(message.received));
|
|
|
|
|
|
|
|
sb.append("<br>");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
builder.setStyle(new NotificationCompat.BigTextStyle()
|
|
|
|
// Message notifications
|
|
|
|
.bigText(HtmlHelper.fromHtml(sb.toString()))
|
|
|
|
|
|
|
|
.setSummaryText(title));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notifications.add(builder.build());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean preview = prefs.getBoolean("notify_preview", true);
|
|
|
|
|
|
|
|
for (TupleMessageEx message : messages) {
|
|
|
|
for (TupleMessageEx message : messages) {
|
|
|
|
ContactInfo info = messageContact.get(message);
|
|
|
|
ContactInfo info = messageContact.get(message);
|
|
|
|
|
|
|
|
|
|
|
@ -1844,10 +1840,11 @@ class Core {
|
|
|
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
|
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
|
|
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
|
|
|
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
|
|
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
|
|
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
|
|
|
.setGroup(group)
|
|
|
|
|
|
|
|
.setGroupSummary(false)
|
|
|
|
|
|
|
|
.setOnlyAlertOnce(true);
|
|
|
|
.setOnlyAlertOnce(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (notify_group)
|
|
|
|
|
|
|
|
mbuilder.setGroup(group).setGroupSummary(false);
|
|
|
|
|
|
|
|
|
|
|
|
if (notify_trash) {
|
|
|
|
if (notify_trash) {
|
|
|
|
Intent trash = new Intent(context, ServiceUI.class).setAction("trash:" + message.id);
|
|
|
|
Intent trash = new Intent(context, ServiceUI.class).setAction("trash:" + message.id);
|
|
|
|
PendingIntent piTrash = PendingIntent.getService(context, ServiceUI.PI_TRASH, trash, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
PendingIntent piTrash = PendingIntent.getService(context, ServiceUI.PI_TRASH, trash, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
@ -1901,7 +1898,7 @@ class Core {
|
|
|
|
if (!TextUtils.isEmpty(message.subject))
|
|
|
|
if (!TextUtils.isEmpty(message.subject))
|
|
|
|
mbuilder.setContentText(message.subject);
|
|
|
|
mbuilder.setContentText(message.subject);
|
|
|
|
|
|
|
|
|
|
|
|
if (message.content && preview)
|
|
|
|
if (message.content && notify_preview)
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String body = Helper.readText(message.getFile(context));
|
|
|
|
String body = Helper.readText(message.getFile(context));
|
|
|
|
StringBuilder sbm = new StringBuilder();
|
|
|
|
StringBuilder sbm = new StringBuilder();
|
|
|
@ -1934,10 +1931,15 @@ class Core {
|
|
|
|
mbuilder.setColorized(true);
|
|
|
|
mbuilder.setColorized(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
|
|
mbuilder.setSound(null);
|
|
|
|
if (notify_group)
|
|
|
|
else
|
|
|
|
mbuilder.setSound(null);
|
|
|
|
mbuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
|
|
|
|
else
|
|
|
|
|
|
|
|
setNotificationSoundAndLight(context, mbuilder);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (notify_group)
|
|
|
|
|
|
|
|
mbuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
notifications.add(mbuilder.build());
|
|
|
|
notifications.add(mbuilder.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1945,6 +1947,20 @@ class Core {
|
|
|
|
return notifications;
|
|
|
|
return notifications;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void setNotificationSoundAndLight(Context context, NotificationCompat.Builder builder) {
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
|
|
|
boolean light = prefs.getBoolean("light", false);
|
|
|
|
|
|
|
|
String sound = prefs.getString("sound", null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (light)
|
|
|
|
|
|
|
|
builder.setLights(Color.GREEN, 1000, 1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Uri uri = (sound == null ? null : Uri.parse(sound));
|
|
|
|
|
|
|
|
if (uri == null || "file".equals(uri.getScheme()))
|
|
|
|
|
|
|
|
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
|
|
|
|
|
|
builder.setSound(uri);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void reportError(Context context, EntityAccount account, EntityFolder folder, Throwable ex) {
|
|
|
|
static void reportError(Context context, EntityAccount account, EntityFolder folder, Throwable ex) {
|
|
|
|
// FolderClosedException: can happen when no connectivity
|
|
|
|
// FolderClosedException: can happen when no connectivity
|
|
|
|
|
|
|
|
|
|
|
|