using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using OwlCore.Extensions;
using StrixMusic.Sdk.Services;
using StrixMusic.Sdk.WinUI.Services.Localization;
using StrixMusic.Shells.ZuneDesktop.Settings.Models;
using Windows.ApplicationModel.Resources;
namespace StrixMusic.Shells.ZuneDesktop.Settings
{
///
/// The settings viewmodel for the Zune Desktop
///
public class ZuneDesktopSettingsViewModel : ObservableObject
{
private readonly Dictionary _displayNameMap;
private readonly Dictionary _zuneBackgroundImages = new Dictionary()
{
{ "None", new ZuneDesktopBackgroundImage() },
{ "AuroraBorealis", new ZuneDesktopBackgroundImage("AuroraBorealis", Windows.UI.Xaml.Media.AlignmentY.Top) },
{ "Bubbles", new ZuneDesktopBackgroundImage("Bubbles") },
{ "Cells", new ZuneDesktopBackgroundImage("Cells", Windows.UI.Xaml.Media.AlignmentY.Center) },
{ "Hero", new ZuneDesktopBackgroundImage("Hero", Windows.UI.Xaml.Media.AlignmentY.Center) },
{ "Meadow", new ZuneDesktopBackgroundImage("Meadow", stretch: Windows.UI.Xaml.Media.Stretch.None) },
{ "Shards", new ZuneDesktopBackgroundImage("Shards", Windows.UI.Xaml.Media.AlignmentY.Top) },
{ "Smooth", new ZuneDesktopBackgroundImage("Smooth") },
{ "Wired", new ZuneDesktopBackgroundImage("Wired", stretch: Windows.UI.Xaml.Media.Stretch.Uniform) },
};
///
/// List of names for the images
///
public IEnumerable ImageNames => _displayNameMap.Keys;
private readonly ZuneDesktopSettings _settings;
private readonly ResourceLoader _localizationService;
private string _selectedBackgroundImage = string.Empty;
///
/// Initializes a new instance of the class.
///
public ZuneDesktopSettingsViewModel()
{
_settings = ZuneShell.Ioc.GetRequiredService();
_localizationService = ResourceLoader.GetForCurrentView("StrixMusic.Shells.ZuneDesktop/ZuneSettings");
_displayNameMap = _zuneBackgroundImages.Keys
.ToDictionary(_localizationService.GetString);
LoadInitialValues().Forget();
}
///
/// Gets or sets if the ZuneShell BackgroundImage is None.
///
public string SelectedBackgroundImage
{
get => _selectedBackgroundImage;
set
{
if (!SetProperty(ref _selectedBackgroundImage, value))
return;
var image = _zuneBackgroundImages[_displayNameMap[value]];
_settings.BackgroundImage = image;
_ = _settings.SaveAsync();
}
}
///
/// Gets initial values from settings and sets the properties
///
///
/// Once general settings are setup, this should be made a virtual method
///
private async Task LoadInitialValues()
{
await _settings.LoadAsync();
string displayName = _localizationService.GetString(_settings.BackgroundImage.Name);
SetProperty(ref _selectedBackgroundImage, displayName);
}
}
}