using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using OwlCore.Extensions;
using StrixMusic.Sdk.ViewModels;
using StrixMusic.Shells.Groove.Helper;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace StrixMusic.Shells.Groove.Controls.Pages
{
///
/// A to display a on a page.
///
public partial class GrooveAlbumPage : Control
{
///
/// Initializes a new instance of the class.
///
public GrooveAlbumPage()
{
DefaultStyleKey = typeof(GrooveAlbumPage);
}
///
/// Backing property for .
///
public static readonly DependencyProperty BackgroundColorProperty =
DependencyProperty.Register(nameof(BackgroundColor), typeof(Color?), typeof(GrooveAlbumPage), new PropertyMetadata(null, null));
///
/// Gets or sets the color of the background for the .
///
public Color? BackgroundColor
{
get => (Color)GetValue(BackgroundColorProperty);
set => SetValue(BackgroundColorProperty, value);
}
///
/// Backing property for .
///
public static readonly DependencyProperty AlbumProperty =
DependencyProperty.Register(nameof(Album), typeof(AlbumViewModel), typeof(GrooveAlbumPage), new PropertyMetadata(null, (d, e) => d.Cast().OnAlbumChanged()));
///
/// The album being displayed.
///
public AlbumViewModel? Album
{
get => (AlbumViewModel)GetValue(AlbumProperty);
set => SetValue(AlbumProperty, value);
}
private void OnAlbumChanged()
{
if (!(Album is null))
_ = ProcessAlbumArtColorAsync(Album);
}
private async Task ProcessAlbumArtColorAsync(AlbumViewModel album)
{
// Load images if there aren't images loaded.
await album.InitImageCollectionAsync();
if (album.Images.Count > 0)
BackgroundColor = await Task.Run(() => DynamicColorHelper.GetImageAccentColorAsync(album.Images[0].Uri));
}
}
}