user-notifier
continuous-integration/drone/push Build is passing Details

pull/55/head
Leo TUAILLON 2 years ago
parent d269e2708c
commit 6c61fbe1a4

@ -0,0 +1,4 @@
[*.cs]
# CS0618: Le type ou le membre est obsolète
dotnet_diagnostic.CS0618.severity = silent

@ -10,7 +10,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalServices", "LocalServices\LocalServices.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Services\Services.csproj", "{C976BDD8-710D-4162-8A42-973B634491F9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{C976BDD8-710D-4162-8A42-973B634491F9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6DEA92EF-71CD-4A21-9CC0-67F228E1155D}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

@ -1,4 +1,6 @@
using CommunityToolkit.Maui.Views;
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Views;
using ShoopNCook.Views.Components;
using System;
using System.Collections.Generic;
@ -10,31 +12,37 @@ namespace ShoopNCook
{
internal class UserNotifier
{
private static void Show(NoticePopup popup)
private static async Task Show(string message, string messageType)
{
var page = Shell.Current.CurrentPage;
page.ShowPopup(new Popup
{
Content = popup
});
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
// Vous pouvez configurer la durée et la taille de police ici.
ToastDuration duration = ToastDuration.Short;
double fontSize = 14;
var toast = Toast.Make(message, duration, fontSize);
await toast.Show(cancellationTokenSource.Token);
}
public static void Error(string message)
{
Show(new NoticePopup());
Show(message, "Error");
}
public static void Warn(string message)
{
Show(new NoticePopup());
Show(message, "Warning");
}
public static void Notice(string message)
{
Show(new NoticePopup());
Show(message, "Notice");
}
public static void Success(string message)
{
Show(new NoticePopup());
Show(message, "Success");
}
}
}

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Views.Components.NoticePopup">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
x:Name="MessageLabel"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>

@ -1,9 +1,39 @@
namespace ShoopNCook.Views.Components;
using Microsoft.Maui.Graphics;
public partial class NoticePopup : ContentView
{
public NoticePopup()
{
InitializeComponent();
}
public NoticePopup(string message, string messageType)
{
InitializeComponent();
MessageLabel.Text = message;
switch (messageType)
{
case "Error":
this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Red;
break;
case "Warning":
this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Yellow;
break;
case "Notice":
this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Blue;
break;
case "Success":
this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Green;
break;
}
// Display the toast for 3 seconds
Device.StartTimer(TimeSpan.FromSeconds(3), () =>
{
// Close the toast
// You need to replace this with your actual code to close the toast
this.IsVisible = false;
return false;
});
}
}
Loading…
Cancel
Save