gagsafafsd

This commit is contained in:
Royce551 2022-04-21 14:32:45 -05:00
parent 630ec1c72a
commit e0a52c9279
7 changed files with 236 additions and 19 deletions

View file

@ -0,0 +1,65 @@
using Avalonia.Controls;
using FRESHMusicPlayer.Properties;
using FRESHMusicPlayer.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FRESHMusicPlayer.Controls
{
public class OpenFileDialogEx
{
public FileDialogFilter[] Filters { get; init; }
public bool AllowMultiple { get; init; }
public string WindowTitle { get; init; }
public string AcceptButtonLabel { get; init; }
public bool IncludeOtherOption { get; init; }
public async Task<string[]> ShowAsync(Window window)
{
if (await FreedesktopPortal.IsPortalAvailable()) // FreeDesktopPortal allows us to display a more appropiate file
{ // selector for the user's DE on Linux rather than always using the GTK
var dialogProperties = new Dictionary<string, object>() // one
{
{ "multiple", AllowMultiple },
{ "accept_label", AcceptButtonLabel ?? Resources.OK },
};
// pain
List<(string, (int, string)[])> nativeFilters = new();
foreach (var filter in Filters)
{
var nativeExtensions = new List<(int, string)>();
foreach (var extension in filter.Extensions)
{
nativeExtensions.Add(new(0, $"*.{extension}"));
}
if (IncludeOtherOption) nativeExtensions.Add(new(0, "*"));
nativeFilters.Add((filter.Name, nativeExtensions.ToArray()));
}
dialogProperties.Add("filters", nativeFilters.ToArray());
return await FreedesktopPortal.OpenFiles(WindowTitle, dialogProperties);
}
else
{
var dialog = new OpenFileDialog()
{
Filters = Filters.ToList(),
AllowMultiple = AllowMultiple,
Title = WindowTitle
};
if (IncludeOtherOption)
dialog.Filters.Add(new() { Name = Resources.FileFilter_Other, Extensions = new() { "*" } });
return await dialog.ShowAsync(window);
}
}
}
}

View file

@ -36,23 +36,14 @@
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.13" />
<PackageReference Include="Avalonia.Svg.Skia" Version="0.10.10" />
<PackageReference Include="DiscordRichPresence" Version="1.0.150" />
<PackageReference Include="FRESHMusicPlayer.Core" Version="4.0.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
<PackageReference Include="Tmds.DBus" Version="0.9.1" />
<PackageReference Include="z440.atl.core" Version="3.19.0" />
<PackageReference Include="LiteDB" Version="5.0.9" />
<PackageReference Include="System.Composition" Version="1.4.1" />
<PackageReference Include="NAudio" Version="1.10.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="SIADL.Avalonia">
<HintPath>Dependencies\SIADL.Avalonia.dll</HintPath>
</Reference>
<Reference Include="FRESHMusicPlayer.Core">
<HintPath>..\..\..\freshmusicplayer-core\FRESHMusicPlayer.Player\FRESHMusicPlayer.Player\bin\Release\netstandard2.0\FRESHMusicPlayer.Core.dll</HintPath>
</Reference>
<Reference Include="FRESHMusicPlayer.Core">
<HintPath>..\..\..\..\..\..\Users\squid\Desktop\freshmusicplayer-core\FRESHMusicPlayer.Player\FmpBassBackend\bin\Release\netstandard2.0\FRESHMusicPlayer.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">

View file

@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ATL.Playlist;
using Avalonia.Controls;
using FRESHMusicPlayer.Controls;
using FRESHMusicPlayer.Handlers.Notifications;
using FRESHMusicPlayer.Properties;
using ReactiveUI;
namespace FRESHMusicPlayer.ViewModels
{
public class ImportTabViewModel : ViewModelBase
{
public MainWindowViewModel Window { get; set; }
private List<string> acceptableFilePaths = "wav;aiff;mp3;wma;3g2;3gp;3gp2;3gpp;asf;wmv;aac;adts;avi;m4a;m4a;m4v;mov;mp4;sami;smi;flac".Split(';').ToList();
public async void BrowseTracksCommand()
{
var dialog = new OpenFileDialogEx()
{
Filters = new[]
{
new FileDialogFilter()
{
Name = Resources.FileFilter_AudioFiles,
Extensions = acceptableFilePaths
}
},
AllowMultiple = true,
WindowTitle = Resources.Import,
AcceptButtonLabel = Resources.Import
};
var files = await dialog.ShowAsync(GetMainWindow());
if (files.Length > 0 && files is not null) await Task.Run(() => Window.Library.Import(files));
}
public async void BrowsePlaylistsCommand()
{
string[] acceptableFiles = { "xspf", "asx", "wvx", "b4s", "m3u", "m3u8", "pls", "smil", "smi", "zpl" };
var dialog = new OpenFileDialogEx()
{
Filters = new[]
{
new FileDialogFilter()
{
Name = Resources.FileFilter_PlaylistFiles,
Extensions = acceptableFiles.ToList()
}
},
WindowTitle = Resources.ImportPlaylistFiles,
AcceptButtonLabel = Resources.ImportPlaylistFiles
};
var files = await dialog.ShowAsync(GetMainWindow());
if (files.Length <= 0 && files is null) return;
var reader = PlaylistIOFactory.GetInstance().GetPlaylistIO(files[0]);
foreach (var s in reader.FilePaths)
{
if (!File.Exists(s))
{
Window.Notifications.Add(new()
{
ContentText = string.Format(Properties.Resources.Notification_FileInPlaylistMissing,
Path.GetFileName(s)),
DisplayAsToast = true,
IsImportant = true,
Type = NotificationType.Failure
});
continue;
}
}
Window.Player.Queue.Add(reader.FilePaths.ToArray());
await Task.Run(() => Window.Library.Import(reader.FilePaths.ToArray()));
await Window.Player.PlayAsync();
}
//public void BrowseFoldersCommand()
//{
//}
private string filePath;
public string FilePath
{
get => filePath;
set => this.RaiseAndSetIfChanged(ref filePath, value);
}
public async void ImportFilePathCommand()
{
if (string.IsNullOrEmpty(FilePath)) return;
Window.Library.Import(FilePath);
await Window.Player.PlayAsync(FilePath);
}
}
}

