You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
3.0 KiB

using AMC.Model.Models;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace AMC.ViewModel.ViewModels
{
public class AlbumViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
private readonly Album album = new();
public int Id => album.Id;
public string Title => album.Title;
public string Artist => album.Artist;
public string CoverImage => album.CoverImage;
public (string Genre, int Year) Details => (album.Genre, album.Year);
public DateTime ReleaseDate => album.ReleaseDate;
public (int SongCount, int TotalDuration) SongsInfo
=> (album.Songs.Count, album.Songs.Sum(song => song.Duration) / 60);
public (int CopyrightYear, string ProducerBlurb) CopyrightInfo
=> (album.CopyrightYear, album.ProducerBlurb);
public ReadOnlyObservableCollection<SongViewModel> Songs => new(songs);
private readonly ObservableCollection<SongViewModel> songs;
public AlbumViewModel(Album? album)
{
// Mocked data for testing
this.album = album ?? new Album
{
Id = 1,
Title = "Test Album",
Artist = "Test Artist",
CoverImage = "macroblank.png",
Genre = "Test genre",
Year = 1970,
ReleaseDate = new DateTime(1970, 01, 01),
CopyrightYear = 1996,
ProducerBlurb = "Test Records Ltd",
Songs = new List<Song>
{
new Song { Id = 1, Title = "Test Song 1", Duration = 210 },
new Song { Id = 2, Title = "Test Song 2", Duration = 260 },
new Song { Id = 3, Title = "Test Soooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong 3", Duration = 817 },
new Song { Id = 4, Title = "Test Song 4", Duration = 654 },
new Song { Id = 5, Title = "Test Song 5", Duration = 768 },
new Song { Id = 6, Title = "Test Song 6", Duration = 435 },
new Song { Id = 7, Title = "Test Song 7", Duration = 864 },
new Song { Id = 8, Title = "Test Song 8", Duration = 456 },
new Song { Id = 9, Title = "Test Song 9", Duration = 83 },
new Song { Id = 10, Title = "Test Song 10", Duration = 4533 },
new Song { Id = 11, Title = "Test Song 11", Duration = 785 },
new Song { Id = 12, Title = "Test Song 12", Duration = 712 },
new Song { Id = 13, Title = "Test Song 13", Duration = 523 },
}
};
int index = 1;
foreach (var song in this.album.Songs)
{
song.Index = index++;
}
songs = new ObservableCollection<SongViewModel>(this.album.Songs.Select(song => new SongViewModel(song)));
}
}
}