You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Snooze/dismiss support in toast button builders (#3694)
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 -->
<!-- 📝 It is preferred if you keep the "☑️ Allow edits by maintainers" checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 -->
## Fixes#3614
<!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes#1234) which will automatically close the issue once the PR is merged. -->
<!-- Add a brief overview here of the feature/bug & fix. -->
The toast button builders we added in 7.0 so far didn't support snooze/dismiss activation, it makes sense to have a single way of constructing a button regardless of the activation type.
Additionally, this helps us converge on using `Uri` types for images rather than `string` as mentioned in issue #3614.
## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->
<!-- - Bugfix -->
- Feature
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->
## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
Had to use a separate button type previously...
```csharp
new ToastContentBuilder()
.AddButton(new ToastButton()
.SetContent("Delete")
.SetImageUri(new Uri("delete.png"))
.AddArgument("action", "delete")
.SetBackgroundActivation()
.AddButton(new ToastButtonDismiss()
{
ImageUri = "dismiss.png"
});
```
## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
Can use the same button builder, and the image consistently uses `Uri` type.
```csharp
new ToastContentBuilder()
.AddButton(new ToastButton()
.SetContent("Delete")
.SetImageUri(new Uri("delete.png"))
.AddArgument("action", "delete")
.SetBackgroundActivation()
.AddButton(new ToastButton()
.SetImageUri(new Uri("dismiss.png"))
.SetDismissActivation());
```
## PR Checklist
Please check if your PR fulfills the following requirements:
- [x] Tested code with current [supported SDKs](../readme.md#supported)
- [x] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [x] Sample in sample app has been added / updated (for bug fixes / features)
- [x] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [x] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
- [x] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [x] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [x] Contains **NO** breaking changes
<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below.
Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. -->
## Other information
thrownewInvalidOperationException("You cannot use the AddArgument methods when using dismiss or snooze activation.");
230
+
}
231
+
216
232
boolalreadyExists=_arguments.ContainsKey(key);
217
233
218
234
_arguments[key]=value;
@@ -314,6 +330,48 @@ public ToastButton SetAfterActivationBehavior(ToastAfterActivationBehavior after
314
330
returnthis;
315
331
}
316
332
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
+
publicToastButtonSetSnoozeActivation()
338
+
{
339
+
returnSetSnoozeActivation(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>
thrownewInvalidOperationException($"{nameof(SetSnoozeActivation)} cannot be used in conjunction with ${nameof(AddArgument)}.");
352
+
}
353
+
354
+
_usingSnoozeActivation=true;
355
+
_snoozeSelectionBoxId=selectionBoxId;
356
+
357
+
returnthis;
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
+
publicToastButtonSetDismissActivation()
365
+
{
366
+
if(_arguments.Count>0)
367
+
{
368
+
thrownewInvalidOperationException($"{nameof(SetDismissActivation)} cannot be used in conjunction with ${nameof(AddArgument)}.");
369
+
}
370
+
371
+
_usingDismissActivation=true;
372
+
returnthis;
373
+
}
374
+
317
375
/// <summary>
318
376
/// 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.
319
377
/// </summary>
@@ -349,7 +407,7 @@ public ToastButton SetTextBoxId(string textBoxId)
0 commit comments