mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2026-03-17 14:52:57 +00:00
refactor: Removed avalonia code.
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
<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:ui="using:FluentAvalonia.UI.Controls"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:fluent="clr-namespace:FluentIcons.Avalonia.Fluent;assembly=FluentIcons.Avalonia.Fluent"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="ZonyLrcTools.Desktop.Views.MainView">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<Grid Name="TitleBarHost"
|
||||
Background="Transparent"
|
||||
ColumnDefinitions="Auto,Auto,*,Auto,0">
|
||||
<Grid.Styles>
|
||||
<Style Selector="Button.AppBarButton">
|
||||
<Setter Property="Padding" Value="8" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Theme" Value="{StaticResource TransparentButton}" />
|
||||
</Style>
|
||||
</Grid.Styles>
|
||||
|
||||
<Image Width="20" Height="20" Margin="14"
|
||||
Source="/Assets/logo.ico" IsHitTestVisible="False"
|
||||
IsVisible="{Binding !#FrameView.CanGoBack}"
|
||||
RenderOptions.BitmapInterpolationMode="HighQuality" />
|
||||
|
||||
<Button Grid.Column="0" Margin="6"
|
||||
Classes="AppBarButton" Command="{Binding #FrameView.GoBack}"
|
||||
IsEnabled="{Binding #FrameView.CanGoBack}"
|
||||
IsVisible="{Binding #FrameView.CanGoBack}">
|
||||
<Button.Content>
|
||||
<fluent:SymbolIcon Symbol="ArrowLeft" />
|
||||
</Button.Content>
|
||||
<ToolTip.Tip>Back</ToolTip.Tip>
|
||||
</Button>
|
||||
|
||||
<TextBlock Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="12"
|
||||
Text="ZonyLrcToolsX" IsHitTestVisible="False" />
|
||||
|
||||
<StackPanel Grid.Column="3"
|
||||
Orientation="Horizontal" Margin="6" Spacing="6">
|
||||
<Button Name="OpenFolderButton" Classes="AppBarButton">
|
||||
<Button.Content>
|
||||
<fluent:SymbolIcon Symbol="FolderAdd" />
|
||||
</Button.Content>
|
||||
<ToolTip.Tip>扫描文件夹</ToolTip.Tip>
|
||||
</Button>
|
||||
|
||||
<Button Name="DownloadButton" Classes="AppBarButton">
|
||||
<Button.Content>
|
||||
<fluent:SymbolIcon Symbol="ArrowDownload" />
|
||||
</Button.Content>
|
||||
<ToolTip.Tip>下载歌词</ToolTip.Tip>
|
||||
</Button>
|
||||
|
||||
<Button Name="SettingsButton" Classes="AppBarButton">
|
||||
<Button.Content>
|
||||
<fluent:SymbolIcon Symbol="Settings" />
|
||||
</Button.Content>
|
||||
<ToolTip.Tip>软件设置</ToolTip.Tip>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="1" Grid.ColumnSpan="3"
|
||||
Background="{DynamicResource LayerFillColorDefaultBrush}"
|
||||
BorderBrush="{DynamicResource CardStrokeColorDefaultBrush}"
|
||||
BorderThickness="0,1,0,0"
|
||||
CornerRadius="8 8 0 0">
|
||||
<ui:Frame Name="FrameView" />
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,102 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using DynamicData;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZonyLrcTools.Common;
|
||||
using ZonyLrcTools.Common.Lyrics;
|
||||
using ZonyLrcTools.Desktop.Pages;
|
||||
using ZonyLrcTools.Desktop.ViewModels;
|
||||
|
||||
namespace ZonyLrcTools.Desktop.Views;
|
||||
|
||||
public partial class MainView : UserControl
|
||||
{
|
||||
private Window? _window;
|
||||
|
||||
private Frame? _frameView;
|
||||
private Button? _settingsButton;
|
||||
private Button? _openFolderButton;
|
||||
private Button? _downloadButton;
|
||||
|
||||
public MainView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
|
||||
_window = e.Root as Window;
|
||||
|
||||
_frameView = this.FindControl<Frame>("FrameView");
|
||||
_frameView?.Navigate(typeof(HomePage));
|
||||
|
||||
_settingsButton = this.FindControl<Button>("SettingsButton");
|
||||
if (_settingsButton != null) _settingsButton.Click += OnSettingsButtonClick;
|
||||
|
||||
_openFolderButton = this.FindControl<Button>("OpenFolderButton");
|
||||
if (_openFolderButton != null) _openFolderButton.Click += OnOpenFolderButtonClick;
|
||||
_downloadButton = this.FindControl<Button>("DownloadButton");
|
||||
if (_downloadButton != null) _downloadButton.Click += OnDownloadButtonClick;
|
||||
}
|
||||
|
||||
private async void OnDownloadButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var downloader = App.Current.Services.GetRequiredService<ILyricsDownloader>();
|
||||
if (DataContext is HomeViewModel vm)
|
||||
{
|
||||
var needDownloadMusicInfos = vm.Songs
|
||||
.Where(x => x.DownloadStatus == DownloadStatus.NotStarted)
|
||||
.Select(x => x.Info)
|
||||
.ToList();
|
||||
|
||||
vm.DownloadProgress = 0;
|
||||
vm.MaxProgress = needDownloadMusicInfos.Count;
|
||||
|
||||
await downloader.DownloadAsync(needDownloadMusicInfos, callback: info =>
|
||||
{
|
||||
var song = vm.Songs.FirstOrDefault(x => x.Info == info);
|
||||
if (song != null)
|
||||
{
|
||||
song.DownloadStatus = DownloadStatus.Completed;
|
||||
}
|
||||
|
||||
vm.DownloadProgress++;
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnOpenFolderButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var storage = _window?.StorageProvider;
|
||||
var musicInfoLoader = App.Current.Services.GetRequiredService<IMusicInfoLoader>();
|
||||
|
||||
if (storage?.CanOpen == true && DataContext is HomeViewModel vm)
|
||||
{
|
||||
var options = new FolderPickerOpenOptions
|
||||
{
|
||||
SuggestedStartLocation = await storage.TryGetWellKnownFolderAsync(WellKnownFolder.Music)
|
||||
};
|
||||
var folders = await storage.OpenFolderPickerAsync(options);
|
||||
if (folders.Count == 0) return;
|
||||
var folderPath = folders[0].Path.LocalPath;
|
||||
var musicInfos = await musicInfoLoader.LoadAsync(folderPath);
|
||||
|
||||
vm.Songs.Clear();
|
||||
vm.Songs.AddRange(musicInfos.Select(x => new SongInfoViewModel(x!)));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSettingsButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_frameView?.CurrentSourcePageType != typeof(SettingsPage))
|
||||
_frameView?.Navigate(typeof(SettingsPage));
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<Window 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:views="clr-namespace:ZonyLrcTools.Desktop.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="ZonyLrcTools.Desktop.Views.MainWindow"
|
||||
Background="{DynamicResource AcrylicBackgroundFillColorDefaultBrush}"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
Title="ZonyLrcTools.Desktop">
|
||||
|
||||
<Panel>
|
||||
<views:MainView />
|
||||
</Panel>
|
||||
|
||||
</Window>
|
||||
@@ -1,13 +0,0 @@
|
||||
using Avalonia.Controls;
|
||||
using ZonyLrcTools.Desktop.ViewModels;
|
||||
|
||||
namespace ZonyLrcTools.Desktop.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
DataContext = new HomeViewModel();
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user