Commit 15bb160f by Sebastián Katzer

Initial basic support for action buttons

parent df93be14
......@@ -60,7 +60,7 @@ exports.request = function (success, error) {
* @return [ Void ]
*/
exports.schedule = function (success, error, args) {
var options = [];
var options = [], buttons = [];
for (var i = 0, props, opts; i < args.length; i++) {
props = args[i];
......@@ -72,6 +72,22 @@ exports.schedule = function (success, error, args) {
}
}
for (var j = 0, action; j < props.actions.length; j++) {
action = props.actions[j];
if (!action.type || action.type == 'button') {
var button = new LocalNotification.Button();
button.id = action.id;
button.title = action.title;
button.launch = action.launch;
buttons.push(button);
}
}
opts.buttons = buttons;
options.push(opts);
}
......
......@@ -75,6 +75,11 @@ namespace LocalNotificationProxy.LocalNotification
AppLogoOverride = this.Options.ToastLogo
}
},
Actions = new ToastActionsCustom()
{
Buttons = { }
}
};
......@@ -83,6 +88,11 @@ namespace LocalNotificationProxy.LocalNotification
toast.Visual.BindingGeneric.Children.Add(image);
}
foreach (var btn in this.Options.ToastButtons)
{
(toast.Actions as ToastActionsCustom).Buttons.Add(btn);
}
var xml = toast.GetXml();
var at = this.Options.TriggerDate;
ScheduledToastNotification notification;
......
/*
* Apache 2.0 License
*
* Copyright (c) Sebastian Katzer 2017
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*/
namespace LocalNotificationProxy.LocalNotification
{
using Microsoft.Toolkit.Uwp.Notifications;
public sealed class Button
{
/// <summary>
/// Gets or sets button ID.
/// </summary>
public string ID { get; set; }
/// <summary>
/// Gets or sets button title.
/// </summary>
public string Title { get; set; }
/// <summary>
/// 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
};
}
}
}
}
......@@ -22,14 +22,12 @@
namespace LocalNotificationProxy.LocalNotification
{
using System;
using System.Collections.Generic;
using Microsoft.Toolkit.Uwp.Notifications;
using Windows.Data.Xml.Dom;
using System.Collections;
using System.Collections.Generic;
public sealed class Options
{
/// <summary>
/// Gets or sets notification ID.
/// </summary>
......@@ -81,6 +79,11 @@ namespace LocalNotificationProxy.LocalNotification
public string[] Attachments { get; set; }
/// <summary>
/// Gets or sets the notification buttons.
/// </summary>
public Button[] Buttons { get; set; }
/// <summary>
/// Gets the date when to trigger the notification.
/// </summary>
internal DateTime TriggerDate
......@@ -304,6 +307,24 @@ namespace LocalNotificationProxy.LocalNotification
}
/// <summary>
/// Gets all toast buttons.
/// </summary>
internal List<ToastButton> ToastButtons
{
get
{
var buttons = new List<ToastButton>();
foreach (var action in this.Buttons)
{
buttons.Add(action.ToastButton);
}
return buttons;
}
}
/// <summary>
/// Deserializes the XML string into an instance of Options.
/// </summary>
/// <param name="identifier">The serialized instance of Options as an xml string.</param>
......
......@@ -112,6 +112,7 @@
<ItemGroup>
<Compile Include="LocalNotificationProxy.cs" />
<Compile Include="LocalNotification\Builder.cs" />
<Compile Include="LocalNotification\Button.cs" />
<Compile Include="LocalNotification\Options.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
......
......@@ -33,7 +33,7 @@ exports._defaults = {
data: undefined,
every: undefined,
at: undefined,
actions: undefined,
actions: [],
actionGroupId: undefined,
attachments: []
};
......
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