Skip to content

Commit

Permalink
添加每日推荐歌曲功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Miaoyww committed Jul 22, 2024
1 parent 82bca77 commit 90525e1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
3 changes: 2 additions & 1 deletion NonsPlayer.Core/Contracts/Adapters/ICommonAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace NonsPlayer.Core.Contracts.Adapters;
public interface ICommonAdapter: ISubAdapter
{
Task<IPlaylist[]> GetRecommendedPlaylistAsync(int count);

Task<IMusic[]> GetDailyRecommended();
Task<IMusic[]> GetRadioSong();
}
4 changes: 2 additions & 2 deletions NonsPlayer.Core/Contracts/Models/Music/IAlbum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public interface IAlbum : IMusicModel
{
[JsonPropertyName("create_date")] public DateTime CreateDate { get; set; }
[JsonPropertyName("description")] public string Description { get; set; }
[JsonPropertyName("musics")] public List<IMusic> Musics { get; set; }
[JsonPropertyName("artists")] public List<IArtist> Artists { get; set; }
[JsonPropertyName("musics")] public IMusic[] Musics { get; set; }
[JsonPropertyName("artists")] public IArtist[] Artists { get; set; }
[JsonIgnore] public string ArtistsName => string.Join("/", Artists.Select(x => x.Name));
[JsonPropertyName("collection_count")] public int CollectionCount { set; get; }
[JsonPropertyName("track_count")] public int TrackCount { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions NonsPlayer.Core/Models/LocalAlbum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class LocalAlbum: IAlbum
public string AvatarUrl { get; set; }
public DateTime CreateDate { get; set; }
public string Description { get; set; }
public List<IMusic> Musics { get; set; }
public List<IArtist> Artists { get; set; }
public IMusic[] Musics { get; set; }
public IArtist[] Artists { get; set; }
public int CollectionCount { get; set; }
public int TrackCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using Windows.UI;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.WinUI.UI.Controls;
Expand All @@ -18,17 +19,22 @@ namespace NonsPlayer.Components.ViewModels;
public partial class RecommendedPlaylistCardViewModel : ObservableObject
{
[ObservableProperty] private ImageSource cover;
[ObservableProperty] private Brush fontColor;
[ObservableProperty] private Visibility tipVisibility = Visibility.Collapsed;

public RecommendedPlaylistCardViewModel()
public async void Init(IMusic[] music)
{
if (music != null)
{
var firstMusic = music[0];
Cover = (await CacheHelper.GetImageBrushAsync(firstMusic.CacheAvatarId,
firstMusic.GetCoverUrl())).ImageSource;
TipVisibility = Visibility.Collapsed;
FontColor = App.Current.Resources["LightTextColor"] as SolidColorBrush;
return;
}

}

public async void Init(IPlaylist playList)
{
if (!playList.IsInitialized) await playList.InitializeMusics();
var firstMusic = playList.Musics[0];
Cover = (await CacheHelper.GetImageBrushAsync(firstMusic.CacheAvatarId,
firstMusic.GetCoverUrl())).ImageSource;
TipVisibility = Visibility.Visible;
FontColor = App.Current.Resources["CommonTextColor"] as SolidColorBrush;
}
}
9 changes: 5 additions & 4 deletions NonsPlayer/Components/Views/Home/RecentlyPlayItemCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:winUi="using:CommunityToolkit.WinUI"
mc:Ignorable="d">
<Border x:Name="BodyBorder"
PointerPressed="BodyBorder_OnPointerPressed"
Width="100" Height="100" Background="{x:Bind ViewModel.Cover, Mode=OneWay}"
CornerRadius="20" />
<Border
x:Name="BodyBorder"
PointerPressed="BodyBorder_OnPointerPressed"
Width="100" Height="100" Background="{x:Bind ViewModel.Cover, Mode=OneWay}"
CornerRadius="20" />
</UserControl>
19 changes: 14 additions & 5 deletions NonsPlayer/Components/Views/RecommendedPlaylistCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Border CornerRadius="20" Width="500" Height="200">
<Border
Background="{StaticResource ComponentsCardBackground}"
CornerRadius="20" Width="500" Height="200">
<Grid>
<Grid.Resources>
<Storyboard x:Name="AvatarAnimation">
Expand All @@ -17,18 +19,25 @@
</DoubleAnimation>
</Storyboard>
</Grid.Resources>

<Viewbox Stretch="UniformToFill">
<Image Name="Cover" Source="{x:Bind ViewModel.Cover, Mode=OneWay}">
<Image.RenderTransform>
<TranslateTransform x:Name="AvatarTransform" />
</Image.RenderTransform>
</Image>
</Viewbox>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center"
Orientation="Vertical">
<TextBlock x:Uid="DailyRecommendedPlaylist"
Margin="20,10,0,0"
Foreground="{x:Bind ViewModel.FontColor, Mode=OneWay}" FontSize="24"
FontWeight="Bold" CharacterSpacing="300" />

<TextBlock Foreground="{x:Bind ViewModel.FontColor, Mode=OneWay}" FontSize="24"
FontWeight="Bold" Text="³¢ÊԵǼºó¿ÉÓÃ" Visibility="{x:Bind ViewModel.TipVisibility, Mode=OneWay}" />
</StackPanel>

<TextBlock x:Uid="DailyRecommendedPlaylist" Margin="20,10,0,0"
FontFamily="HarmonyOS Sans SC" Foreground="#FFFFFF" FontSize="24"
FontWeight="Bold" CharacterSpacing="300"
VerticalAlignment="Top" HorizontalAlignment="Center" />
</Grid>
</Border>
</UserControl>
8 changes: 7 additions & 1 deletion NonsPlayer/Components/Views/RecommendedPlaylistCard.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Windows.Forms;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
using NonsPlayer.Components.ViewModels;
using NonsPlayer.Core.Contracts.Models.Music;
using NonsPlayer.Core.Models;
using NonsPlayer.Core.Services;
using NonsPlayer.Helpers;
using UserControl = Microsoft.UI.Xaml.Controls.UserControl;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand All @@ -23,4 +24,9 @@ public RecommendedPlaylistCard()
}

public RecommendedPlaylistCardViewModel ViewModel { get; }

public IMusic[] Music
{
set => ViewModel.Init(value);
}
}

0 comments on commit 90525e1

Please sign in to comment.