Skip to content

Commit 5c96149

Browse files
committed
Implemented delayed dismiss
1 parent 2da6456 commit 5c96149

File tree

7 files changed

+130
-12
lines changed

7 files changed

+130
-12
lines changed

Changelog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
8+
## [1.1.0] - 2018-04-03
9+
### Added
10+
- Support for delayed dismiss `WithDelay` extension method for LINQ builder.
11+
12+
## [1.0.0] - 2017-03-08
13+
### Added
14+
- Initial release.

Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@
7575
Content="Error message"
7676
Style="{StaticResource NotificationMessageButtonStyle}" />
7777

78+
<Button
79+
Margin="8"
80+
Padding="12,8"
81+
HorizontalAlignment="Left"
82+
VerticalAlignment="Top"
83+
Background="#1751C3"
84+
Click="ButtonBaseInfoDelayOnClick"
85+
Content="Info message with delayed dismiss (5s)"
86+
Style="{StaticResource NotificationMessageButtonStyle}" />
87+
7888
</StackPanel>
7989
</Grid>
8090
</controls1:MetroWindow>

Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ private void ButtonBaseInfoOnClick(object sender, RoutedEventArgs e)
7373
.Queue();
7474
}
7575

76+
private void ButtonBaseInfoDelayOnClick(object sender, RoutedEventArgs e)
77+
{
78+
this.Manager
79+
.CreateMessage()
80+
.Accent("#1751C3")
81+
.Background("#333")
82+
.HasBadge("Info")
83+
.HasMessage("Update will be installed on next application restart. This message will be dismissed after 5 seconds.")
84+
.Dismiss().WithButton("Update now", button => { })
85+
.Dismiss().WithButton("Release notes", button => { })
86+
.Dismiss().WithDelay(TimeSpan.FromSeconds(5))
87+
.Queue();
88+
}
89+
7690
public INotificationMessageManager Manager { get; } = new NotificationMessageManager();
7791
}
7892
}

Enterwell.Clients.Wpf.Notifications.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enterwell.Clients.Wpf.Notif
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3AF6FCB5-2016-41CA-9DBD-5C628B3509AE}"
1111
ProjectSection(SolutionItems) = preProject
12+
Changelog.md = Changelog.md
1213
Readme.md = Readme.md
1314
EndProjectSection
1415
EndProject
@@ -30,4 +31,7 @@ Global
3031
GlobalSection(SolutionProperties) = preSolution
3132
HideSolutionNode = FALSE
3233
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {007773A2-8852-4770-8634-FC68BA83ACE6}
36+
EndGlobalSection
3337
EndGlobal

Enterwell.Clients.Wpf.Notifications/NotificationMessageBuilder.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using System.Windows.Media;
34

45
namespace Enterwell.Clients.Wpf.Notifications
@@ -111,18 +112,39 @@ public INotificationMessage Queue()
111112
return this.Message;
112113
}
113114

115+
/// <summary>
116+
/// Executes the action after specified delay time.
117+
/// </summary>
118+
/// <param name="delayMilliseconds">The delay in milliseconds.</param>
119+
/// <param name="action">The action.</param>
120+
public void Delay(int delayMilliseconds, Action<INotificationMessage> action)
121+
{
122+
this.Delay(TimeSpan.FromMilliseconds(delayMilliseconds), action);
123+
}
124+
125+
/// <summary>
126+
/// Executes the action after specified delay time.
127+
/// </summary>
128+
/// <param name="delay">The delay.</param>
129+
/// <param name="action">The action.</param>
130+
public void Delay(TimeSpan delay, Action<INotificationMessage> action)
131+
{
132+
Task.Delay(delay).ContinueWith(
133+
context => action(this.Message),
134+
TaskScheduler.FromCurrentSynchronizationContext());
135+
}
114136

115137
/// <summary>
116138
/// The notification message button that is required to dismiss the notification.
117139
/// </summary>
118-
public class DismissNotificationMessageButton
140+
public class DismissNotificationMessage
119141
{
120142
/// <summary>
121-
/// Initializes a new instance of the <see cref="DismissNotificationMessageButton"/> class.
143+
/// Initializes a new instance of the <see cref="DismissNotificationMessage"/> class.
122144
/// </summary>
123145
/// <param name="builder">The builder.</param>
124146
/// <exception cref="ArgumentNullException">builder</exception>
125-
public DismissNotificationMessageButton(NotificationMessageBuilder builder)
147+
public DismissNotificationMessage(NotificationMessageBuilder builder)
126148
{
127149
this.Builder = builder ?? throw new ArgumentNullException(nameof(builder));
128150
}

Enterwell.Clients.Wpf.Notifications/NotificationMessageBuilderLinq.cs

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,30 +131,64 @@ public static NotificationMessageBuilder CreateMessage(
131131
}
132132

133133
/// <summary>
134-
/// Marks next button to be dismiss button.
134+
/// Marks next button to be dismiss.
135135
/// This button will dismiss the noitification message when clicked.
136136
/// </summary>
137137
/// <param name="builder">The builder.</param>
138138
/// <returns>Returns the notiification message builder.</returns>
139-
public static NotificationMessageBuilder.DismissNotificationMessageButton Dismiss(
139+
public static NotificationMessageBuilder.DismissNotificationMessage Dismiss(
140140
this NotificationMessageBuilder builder)
141141
{
142-
return new NotificationMessageBuilder.DismissNotificationMessageButton(builder);
142+
return new NotificationMessageBuilder.DismissNotificationMessage(builder);
143+
}
144+
145+
/// <summary>
146+
/// Dismisses the notification message after specified time.
147+
/// </summary>
148+
/// <param name="dismiss">The dismiss.</param>
149+
/// <param name="delayMilliseconds">The delay in milliseconds.</param>
150+
/// <param name="callback">The callback.</param>
151+
/// <returns>Returns the notification message builder.</returns>
152+
public static NotificationMessageBuilder WithDelay(
153+
this NotificationMessageBuilder.DismissNotificationMessage dismiss,
154+
int delayMilliseconds,
155+
Action<INotificationMessage> callback = null)
156+
{
157+
dismiss.Builder.Delay(delayMilliseconds, dismiss.Builder.DismissBefore(callback));
158+
159+
return dismiss.Builder;
160+
}
161+
162+
/// <summary>
163+
/// Withes the delay.
164+
/// </summary>
165+
/// <param name="dismiss">The dismiss.</param>
166+
/// <param name="delay">The delay.</param>
167+
/// <param name="callback">The callback.</param>
168+
/// <returns>Returns the notification message builder.</returns>
169+
public static NotificationMessageBuilder WithDelay(
170+
this NotificationMessageBuilder.DismissNotificationMessage dismiss,
171+
TimeSpan delay,
172+
Action<INotificationMessage> callback = null)
173+
{
174+
dismiss.Builder.Delay(delay, dismiss.Builder.DismissBefore(callback));
175+
176+
return dismiss.Builder;
143177
}
144178

145179
/// <summary>
146180
/// Adds the button to the notification message.
147181
/// </summary>
148-
/// <param name="dismissButton">The dismiss button.</param>
182+
/// <param name="dismiss">The dismiss.</param>
149183
/// <param name="content">The content.</param>
150184
/// <param name="callback">The callback.</param>
151185
/// <returns>Returns the notification message builder.</returns>
152186
public static NotificationMessageBuilder WithButton(
153-
this NotificationMessageBuilder.DismissNotificationMessageButton dismissButton,
187+
this NotificationMessageBuilder.DismissNotificationMessage dismiss,
154188
object content,
155189
Action<INotificationMessageButton> callback)
156190
{
157-
return dismissButton.Builder.WithButton(content, dismissButton.Builder.DismissBefore(callback));
191+
return dismiss.Builder.WithButton(content, dismiss.Builder.DismissBefore(callback));
158192
}
159193

160194
/// <summary>
@@ -178,6 +212,26 @@ public static NotificationMessageBuilder WithButton(
178212
return builder;
179213
}
180214

215+
/// <summary>
216+
/// Attaches the dismiss action before callback action.
217+
/// </summary>
218+
/// <param name="builder">The builder.</param>
219+
/// <param name="callback">The callback.</param>
220+
/// <returns>
221+
/// Returns the action that will call manager dismiss for notification
222+
/// message builder when called and then call the callback action.
223+
/// </returns>
224+
private static Action<INotificationMessage> DismissBefore(
225+
this NotificationMessageBuilder builder,
226+
Action<INotificationMessage> callback)
227+
{
228+
return call =>
229+
{
230+
builder.Manager.Dismiss(builder.Message);
231+
callback?.Invoke(builder.Message);
232+
};
233+
}
234+
181235
/// <summary>
182236
/// Attached the dismiss action before callback action.
183237
/// </summary>

Enterwell.Clients.Wpf.Notifications/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Enterwell d.o.o.")]
1212
[assembly: AssemblyProduct("Enterwell.Clients.Wpf.Notifications")]
13-
[assembly: AssemblyCopyright("Copyright © Enterwell d.o.o. 2017")]
13+
[assembly: AssemblyCopyright("Copyright © Enterwell d.o.o. 2017-2018")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -49,5 +49,5 @@
4949
// You can specify all the values or you can default the Build and Revision Numbers
5050
// by using the '*' as shown below:
5151
// [assembly: AssemblyVersion("1.0.*")]
52-
[assembly: AssemblyVersion("1.0.0.0")]
53-
[assembly: AssemblyFileVersion("1.0.0.0")]
52+
[assembly: AssemblyVersion("1.1.0.0")]
53+
[assembly: AssemblyFileVersion("1.1.0.0")]

0 commit comments

Comments
 (0)