Skip to content

Commit 8ba0622

Browse files
authored
Merge branch 'master' into feature/tabbedcommandbar
2 parents 68fd805 + 31b2603 commit 8ba0622

File tree

27 files changed

+222
-928
lines changed

27 files changed

+222
-928
lines changed

Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.Actions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public ToastContentBuilder AddButton(string content, ToastActivationType activat
112112
/// <returns>The current instance of <see cref="ToastContentBuilder"/></returns>
113113
public ToastContentBuilder AddButton(IToastButton button)
114114
{
115-
if (button is ToastButton toastButton && toastButton.Content == null)
115+
if (button is ToastButton toastButton && toastButton.Content == null && toastButton.NeedsContent())
116116
{
117117
throw new InvalidOperationException("Content is required on button.");
118118
}

Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastButton.cs

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ public sealed class ToastButton :
2020

2121
private bool _usingCustomArguments;
2222

23+
private bool _usingSnoozeActivation;
24+
private string _snoozeSelectionBoxId;
25+
26+
private bool _usingDismissActivation;
27+
28+
internal bool NeedsContent()
29+
{
30+
// Snooze/dismiss buttons don't need content (the system will auto-add the localized strings).
31+
return !_usingDismissActivation && !_usingSnoozeActivation;
32+
}
33+
2334
/// <summary>
2435
/// Initializes a new instance of the <see cref="ToastButton"/> class.
2536
/// </summary>
@@ -213,6 +224,11 @@ private ToastButton AddArgumentHelper(string key, string value)
213224
throw new InvalidOperationException("You cannot use the AddArgument methods when using protocol activation.");
214225
}
215226

227+
if (_usingDismissActivation || _usingSnoozeActivation)
228+
{
229+
throw new InvalidOperationException("You cannot use the AddArgument methods when using dismiss or snooze activation.");
230+
}
231+
216232
bool alreadyExists = _arguments.ContainsKey(key);
217233

218234
_arguments[key] = value;
@@ -314,6 +330,48 @@ public ToastButton SetAfterActivationBehavior(ToastAfterActivationBehavior after
314330
return this;
315331
}
316332

333+
/// <summary>
334+
/// Configures the button to use system snooze activation when the button is clicked, using the default system snooze time.
335+
/// </summary>
336+
/// <returns>The current instance of <see cref="ToastButton"/></returns>
337+
public ToastButton SetSnoozeActivation()
338+
{
339+
return SetSnoozeActivation(null);
340+
}
341+
342+
/// <summary>
343+
/// Configures the button to use system snooze activation when the button is clicked, with a snooze time defined by the specified selection box.
344+
/// </summary>
345+
/// <param name="selectionBoxId">The ID of an existing <see cref="ToastSelectionBox"/> which allows the user to pick a custom snooze time. The ID's of the <see cref="ToastSelectionBoxItem"/>s inside the selection box must represent the snooze interval in minutes. For example, if the user selects an item that has an ID of "120", then the notification will be snoozed for 2 hours. When the user clicks this button, if you specified a SelectionBoxId, the system will parse the ID of the selected item and snooze by that amount of minutes.</param>
346+
/// <returns>The current instance of <see cref="ToastButton"/></returns>
347+
public ToastButton SetSnoozeActivation(string selectionBoxId)
348+
{
349+
if (_arguments.Count > 0)
350+
{
351+
throw new InvalidOperationException($"{nameof(SetSnoozeActivation)} cannot be used in conjunction with ${nameof(AddArgument)}.");
352+
}
353+
354+
_usingSnoozeActivation = true;
355+
_snoozeSelectionBoxId = selectionBoxId;
356+
357+
return this;
358+
}
359+
360+
/// <summary>
361+
/// Configures the button to use system dismiss activation when the button is clicked (the toast will simply dismiss rather than activating).
362+
/// </summary>
363+
/// <returns>The current instance of <see cref="ToastButton"/></returns>
364+
public ToastButton SetDismissActivation()
365+
{
366+
if (_arguments.Count > 0)
367+
{
368+
throw new InvalidOperationException($"{nameof(SetDismissActivation)} cannot be used in conjunction with ${nameof(AddArgument)}.");
369+
}
370+
371+
_usingDismissActivation = true;
372+
return this;
373+
}
374+
317375
/// <summary>
318376
/// Sets an identifier used in telemetry to identify your category of action. This should be something like "Delete", "Reply", or "Archive". In the upcoming toast telemetry dashboard in Dev Center, you will be able to view how frequently your actions are being clicked.
319377
/// </summary>
@@ -349,7 +407,7 @@ public ToastButton SetTextBoxId(string textBoxId)
349407

350408
internal bool CanAddArguments()
351409
{
352-
return ActivationType != ToastActivationType.Protocol && !_usingCustomArguments;
410+
return ActivationType != ToastActivationType.Protocol && !_usingCustomArguments && !_usingDismissActivation && !_usingSnoozeActivation;
353411
}
354412

355413
internal bool ContainsArgument(string key)
@@ -362,13 +420,44 @@ internal Element_ToastAction ConvertToElement()
362420
var el = new Element_ToastAction()
363421
{
364422
Content = Content,
365-
Arguments = Arguments,
366-
ActivationType = Element_Toast.ConvertActivationType(ActivationType),
367423
ImageUri = ImageUri,
368424
InputId = TextBoxId,
369425
HintActionId = HintActionId
370426
};
371427

428+
if (_usingSnoozeActivation)
429+
{
430+
el.ActivationType = Element_ToastActivationType.System;
431+
el.Arguments = "snooze";
432+
433+
if (_snoozeSelectionBoxId != null)
434+
{
435+
el.InputId = _snoozeSelectionBoxId;
436+
}
437+
438+
// Content needs to be specified as empty for auto-generated Snooze content
439+
if (el.Content == null)
440+
{
441+
el.Content = string.Empty;
442+
}
443+
}
444+
else if (_usingDismissActivation)
445+
{
446+
el.ActivationType = Element_ToastActivationType.System;
447+
el.Arguments = "dismiss";
448+
449+
// Content needs to be specified as empty for auto-generated Dismiss content
450+
if (el.Content == null)
451+
{
452+
el.Content = string.Empty;
453+
}
454+
}
455+
else
456+
{
457+
el.ActivationType = Element_Toast.ConvertActivationType(ActivationType);
458+
el.Arguments = Arguments;
459+
}
460+
372461
ActivationOptions?.PopulateElement(el);
373462

374463
return el;

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Toast/ToastCode.bind

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ private void PopToast()
1313
("60", "1 hour"),
1414
("240", "4 hours"),
1515
("1440", "1 day"))
16-
.AddButton(new ToastButtonSnooze() { SelectionBoxId = "snoozeTime" })
17-
.AddButton(new ToastButtonDismiss())
16+
.AddButton(new ToastButton()
17+
.SetSnoozeActivation("snoozeTime"))
18+
.AddButton(new ToastButton()
19+
.SetDismissActivation())
1820
.Show();
1921
}

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Toast/ToastPage.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ public static ToastContent GenerateToastContent()
4040
("60", "1 hour"),
4141
("240", "4 hours"),
4242
("1440", "1 day"))
43-
.AddButton(new ToastButtonSnooze() { SelectionBoxId = "snoozeTime" })
44-
.AddButton(new ToastButtonDismiss());
43+
.AddButton(new ToastButton()
44+
.SetSnoozeActivation("snoozeTime"))
45+
.AddButton(new ToastButton()
46+
.SetDismissActivation());
4547

4648
return builder.Content;
4749
}

Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Blur.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.cs

Lines changed: 0 additions & 141 deletions
This file was deleted.

Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.nongeneric.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)