Kaynağa Gözat

Added new Android specific options clock: and timeout:

Sebastián Katzer 7 yıl önce
ebeveyn
işleme
45b5d887eb

+ 2 - 1
README.md

@@ -97,10 +97,11 @@ A notification does have a set of configurable properties. Not all of them are s
 
 | Property      | Property      | Property      | Property      | Property      | Property      | Property      | Property      |
 | :------------ | :------------ | :------------ | :------------ | :------------ | :------------ | :------------ | :------------ |
-| id            | data          | actionGroupId | summary       | led           | showWhen      | channel       | actions       |
+| id            | data          | actionGroupId | summary       | led           | clock         | channel       | actions       |
 | text          | icon          | attachments   | smallIcon     | color         | defaults      | launch        | groupSummary  |
 | title         | silent        | progressBar   | sticky        | vibrate       | priority      | mediaSession  | foreground    |
 | sound         | trigger       | group         | autoClear     | lockscreen    | number        | badge         | wakeup        |
+| timeout       |
 
 For their default values see:
 

+ 3 - 2
src/android/notification/Builder.java

@@ -137,10 +137,11 @@ public final class Builder {
                 .setColor(options.getColor())
                 .setVisibility(options.getVisibility())
                 .setPriority(options.getPriority())
-                .setShowWhen(options.getShowWhen())
-                .setUsesChronometer(options.isWithProgressBar())
+                .setShowWhen(options.showClock())
+                .setUsesChronometer(options.showChronometer())
                 .setGroup(options.getGroup())
                 .setGroupSummary(options.getGroupSummary())
+                .setTimeoutAfter(options.getTimeout())
                 .setLights(options.getLedColor(), options.getLedOn(), options.getLedOff());
 
         if (sound != Uri.EMPTY && !isUpdate()) {

+ 2 - 2
src/android/notification/Notification.java

@@ -308,7 +308,7 @@ public final class Notification {
     public void show() {
         if (builder == null) return;
 
-        if (options.isWithProgressBar()) {
+        if (options.showChronometer()) {
             cacheBuilder();
         }
 
@@ -427,7 +427,7 @@ public final class Notification {
     /**
      * Caches the builder instance so it can be used later.
      */
-    private void cacheBuilder () {
+    private void cacheBuilder() {
 
         if (cache == null) {
             cache = new SparseArray<NotificationCompat.Builder>();

+ 20 - 2
src/android/notification/Options.java

@@ -199,6 +199,13 @@ public final class Options {
         return options.optBoolean("wakeup", true);
     }
 
+    /**
+     * Gets the value for the timeout flag.
+     */
+    long getTimeout() {
+        return options.optLong("timeout");
+    }
+
     /**
      * The channel id of that notification.
      */
@@ -481,8 +488,19 @@ public final class Options {
     /**
      * If the notification shall show the when date.
      */
-    boolean getShowWhen() {
-        return options.optBoolean("showWhen", true);
+    boolean showClock() {
+        Object clock = options.opt("clock");
+
+        return (clock instanceof Boolean) ? (Boolean) clock : true;
+    }
+
+    /**
+     * If the notification shall show the when date.
+     */
+    boolean showChronometer() {
+        Object clock = options.opt("clock");
+
+        return (clock instanceof String) && clock.equals("chronometer");
     }
 
     /**

+ 14 - 1
www/local-notification.js

@@ -30,6 +30,7 @@ exports._defaults = {
     autoClear     : true,
     badge         : null,
     channel       : null,
+    clock         : true,
     color         : null,
     data          : null,
     defaults      : 0,
@@ -45,13 +46,13 @@ exports._defaults = {
     number        : 0,
     priority      : 0,
     progressBar   : false,
-    showWhen      : true,
     silent        : false,
     smallIcon     : 'res://icon',
     sound         : true,
     sticky        : false,
     summary       : null,
     text          : '',
+    timeout       : false,
     title         : '',
     trigger       : { type : 'calendar' },
     vibrate       : false,
@@ -606,6 +607,14 @@ exports._convertProperties = function (options) {
         console.warn('Property "smallIcon" must be of kind res://...');
     }
 
+    if (typeof options.timeout === 'boolean') {
+        options.timeout = options.timeout ? 3600000 : null;
+    }
+
+    if (options.timeout) {
+        options.timeout = parseToInt('timeout', options);
+    }
+
     options.data = JSON.stringify(options.data);
 
     this._convertTrigger(options);
@@ -761,6 +770,10 @@ exports._convertProgressBar = function (options) {
 
     cfg.enabled = !!cfg.enabled;
 
+    if (cfg.enabled && options.clock === true) {
+        options.clock = 'chronometer';
+    }
+
     return options;
 };