From 9e2e07dcbde645899e639dadd7278c50d1d10644 Mon Sep 17 00:00:00 2001 From: Royce551 Date: Sun, 10 Apr 2022 17:43:55 -0500 Subject: [PATCH] Basic library implementation --- .../ViewModels/LibraryTabViewModel.cs | 104 ++++++++++++++++++ .../ViewModels/MainWindowViewModel.cs | 10 +- .../Views/LibraryTab.axaml | 55 +++++++-- .../Views/LibraryTab.axaml.cs | 9 ++ .../Views/MainWindow.axaml | 10 +- 5 files changed, 168 insertions(+), 20 deletions(-) create mode 100644 FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/LibraryTabViewModel.cs diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/LibraryTabViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/LibraryTabViewModel.cs new file mode 100644 index 0000000..719ea05 --- /dev/null +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/LibraryTabViewModel.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using FRESHMusicPlayer.Properties; +using ReactiveUI; + +namespace FRESHMusicPlayer.ViewModels +{ + public class LibraryTabViewModel : ViewModelBase + { + public MainWindowViewModel MainWindowWm { get; set; } + + public void Initialize(Tab selectedTab, string initialSearch = null) + { + // TODO: library changed event handling + LoadLibrary(selectedTab); + if (initialSearch != null) + { + Thread.Sleep(10); + SelectedCategory = initialSearch; + } + } + + private string contentInfo; + public string ContentInfo + { + get => contentInfo; + set => this.RaiseAndSetIfChanged(ref contentInfo, value); + } + + private int sidebarWidth = 222; + public int SidebarWidth + { + get => sidebarWidth; + set + { + this.RaiseAndSetIfChanged(ref sidebarWidth, value); + } + } + + public ObservableCollection CategoryItems { get; set; } = new(); + private string selectedCategory; + public string SelectedCategory + { + get => selectedCategory; + set + { + selectedCategory = value; + } + } + + public ObservableCollection ContentItems { get; set; } = new(); + + public async void LoadLibrary(Tab selectedTab) + { + ContentInfo = null; + switch (selectedTab) + { + case Tab.Tracks: + await ShowTracks(); + break; + case Tab.Artists: + await ShowArtists(); + break; + case Tab.Albums: + await ShowAlbums(); + break; + case Tab.Playlists: + await ShowPlaylists(); + break; + } + } + + public async Task ShowTracks() + { + SidebarWidth = 0; + + ContentItems = new ObservableCollection(MainWindowWm.Library.Read()); + this.RaisePropertyChanged(nameof(ContentItems)); + var lengthTimeSpan = TimeSpan.FromSeconds(ContentItems.Sum(x => x.Length)); + var lengthString = lengthTimeSpan.Days != 0 ? lengthTimeSpan.ToString(@"d\:hh\:mm\:ss") : lengthTimeSpan.ToString(@"hh\:mm\:ss"); + ContentInfo = $"{Resources.Tracks}: {ContentItems.Count} ・ {lengthString}"; + } + + public async Task ShowArtists() + { + + } + + public async Task ShowAlbums() + { + + } + + public async Task ShowPlaylists() + { + + } + } +} diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs index b7863a0..cd65fb7 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs @@ -381,13 +381,7 @@ namespace FRESHMusicPlayer.ViewModels switch (SelectedTab) { case Tab.Tracks: - return new UserControl - { - Content = new TextBlock - { - Text = "Tracks Tab" - } - }; + return new LibraryTab().SetStuff(this, SelectedTab, null); case Tab.Artists: return new UserControl { @@ -477,7 +471,7 @@ namespace FRESHMusicPlayer.ViewModels } } - private int auxPaneWidth = 320; + private int auxPaneWidth = 0; public int AuxPaneWidth { get => auxPaneWidth; diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml index 89c7e99..66988b1 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml @@ -1,8 +1,49 @@ - - Welcome to Avalonia! + + + + + + + + + + + + + +