Преглед на файлове

Handle action button click events

Sebastián Katzer преди 8 години
родител
ревизия
78bf545281

+ 4 - 2
src/windows/LocalNotificationProxy.js

@@ -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

+ 0 - 14
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Button.cs

@@ -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
-                };
-            }
-        }
     }
 }

+ 5 - 1
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Content.cs

@@ -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;

+ 25 - 3
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Options.cs

@@ -21,13 +21,15 @@
 
 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>
@@ -130,6 +132,11 @@ namespace LocalNotificationProxy.LocalNotification
                 options.Data = node.GetAttribute("data");
             }
 
+            if (node.GetAttributeNode("action") != null)
+            {
+                options.Action = node.GetAttribute("action");
+            }
+
             return options;
         }
 
@@ -138,6 +145,16 @@ namespace LocalNotificationProxy.LocalNotification
         /// </summary>
         /// <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");
 
@@ -175,6 +192,11 @@ namespace LocalNotificationProxy.LocalNotification
                 node.SetAttribute("data", this.Data);
             }
 
+            if (action != null)
+            {
+                node.SetAttribute("action", action);
+            }
+
             return node.GetXml();
         }
     }