Skip to content

Commit

Permalink
add support for setWhen on Android notifications
Browse files Browse the repository at this point in the history
Closes MaikuB#596.
  • Loading branch information
nioncode committed Apr 24, 2020
1 parent 60072d6 commit d8ef446
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ private static Notification createNotification(Context context, NotificationDeta
builder.setShowWhen(BooleanUtils.getValue(notificationDetails.showWhen));
}

if (notificationDetails.when != null) {
builder.setWhen(notificationDetails.when);
}

setVisibility(notificationDetails, builder);
applyGrouping(notificationDetails, builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class NotificationDetails {
private static final String CATEGORY = "category";
private static final String TIMEOUT_AFTER = "timeoutAfter";
private static final String SHOW_WHEN = "showWhen";
private static final String WHEN = "when";


public Integer id;
Expand Down Expand Up @@ -151,6 +152,7 @@ public class NotificationDetails {
public Long timeoutAfter;
public String category;
public Boolean showWhen;
public Long when;



Expand Down Expand Up @@ -200,6 +202,7 @@ private static void readPlatformSpecifics(Map<String, Object> arguments, Notific
readGroupingInformation(notificationDetails, platformChannelSpecifics);
notificationDetails.onlyAlertOnce = (Boolean) platformChannelSpecifics.get(ONLY_ALERT_ONCE);
notificationDetails.showWhen = (Boolean) platformChannelSpecifics.get(SHOW_WHEN);
notificationDetails.when = parseLong(platformChannelSpecifics.get(WHEN));
readProgressInformation(notificationDetails, platformChannelSpecifics);
readColor(notificationDetails, platformChannelSpecifics);
readChannelInformation(notificationDetails, platformChannelSpecifics);
Expand All @@ -208,19 +211,21 @@ private static void readPlatformSpecifics(Map<String, Object> arguments, Notific
notificationDetails.ticker = (String) platformChannelSpecifics.get(TICKER);
notificationDetails.visibility = (Integer) platformChannelSpecifics.get(VISIBILITY);
notificationDetails.allowWhileIdle = (Boolean) platformChannelSpecifics.get(ALLOW_WHILE_IDLE);
Object timeoutAfter = platformChannelSpecifics.get(TIMEOUT_AFTER);
if(timeoutAfter != null) {
if(timeoutAfter instanceof Integer) {
notificationDetails.timeoutAfter = ((Integer) timeoutAfter).longValue();
}
else if(timeoutAfter instanceof Long) {
notificationDetails.timeoutAfter = (Long) timeoutAfter;
}
}
notificationDetails.timeoutAfter = parseLong(platformChannelSpecifics.get(TIMEOUT_AFTER));
notificationDetails.category = (String) platformChannelSpecifics.get(CATEGORY);
}
}

private static Long parseLong(Object object) {
if(timeoutAfter instanceof Integer) {
return ((Integer) object).longValue();
}
if(timeoutAfter instanceof Long) {
return (Long) object;
}
return null;
}

private static void readProgressInformation(NotificationDetails notificationDetails, Map<String, Object> platformChannelSpecifics) {
notificationDetails.showProgress = (Boolean) platformChannelSpecifics.get(SHOW_PROGRESS);
if (platformChannelSpecifics.containsKey(MAX_PROGRESS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AndroidNotificationDetails {
this.largeIcon,
this.onlyAlertOnce,
this.showWhen = true,
this.when,
this.channelShowBadge = true,
this.showProgress = false,
this.maxProgress = 0,
Expand Down Expand Up @@ -141,8 +142,19 @@ class AndroidNotificationDetails {
final bool onlyAlertOnce;

/// Specifies if the notification should display the timestamp of when it occurred.
///
/// To control the actual timestamp of the notification, use [when].
final bool showWhen;

/// Specifies the timestamp of the notification.
///
/// If not specified, this will be set to the current time when the
/// notification gets created.
///
/// To control whether the timestamp is shown in the notification, use
/// [showWhen].
final int when;

/// Specifies if the notification will be used to show progress.
final bool showProgress;

Expand Down Expand Up @@ -216,6 +228,7 @@ class AndroidNotificationDetails {
'colorBlue': color?.blue,
'onlyAlertOnce': onlyAlertOnce,
'showWhen': showWhen,
'when': when,
'showProgress': showProgress,
'maxProgress': maxProgress,
'progress': progress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -188,6 +189,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -266,6 +268,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -342,6 +345,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -420,6 +424,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -513,6 +518,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -600,6 +606,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -693,6 +700,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -778,6 +786,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -867,6 +876,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -947,6 +957,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1024,6 +1035,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1108,6 +1120,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1221,6 +1234,7 @@ void main() {
'colorBlue': null,
'onlyAlertOnce': null,
'showWhen': true,
'when': null,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down

0 comments on commit d8ef446

Please sign in to comment.