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
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user