Skip to content

Commit

Permalink
Merge pull request #6 from Enterwell/f.dismiss-delayed
Browse files Browse the repository at this point in the history
Implemented delayed dismiss
  • Loading branch information
AleksandarDev authored Apr 3, 2018
2 parents 2da6456 + 5c96149 commit 0d34930
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 12 deletions.
14 changes: 14 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


## [1.1.0] - 2018-04-03
### Added
- Support for delayed dismiss `WithDelay` extension method for LINQ builder.

## [1.0.0] - 2017-03-08
### Added
- Initial release.
10 changes: 10 additions & 0 deletions Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@
Content="Error message"
Style="{StaticResource NotificationMessageButtonStyle}" />

<Button
Margin="8"
Padding="12,8"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="#1751C3"
Click="ButtonBaseInfoDelayOnClick"
Content="Info message with delayed dismiss (5s)"
Style="{StaticResource NotificationMessageButtonStyle}" />

</StackPanel>
</Grid>
</controls1:MetroWindow>
Expand Down
14 changes: 14 additions & 0 deletions Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ private void ButtonBaseInfoOnClick(object sender, RoutedEventArgs e)
.Queue();
}

private void ButtonBaseInfoDelayOnClick(object sender, RoutedEventArgs e)
{
this.Manager
.CreateMessage()
.Accent("#1751C3")
.Background("#333")
.HasBadge("Info")
.HasMessage("Update will be installed on next application restart. This message will be dismissed after 5 seconds.")
.Dismiss().WithButton("Update now", button => { })
.Dismiss().WithButton("Release notes", button => { })
.Dismiss().WithDelay(TimeSpan.FromSeconds(5))
.Queue();
}

public INotificationMessageManager Manager { get; } = new NotificationMessageManager();
}
}
4 changes: 4 additions & 0 deletions Enterwell.Clients.Wpf.Notifications.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enterwell.Clients.Wpf.Notif
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3AF6FCB5-2016-41CA-9DBD-5C628B3509AE}"
ProjectSection(SolutionItems) = preProject
Changelog.md = Changelog.md
Readme.md = Readme.md
EndProjectSection
EndProject
Expand All @@ -30,4 +31,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {007773A2-8852-4770-8634-FC68BA83ACE6}
EndGlobalSection
EndGlobal
28 changes: 25 additions & 3 deletions Enterwell.Clients.Wpf.Notifications/NotificationMessageBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using System.Windows.Media;

namespace Enterwell.Clients.Wpf.Notifications
Expand Down Expand Up @@ -111,18 +112,39 @@ public INotificationMessage Queue()
return this.Message;
}

/// <summary>
/// Executes the action after specified delay time.
/// </summary>
/// <param name="delayMilliseconds">The delay in milliseconds.</param>
/// <param name="action">The action.</param>
public void Delay(int delayMilliseconds, Action<INotificationMessage> action)
{
this.Delay(TimeSpan.FromMilliseconds(delayMilliseconds), action);
}

/// <summary>
/// Executes the action after specified delay time.
/// </summary>
/// <param name="delay">The delay.</param>
/// <param name="action">The action.</param>
public void Delay(TimeSpan delay, Action<INotificationMessage> action)
{
Task.Delay(delay).ContinueWith(
context => action(this.Message),
TaskScheduler.FromCurrentSynchronizationContext());
}

/// <summary>
/// The notification message button that is required to dismiss the notification.
/// </summary>
public class DismissNotificationMessageButton
public class DismissNotificationMessage
{
/// <summary>
/// Initializes a new instance of the <see cref="DismissNotificationMessageButton"/> class.
/// Initializes a new instance of the <see cref="DismissNotificationMessage"/> class.
/// </summary>
/// <param name="builder">The builder.</param>
/// <exception cref="ArgumentNullException">builder</exception>
public DismissNotificationMessageButton(NotificationMessageBuilder builder)
public DismissNotificationMessage(NotificationMessageBuilder builder)
{
this.Builder = builder ?? throw new ArgumentNullException(nameof(builder));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,64 @@ public static NotificationMessageBuilder CreateMessage(
}

/// <summary>
/// Marks next button to be dismiss button.
/// Marks next button to be dismiss.
/// This button will dismiss the noitification message when clicked.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns>Returns the notiification message builder.</returns>
public static NotificationMessageBuilder.DismissNotificationMessageButton Dismiss(
public static NotificationMessageBuilder.DismissNotificationMessage Dismiss(
this NotificationMessageBuilder builder)
{
return new NotificationMessageBuilder.DismissNotificationMessageButton(builder);
return new NotificationMessageBuilder.DismissNotificationMessage(builder);
}

/// <summary>
/// Dismisses the notification message after specified time.
/// </summary>
/// <param name="dismiss">The dismiss.</param>
/// <param name="delayMilliseconds">The delay in milliseconds.</param>
/// <param name="callback">The callback.</param>
/// <returns>Returns the notification message builder.</returns>
public static NotificationMessageBuilder WithDelay(
this NotificationMessageBuilder.DismissNotificationMessage dismiss,
int delayMilliseconds,
Action<INotificationMessage> callback = null)
{
dismiss.Builder.Delay(delayMilliseconds, dismiss.Builder.DismissBefore(callback));

return dismiss.Builder;
}

/// <summary>
/// Withes the delay.
/// </summary>
/// <param name="dismiss">The dismiss.</param>
/// <param name="delay">The delay.</param>
/// <param name="callback">The callback.</param>
/// <returns>Returns the notification message builder.</returns>
public static NotificationMessageBuilder WithDelay(
this NotificationMessageBuilder.DismissNotificationMessage dismiss,
TimeSpan delay,
Action<INotificationMessage> callback = null)
{
dismiss.Builder.Delay(delay, dismiss.Builder.DismissBefore(callback));

return dismiss.Builder;
}

/// <summary>
/// Adds the button to the notification message.
/// </summary>
/// <param name="dismissButton">The dismiss button.</param>
/// <param name="dismiss">The dismiss.</param>
/// <param name="content">The content.</param>
/// <param name="callback">The callback.</param>
/// <returns>Returns the notification message builder.</returns>
public static NotificationMessageBuilder WithButton(
this NotificationMessageBuilder.DismissNotificationMessageButton dismissButton,
this NotificationMessageBuilder.DismissNotificationMessage dismiss,
object content,
Action<INotificationMessageButton> callback)
{
return dismissButton.Builder.WithButton(content, dismissButton.Builder.DismissBefore(callback));
return dismiss.Builder.WithButton(content, dismiss.Builder.DismissBefore(callback));
}

/// <summary>
Expand All @@ -178,6 +212,26 @@ public static NotificationMessageBuilder WithButton(
return builder;
}

/// <summary>
/// Attaches the dismiss action before callback action.
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="callback">The callback.</param>
/// <returns>
/// Returns the action that will call manager dismiss for notification
/// message builder when called and then call the callback action.
/// </returns>
private static Action<INotificationMessage> DismissBefore(
this NotificationMessageBuilder builder,
Action<INotificationMessage> callback)
{
return call =>
{
builder.Manager.Dismiss(builder.Message);
callback?.Invoke(builder.Message);
};
}

/// <summary>
/// Attached the dismiss action before callback action.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Enterwell d.o.o.")]
[assembly: AssemblyProduct("Enterwell.Clients.Wpf.Notifications")]
[assembly: AssemblyCopyright("Copyright © Enterwell d.o.o. 2017")]
[assembly: AssemblyCopyright("Copyright © Enterwell d.o.o. 2017-2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

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

0 comments on commit 0d34930

Please sign in to comment.