Group non unified folder notifications

pull/180/head
M66B 5 years ago
parent 097cd0b68b
commit 42f02ba743

@ -942,12 +942,19 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
getSupportFragmentManager().popBackStack("unified", 0); getSupportFragmentManager().popBackStack("unified", 0);
long folder = Long.parseLong(action.split(":", 2)[1]); String[] parts = action.split(":");
long folder = Long.parseLong(parts[1]);
if (folder > 0) { if (folder > 0) {
intent.putExtra("folder", folder); intent.putExtra("folder", folder);
onViewMessages(intent); onViewMessages(intent);
} }
if (parts.length > 2) {
Intent clear = new Intent(this, ServiceUI.class)
.setAction("clear:" + parts[2]);
startService(clear);
}
} else if ("why".equals(action)) { } else if ("why".equals(action)) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
getSupportFragmentManager().popBackStack("unified", 0); getSupportFragmentManager().popBackStack("unified", 0);

@ -2923,6 +2923,8 @@ class Core {
} }
long group = (pro && message.accountNotify ? message.account : 0); long group = (pro && message.accountNotify ? message.account : 0);
if (!message.folderUnified)
group = -message.folder;
if (!groupNotifying.containsKey(group)) if (!groupNotifying.containsKey(group))
groupNotifying.put(group, new ArrayList<Long>()); groupNotifying.put(group, new ArrayList<Long>());
if (!groupMessages.containsKey(group)) if (!groupMessages.containsKey(group))
@ -3020,7 +3022,7 @@ class Core {
String tag = "unseen." + group + "." + Math.abs(id); String tag = "unseen." + group + "." + Math.abs(id);
Notification notification = builder.build(); Notification notification = builder.build();
Log.i("Notifying tag=" + tag + " id=" + id + Log.i("Notifying tag=" + tag + " id=" + id + " group=" + notification.getGroup() +
(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : " channel=" + notification.getChannelId())); (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : " channel=" + notification.getChannelId()));
try { try {
nm.notify(tag, 1, notification); nm.notify(tag, 1, notification);
@ -3099,10 +3101,15 @@ class Core {
// Summary notification // Summary notification
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || notify_summary) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || notify_summary) {
// Build pending intents // Build pending intents
Intent unified = new Intent(context, ActivityView.class) Intent content;
if (group < 0)
content = new Intent(context, ActivityView.class)
.setAction("folder:" + (-group) + (notify_remove ? ":" + group : ""));
else
content = new Intent(context, ActivityView.class)
.setAction("unified" + (notify_remove ? ":" + group : "")); .setAction("unified" + (notify_remove ? ":" + group : ""));
unified.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); content.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent piUnified = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, unified, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piContent = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, content, PendingIntent.FLAG_UPDATE_CURRENT);
Intent clear = new Intent(context, ServiceUI.class).setAction("clear:" + group); Intent clear = new Intent(context, ServiceUI.class).setAction("clear:" + group);
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);
@ -3111,14 +3118,18 @@ class Core {
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());
long cgroup = (group >= 0
? group
: (pro && messages.size() > 0 && messages.get(0).accountNotify ? messages.get(0).account : 0));
// Build notification // Build notification
NotificationCompat.Builder builder = NotificationCompat.Builder builder =
new NotificationCompat.Builder(context, EntityAccount.getNotificationChannelId(group)) new NotificationCompat.Builder(context, EntityAccount.getNotificationChannelId(cgroup))
.setSmallIcon(messages.size() > 1 .setSmallIcon(messages.size() > 1
? R.drawable.baseline_mail_more_white_24 ? R.drawable.baseline_mail_more_white_24
: R.drawable.baseline_mail_white_24) : R.drawable.baseline_mail_white_24)
.setContentTitle(title) .setContentTitle(title)
.setContentIntent(piUnified) .setContentIntent(piContent)
.setNumber(messages.size()) .setNumber(messages.size())
.setShowWhen(false) .setShowWhen(false)
.setDeleteIntent(piClear) .setDeleteIntent(piClear)
@ -3148,11 +3159,15 @@ class Core {
if (pro && group != 0 && messages.size() > 0) { if (pro && group != 0 && messages.size() > 0) {
TupleMessageEx amessage = messages.get(0); TupleMessageEx amessage = messages.get(0);
if (amessage.accountColor != null) { Integer color = getColor(amessage);
builder.setColor(amessage.accountColor); if (color != null) {
builder.setColor(color);
builder.setColorized(true); builder.setColorized(true);
} }
if (amessage.folderUnified)
builder.setSubText(amessage.accountName); builder.setSubText(amessage.accountName);
else
builder.setSubText(amessage.accountName + " · " + amessage.getFolderName(context));
} }
Notification pub = builder.build(); Notification pub = builder.build();
@ -3263,8 +3278,11 @@ class Core {
Address[] afrom = messageFrom.get(message.id); Address[] afrom = messageFrom.get(message.id);
String from = MessageHelper.formatAddresses(afrom, name_email, false); String from = MessageHelper.formatAddresses(afrom, name_email, false);
mbuilder.setContentTitle(from) mbuilder.setContentTitle(from);
.setSubText(message.accountName + " · " + message.getFolderName(context)); if (message.folderUnified)
mbuilder.setSubText(message.accountName + " · " + message.getFolderName(context));
else
mbuilder.setSubText(message.accountName);
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -3483,8 +3501,9 @@ class Core {
if (info[0].hasLookupUri()) if (info[0].hasLookupUri())
mbuilder.addPerson(info[0].getLookupUri().toString()); mbuilder.addPerson(info[0].getLookupUri().toString());
if (pro && message.accountColor != null) { Integer color = getColor(message);
mbuilder.setColor(message.accountColor); if (pro && color != null) {
mbuilder.setColor(color);
mbuilder.setColorized(true); mbuilder.setColorized(true);
} }
@ -3501,6 +3520,12 @@ class Core {
return notifications; return notifications;
} }
private static Integer getColor(TupleMessageEx message) {
if (!message.folderUnified && message.folderColor != null)
return message.folderColor;
return message.accountColor;
}
private static void setLightAndSound(NotificationCompat.Builder builder, boolean light, String sound) { private static void setLightAndSound(NotificationCompat.Builder builder, boolean light, String sound) {
int def = 0; int def = 0;

@ -48,7 +48,7 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" +
", '[' || group_concat(message.`from`, ',') || ']' AS senders" + ", '[' || group_concat(message.`from`, ',') || ']' AS senders" +
", '[' || group_concat(message.`to`, ',') || ']' AS recipients" + ", '[' || group_concat(message.`to`, ',') || ']' AS recipients" +
@ -126,7 +126,7 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" +
", '[' || group_concat(message.`from`, ',') || ']' AS senders" + ", '[' || group_concat(message.`from`, ',') || ']' AS senders" +
", '[' || group_concat(message.`to`, ',') || ']' AS recipients" + ", '[' || group_concat(message.`to`, ',') || ']' AS recipients" +
@ -195,7 +195,7 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +
", message.`to` AS recipients" + ", message.`to` AS recipients" +
@ -387,7 +387,7 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, identity.color AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, identity.color AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +
", message.`to` AS recipients" + ", message.`to` AS recipients" +
@ -419,7 +419,7 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +
", message.`to` AS recipients" + ", message.`to` AS recipients" +

@ -184,7 +184,11 @@ public class ServiceUI extends IntentService {
private void onClear(long group) { private void onClear(long group) {
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
int cleared = db.message().ignoreAll(group == 0 ? null : group, null); int cleared;
if (group < 0)
cleared = db.message().ignoreAll(null, -group);
else
cleared = db.message().ignoreAll(group == 0 ? null : group, null);
Log.i("Cleared=" + cleared); Log.i("Cleared=" + cleared);
} }

@ -42,6 +42,7 @@ public class TupleMessageEx extends EntityMessage {
public Integer folderColor; public Integer folderColor;
public String folderDisplay; public String folderDisplay;
public String folderType; public String folderType;
public boolean folderUnified;
public boolean folderReadOnly; public boolean folderReadOnly;
public String identityName; public String identityName;
public String identityEmail; public String identityEmail;
@ -101,6 +102,7 @@ public class TupleMessageEx extends EntityMessage {
this.folderName.equals(other.folderName) && this.folderName.equals(other.folderName) &&
Objects.equals(this.folderDisplay, other.folderDisplay) && Objects.equals(this.folderDisplay, other.folderDisplay) &&
this.folderType.equals(other.folderType) && this.folderType.equals(other.folderType) &&
this.folderUnified == other.folderUnified &&
this.folderReadOnly == other.folderReadOnly && this.folderReadOnly == other.folderReadOnly &&
Objects.equals(this.identityName, other.identityName) && Objects.equals(this.identityName, other.identityName) &&
Objects.equals(this.identityEmail, other.identityEmail) && Objects.equals(this.identityEmail, other.identityEmail) &&

Loading…
Cancel
Save