Commit cb831ad8 by Sebastián Katzer

Implemented trigger: before for Android and Windows

parent fb993c31
......@@ -285,7 +285,7 @@ The properties depend on the trigger type. Not all of them are supported across
| | every | String | `month` | x | x | x |
| | every | String | `quarter` | x | | x |
| | every | String | `year` | x | x | x |
| | before | Date | |
| | before | Date | | x | | x |
| | firstAt | Date | | x | x | x |
| Match |
| | count | Int | | x | | x |
......@@ -299,7 +299,7 @@ The properties depend on the trigger type. Not all of them are supported across
| | every | Object | `month` | x | x | x |
| | every | Object | `quarter` | | x |
| | every | Object | `year` | x | x | x |
| | before | Date | |
| | before | Date | | x | | x |
| | after | Date | | x | x | x |
| Location |
| | center | Array | `[lat, long]` | | x |
......
......@@ -88,7 +88,7 @@ public final class Request {
*
* @return The notification ID as the string
*/
public String getIdentifier() {
String getIdentifier() {
return options.getId().toString() + "-" + getOccurrence();
}
......@@ -130,9 +130,13 @@ public final class Request {
if (triggerDate == null)
return null;
if ((now.getTimeInMillis() - triggerDate.getTime()) > 60000) {
long time = triggerDate.getTime();
if ((now.getTimeInMillis() - time) > 60000)
return null;
if (time >= spec.optLong("before", time + 1))
return null;
}
return triggerDate;
}
......@@ -151,8 +155,8 @@ public final class Request {
Object every = spec.opt("every");
if (every instanceof JSONObject) {
List<Integer> cmp1 = getMatchers();
List<Integer> cmp2 = getSpecials();
List<Integer> cmp1 = getMatchingComponents();
List<Integer> cmp2 = getSpecialMatchingComponents();
return new MatchTrigger(cmp1, cmp2);
}
......@@ -208,7 +212,7 @@ public final class Request {
*
* @return [min, hour, day, month, year]
*/
private List<Integer> getMatchers() {
private List<Integer> getMatchingComponents() {
JSONObject every = spec.optJSONObject("every");
return Arrays.asList(
......@@ -223,9 +227,9 @@ public final class Request {
/**
* Gets an array of all date parts to construct a datetime instance.
*
* @return [weekday, weekdayOrdinal, weekOfMonth, quarter]
* @return [min, hour, day, month, year]
*/
private List<Integer> getSpecials() {
private List<Integer> getSpecialMatchingComponents() {
JSONObject every = spec.optJSONObject("every");
return Arrays.asList(
......
......@@ -85,6 +85,16 @@ namespace LocalNotificationProxy.LocalNotification
return null;
}
if (this.spec.Before != 0)
{
var before = this.ToDateTime(this.spec.Before);
if (this.triggerDate.Value >= before)
{
return null;
}
}
var minDate = DateTime.Now.AddSeconds(0.2);
if (this.triggerDate >= minDate)
......@@ -238,18 +248,28 @@ namespace LocalNotificationProxy.LocalNotification
{
if (this.spec.At != 0)
{
return DateTimeOffset.FromUnixTimeMilliseconds(this.spec.At).LocalDateTime;
return this.ToDateTime(this.spec.At);
}
else if (this.spec.FirstAt != 0)
{
return DateTimeOffset.FromUnixTimeMilliseconds(this.spec.FirstAt).LocalDateTime;
return this.ToDateTime(this.spec.FirstAt);
}
else if (this.spec.After != 0)
{
return DateTimeOffset.FromUnixTimeMilliseconds(this.spec.After).LocalDateTime;
return this.ToDateTime(this.spec.After);
}
return DateTime.Now;
}
/// <summary>
/// Unix time from milliseconds.
/// </summary>
/// <param name="ms">Milliseconds </param>
/// <returns>DateTime object.</returns>
private DateTime ToDateTime(long ms)
{
return DateTimeOffset.FromUnixTimeMilliseconds(ms).LocalDateTime;
}
}
}
......@@ -43,6 +43,11 @@ namespace LocalNotificationProxy.LocalNotification.Toast
public long FirstAt { get; set; } = 0;
/// <summary>
/// Gets or sets the before trigger date.
/// </summary>
public long Before { get; set; } = 0;
/// <summary>
/// Gets or sets the after trigger date.
/// </summary>
public long After { get; set; } = 0;
......@@ -85,9 +90,10 @@ namespace LocalNotificationProxy.LocalNotification.Toast
var trigger = new Trigger();
var node = doc.DocumentElement;
trigger.At = int.Parse(node.GetAttribute("at"));
trigger.FirstAt = int.Parse(node.GetAttribute("firstAt"));
trigger.After = int.Parse(node.GetAttribute("after"));
trigger.At = long.Parse(node.GetAttribute("at"));
trigger.FirstAt = long.Parse(node.GetAttribute("firstAt"));
trigger.Before = long.Parse(node.GetAttribute("before"));
trigger.After = long.Parse(node.GetAttribute("after"));
trigger.In = int.Parse(node.GetAttribute("in"));
trigger.Count = int.Parse(node.GetAttribute("count"));
trigger.Occurrence = int.Parse(node.GetAttribute("occurrence"));
......@@ -119,6 +125,7 @@ namespace LocalNotificationProxy.LocalNotification.Toast
node.SetAttribute("at", this.At.ToString());
node.SetAttribute("firstAt", this.FirstAt.ToString());
node.SetAttribute("before", this.Before.ToString());
node.SetAttribute("after", this.After.ToString());
node.SetAttribute("in", this.In.ToString());
node.SetAttribute("count", this.Count.ToString());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment