Skip to content

Commit

Permalink
v.2.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Mar 30, 2024
2 parents 1567683 + da49ee7 commit 7eb251f
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Sources/Stylophone.Common/Services/AlbumArtService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void Stop()
/// <param name="f">MpdFile to check for art</param>
/// <returns>True if the art is cached, false otherwise.</returns>
public async Task<bool> IsAlbumArtCachedAsync(IMpdFile f) => await _applicationStorageService.DoesFileExistAsync(Miscellaneous.GetFileIdentifier(f), "AlbumArt");
public async Task<bool> IsAlbumArtCachedAsync(string albumName) => await _applicationStorageService.DoesFileExistAsync(albumName, "AlbumArt");

/// <summary>
/// Queue up an AlbumViewModel for the service to grab its album art.
Expand Down Expand Up @@ -224,7 +225,7 @@ private QuantizedColor GetDominantColor(SKBitmap art)

private async Task SaveArtToFileAsync(string fileName, List<byte> data) => await _applicationStorageService.SaveDataToFileAsync(fileName, data.ToArray(), "AlbumArt");

private async Task<SKBitmap> LoadImageFromFile(string fileName)
internal async Task<SKBitmap> LoadImageFromFile(string fileName)
{
try
{
Expand Down
1 change: 1 addition & 0 deletions Sources/Stylophone.Common/Services/MPDConnectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public async Task InitializeAsync(bool withRetry = false)
{
System.Diagnostics.Debug.WriteLine($"Error while connecting: {e.Message}");

IsConnecting = false;
ConnectionChanged?.Invoke(this, new EventArgs());

if (withRetry && !cancelToken.IsCancellationRequested)
Expand Down
10 changes: 5 additions & 5 deletions Sources/Stylophone.Common/Stylophone.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

<ItemGroup>
<PackageReference Include="CodeProject.ObjectPool" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Common" Version="8.2.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="CommunityToolkit.Common" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="LibVLCSharp" Version="3.7.0" />
<PackageReference Include="MpcNET" Version="1.5.0" />
<PackageReference Include="SkiaSharp" Version="2.88.5" />
<PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.5" />
<PackageReference Include="MpcNET" Version="1.6.5" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.7" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.2" />
</ItemGroup>

Expand Down
23 changes: 17 additions & 6 deletions Sources/Stylophone.Common/ViewModels/Bases/LibraryViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@

namespace Stylophone.Common.ViewModels
{

public abstract partial class LibraryViewModelBase : ViewModelBase
{
private record Album
{
public string Name { get; set; }
public string SortName { get; set; }
}

private INavigationService _navigationService;
private MPDConnectionService _mpdService;
private AlbumViewModelFactory _albumVmFactory;
Expand All @@ -40,9 +47,13 @@ public async Task LoadDataAsync()
FilteredSource.CollectionChanged += (s, e) => OnPropertyChanged(nameof(IsSourceEmpty));

Source.Clear();
var response = await _mpdService.SafelySendCommandAsync(new ListCommand(MpdTags.AlbumSort));
var albumList = await _mpdService.SafelySendCommandAsync(new ListCommand(MpdTags.Album));
var albumSortList = await _mpdService.SafelySendCommandAsync(new ListCommand(MpdTags.AlbumSort));

// Create a list of tuples
var response = albumList.Zip(albumSortList, (album, albumSort) => new Album{ Name = album, SortName = albumSort });

if (response != null)
if (albumSortList != null)
GroupAlbumsByName(response);

if (Source.Count > 0)
Expand All @@ -63,10 +74,10 @@ public void FilterLibrary(string text)
AddBack(filtered);
}

public void GroupAlbumsByName(List<string> albums)
private void GroupAlbumsByName(IEnumerable<Album> albums)
{
var query = from item in albums
group item by GetGroupHeader(item) into g
group item by GetGroupHeader(item.SortName) into g
orderby g.Key
select new { GroupName = g.Key, Items = g };

Expand All @@ -76,9 +87,9 @@ orderby g.Key
//GroupInfosList info = new GroupInfosList();
//info.Key = g.GroupName + " (" + g.Items.Count() + ")";

foreach (var item in g.Items.OrderBy(s => s.ToLower()))
foreach (var item in g.Items.OrderBy(s => s.SortName.ToLower()))
{
Source.Add(_albumVmFactory.GetAlbumViewModel(item));
Source.Add(_albumVmFactory.GetAlbumViewModel(item.Name));
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion Sources/Stylophone.Common/ViewModels/Items/AlbumViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
using MpcNET.Tags;
using MpcNET.Types;
using SkiaSharp;
using Stylophone.Common.Helpers;
using Stylophone.Common.Interfaces;
using Stylophone.Common.Services;
using Stylophone.Localization.Strings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using System.Windows.Input;

Expand Down Expand Up @@ -180,6 +182,16 @@ private async Task PlayAlbum()
}
}

public async Task LoadAlbumArtFromCacheAsync()
{
// Try to show album art early if we have it in cache
var cacheName = Miscellaneous.EscapeFilename(Name);
if (await _albumArtService.IsAlbumArtCachedAsync(cacheName))
{
AlbumArt = SKImage.FromBitmap(await _albumArtService.LoadImageFromFile(cacheName));
}
}

/// <summary>
/// Load Album Data. You can either provide a MpcConnection object (for batch loading)
/// or leave as empty to automatically pick up a connection from the datasource.
Expand All @@ -196,7 +208,8 @@ public async Task LoadAlbumDataAsync()
public async Task LoadAlbumDataAsync(MpcConnection c)
{
IsDetailLoading = true;
AlbumArt = await _interop.GetPlaceholderImageAsync();
AlbumArt ??= await _interop.GetPlaceholderImageAsync();

try
{
var findReq = await c.SendAsync(new FindCommand(MpdTags.Album, Name));
Expand Down
4 changes: 2 additions & 2 deletions Sources/Stylophone.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<string>zh</string>
</array>
<key>CFBundleShortVersionString</key>
<string>2.6.0</string>
<string>2.6.1</string>
<key>CFBundleVersion</key>
<string>2.6.0</string>
<string>2.6.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Stylophone.iOS/Services/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void ShowInAppNotification(InAppNotification notification)
{
// Let's just use alerts until TipKit is available... This is cheap but w/e
var alert = new UIAlertView(notification.NotificationTitle, notification.NotificationText, null, "Ok");
alert.Show();
UIApplication.SharedApplication.InvokeOnMainThread(() => alert.Show());
return;
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Stylophone.iOS/Stylophone.iOS.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0-ios</TargetFrameworks>
<TargetFrameworks>net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
Expand Down Expand Up @@ -61,12 +61,12 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Essentials" Version="1.8.0" />
<PackageReference Include="SkiaSharp.Views" Version="2.88.5" />
<PackageReference Include="SkiaSharp.Views" Version="2.88.7" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.2" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="VideoLAN.LibVLC.iOS" Version="3.3.18" />
<PackageReference Include="MpcNET" Version="1.5.0" />
<PackageReference Include="MpcNET" Version="1.6.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Stylophone.Common\Stylophone.Common.csproj">
Expand Down
7 changes: 7 additions & 0 deletions Sources/Stylophone.iOS/ViewModels/LibraryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ internal void LoadItems(IEnumerable<int> indexes, CancellationToken token = defa
// Albumart loads still use their own connections.
Task.Run(async () =>
{
// Try to show album artwork early if we have it in cache
foreach (var i in indexes)
{
var album = BackingCollection[i];
await album.LoadAlbumArtFromCacheAsync();
}
using (var c = await _mpdService.GetConnectionAsync(token))
foreach (var i in indexes)
{
Expand Down
2 changes: 1 addition & 1 deletion Sources/Stylophone/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Identity
Name="StylophoneDebug"
Publisher="CN=B2F6FFCA-07C7-479C-AC33-2C75463C7DCE"
Version="2.6.0.0" />
Version="2.6.1.0" />

<mp:PhoneIdentity PhoneProductId="b9cbe0bc-1e9d-42c8-abf1-85c63af45f83" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
2 changes: 1 addition & 1 deletion Sources/Stylophone/Package.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<#@ output extension=".appxmanifest" #>
<#@ parameter type="System.String" name="BuildConfiguration" #>
<#
string version = "2.6.0.0";
string version = "2.6.2.0";

// Get configuration name at Build time
string configName = Host.ResolveParameterValue("-", "-", "BuildConfiguration");
Expand Down
28 changes: 14 additions & 14 deletions Sources/Stylophone/Stylophone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,22 @@
<PackageReference Include="Microsoft.Services.Store.Engagement">
<Version>10.1901.28001</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
<PackageReference Include="Microsoft.Toolkit.Uwp" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.Uwp.Animations" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Behaviors" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.Primitives" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.SettingsControls" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.Segmented" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.HeaderedControls" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Converters" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Extensions" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Media" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Uwp.Helpers" Version="8.0.230907" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Microsoft.Toolkit.Uwp" Version="7.1.3" />
<PackageReference Include="CommunityToolkit.Uwp.Animations" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Behaviors" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.Primitives" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.SettingsControls" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.Segmented" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.HeaderedControls" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Converters" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Extensions" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Media" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.Uwp.Helpers" Version="8.0.240109" />
<PackageReference Include="Microsoft.UI.Xaml" Version="2.7.3" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" Version="2.0.1" />
<PackageReference Include="MpcNET" Version="1.5.0" />
<PackageReference Include="SkiaSharp.Views" Version="2.88.1" />
<PackageReference Include="MpcNET" Version="1.6.5" />
<PackageReference Include="SkiaSharp.Views" Version="2.88.7" />
<PackageReference Include="VideoLAN.LibVLC.UWP" Version="3.3.2" />
<PackageReference Include="WindowsStateTriggers">
<Version>1.1.0</Version>
Expand Down
7 changes: 7 additions & 0 deletions Sources/Stylophone/ViewModels/LibraryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public void RangesChanged(ItemIndexRange visibleRange, IReadOnlyList<ItemIndexRa
// Albumart loads still use their own connections.
Task.Run(async () =>
{
// Try to show album artwork early if we have it in cache
for (var i = visibleRange.FirstIndex; i < visibleRange.LastIndex + 1; i++) // Increment LastIndex by one to properly cover the visible range
{
var album = this[i];
await album.LoadAlbumArtFromCacheAsync();
}
using (var c = await _mpdService.GetConnectionAsync(token))
for (var i = visibleRange.FirstIndex; i < visibleRange.LastIndex + 1; i++) // Increment LastIndex by one to properly cover the visible range
{
Expand Down
3 changes: 2 additions & 1 deletion Sources/Stylophone/Views/ServerQueuePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
ItemsSource="{x:Bind ViewModel.Source, Mode=OneWay}"
ReorderMode="Enabled"
RightTapped="Select_Item"
SelectionMode="Extended">
SelectionMode="Extended"
Visibility="{x:Bind ViewModel.IsSourceEmpty, Mode=OneWay, Converter={StaticResource ReverseBoolToVisibilityConverter}}">
<interactivity:Interaction.Behaviors>
<behaviors:AlternatingListViewBehavior
AlternateBackground="{ThemeResource SubtleFillColorTertiaryBrush}"
Expand Down

0 comments on commit 7eb251f

Please sign in to comment.