Skip to content

Commit

Permalink
add shadow main color for playlists and track album tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Oct 12, 2024
1 parent 6443325 commit 65ead1a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
2 changes: 2 additions & 0 deletions MusicX.Core/Models/Album.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ public Uri? Cover
return url is null ? null : new(url);
}
}

public string? MainColor { get; set; }
}
}
2 changes: 2 additions & 0 deletions MusicX.Core/Models/Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,7 @@ public string Cover

}
}

public string? MainColor { get; set; }
}
}
2 changes: 1 addition & 1 deletion MusicX.Shared/Player/PlaylistTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public record IdInfo(long Id, long OwnerId, string AccessKey)
[ProtoContract(ImplicitFields = ImplicitFields.AllPublic, SkipConstructor = true)]
public sealed record VkTrackData(string Url, bool IsLiked, bool IsExplicit, bool? HasLyrics, TimeSpan Duration,
IdInfo Info, string TrackCode, string? ParentBlockId,
IdInfo? Playlist) : TrackData(Url, IsLiked, IsExplicit, Duration)
IdInfo? Playlist, string? AlbumMainColor) : TrackData(Url, IsLiked, IsExplicit, Duration)
{
public bool Equals(VkTrackData? other)
{
Expand Down
3 changes: 3 additions & 0 deletions MusicX/Controls/PlayerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
<Border.Background>
<ImageBrush ImageSource="{Binding AlbumId.CoverUrl, FallbackValue={x:Null}}" />
</Border.Background>
<Border.Effect>
<DropShadowEffect ShadowDepth="0" Opacity="0.4" BlurRadius="15" RenderingBias="Performance" x:Name="AlbumTooltipShadowEffect" />
</Border.Effect>
</Border>
<TextBlock
Margin="10,0,0,0"
Expand Down
11 changes: 11 additions & 0 deletions MusicX/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -68,6 +69,7 @@ public IEnumerable TracksSource

private readonly ListenTogetherService listenTogetherService;
private readonly Logger logger;
private readonly ColorConverter _colorConverter = new();
private ConfigModel config;

public PlayerControl()
Expand Down Expand Up @@ -235,6 +237,15 @@ private async void PlayerService_TrackChangedEvent(object? sender, EventArgs e)
break;
}

if (PlayerService.CurrentTrack?.Data is VkTrackData vkTrackData)
{
AlbumTooltipShadowEffect.Color = !string.IsNullOrEmpty(vkTrackData.AlbumMainColor) &&
_colorConverter.ConvertFrom(vkTrackData.AlbumMainColor) is
Color color
? color
: Colors.Transparent;
}

await SaveVolume();
}
catch (Exception ex)
Expand Down
10 changes: 6 additions & 4 deletions MusicX/Services/Player/Playlists/TrackExtensions.Vk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public static PlaylistTrack ToTrack(this Audio audio, Playlist? playlist)
}else
{
trackData =
new VkTrackData(audio.Url, isLiked, audio.IsExplicit, audio.HasLyrics, TimeSpan.FromSeconds(audio.Duration), new(
audio.Id,
audio.OwnerId, audio.AccessKey), audio.TrackCode, audio.ParentBlockId,
playlist is null ? null : new(playlist.Id, playlist.OwnerId, playlist.AccessKey));
new VkTrackData(audio.Url, isLiked, audio.IsExplicit, audio.HasLyrics,
TimeSpan.FromSeconds(audio.Duration), new(
audio.Id,
audio.OwnerId, audio.AccessKey), audio.TrackCode, audio.ParentBlockId,
playlist is null ? null : new(playlist.Id, playlist.OwnerId, playlist.AccessKey),
audio.Album?.MainColor);
}

return new(audio.Title, audio.Subtitle, audio.Album?.ToAlbumId(), mainArtists,
Expand Down
3 changes: 2 additions & 1 deletion MusicX/ViewModels/PlaylistViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class PlaylistViewModel:BaseViewModel
public bool IsLoading { get; set; } = true;
public bool IsLoaded { get; set; }
public string Cover { get; set; }
public string? MainColor { get; set; }
public ObservableRangeCollection<Audio> Tracks { get; } = new();

public Playlist Playlist { get; private set; }
Expand Down Expand Up @@ -200,7 +201,7 @@ public async Task LoadPlaylist(Playlist playlist, bool delete = true)
this.Plays = playlist.Plays.ToString();
}


MainColor = playlist.MainColor;

IsLoaded = true;
IsLoading = false;
Expand Down
6 changes: 3 additions & 3 deletions MusicX/Views/PlaylistView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@
<Rectangle.Effect>
<DropShadowEffect
BlurRadius="40"
Opacity="0.3"
ShadowDepth="5"
Color="Black" />
Opacity="0.6"
ShadowDepth="0"
Color="{Binding MainColor, FallbackValue=#000000, Mode=OneWay}" />
</Rectangle.Effect>
</Rectangle>
</Grid>
Expand Down

0 comments on commit 65ead1a

Please sign in to comment.