Merge remote-tracking branch 'origin/main' into j.lechner/openverse
# Conflicts: # src/Radiosender/Views/MainWindow.xaml
This commit is contained in:
commit
d3f9da32b8
14 files changed
+729
No files matched your search
@@ -22,6 +22,9 @@
|
||||
<ui:NavigationViewItem Content="Home"
|
||||
Icon="{ui:SymbolIcon Home24}"
|
||||
TargetPageType="{x:Type pages:HomePage}" />
|
||||
<ui:NavigationViewItem Content="Library"
|
||||
Icon="{ui:SymbolIcon MusicNote224}"
|
||||
TargetPageType="{x:Type pages:LibraryPage}" />
|
||||
<ui:NavigationViewItem Content="Openverse"
|
||||
Icon="{ui:SymbolIcon Search24}"
|
||||
TargetPageType="{x:Type pages:OpenversePage}" />
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<Page x:Class="Radiosender.Views.Pages.LibraryPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Library"
|
||||
Loaded="OnLoaded">
|
||||
<Grid Margin="24">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ui:TextBlock Grid.Row="0" FontTypography="Title" Text="Library" />
|
||||
|
||||
<DockPanel Grid.Row="1" Margin="0,16,0,12" LastChildFill="True">
|
||||
<ui:Button x:Name="DeleteButton"
|
||||
DockPanel.Dock="Right"
|
||||
Margin="8,0,0,0"
|
||||
Content="Delete"
|
||||
Icon="{ui:SymbolIcon Delete24}"
|
||||
IsEnabled="False"
|
||||
Click="OnDelete" />
|
||||
<ui:Button x:Name="EditButton"
|
||||
DockPanel.Dock="Right"
|
||||
Margin="8,0,0,0"
|
||||
Content="Edit"
|
||||
Icon="{ui:SymbolIcon Edit24}"
|
||||
IsEnabled="False"
|
||||
Click="OnEdit" />
|
||||
<ui:TextBox x:Name="SearchBox"
|
||||
AutomationProperties.Name="Search songs"
|
||||
PlaceholderText="Search title or artist"
|
||||
Icon="{ui:SymbolIcon Search24}"
|
||||
TextChanged="OnSearchChanged" />
|
||||
</DockPanel>
|
||||
|
||||
<ui:ListView x:Name="SongList"
|
||||
Grid.Row="2"
|
||||
SelectionMode="Single"
|
||||
AutomationProperties.Name="Songs"
|
||||
SelectionChanged="OnSelectionChanged"
|
||||
MouseDoubleClick="OnEdit">
|
||||
<ui:ListView.View>
|
||||
<ui:GridView>
|
||||
<ui:GridViewColumn Width="260" Header="Title" DisplayMemberBinding="{Binding Title}" />
|
||||
<ui:GridViewColumn Width="200" Header="Artist" DisplayMemberBinding="{Binding Artist}" />
|
||||
<ui:GridViewColumn Width="80" Header="Duration">
|
||||
<ui:GridViewColumn.DisplayMemberBinding>
|
||||
<Binding Path="Duration" StringFormat="m\:ss" />
|
||||
</ui:GridViewColumn.DisplayMemberBinding>
|
||||
</ui:GridViewColumn>
|
||||
<ui:GridViewColumn Width="140" Header="License" DisplayMemberBinding="{Binding License}" />
|
||||
<ui:GridViewColumn Width="220" Header="Attribution" DisplayMemberBinding="{Binding Attribution}" />
|
||||
</ui:GridView>
|
||||
</ui:ListView.View>
|
||||
</ui:ListView>
|
||||
|
||||
<ui:TextBlock x:Name="EmptyText"
|
||||
Grid.Row="2"
|
||||
Margin="0,48,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Text="No songs found."
|
||||
Visibility="Collapsed" />
|
||||
</Grid>
|
||||
</Page>
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Radiosender.Controllers;
|
||||
using Radiosender.Models;
|
||||
using Wpf.Ui.Controls;
|
||||
using MessageBox = Wpf.Ui.Controls.MessageBox;
|
||||
|
||||
namespace Radiosender.Views.Pages;
|
||||
|
||||
public partial class LibraryPage : Page
|
||||
{
|
||||
private readonly LibraryController _controller = new(App.Songs);
|
||||
|
||||
public LibraryPage() => InitializeComponent();
|
||||
|
||||
private Song? Selected => SongList.SelectedItem as Song;
|
||||
|
||||
// Loaded fires on every navigation to the page, so the list is reloaded from the database each time.
|
||||
private void OnLoaded(object sender, RoutedEventArgs e) => Refresh();
|
||||
|
||||
private void OnSearchChanged(object sender, TextChangedEventArgs e) => Refresh();
|
||||
|
||||
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) =>
|
||||
EditButton.IsEnabled = DeleteButton.IsEnabled = Selected is not null;
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
var songs = _controller.Search(SearchBox.Text);
|
||||
SongList.ItemsSource = songs;
|
||||
EmptyText.Visibility = songs.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void OnEdit(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (Selected is not { } song)
|
||||
return;
|
||||
|
||||
var dialog = new SongEditWindow(song) { Owner = Window.GetWindow(this) };
|
||||
if (dialog.ShowDialog() == true)
|
||||
_controller.Update(song.Id, dialog.SongTitle, dialog.Artist, dialog.License, dialog.Attribution);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private async void OnDelete(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (Selected is not { } song)
|
||||
return;
|
||||
|
||||
var result = await new MessageBox
|
||||
{
|
||||
Title = "Delete song",
|
||||
Content = $"Delete \"{song.Title}\" by {song.Artist} from the library?",
|
||||
PrimaryButtonText = "Delete",
|
||||
CloseButtonText = "Cancel",
|
||||
}.ShowDialogAsync();
|
||||
|
||||
if (result != Wpf.Ui.Controls.MessageBoxResult.Primary)
|
||||
return;
|
||||
|
||||
_controller.Delete(song.Id);
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<ui:FluentWindow x:Class="Radiosender.Views.SongEditWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Edit song"
|
||||
Width="460" SizeToContent="Height"
|
||||
ResizeMode="NoResize"
|
||||
ShowInTaskbar="False"
|
||||
ExtendsContentIntoTitleBar="True"
|
||||
WindowBackdropType="Mica"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
FocusManager.FocusedElement="{Binding ElementName=TitleBox}">
|
||||
<StackPanel>
|
||||
<ui:TitleBar Title="Edit song" ShowMinimize="False" ShowMaximize="False" />
|
||||
|
||||
<StackPanel Margin="24,8,24,24">
|
||||
<Label Content="_Title" Target="{Binding ElementName=TitleBox}" />
|
||||
<ui:TextBox x:Name="TitleBox" Margin="0,0,0,12" />
|
||||
|
||||
<Label Content="_Artist" Target="{Binding ElementName=ArtistBox}" />
|
||||
<ui:TextBox x:Name="ArtistBox" Margin="0,0,0,12" />
|
||||
|
||||
<Label Content="_License" Target="{Binding ElementName=LicenseBox}" />
|
||||
<ui:TextBox x:Name="LicenseBox" Margin="0,0,0,12" PlaceholderText="Optional, e.g. CC BY 4.0" />
|
||||
|
||||
<Label Content="Attri_bution" Target="{Binding ElementName=AttributionBox}" />
|
||||
<ui:TextBox x:Name="AttributionBox" PlaceholderText="Optional" />
|
||||
|
||||
<TextBlock x:Name="ErrorText"
|
||||
Margin="0,12,0,0"
|
||||
Foreground="{DynamicResource SystemFillColorCriticalBrush}"
|
||||
Text="Title and artist are required."
|
||||
Visibility="Collapsed" />
|
||||
|
||||
<StackPanel Margin="0,24,0,0" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<ui:Button Content="Save" Appearance="Primary" IsDefault="True" MinWidth="90" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" Content="Cancel" IsCancel="True" MinWidth="90" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ui:FluentWindow>
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Windows;
|
||||
using Radiosender.Models;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
namespace Radiosender.Views;
|
||||
|
||||
/// <summary>Dialog for the editable song metadata. Only collects input; saving is done by the caller.</summary>
|
||||
public partial class SongEditWindow : FluentWindow
|
||||
{
|
||||
public SongEditWindow(Song song)
|
||||
{
|
||||
InitializeComponent();
|
||||
TitleBox.Text = song.Title;
|
||||
ArtistBox.Text = song.Artist;
|
||||
LicenseBox.Text = song.License;
|
||||
AttributionBox.Text = song.Attribution;
|
||||
}
|
||||
|
||||
public string SongTitle => TitleBox.Text;
|
||||
public string Artist => ArtistBox.Text;
|
||||
public string License => LicenseBox.Text;
|
||||
public string Attribution => AttributionBox.Text;
|
||||
|
||||
private void OnSave(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(SongTitle) || string.IsNullOrWhiteSpace(Artist))
|
||||
{
|
||||
ErrorText.Visibility = Visibility.Visible;
|
||||
return;
|
||||
}
|
||||
|
||||
DialogResult = true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user