Commit 78bf5452 by Sebastián Katzer

Handle action button click events

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