mirror of
https://github.com/Royce551/FRESHMusicPlayer.git
synced 2025-01-22 10:51:52 -05:00
Basic library implementation
This commit is contained in:
parent
82dd9feb5e
commit
9e2e07dcbd
5 changed files with 168 additions and 20 deletions
|
@ -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<string> CategoryItems { get; set; } = new();
|
||||
private string selectedCategory;
|
||||
public string SelectedCategory
|
||||
{
|
||||
get => selectedCategory;
|
||||
set
|
||||
{
|
||||
selectedCategory = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<DatabaseTrack> 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<DatabaseTrack>(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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -1,8 +1,49 @@
|
|||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="FRESHMusicPlayer.Views.LibraryTab">
|
||||
Welcome to Avalonia!
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:FRESHMusicPlayer.ViewModels"
|
||||
xmlns:resx ="clr-namespace:FRESHMusicPlayer.Properties"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="500"
|
||||
x:Class="FRESHMusicPlayer.Views.LibraryTab">
|
||||
<UserControl.DataContext>
|
||||
<vm:LibraryTabViewModel/>
|
||||
</UserControl.DataContext>
|
||||
|
||||
<DockPanel>
|
||||
<ListBox DockPanel.Dock="Left" Background="{DynamicResource SecondaryColor}" Width="{Binding SidebarWidth}" Items="{Binding CategoryItems}">
|
||||
|
||||
</ListBox>
|
||||
|
||||
<DockPanel DockPanel.Dock="Bottom" LastChildFill="False">
|
||||
<TextBlock Text="{Binding ContentInfo}" Foreground="{DynamicResource SecondaryTextColor}" VerticalAlignment="Center" FontSize="12" Margin="10"/>
|
||||
|
||||
<Button DockPanel.Dock="Right" Command="{Binding PlayAllCommand}" Content="Play All" Margin="10" FontSize="12"/>
|
||||
<Button DockPanel.Dock="Right" Command="{Binding EnqueueAllCommand}" Content="Enqueue All" FontSize="12"/>
|
||||
</DockPanel>
|
||||
|
||||
<ListBox Background="{DynamicResource BackgroundColor}" Items="{Binding ContentItems}" VirtualizationMode="Simple">
|
||||
<ListBox.Styles>
|
||||
<Style Selector="ListBoxItem">
|
||||
<Setter Property="Padding" Value="10,2"/>
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
<Setter Property="IsHitTestVisible" Value="False"/>
|
||||
</Style>
|
||||
</ListBox.Styles>
|
||||
<ListBox.DataTemplates>
|
||||
<DataTemplate>
|
||||
<Border CornerRadius="2" BorderBrush="{DynamicResource ForegroundColor}" Background="{DynamicResource ForegroundColor}" BorderThickness="1">
|
||||
<Grid RowDefinitions="1*,Auto" ColumnDefinitions="1*,Auto" Margin="5,2">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Title}" FontSize="16" TextTrimming="CharacterEllipsis"/>
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Artist}" FontSize="9" Foreground="{DynamicResource SecondaryTextColor}"/>
|
||||
<TextBlock Text="・ " FontSize="9" Foreground="{DynamicResource SecondaryTextColor}"/>
|
||||
<TextBlock Text="{Binding Album}" FontSize="9" Foreground="{DynamicResource SecondaryTextColor}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.DataTemplates>
|
||||
</ListBox>
|
||||
</DockPanel>
|
||||
</UserControl>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using FRESHMusicPlayer.ViewModels;
|
||||
|
||||
namespace FRESHMusicPlayer.Views
|
||||
{
|
||||
|
@ -11,6 +12,14 @@ namespace FRESHMusicPlayer.Views
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
public LibraryTab SetStuff(MainWindowViewModel mainWindowVm, Tab selectedTab, string initialSearch = null)
|
||||
{
|
||||
var viewModel = DataContext as LibraryTabViewModel;
|
||||
viewModel.MainWindowWm = mainWindowVm;
|
||||
viewModel.Initialize(selectedTab, initialSearch);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
|
|
|
@ -187,11 +187,11 @@
|
|||
</Grid>
|
||||
|
||||
<DockPanel DockPanel.Dock="Top" Height="30" LastChildFill="False">
|
||||
<TextBlock x:Name="TracksHeader" Text="Tracks" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="10,0,10,0" Cursor="Hand" PointerPressed="OnTracksPressed" FontWeight="{Binding TracksTabWeight}"/>
|
||||
<TextBlock x:Name="ArtistsHeader" Text="Artists" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,10,0" Cursor="Hand" PointerPressed="OnArtistsPressed" FontWeight="{Binding ArtistsTabWeight}"/>
|
||||
<TextBlock x:Name="AlbumsHeader" Text="Albums" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,10,0" Cursor="Hand" PointerPressed="OnAlbumsPressed" FontWeight="{Binding AlbumsTabWeight}"/>
|
||||
<TextBlock x:Name="PlaylistsHeader" Text="Playlists" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,10,0" Cursor="Hand" PointerPressed="OnPlaylistsPressed" FontWeight="{Binding PlaylistsTabWeight}"/>
|
||||
<TextBlock x:Name="ImportHeader" Text="Import" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,10,0" Cursor="Hand" PointerPressed="OnImportPressed" FontWeight="{Binding ImportTabWeight}"/>
|
||||
<TextBlock x:Name="TracksHeader" Text="Tracks" FontSize="16" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="10,0,15,0" Cursor="Hand" PointerPressed="OnTracksPressed" FontWeight="{Binding TracksTabWeight}"/>
|
||||
<TextBlock x:Name="ArtistsHeader" Text="Artists" FontSize="16" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,15,0" Cursor="Hand" PointerPressed="OnArtistsPressed" FontWeight="{Binding ArtistsTabWeight}"/>
|
||||
<TextBlock x:Name="AlbumsHeader" Text="Albums" FontSize="16" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,15,0" Cursor="Hand" PointerPressed="OnAlbumsPressed" FontWeight="{Binding AlbumsTabWeight}"/>
|
||||
<TextBlock x:Name="PlaylistsHeader" Text="Playlists" FontSize="16" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,15,0" Cursor="Hand" PointerPressed="OnPlaylistsPressed" FontWeight="{Binding PlaylistsTabWeight}"/>
|
||||
<TextBlock x:Name="ImportHeader" Text="Import" FontSize="16" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,15,0" Cursor="Hand" PointerPressed="OnImportPressed" FontWeight="{Binding ImportTabWeight}"/>
|
||||
|
||||
<Button Command="{Binding OpenSettingsCommand}" Margin="0,2,5,2" DockPanel.Dock="Right" ToolTip.Tip="{x:Static resx:Resources.Settings}">
|
||||
<Image Source="{DynamicResource Settings}"/>
|
||||
|
|
Loading…
Reference in a new issue