Added ContextMenu/Flyout animations. Added platform services. Use bitmap cache for all views.
This commit is contained in:
@@ -2,17 +2,11 @@
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
using Harmonia.Core.Engine;
|
||||
using Harmonia.Core.Playlists;
|
||||
using Harmonia.UI.ViewModels;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -21,22 +15,32 @@ namespace Harmonia.UI.Views;
|
||||
public partial class PlaylistView : UserControl
|
||||
{
|
||||
private readonly PlaylistViewModel _viewModel;
|
||||
private readonly IAudioEngine _audioEngine;
|
||||
private readonly ConcurrentDictionary<int, CancellationTokenSource> _imageCancellationTokens = [];
|
||||
|
||||
private IStorageProvider? _storageProvider;
|
||||
|
||||
public PlaylistView()
|
||||
{
|
||||
InitializeComponent();
|
||||
_viewModel = (PlaylistViewModel)DataContext!;
|
||||
|
||||
_audioEngine = App.ServiceProvider.GetRequiredService<IAudioEngine>();
|
||||
_viewModel = (PlaylistViewModel)DataContext!;
|
||||
_viewModel.PropertyChanged += OnViewModelPropertyChanged;
|
||||
}
|
||||
|
||||
private async void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(_viewModel.FilteredPlaylistSongs))
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(SlideInSongs);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SlideInSongs()
|
||||
{
|
||||
await Animations.Animations.SlideFromRight(100, duration: 300).RunAsync(PlaylistListBox);
|
||||
}
|
||||
|
||||
private void OnLoaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
_storageProvider = TopLevel.GetTopLevel(this)?.StorageProvider;
|
||||
//_storageProvider = TopLevel.GetTopLevel(this)?.StorageProvider;
|
||||
}
|
||||
|
||||
private async void ListBox_DoubleTapped(object? sender, TappedEventArgs e)
|
||||
@@ -85,7 +89,7 @@ public partial class PlaylistView : UserControl
|
||||
if (sender is not Image image)
|
||||
return;
|
||||
|
||||
if (image.DataContext is not PlaylistSong playlistSong)
|
||||
if (image.DataContext is not PlaylistSong)
|
||||
return;
|
||||
|
||||
if (image.Source is Bitmap bitmap)
|
||||
@@ -100,49 +104,4 @@ public partial class PlaylistView : UserControl
|
||||
_imageCancellationTokens.TryGetValue(hashCode, out CancellationTokenSource? cancellationTokenSource);
|
||||
cancellationTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
//private async void AddFiles_Click(object? sender, RoutedEventArgs e)
|
||||
//{
|
||||
// if (_storageProvider == null)
|
||||
// return;
|
||||
|
||||
// FilePickerOpenOptions openOptions = new()
|
||||
// {
|
||||
// FileTypeFilter = [GetAudioFileTypes()],
|
||||
// AllowMultiple = true
|
||||
// };
|
||||
|
||||
// IReadOnlyList<IStorageFile> result = await _storageProvider.OpenFilePickerAsync(openOptions);
|
||||
// string[] fileNames = [.. result.Select(file => file.TryGetLocalPath() ?? string.Empty)];
|
||||
|
||||
// CancellationToken cancellationToken = default;
|
||||
// await _viewModel.AddFilesAsync(fileNames, cancellationToken);
|
||||
//}
|
||||
|
||||
//private FilePickerFileType GetAudioFileTypes()
|
||||
//{
|
||||
// return new("Audo Files")
|
||||
// {
|
||||
// Patterns = [.. _audioEngine.SupportedFormats]
|
||||
// };
|
||||
//}
|
||||
|
||||
//private async void AddFolder_Click(object? sender, RoutedEventArgs e)
|
||||
//{
|
||||
// if (_storageProvider == null)
|
||||
// return;
|
||||
|
||||
// FolderPickerOpenOptions options = new()
|
||||
// {
|
||||
// AllowMultiple = true
|
||||
// };
|
||||
|
||||
// IReadOnlyList<IStorageFolder> folders = await _storageProvider.OpenFolderPickerAsync(options);
|
||||
|
||||
// if (folders.Count == 0)
|
||||
// return;
|
||||
|
||||
// CancellationToken cancellationToken = default;
|
||||
// await _viewModel.AddFolderAsync(folders[0].TryGetLocalPath() ?? string.Empty, cancellationToken);
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user