Simplified notifications when using biometric authentication

pull/157/head
M66B 5 years ago
parent c3b7275a48
commit 31923694be

@ -1799,7 +1799,6 @@ class Core {
return; return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean biometrics = prefs.getBoolean("biometrics", false);
boolean badge = prefs.getBoolean("badge", true); boolean badge = prefs.getBoolean("badge", true);
boolean pro = Helper.isPro(context); boolean pro = Helper.isPro(context);
@ -1854,7 +1853,6 @@ 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)
@ -1864,8 +1862,6 @@ class Core {
} else { } else {
remove.remove(-id); remove.remove(-id);
add.add(id); add.add(id);
if (biometrics && groupNotifying.get(group).contains(-id))
updates++;
Log.i("Notify adding=" + id); Log.i("Notify adding=" + id);
} }
} }
@ -1887,7 +1883,7 @@ class Core {
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 && add.size() + remove.size() - updates > 0) || (add.contains(id) && !biometrics)) { if ((id == 0 && add.size() + remove.size() > 0) || add.contains(id)) {
String tag = "unseen." + group + "." + Math.abs(id); String tag = "unseen." + group + "." + Math.abs(id);
Log.i("Notifying tag=" + tag + Log.i("Notifying tag=" + tag +
(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : " channel=" + notification.getChannelId())); (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : " channel=" + notification.getChannelId()));
@ -1970,7 +1966,10 @@ class Core {
.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)
.setGroupSummary(true)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
Notification pub = builder.build(); Notification pub = builder.build();
builder builder
@ -1978,10 +1977,6 @@ class Core {
.setPublicVersion(pub); .setPublicVersion(pub);
if (!biometrics) { if (!biometrics) {
builder.setGroup(group)
.setGroupSummary(true)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (EntityMessage message : messages) { for (EntityMessage message : messages) {
@ -2039,17 +2034,10 @@ class Core {
channelName = EntityAccount.getNotificationChannelId( channelName = EntityAccount.getNotificationChannelId(
pro && message.accountNotify ? message.account : 0); pro && message.accountNotify ? message.account : 0);
// Get folder name
String folderName = message.folderDisplay == null
? Helper.localizeFolderName(context, message.folderName)
: message.folderDisplay;
NotificationCompat.Builder mbuilder = NotificationCompat.Builder mbuilder =
new NotificationCompat.Builder(context, channelName) new NotificationCompat.Builder(context, channelName)
.addExtras(args) .addExtras(args)
.setSmallIcon(R.drawable.baseline_email_white_24) .setSmallIcon(R.drawable.baseline_email_white_24)
.setContentTitle(info.getDisplayName(true))
.setSubText(message.accountName + " · " + folderName)
.setContentIntent(piContent) .setContentIntent(piContent)
.setWhen(message.received) .setWhen(message.received)
.setDeleteIntent(piIgnore) .setDeleteIntent(piIgnore)
@ -2061,6 +2049,18 @@ class Core {
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN) .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
.setOnlyAlertOnce(true); .setOnlyAlertOnce(true);
if (biometrics)
mbuilder.setContentTitle(context.getResources().getQuantityString(
R.plurals.title_notification_unseen, 1, 1));
else {
String folderName = message.folderDisplay == null
? Helper.localizeFolderName(context, message.folderName)
: message.folderDisplay;
mbuilder.setContentTitle(info.getDisplayName(true))
.setSubText(message.accountName + " · " + folderName);
}
if (notify_trash) { if (notify_trash) {
Intent trash = new Intent(context, ServiceUI.class) Intent trash = new Intent(context, ServiceUI.class)
.setAction("trash:" + message.id) .setAction("trash:" + message.id)
@ -2122,40 +2122,42 @@ class Core {
mbuilder.addAction(actionSeen.build()); mbuilder.addAction(actionSeen.build());
} }
if (!TextUtils.isEmpty(message.subject)) if (!biometrics) {
mbuilder.setContentText(message.subject); if (!TextUtils.isEmpty(message.subject))
mbuilder.setContentText(message.subject);
if (message.content && notify_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();
if (!TextUtils.isEmpty(message.subject)) if (!TextUtils.isEmpty(message.subject))
sbm.append(message.subject).append("<br>"); sbm.append(message.subject).append("<br>");
String text = Jsoup.parse(body).text(); String text = Jsoup.parse(body).text();
if (!TextUtils.isEmpty(text)) { if (!TextUtils.isEmpty(text)) {
sbm.append("<em>"); sbm.append("<em>");
if (text.length() > HtmlHelper.PREVIEW_SIZE) { if (text.length() > HtmlHelper.PREVIEW_SIZE) {
sbm.append(text.substring(0, HtmlHelper.PREVIEW_SIZE)); sbm.append(text.substring(0, HtmlHelper.PREVIEW_SIZE));
sbm.append("…"); sbm.append("…");
} else } else
sbm.append(text); sbm.append(text);
sbm.append("</em>"); sbm.append("</em>");
}
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(HtmlHelper.fromHtml(sbm.toString())));
} catch (IOException ex) {
Log.e(ex);
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(ex.toString()));
} }
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(HtmlHelper.fromHtml(sbm.toString())));
} catch (IOException ex) {
Log.e(ex);
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(ex.toString()));
}
if (info.hasPhoto()) if (info.hasPhoto())
mbuilder.setLargeIcon(info.getPhotoBitmap()); mbuilder.setLargeIcon(info.getPhotoBitmap());
if (info.hasLookupUri()) if (info.hasLookupUri())
mbuilder.addPerson(info.getLookupUri().toString()); mbuilder.addPerson(info.getLookupUri().toString());
if (pro && message.accountColor != null) { if (pro && message.accountColor != null) {
mbuilder.setColor(message.accountColor); mbuilder.setColor(message.accountColor);
mbuilder.setColorized(true); mbuilder.setColorized(true);
}
} }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {

Loading…
Cancel
Save