View file

@ -75,7 +75,7 @@ namespace FRESHMusicPlayer.ViewModels
#if DEBUG // allow multiple instances of FMP in debug (at the expense of stability with heavy library use)
var library = new LiteDatabase($"Filename=\"{Path.Combine(App.DataFolderLocation, "database.fdb2")}\";Connection=shared");
#elif !DEBUG
var library = new LiteDatabase(Path.Combine(App.DataFolderLocation "database.fdb2"));
var library = new LiteDatabase(Path.Combine(App.DataFolderLocation, "database.fdb2"));
#endif
Library = new Library(library);
}
@ -389,13 +389,7 @@ namespace FRESHMusicPlayer.ViewModels
case Tab.Playlists:
return new LibraryTab().SetStuff(this, SelectedTab, null);
case Tab.Import:
return new UserControl
{
Content = new TextBlock
{
Text = "Import Tab"
}
};
return new ImportTab().SetStuff(this);
case Tab.Fullscreen:
return new UserControl
{

View file

@ -0,0 +1,24 @@
<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="using:FRESHMusicPlayer.ViewModels"
xmlns:resx ="clr-namespace:FRESHMusicPlayer.Properties"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="FRESHMusicPlayer.Views.ImportTab">
<UserControl.DataContext>
<vm:ImportTabViewModel/>
</UserControl.DataContext>
<StackPanel Margin="15" Spacing="10">
<TextBlock FontSize="32" FontWeight="Bold" Text="Import"/>
<Button Command="{Binding BrowseTracksCommand}" Content="Browse for tracks"/>
<Button Command="{Binding BrowsePlaylistsCommand}" Content="Browse for playlist files"/>
<Button Command="{Binding BrowseFoldersCommand}" Content="Browse for folders"/>
<WrapPanel Orientation="Horizontal">
<TextBox Watermark="File path or URL" Text="{Binding FilePath}"/>
<Button Margin="10,0,0,0" DockPanel.Dock="Right" Command="{Binding ImportFilePathCommand}" Content="Import"/>
</WrapPanel>
<TextBlock Text="You can also drag and drop to this page."/>
</StackPanel>
</UserControl>

View file

@ -0,0 +1,27 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using FRESHMusicPlayer.ViewModels;
namespace FRESHMusicPlayer.Views
{
public partial class ImportTab : UserControl
{
public ImportTab()
{
InitializeComponent();
}
public ImportTab SetStuff(MainWindowViewModel MainWindow)
{
var viewModel = DataContext as ImportTabViewModel;
viewModel.Window = MainWindow;
return this;
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}

View file

@ -17,7 +17,7 @@
</UserControl.Resources>
<DockPanel>
<ListBox DockPanel.Dock="Left" Background="{DynamicResource SecondaryColor}" Width="{Binding SidebarWidth}" Items="{Binding CategoryItems}" SelectedItem="{Binding SelectedCategory}" VirtualizationMode="Simple">
<ListBox DockPanel.Dock="Left" Background="{DynamicResource SecondaryColor}" Width="{Binding SidebarWidth}" Items="{Binding CategoryItems}" VirtualizationMode="Simple" SelectedItem="{Binding SelectedCategory}">
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Padding" Value="10,1"/>
@ -43,6 +43,20 @@
<ListBox.DataTemplates>
<DataTemplate>
<Border CornerRadius="2" BorderBrush="{DynamicResource ForegroundColor}" Background="{DynamicResource ForegroundColor}" BorderThickness="1">
<Border.Styles>
<Style Selector="Border">
<Style.Animations>
<Animation Duration="0:0:.15">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="0.6"/>
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="1"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</Border.Styles>
<Grid RowDefinitions="1*,Auto" ColumnDefinitions="1*,Auto" Margin="5,0">
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Title}" FontSize="16" TextTrimming="CharacterEllipsis" Margin="0,2,0,0"/>
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" Margin="0,0,0,2">