mirror of https://github.com/M66B/FairEmail.git
Workaround notification sound before Android 8
This commit is contained in:
parent
a8d18b8bf7
commit
9138720150
|
@ -1865,6 +1865,7 @@ class Core {
|
||||||
final List<Long> add = new ArrayList<>();
|
final List<Long> add = new ArrayList<>();
|
||||||
final List<Long> remove = groupNotifying.get(group);
|
final List<Long> remove = groupNotifying.get(group);
|
||||||
|
|
||||||
|
int updates = 0;
|
||||||
for (Notification notification : notifications) {
|
for (Notification notification : notifications) {
|
||||||
Long id = notification.extras.getLong("id", 0);
|
Long id = notification.extras.getLong("id", 0);
|
||||||
if (id != 0)
|
if (id != 0)
|
||||||
|
@ -1872,16 +1873,20 @@ class Core {
|
||||||
remove.remove(id);
|
remove.remove(id);
|
||||||
Log.i("Notify existing=" + id);
|
Log.i("Notify existing=" + id);
|
||||||
} else {
|
} else {
|
||||||
remove.remove(-id);
|
if (remove.contains(-id)) {
|
||||||
|
updates++;
|
||||||
|
remove.remove(-id);
|
||||||
|
}
|
||||||
add.add(id);
|
add.add(id);
|
||||||
Log.i("Notify adding=" + id);
|
Log.i("Notify adding=" + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i("Notify group=" + group + " count=" + notifications.size() +
|
Log.i("Notify group=" + group + " count=" + notifications.size() +
|
||||||
" added=" + add.size() + " removed=" + remove.size());
|
" added=" + add.size() + " removed=" + remove.size() + " updates=" + updates);
|
||||||
|
|
||||||
if (notifications.size() == 0) {
|
if (notifications.size() == 0 ||
|
||||||
|
(Build.VERSION.SDK_INT < Build.VERSION_CODES.O && add.size() - updates > 0)) {
|
||||||
String tag = "unseen." + group + "." + 0;
|
String tag = "unseen." + group + "." + 0;
|
||||||
Log.i("Notify cancel tag=" + tag);
|
Log.i("Notify cancel tag=" + tag);
|
||||||
nm.cancel(tag, 1);
|
nm.cancel(tag, 1);
|
||||||
|
@ -1983,7 +1988,10 @@ class Core {
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setGroup(group)
|
.setGroup(group)
|
||||||
.setGroupSummary(true)
|
.setGroupSummary(true)
|
||||||
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
|
.setGroupAlertBehavior(Build.VERSION.SDK_INT < Build.VERSION_CODES.O
|
||||||
|
? NotificationCompat.GROUP_ALERT_SUMMARY
|
||||||
|
: NotificationCompat.GROUP_ALERT_CHILDREN)
|
||||||
|
.setOnlyAlertOnce(true);
|
||||||
|
|
||||||
Notification pub = builder.build();
|
Notification pub = builder.build();
|
||||||
builder
|
builder
|
||||||
|
@ -2006,6 +2014,19 @@ class Core {
|
||||||
.setSummaryText(title));
|
.setSummaryText(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
|
if (light) {
|
||||||
|
builder.setLights(Color.WHITE, 1000, 1000);
|
||||||
|
Log.i("Notify light enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri uri = (sound == null ? null : Uri.parse(sound));
|
||||||
|
if (uri == null || "file".equals(uri.getScheme()))
|
||||||
|
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||||
|
builder.setSound(uri);
|
||||||
|
Log.i("Notify sound=" + uri);
|
||||||
|
}
|
||||||
|
|
||||||
notifications.add(builder.build());
|
notifications.add(builder.build());
|
||||||
|
|
||||||
// Message notifications
|
// Message notifications
|
||||||
|
@ -2060,7 +2081,9 @@ class Core {
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||||
.setGroup(group)
|
.setGroup(group)
|
||||||
.setGroupSummary(false)
|
.setGroupSummary(false)
|
||||||
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
|
.setGroupAlertBehavior(Build.VERSION.SDK_INT < Build.VERSION_CODES.O
|
||||||
|
? NotificationCompat.GROUP_ALERT_SUMMARY
|
||||||
|
: NotificationCompat.GROUP_ALERT_CHILDREN)
|
||||||
.setOnlyAlertOnce(true);
|
.setOnlyAlertOnce(true);
|
||||||
|
|
||||||
if (biometrics)
|
if (biometrics)
|
||||||
|
@ -2174,15 +2197,8 @@ class Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
|
||||||
if (light)
|
mbuilder.setSound(null);
|
||||||
mbuilder.setLights(Color.WHITE, 1000, 1000);
|
|
||||||
|
|
||||||
Uri uri = (sound == null ? null : Uri.parse(sound));
|
|
||||||
if (uri == null || "file".equals(uri.getScheme()))
|
|
||||||
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
||||||
mbuilder.setSound(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications.add(mbuilder.build());
|
notifications.add(mbuilder.build());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue