Commit 78bf5452 by Sebastián Katzer

Handle action button click events

parent b01a1375
......@@ -104,8 +104,10 @@ exports.schedule = function (success, error, args) {
* @return [ Void ]
*/
exports.clicked = function (xml) {
var notification = LocalNotification.Options.parse(xml);
cordova.plugins.notification.local.core.fireEvent('click', notification);
var toast = LocalNotification.Options.parse(xml),
event = toast.action || 'click';
cordova.plugins.notification.local.core.fireEvent(event, toast);
};
// Handle onclick event
......
......@@ -39,19 +39,5 @@ namespace LocalNotificationProxy.LocalNotification
/// Gets or sets a value indicating whether to launch the app.
/// </summary>
public bool Launch { get; set; }
/// <summary>
/// Gets the parsed toast button.
/// </summary>
internal ToastButton ToastButton
{
get
{
return new ToastButton(this.Title, this.ID)
{
ActivationType = this.Launch ? ToastActivationType.Foreground : ToastActivationType.Background
};
}
}
}
}
......@@ -178,7 +178,11 @@
foreach (var action in this.Options.Buttons)
{
buttons.Add(action.ToastButton);
buttons.Add(
new ToastButton(action.Title, this.Options.GetXml(action.ID))
{
ActivationType = action.Launch ? ToastActivationType.Foreground : ToastActivationType.Background
});
}
return buttons;
......
......@@ -21,14 +21,16 @@
namespace LocalNotificationProxy.LocalNotification
{
using System;
using System.Collections.Generic;
using Microsoft.Toolkit.Uwp.Notifications;
using Windows.Data.Xml.Dom;
public sealed class Options
{
/// <summary>
/// Gets notification event.
/// </summary>
public string Action { get; private set; } = "click";
/// <summary>
/// Gets or sets notification ID.
/// </summary>
public int ID { get; set; }
......@@ -130,6 +132,11 @@ namespace LocalNotificationProxy.LocalNotification
options.Data = node.GetAttribute("data");
}
if (node.GetAttributeNode("action") != null)
{
options.Action = node.GetAttribute("action");
}
return options;
}
......@@ -139,6 +146,16 @@ namespace LocalNotificationProxy.LocalNotification
/// <returns>Element with all property values set as attributes.</returns>
public string GetXml()
{
return this.GetXml(null);
}
/// <summary>
/// Gets the instance as an serialized xml element.
/// </summary>
/// <param name="action">Optional (internal) event name.</param>
/// <returns>Element with all property values set as attributes.</returns>
internal string GetXml(string action)
{
var node = new XmlDocument().CreateElement("options");
node.SetAttribute("id", this.ID.ToString());
......@@ -175,6 +192,11 @@ namespace LocalNotificationProxy.LocalNotification
node.SetAttribute("data", this.Data);
}
if (action != null)
{
node.SetAttribute("action", action);
}
return node.GetXml();
}
}
......
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