Added playing song info view and view model.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<views:PlayingSongInfo Grid.Row="0"></views:PlayingSongInfo>
|
||||
<views:PlaybackBar Grid.Row="1"></views:PlaybackBar>
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -1,11 +1,61 @@
|
||||
using Avalonia.Controls;
|
||||
using Harmonia.Core.Engine;
|
||||
using Harmonia.Core.Models;
|
||||
using Harmonia.Core.Player;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace Harmonia.UI.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
private readonly IAudioPlayer _audioPlayer;
|
||||
|
||||
private const string ApplicationTitle = "Harmonia";
|
||||
|
||||
public MainWindow(IAudioPlayer audioPlayer)
|
||||
{
|
||||
_audioPlayer = audioPlayer;
|
||||
_audioPlayer.PropertyChanged += OnAudioPlayerPropertyChanged;
|
||||
|
||||
Title = ApplicationTitle;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnAudioPlayerPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(_audioPlayer.State):
|
||||
Title = GetUpdatedAppTitle();
|
||||
//PropertyChanged(nameof(Title));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetUpdatedAppTitle()
|
||||
{
|
||||
return _audioPlayer.State switch
|
||||
{
|
||||
AudioPlaybackState.Stopped => ApplicationTitle,
|
||||
_ => $"{GetSongArtistsAndTitle()} - {ApplicationTitle}"
|
||||
};
|
||||
}
|
||||
|
||||
private string GetSongArtistsAndTitle()
|
||||
{
|
||||
if (_audioPlayer.PlayingSong == null)
|
||||
return string.Empty;
|
||||
|
||||
Song song = _audioPlayer.PlayingSong.Song;
|
||||
|
||||
string[] values =
|
||||
[
|
||||
string.Join(" / ", song.Artists ?? song.AlbumArtists),
|
||||
song.Title ?? song.ShortFileName
|
||||
];
|
||||
|
||||
return string.Join(" - ", values.Where(value => string.IsNullOrWhiteSpace(value) == false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public partial class PlaybackBar : UserControl
|
||||
_viewModel = (PlaybackBarViewModel)DataContext!;
|
||||
}
|
||||
|
||||
private void Slider_Loaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
private void Slider_Loaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Slider slider)
|
||||
return;
|
||||
|
||||
27
Harmonia.UI/Views/PlayingSongInfo.axaml
Normal file
27
Harmonia.UI/Views/PlayingSongInfo.axaml
Normal file
@@ -0,0 +1,27 @@
|
||||
<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="clr-namespace:Harmonia.UI.ViewModels"
|
||||
xmlns:converter="clr-namespace:Harmonia.UI.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
DataContext="{x:Static vm:ViewModelLocator.PlayingSongInfoViewModel}"
|
||||
x:Class="Harmonia.UI.Views.PlayingSongInfo"
|
||||
x:DataType="vm:PlayingSongInfoViewModel">
|
||||
<Grid>
|
||||
<Image Source="{Binding SongImageSource, Mode=OneWay}" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Image.Effect>
|
||||
<BlurEffect Radius="20" />
|
||||
</Image.Effect>
|
||||
<Image.RenderTransform>
|
||||
<ScaleTransform ScaleX="1.05" ScaleY="1.05" />
|
||||
</Image.RenderTransform>
|
||||
</Image>
|
||||
<Canvas Background="#99000000"></Canvas>
|
||||
<Image Source="{Binding SongImageSource}" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20">
|
||||
<Image.Effect>
|
||||
<DropShadowEffect BlurRadius="10" Opacity=".4" OffsetX="3" OffsetY="3" />
|
||||
</Image.Effect>
|
||||
</Image>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
17
Harmonia.UI/Views/PlayingSongInfo.axaml.cs
Normal file
17
Harmonia.UI/Views/PlayingSongInfo.axaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Harmonia.UI.ViewModels;
|
||||
|
||||
namespace Harmonia.UI.Views;
|
||||
|
||||
public partial class PlayingSongInfo : UserControl
|
||||
{
|
||||
private readonly PlayingSongInfoViewModel _viewModel;
|
||||
|
||||
public PlayingSongInfo()
|
||||
{
|
||||
InitializeComponent();
|
||||
_viewModel = (PlayingSongInfoViewModel)DataContext!;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user