From ca64bea4223086717939a078a818d7ad57f5f37d Mon Sep 17 00:00:00 2001 From: Royce551 Date: Mon, 11 Apr 2022 06:07:44 -0500 Subject: [PATCH] Play/enqueue/delete buttons! --- .../Views/LibraryTab.axaml | 29 ++++++++++++--- .../Views/LibraryTab.axaml.cs | 37 +++++++++++++++++-- .../Views/MainWindow.axaml | 2 - 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml index d887b70..d542f15 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml @@ -4,12 +4,18 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:FRESHMusicPlayer.ViewModels" xmlns:resx ="clr-namespace:FRESHMusicPlayer.Properties" + xmlns:svg="clr-namespace:Avalonia.Svg.Skia;assembly=Avalonia.Svg.Skia" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="500" x:Class="FRESHMusicPlayer.Views.LibraryTab"> - + + + + + + @@ -27,24 +33,35 @@ + + + diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml.cs index cf0d21b..7e42c13 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/LibraryTab.axaml.cs @@ -1,5 +1,7 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Input; +using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using FRESHMusicPlayer.ViewModels; @@ -7,6 +9,8 @@ namespace FRESHMusicPlayer.Views { public partial class LibraryTab : UserControl { + private LibraryTabViewModel ViewModel => DataContext as LibraryTabViewModel; + public LibraryTab() { InitializeComponent(); @@ -14,12 +18,39 @@ namespace FRESHMusicPlayer.Views public LibraryTab SetStuff(MainWindowViewModel mainWindowVm, Tab selectedTab, string initialSearch = null) { - var viewModel = DataContext as LibraryTabViewModel; - viewModel.MainWindowWm = mainWindowVm; - viewModel.Initialize(selectedTab, initialSearch); + ViewModel.MainWindowWm = mainWindowVm; + ViewModel.Initialize(selectedTab, initialSearch); return this; } + private async void OnPlayButtonClick(object sender, RoutedEventArgs e) + { + var cmd = (Button)sender; + if (cmd.DataContext is DatabaseTrack x) + { + ViewModel.MainWindowWm.Player.Queue.Clear(); + await ViewModel.MainWindowWm.Player.PlayAsync(x.Path); + } + } + + private void OnEnqueueButtonClick(object sender, RoutedEventArgs e) + { + var cmd = (Button)sender; + if (cmd.DataContext is DatabaseTrack x) + { + ViewModel.MainWindowWm.Player.Queue.Add(x.Path); + } + } + + private void OnDeleteButtonClick(object sender, RoutedEventArgs e) + { + var cmd = (Button)sender; + if (cmd.DataContext is DatabaseTrack x) + { + ViewModel.MainWindowWm.Library.Remove(x.Path); + } + } + private void InitializeComponent() { AvaloniaXamlLoader.Load(this); diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml index 1c5e600..7f9a9a6 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml @@ -23,8 +23,6 @@ - -