sharee.bike-App/SharedBusinessLogic/Services/ThemeNS/Theme.cs

47 lines
1.1 KiB
C#
Raw Normal View History

2024-04-09 12:53:23 +02:00
using System;
2022-08-30 15:42:25 +02:00
using System.Collections.Generic;
using Xamarin.Forms;
2024-04-09 12:53:23 +02:00
namespace ShareeBike.Services.ThemeNS
2022-08-30 15:42:25 +02:00
{
2022-09-06 16:08:19 +02:00
/// <summary>
/// Manges themeing functionalty.
2024-04-09 12:53:23 +02:00
/// Objects ResourceDictionary, Themes.ShareeBike, ... need Xamarin.Forms framework to be initialized which might break tests.
2022-09-06 16:08:19 +02:00
/// </summary>
public class Theme : ITheme
{
private ICollection<ResourceDictionary> _MergedDictionaries;
public Theme(ICollection<ResourceDictionary> mergedDictionaries)
{
_MergedDictionaries = mergedDictionaries ?? throw new ArgumentNullException(nameof(mergedDictionaries));
}
/// <summary>
/// Sets active theme.
/// </summary>
/// <param name="themeName">Name of the new active theme.</param>
public void SetActiveTheme(string themeName)
{
if (!Enum.TryParse(themeName, false, out ThemeSet theme))
return;
if (_MergedDictionaries == null)
return;
_MergedDictionaries.Clear();
switch (theme)
{
case ThemeSet.LastenradBayern:
_MergedDictionaries.Add(new Themes.LastenradBayern());
break;
default:
_MergedDictionaries.Add(new Themes.ShareeBike());
break;
}
}
}
2022-08-30 15:42:25 +02:00
}