Skip to content

Commit

Permalink
Merge pull request #353 from Fooxboy/183-добавить-нормальное-отображе…
Browse files Browse the repository at this point in the history
…ние-исполнителей-в-плеер

#183 добавить нормальное отображение исполнителей в плеер
  • Loading branch information
Fooxboy authored Nov 29, 2023
2 parents 6b3f1af + e4aab94 commit 64d1802
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
3 changes: 0 additions & 3 deletions MusicX/Controls/PlayerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@
<TextBlock
x:Name="ArtistName"
FontFamily="{StaticResource VKSansRegular}"
MouseEnter="ArtistName_MouseEnter"
MouseLeave="ArtistName_MouseLeave"
MouseLeftButtonDown="ArtistName_MouseLeftButtonDown"
Opacity="0.7"
Text="Artist name">
<TextBlock.ToolTip>
Expand Down
55 changes: 34 additions & 21 deletions MusicX/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
Expand Down Expand Up @@ -136,21 +137,38 @@ private async void PlayerService_TrackChangedEvent(object? sender, EventArgs e)
}

TrackTitle.Text = playerService.CurrentTrack.Title;
string s = string.Empty;

if (ArtistName.Inlines.Count > 0)
ArtistName.Inlines.Clear();

if (playerService.CurrentTrack!.MainArtists.Any())
{
foreach (var trackArtist in playerService.CurrentTrack.MainArtists)
ArtistName.Inlines.AddRange(playerService.CurrentTrack.MainArtists.Select(b =>
{
s += trackArtist.Name + ", ";
}

var artists = s.Remove(s.Length - 2);

ArtistName.Text = artists;
var run = new Run(b.Name + ", ")
{
Tag = b
};

run.MouseEnter += ArtistName_MouseEnter;
run.MouseLeave += ArtistName_MouseLeave;
run.MouseLeftButtonUp += ArtistName_MouseLeftButtonUp;

return run;
}));

var lastInline = (Run)ArtistName.Inlines.LastInline;
lastInline.Text = lastInline.Text[..^2];
}
else
{
ArtistName.Text = playerService.CurrentTrack.GetArtistsString();
var run = new Run(playerService.CurrentTrack.GetArtistsString());

run.MouseEnter += ArtistName_MouseEnter;
run.MouseLeave += ArtistName_MouseLeave;
run.MouseLeftButtonUp += ArtistName_MouseLeftButtonUp;

ArtistName.Inlines.Add(run);
}


Expand Down Expand Up @@ -297,22 +315,17 @@ private async void PrevButton_Click(object sender, RoutedEventArgs e)

private void ArtistName_MouseEnter(object sender, MouseEventArgs e)
{
//if (playerService.CurrentTrack.MainArtists == null) return;
ArtistName.TextDecorations.Add(TextDecorations.Underline);
this.Cursor = Cursors.Hand;

((Run)sender).TextDecorations.Add(TextDecorations.Underline);
this.Cursor = Cursors.Hand;
}

private void ArtistName_MouseLeave(object sender, MouseEventArgs e)
{
//if (playerService.CurrentTrack.MainArtists == null) return;

foreach (var dec in TextDecorations.Underline)
{
ArtistName.TextDecorations.Remove(dec);
((Run)sender).TextDecorations.Remove(dec);
}
this.Cursor = Cursors.Arrow;

}

private async Task SaveVolume()
Expand All @@ -331,13 +344,13 @@ private async Task SaveVolume()
await configService.SetConfig(conf);
}

private async void ArtistName_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
private async void ArtistName_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
try
{
var navigationService = StaticService.Container.GetRequiredService<NavigationService>();

if (playerService.CurrentTrack?.MainArtists.First().Id is {Type: ArtistIdType.Vk} artistId)
if (((Run)sender).Tag is TrackArtist { Id: { Type: ArtistIdType.Vk } artistId })
{
navigationService.OpenSection(artistId.Id, SectionType.Artist);
}
Expand Down Expand Up @@ -395,13 +408,13 @@ private async void LikeTrack_Click(object sender, RoutedEventArgs e)
LikeIcon.Filled = true;

snackbarService.Show("Добавлено в вашу библиотеку",
$"Трек {ArtistName.Text} - {TrackTitle.Text} теперь находится в Вашей музыке!", ControlAppearance.Success);
$"Трек {playerService.CurrentTrack.GetArtistsString()} - {playerService.CurrentTrack.Title} теперь находится в Вашей музыке!", ControlAppearance.Success);
return;
}

LikeIcon.Filled = false;
snackbarService.Show("Удалено из вашей библиотеки",
$"Трек {ArtistName.Text} - {TrackTitle.Text} теперь удален из вашей музыки", ControlAppearance.Success);
$"Трек {playerService.CurrentTrack.GetArtistsString()} - {playerService.CurrentTrack.Title} теперь удален из вашей музыки", ControlAppearance.Success);
}
catch(Exception ex)
{
Expand Down

0 comments on commit 64d1802

Please sign in to comment.