Skip to content

Commit

Permalink
Merge pull request #54 from Difegue/dev
Browse files Browse the repository at this point in the history
2.5.0
  • Loading branch information
Difegue authored Sep 11, 2022
2 parents b807f89 + 36bd660 commit eb9549a
Show file tree
Hide file tree
Showing 210 changed files with 2,760 additions and 3,963 deletions.
Binary file modified Screenshots/Screen1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/ScreenXbox.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Sources/Stylophone.Common/Interfaces/INavigationService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Toolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using System;

namespace Stylophone.Common.Interfaces
{
public class CoreNavigationEventArgs : EventArgs { public Type NavigationTarget { get; set; } public object Parameter { get; set; } }

public interface INavigationService
{
Type CurrentPageViewModelType { get; }
Expand Down
44 changes: 35 additions & 9 deletions Sources/Stylophone.Common/Interfaces/INotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,55 @@

namespace Stylophone.Common.Interfaces
{
public class InAppNotificationRequestedEventArgs : EventArgs { public string NotificationText { get; set; } public int NotificationTime { get; set; } }
public class InAppNotification
{
public string NotificationTitle { get; set; }
public string NotificationText { get; set; }
public NotificationType NotificationType { get; set; }
}

public enum NotificationType
{
Info,
Warning,
Error
}

public interface INotificationService
{
void ShowBasicToastNotification(string title, string description);

void ShowInAppNotification(string notification, bool autoHide = true);
void ShowInAppNotification(string text, string description = "", NotificationType type = NotificationType.Info);
void ShowInAppNotification(InAppNotification notification);

void ShowErrorNotification(Exception ex);
}

public abstract class NotificationServiceBase: INotificationService
{
public event EventHandler<InAppNotificationRequestedEventArgs> InAppNotificationRequested;

public void InvokeInAppNotificationRequested(InAppNotificationRequestedEventArgs args)
public void ShowInAppNotification(string text, string description = "", NotificationType type = NotificationType.Info)
{
InAppNotificationRequested?.Invoke(this, args);
var notification = new InAppNotification
{
NotificationTitle = text,
NotificationText = description,
NotificationType = type
};
ShowInAppNotification(notification);
}

public void ShowErrorNotification(Exception ex) => ShowInAppNotification(string.Format(Resources.ErrorGeneric, ex), false);

public void ShowErrorNotification(Exception ex)
{
var notification = new InAppNotification
{
NotificationTitle = string.Format(Resources.ErrorGeneric, ex.Message),
NotificationText = ex.StackTrace,
NotificationType = NotificationType.Error
};
ShowInAppNotification(notification);
}

public abstract void ShowBasicToastNotification(string title, string description);
public abstract void ShowInAppNotification(string notification, bool autoHide = true);
public abstract void ShowInAppNotification(InAppNotification notification);
}
}
22 changes: 15 additions & 7 deletions Sources/Stylophone.Common/Services/AlbumArtService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ColorThiefDotNet;
using Microsoft.Toolkit.Mvvm.DependencyInjection;
using MpcNET.Commands.Database;
using MpcNET.Types;
using SkiaSharp;
Expand All @@ -9,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -26,12 +26,14 @@ public class AlbumArtService
private CancellationTokenSource _queueCanceller;

private IApplicationStorageService _applicationStorageService;
private INotificationService _notificationService;
private MPDConnectionService _mpdService;

public AlbumArtService(MPDConnectionService mpdService, IApplicationStorageService appStorage)
public AlbumArtService(MPDConnectionService mpdService, IApplicationStorageService appStorage, INotificationService notificationService)
{
_mpdService = mpdService;
_applicationStorageService = appStorage;
_notificationService = notificationService;
}

public void Initialize()
Expand Down Expand Up @@ -73,6 +75,7 @@ public void Initialize()
catch (Exception e)
{
Debug.WriteLine("Exception while processing albumart queue: " + e);
_notificationService.ShowErrorNotification(e);
}
}
}).ConfigureAwait(false);
Expand Down Expand Up @@ -189,6 +192,7 @@ private async Task<SKBitmap> GetAlbumBitmap(IMpdFile f, CancellationToken token
catch (Exception e)
{
Debug.WriteLine("Exception caught while getting albumart: " + e);
_notificationService.ShowErrorNotification(e);
return null;
}

Expand Down Expand Up @@ -217,13 +221,17 @@ private async Task<SKBitmap> LoadImageFromFile(string fileName)
{
try
{
var fileStream = await _applicationStorageService.OpenFileAsync(fileName, "AlbumArt");
SKBitmap image = SKBitmap.Decode(fileStream);
fileStream.Dispose();
return image;
// Go through a SKData object to sidestep https://github.com/mono/SkiaSharp/issues/1551
using (var fileStream = await _applicationStorageService.OpenFileAsync(fileName, "AlbumArt"))
using (var skData = SKData.Create(fileStream))
{
return SKBitmap.Decode(skData);
}
}
catch (Exception)
catch (Exception e)
{
Debug.WriteLine("Exception caught while loading albumart from file: " + e);
_notificationService.ShowErrorNotification(e);
return null;
}
}
Expand Down
11 changes: 7 additions & 4 deletions Sources/Stylophone.Common/Services/MPDConnectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using MpcNET.Commands.Status;
using Stylophone.Common.Interfaces;
using MpcNET.Commands.Reflection;
using Stylophone.Localization.Strings;

namespace Stylophone.Common.Services
{
Expand Down Expand Up @@ -129,7 +130,8 @@ private void ClearResources()
private async Task TryConnecting(CancellationToken token)
{
if (token.IsCancellationRequested) return;
if (!IPAddress.TryParse(_host, out var ipAddress)) return;
if (!IPAddress.TryParse(_host, out var ipAddress))
throw new Exception("Invalid IP address");

_mpdEndpoint = new IPEndPoint(ipAddress, _port);

Expand Down Expand Up @@ -196,7 +198,8 @@ public async Task<T> SafelySendCommandAsync<T>(IMpcCommand<T> command)
}
catch (Exception e)
{
_notificationService.ShowInAppNotification($"Sending {command.GetType().Name} failed: {e.Message}", false);
_notificationService.ShowInAppNotification(string.Format(Resources.ErrorSendingMPDCommand, command.GetType().Name),
e.Message, NotificationType.Error);
}

return default(T);
Expand All @@ -214,7 +217,7 @@ private async Task<MpcConnection> GetConnectionInternalAsync(CancellationToken t
if (!r.IsResponseValid)
{
var mpdError = r.Response?.Result?.MpdError;
_notificationService.ShowInAppNotification($"Invalid password: {mpdError ?? r.ToString()}", false);
_notificationService.ShowInAppNotification(Resources.ErrorPassword, $"{mpdError ?? r.ToString()}", NotificationType.Error);
}
}

Expand All @@ -235,7 +238,7 @@ private void InitializeStatusUpdater(CancellationToken token = default)
{
try
{
if (token.IsCancellationRequested || _idleConnection == null)
if (token.IsCancellationRequested || _idleConnection == null || !_idleConnection.IsConnected)
break;

var idleChanges = await _idleConnection.SendAsync(new IdleCommand("stored_playlist playlist player mixer output options update"));
Expand Down
15 changes: 8 additions & 7 deletions Sources/Stylophone.Common/Stylophone.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>9.0</LangVersion>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CodeProject.ObjectPool" Version="5.0.3" />
<PackageReference Include="LibVLCSharp" Version="3.6.0" />
<PackageReference Include="Microsoft.Toolkit" Version="7.1.2" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="MpcNET" Version="1.3.0" />
<PackageReference Include="CodeProject.ObjectPool" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Common" Version="8.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
<PackageReference Include="LibVLCSharp" Version="3.6.6" />
<PackageReference Include="MpcNET" Version="1.4.0" />
<PackageReference Include="RangedObservableCollection" Version="1.0.1" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.80.2" />
<PackageReference Include="SkiaSharp" Version="2.88.1" />
<PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.1" />
</ItemGroup>

<ItemGroup>
Expand Down
33 changes: 10 additions & 23 deletions Sources/Stylophone.Common/ViewModels/AlbumDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MpcNET.Commands.Playlist;
using MpcNET.Commands.Queue;
using MpcNET.Commands.Reflection;
Expand All @@ -17,7 +16,7 @@

namespace Stylophone.Common.ViewModels
{
public class AlbumDetailViewModel : ViewModelBase
public partial class AlbumDetailViewModel : ViewModelBase
{

private IDialogService _dialogService;
Expand All @@ -36,27 +35,18 @@ public AlbumDetailViewModel(IDialogService dialogService, INotificationService n
Source.CollectionChanged += (s, e) => OnPropertyChanged(nameof(IsSourceEmpty));
}

[ObservableProperty]
private AlbumViewModel _item;
public AlbumViewModel Item
{
get { return _item; }
set { Set(ref _item, value); }
}

private string _info;
public string PlaylistInfo
{
get => _info;
private set => Set(ref _info, value);
}
[ObservableProperty]
private string _playlistInfo;

public ObservableCollection<TrackViewModel> Source { get; } = new ObservableCollection<TrackViewModel>();

public bool IsSourceEmpty => Source.Count == 0;

private ICommand _addToQueueCommand;
public ICommand AddToQueueCommand => _addToQueueCommand ?? (_addToQueueCommand = new RelayCommand<IList<object>>(QueueTrack));

private async void QueueTrack(object list)
[RelayCommand]
private async void AddToQueue(object list)
{
var selectedTracks = (IList<object>)list;

Expand All @@ -76,9 +66,7 @@ private async void QueueTrack(object list)
}
}

private ICommand _addToPlaylistCommand;
public ICommand AddToPlayListCommand => _addToPlaylistCommand ?? (_addToPlaylistCommand = new RelayCommand<IList<object>>(AddToPlaylist));

[RelayCommand]
private async void AddToPlaylist(object list)
{
var playlistName = await _dialogService.ShowAddToPlaylistDialog();
Expand Down Expand Up @@ -131,7 +119,6 @@ public void Initialize(AlbumViewModel album)
await _dispatcherService.ExecuteOnUIThreadAsync(() => CreateTrackViewModels());
}).ConfigureAwait(false);
}

}

private void CreateTrackViewModels()
Expand Down
15 changes: 4 additions & 11 deletions Sources/Stylophone.Common/ViewModels/Bases/LibraryViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Input;
using MpcNET.Commands.Database;
using MpcNET.Tags;
using Stylophone.Common.Helpers;
Expand All @@ -18,7 +13,7 @@

namespace Stylophone.Common.ViewModels
{
public abstract class LibraryViewModelBase : ViewModelBase
public abstract partial class LibraryViewModelBase : ViewModelBase
{
private INavigationService _navigationService;
private MPDConnectionService _mpdService;
Expand All @@ -36,9 +31,6 @@ public LibraryViewModelBase(INavigationService navigationService, IDispatcherSer

public static new string GetHeader() => Resources.LibraryHeader;

private ICommand _itemClickCommand;
public ICommand ItemClickCommand => _itemClickCommand ?? (_itemClickCommand = new RelayCommand<AlbumViewModel>(OnItemClick));

public List<AlbumViewModel> Source { get; } = new List<AlbumViewModel>();
public bool IsSourceEmpty => FilteredSource.Count == 0;

Expand Down Expand Up @@ -97,7 +89,8 @@ private string GetGroupHeader(string title)
return char.IsLetter(c) ? c.ToString() : char.IsDigit(c) ? "#" : "&";
}

private void OnItemClick(AlbumViewModel clickedItem)
[RelayCommand]
private void ItemClick(AlbumViewModel clickedItem)
{
if (clickedItem != null)
{
Expand Down
Loading

0 comments on commit eb9549a

Please sign in to comment.