-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from jibedoubleve/issue/319
(#319) Add icons in toast notifications
- Loading branch information
Showing
7 changed files
with
98 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Lanceur.SharedKernel.Mixins; | ||
|
||
public static class UriMixin | ||
{ | ||
#region Methods | ||
|
||
public static Uri ToUri(this string path, UriKind kind) => new(path, kind); | ||
|
||
public static Uri ToUriAbsolute(this string path) => path.ToUri(UriKind.Absolute); | ||
|
||
public static Uri ToUriRelative(this string path) => path.ToUri(UriKind.Relative); | ||
|
||
#endregion Methods | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,77 @@ | ||
using Microsoft.Toolkit.Uwp.Notifications; | ||
using System.IO; | ||
using System.Reflection; | ||
using Lanceur.SharedKernel.Mixins; | ||
using Microsoft.Toolkit.Uwp.Notifications; | ||
using System.Runtime.CompilerServices; | ||
using System.Windows.Shapes; | ||
using FileLocation = System.IO.Path; | ||
|
||
namespace Lanceur.Ui | ||
namespace Lanceur.Ui; | ||
|
||
public class ToastNotification : INotification | ||
{ | ||
public class ToastNotification : INotification | ||
#region Enums | ||
|
||
private enum Level | ||
{ | ||
#region Methods | ||
Information, | ||
Warning, | ||
Error | ||
}; | ||
|
||
#endregion Enums | ||
|
||
private void Show(string message, [CallerMemberName] string title = null) | ||
#region Methods | ||
|
||
private static void Show(Level level, string message, [CallerMemberName] string title = null) | ||
{ | ||
var uri = level switch | ||
{ | ||
new ToastContentBuilder() | ||
.AddText(title) | ||
.AddText(message) | ||
.Show(); | ||
Level.Information => Icon.Info, | ||
Level.Warning => Icon.Warn, | ||
Level.Error => Icon.Error, | ||
_ => Icon.None | ||
}; | ||
new ToastContentBuilder() | ||
.AddText(title) | ||
.AddText(message) | ||
.AddAppLogoOverride(uri.ToUriRelative(), ToastGenericAppLogoCrop.Circle) | ||
.Show(); | ||
} | ||
|
||
public void Error(string message) => Show(Level.Error, message); | ||
|
||
public void Information(string message) => Show(Level.Information, message); | ||
|
||
public void Warning(string message) => Show(Level.Warning, message); | ||
|
||
#endregion Methods | ||
|
||
#region Classes | ||
|
||
private static class Icon | ||
{ | ||
#region Constructors | ||
|
||
static Icon() | ||
{ | ||
var path = FileLocation.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
Info = FileLocation.Combine(path, @"Assets\IconInfo.png"); | ||
Warn = FileLocation.Combine(path, @"Assets\IconWarn.png"); | ||
Error = FileLocation.Combine(path, @"Assets\IconError.png"); | ||
} | ||
|
||
public void Error(string message) => Show(message); | ||
#endregion Constructors | ||
|
||
public void Information(string message) => Show(message); | ||
#region Properties | ||
|
||
public void Warning(string message) => Show(message); | ||
public static string Error { get; } | ||
public static string Info { get; } | ||
public static string Warn { get; } | ||
public static string None => string.Empty; | ||
|
||
#endregion Methods | ||
} | ||
#endregion Properties | ||
}; | ||
|
||
#endregion Classes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters