107 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Maui.Core;
using Font = Microsoft.Maui.Font;
namespace gehGassiApp.Helper
{
/// <summary>
/// Hilfsklasse für den Zugriff auf das Resourcedictionary
/// </summary>
public static class ResourceHelper
{
/// <summary>
/// Gibt einen Style aus dem Resourcedictionary zurück
/// </summary>
/// <param name="key">Key des Styles</param>
/// <returns>Style oder null, wenn nicht gefunden</returns>
public static Style GetStyle(string key)
{
var dictionaries = Application.Current?.Resources.MergedDictionaries.ToList();
if (dictionaries != null && dictionaries.Count > 1)
{
var rd = dictionaries![1];
return (Style)rd[key];
//if (rd != null && rd.ContainsKey(key))
// return (Style)rd[key];
}
return null;
}
/// <summary>
/// Gibt eine Farbe aus dem Resourcedictionary zurück
/// </summary>
/// <param name="key">Key der Farbe</param>
/// <returns>Farbe oder weiss wenn nicht gefunden</returns>
public static Color GetColor(string key)
{
var dictionaries = Application.Current?.Resources.MergedDictionaries.ToList();
if (dictionaries != null && dictionaries.Count >= 1)
{
var rd = dictionaries![0];
return (Color)rd[key];
//if (rd != null && rd.ContainsKey(key))
// return (Color)rd[key];
}
return Color.FromArgb("#FFFFFFFF");
}
/// <summary>
/// Gibt die Snackbar-Optionen für eine Fehlermeldung zurück
/// </summary>
/// <returns>Snackbar-Optionen</returns>
public static SnackbarOptions GetSnackbarAlertOptions()
{
var options = new SnackbarOptions()
{
BackgroundColor = ResourceHelper.GetColor("Alert_Red"),
TextColor = ResourceHelper.GetColor("Primary_White"),
ActionButtonTextColor = ResourceHelper.GetColor("Primary_White"),
Font = Font.OfSize("InterMedium", 12, FontWeight.Regular, FontSlant.Default, false),
ActionButtonFont = Font.OfSize("InterSemiBold", 12, FontWeight.Regular, FontSlant.Default, false),
CornerRadius = new CornerRadius(12)
};
return options;
}
/// <summary>
/// Gibt die Snackbar-Optionen für eine Erfolgsmeldung zurück
/// </summary>
/// <returns>Snackbar-Optionen</returns>
public static SnackbarOptions GetSnackbarSuccessOptions()
{
var options = new SnackbarOptions()
{
BackgroundColor = ResourceHelper.GetColor("Accent_Green"),
TextColor = ResourceHelper.GetColor("Primary_White"),
ActionButtonTextColor = ResourceHelper.GetColor("Primary_White"),
Font = Font.OfSize("InterMedium", 12, FontWeight.Regular, FontSlant.Default, false),
ActionButtonFont = Font.OfSize("InterSemiBold", 12, FontWeight.Regular, FontSlant.Default, false),
CornerRadius = new CornerRadius(12)
};
return options;
}
/// <summary>
/// Gibt die Snackbar-Optionen für eine Infomeldung zurück
/// </summary>
/// <returns>Snackbar-Optionen</returns>
public static SnackbarOptions GetSnackbarInfoOptions()
{
var options = new SnackbarOptions()
{
BackgroundColor = ResourceHelper.GetColor("Primary_LightBlue"),
TextColor = ResourceHelper.GetColor("Primary_DarkBlue"),
ActionButtonTextColor = ResourceHelper.GetColor("Primary_DarkBlue"),
Font = Font.OfSize("InterMedium", 12, FontWeight.Regular, FontSlant.Default, false),
ActionButtonFont = Font.OfSize("InterSemiBold", 12, FontWeight.Regular, FontSlant.Default, false),
CornerRadius = new CornerRadius(12)
};
return options;
}
}
}