Ver código fonte

Support for firstAt on Android

Sebastián Katzer 8 anos atrás
pai
commit
99df92d9a3
3 arquivos alterados com 28 adições e 7 exclusões
  1. 3 4
      README.md
  2. 7 1
      src/android/notification/Request.java
  3. 18 2
      www/local-notification-util.js

+ 3 - 4
README.md

@@ -263,7 +263,7 @@ The properties depend on the trigger type. Not all of them are supported across
 | Type         | Property      | Type    | Value            | Android | iOS | Windows |
 | :----------- | :------------ | :------ | :--------------- | :------ | :-- | :------ |
 | Fix          | 
-|              | at            | Date    |                  |  x      | x   | x       |
+|              | at            | Date    |                  | x       | x   | x       |
 | Timespan     |
 |              | in            | Int     |                  | x       | x   | x       |
 |              | unit          | String  | `second`         | x       | x   | x       |
@@ -283,8 +283,7 @@ The properties depend on the trigger type. Not all of them are supported across
 |              | every         | String  | `month`          | x       | x   | x       |
 |              | every         | String  | `year`           | x       | x   | x       |
 |              | before        | Date    |                  |
-|              | firstAt       | Date    |                  |
-|              | after         | Date    |                  |
+|              | firstAt       | Date    |                  | x       |
 | Match        |
 |              | count         | Int     |                  | x       |     | x       |
 |              | every         | Object  | `minute`         | x       | x   | x       |
@@ -298,7 +297,7 @@ The properties depend on the trigger type. Not all of them are supported across
 |              | every         | Object  | `quarter`        |         | x   |
 |              | every         | Object  | `year`           | x       | x   | x       |
 |              | before        | Date    |                  |
-|              | after         | Date    |                  |
+|              | after         | Date    |                  | x       |
 | Location     |
 |              | center        | Array   | `[lat, long]`    |         | x   |
 |              | radius        | Int     |                  |         | x   |

+ 7 - 1
src/android/notification/Request.java

@@ -241,7 +241,13 @@ public final class Request {
      */
     private Date getBaseDate() {
         if (spec.has("at")) {
-            return new Date(spec.optLong("at", 0) * 1000);
+            return new Date(1000 * spec.optLong("at", 0));
+        } else
+        if (spec.has("firstAt")) {
+            return new Date(1000 * spec.optLong("firstAt", 0));
+        } else
+        if (spec.has("after")) {
+            return new Date(1000 * spec.optLong("after", 0));
         } else {
             return new Date();
         }

+ 18 - 2
www/local-notification-util.js

@@ -201,6 +201,11 @@ exports.convertTrigger = function (options) {
     var trigger  = options.trigger || {},
         date     = this.getValueFor(trigger, 'at', 'firstAt', 'date');
 
+    var dateToNum = function (date) {
+        var num = typeof date == 'object' ? date.getTime() : date;
+        return Math.round(num / 1000);
+    };
+
     if (!options.trigger)
         return;
 
@@ -223,8 +228,19 @@ exports.convertTrigger = function (options) {
     }
 
     if (isCal && date) {
-        date       = typeof date == 'object' ? date.getTime() : date;
-        trigger.at = Math.round(date / 1000);
+        trigger.at = dateToNum(date);
+    }
+
+    if (isCal && trigger.firstAt) {
+        trigger.firstAt = dateToNum(trigger.firstAt);
+    }
+
+    if (isCal && trigger.before) {
+        trigger.before = dateToNum(trigger.before);
+    }
+
+    if (isCal && trigger.after) {
+        trigger.after = dateToNum(trigger.after);
     }
 
     if (!trigger.count && device.platform == 'windows') {