Skip to content

Commit fb98522

Browse files
committed
Merge branch 'snackbar'
2 parents e9a33e6 + 3aa35de commit fb98522

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

MaterialDesignThemes.Wpf/ISnackbarMessageQueue.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,58 @@ namespace MaterialDesignThemes.Wpf
44
{
55
public interface ISnackbarMessageQueue
66
{
7+
/// <summary>
8+
/// Queues a notificaton message for display in a snackbar.
9+
/// </summary>
10+
/// <param name="content">Message.</param>
711
void Enqueue(object content);
812

13+
/// <summary>
14+
/// Queues a notificaton message for display in a snackbar.
15+
/// </summary>
16+
/// <param name="content">Message.</param>
17+
/// <param name="actionContent">Content for the action button.</param>
18+
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
919
void Enqueue(object content, object actionContent, Action actionHandler);
1020

21+
/// <summary>
22+
/// Queues a notificaton message for display in a snackbar.
23+
/// </summary>
24+
/// <param name="content">Message.</param>
25+
/// <param name="actionContent">Content for the action button.</param>
26+
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
27+
/// <param name="actionArgument">Argument to pass to <paramref name="actionHandler"/>.</param>
1128
void Enqueue<TArgument>(object content, object actionContent, Action<TArgument> actionHandler, TArgument actionArgument);
1229

30+
/// <summary>
31+
/// Queues a notificaton message for display in a snackbar.
32+
/// </summary>
33+
/// <param name="content">Message.</param>
34+
/// <param name="neverConsiderToBeDuplicate">Subsequent, duplicate messages queued within a short time span will
35+
/// be discarded. To override this behaviour and ensure the message always gets displayed set to <c>true</c>.</param>
36+
void Enqueue(object content, bool neverConsiderToBeDuplicate);
37+
38+
/// <summary>
39+
/// Queues a notificaton message for display in a snackbar.
40+
/// </summary>
41+
/// <param name="content">Message.</param>
42+
/// <param name="actionContent">Content for the action button.</param>
43+
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
44+
/// <param name="neverConsiderToBeDuplicate">Subsequent, duplicate messages queued within a short time span will
45+
/// be discarded. To override this behaviour and ensure the message always gets displayed set to <c>true</c>.</param>
46+
void Enqueue(object content, object actionContent, Action actionHandler, bool neverConsiderToBeDuplicate);
47+
48+
/// <summary>
49+
/// Queues a notificaton message for display in a snackbar.
50+
/// </summary>
51+
/// <param name="content">Message.</param>
52+
/// <param name="actionContent">Content for the action button.</param>
53+
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
54+
/// <param name="actionArgument">Argument to pass to <paramref name="actionHandler"/>.</param>
55+
/// <param name="neverConsiderToBeDuplicate">Subsequent, duplicate messages queued within a short time span will
56+
/// be discarded. To override this behaviour and ensure the message always gets displayed set to <c>true</c>.</param>
57+
void Enqueue<TArgument>(object content, object actionContent, Action<TArgument> actionHandler, TArgument actionArgument, bool neverConsiderToBeDuplicate);
58+
1359
//TODO consider additional variants of Enqueue:
1460
// ShowAsync(. . .)
1561
}

MaterialDesignThemes.Wpf/SnackbarMessageQueue.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ internal Action Pause()
185185
}
186186

187187
public void Enqueue(object content)
188+
{
189+
Enqueue(content, false);
190+
}
191+
192+
public void Enqueue(object content, bool neverConsiderToBeDuplicate)
188193
{
189194
if (content == null) throw new ArgumentNullException(nameof(content));
190195

@@ -193,6 +198,11 @@ public void Enqueue(object content)
193198
}
194199

195200
public void Enqueue(object content, object actionContent, Action actionHandler)
201+
{
202+
Enqueue(content, actionContent, actionHandler, false);
203+
}
204+
205+
public void Enqueue(object content, object actionContent, Action actionHandler, bool neverConsiderToBeDuplicate)
196206
{
197207
if (content == null) throw new ArgumentNullException(nameof(content));
198208

@@ -202,6 +212,12 @@ public void Enqueue(object content, object actionContent, Action actionHandler)
202212

203213
public void Enqueue<TArgument>(object content, object actionContent, Action<TArgument> actionHandler,
204214
TArgument actionArgument)
215+
{
216+
Enqueue<TArgument>(content, actionContent, actionHandler, actionArgument, false);
217+
}
218+
219+
public void Enqueue<TArgument>(object content, object actionContent, Action<TArgument> actionHandler,
220+
TArgument actionArgument, bool neverConsiderToBeDuplicate)
205221
{
206222
if (content == null) throw new ArgumentNullException(nameof(content));
207223

@@ -249,9 +265,11 @@ private async void PumpAsync()
249265
if (snackbar != null)
250266
{
251267
var message = _snackbarMessages.Dequeue();
252-
if (_latestShownItem == null || !Equals(_latestShownItem.Item1.Content, message.Content) ||
253-
!Equals(_latestShownItem.Item1.ActionContent, message.ActionContent) ||
254-
_latestShownItem.Item2 <= DateTime.Now.Subtract(_messageDuration))
268+
if (_latestShownItem == null
269+
|| message.NeverConsiderToBeDuplicate
270+
|| !Equals(_latestShownItem.Item1.Content, message.Content)
271+
|| !Equals(_latestShownItem.Item1.ActionContent, message.ActionContent)
272+
|| _latestShownItem.Item2 <= DateTime.Now.Subtract(_messageDuration))
255273
{
256274
await ShowAsync(snackbar, message);
257275
_latestShownItem = new Tuple<SnackbarMessageQueueItem, DateTime>(message, DateTime.Now);

MaterialDesignThemes.Wpf/SnackbarMessageQueueItem.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ namespace MaterialDesignThemes.Wpf
44
{
55
internal class SnackbarMessageQueueItem
66
{
7-
public SnackbarMessageQueueItem(object content, object actionContent = null, object actionHandler = null, object actionArgument = null, Type argumentType = null)
7+
public SnackbarMessageQueueItem(object content, object actionContent = null, object actionHandler = null, object actionArgument = null, Type argumentType = null, bool neverConsiderToBeDuplicate = false)
88
{
99
Content = content;
1010
ActionContent = actionContent;
1111
ActionHandler = actionHandler;
1212
ActionArgument = actionArgument;
1313
ArgumentType = argumentType;
14+
NeverConsiderToBeDuplicate = neverConsiderToBeDuplicate;
1415
}
1516

1617
public object Content { get; }
@@ -22,5 +23,7 @@ public SnackbarMessageQueueItem(object content, object actionContent = null, obj
2223
public object ActionArgument { get; }
2324

2425
public Type ArgumentType { get; }
26+
27+
public bool NeverConsiderToBeDuplicate { get; }
2528
}
2629
}

0 commit comments

Comments
 (0)