Skip to content

Commit

Permalink
Merge pull request #57 from maxinglo/develop
Browse files Browse the repository at this point in the history
[WIP] [Feat]  完善PlayListPage
  • Loading branch information
zhh135 authored Jun 25, 2024
2 parents 4e2c5be + 33f2d04 commit e5b3333
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ await RequestAsync(
await RequestAsync(NeteaseApis.PlaylistSubscribeApi,
new PlaylistSubscribeRequest()
{
IsSubscribe = true,
IsSubscribe = false,
PlaylistId = inProviderId.Substring(2)
}, ctk).ConfigureAwait(false);
}
Expand Down
3 changes: 3 additions & 0 deletions src/HyPlayer.App/Resources/Converters.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
<converters:BooleanToNavButtonVisibleConverter x:Key="BooleanToNavButtonVisibleConverter" />
<converters:StringToImageSourceConverter x:Key="StringToImageSourceConverter" />
<converters:BrushToColorConverter x:Key="BrushToColorConverter" />
<converters:TimeStampToDateConverter x:Key="TimeStampToDateConverter"/>
<converters:ArtistListToStringConverter x:Key="ArtistListToStringConverter"/>
<converters:BoolToStringConverter x:Key="BoolToStringConverter"/>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.UI.Xaml.Media;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HyPlayer.NeteaseProvider.Models;
using Microsoft.UI.Xaml.Data;
using HyPlayer.PlayCore.Abstraction.Models.Containers;

namespace HyPlayer.ViewModels.Converters
{
internal class ArtistListToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is List<PersonBase> artistList)
{
return string.Join("、", artistList.Select(t => t.Name));
}
return string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
23 changes: 23 additions & 0 deletions src/HyPlayer.App/ViewModels/Converters/BoolToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HyPlayer.ViewModels.Converters
{
public class BoolToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var texts = ((string)parameter).Split('|');
return (bool)value ? texts[1] : texts[0];
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
44 changes: 44 additions & 0 deletions src/HyPlayer.App/ViewModels/Converters/TimeStampToDateConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HyPlayer.ViewModels.Converters
{
class TimeStampToDateConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, string language)
{
if (value is not long timeStamp) return null;
var localDateTime = (new DateTime(1970, 1, 1).AddMilliseconds(timeStamp)).ToLocalTime();
var now = DateTime.Now;
var timeSpan = now - localDateTime;
if (timeSpan.TotalDays <= 1)
{
if (timeSpan.TotalHours >= 1)
{
return $"{(int)timeSpan.TotalHours} 小时之前";
}if (timeSpan.TotalMinutes >= 1)
{
return $"{(int)timeSpan.TotalMinutes} 分钟之前";
}
{
return "刚刚";
}
}
else
{
return localDateTime.ToString("yyyy-MM-dd");
}
}

public object ConvertBack(object value, Type targetType,
object parameter, string language)
{
throw new NotImplementedException();
}
}
}
59 changes: 55 additions & 4 deletions src/HyPlayer.App/ViewModels/NeteasePlaylistViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using HyPlayer.NeteaseProvider.Models;
using HyPlayer.PlayCore.Abstraction.Models.SingleItems;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

Expand All @@ -24,8 +25,10 @@ public partial class NeteasePlaylistViewModel : ObservableObject, IScrollableVie
public long? PlayCount => PlayList?.PlayCount;
public long? ShareCount => PlayList?.ShareCount;
[ObservableProperty]
public List<NeteaseSong>? _songsList;

public ObservableCollection<NeteaseSong>? _songsList;
public int SortOrder = 0; // 0: 不排序, 1: 升序, 2: 降序
public string SortTypes = "SongName";
private ObservableCollection<NeteaseSong> tempSong;

public NeteasePlaylistViewModel(NeteaseProvider.NeteaseProvider provider)
{
Expand All @@ -37,8 +40,56 @@ public async Task GetSongsAsync()
{
if(PlayList is not null)
{
SongsList = (await PlayList.GetAllItemsAsync())?.Select(t => (NeteaseSong)t).ToList();
SongsList = new ObservableCollection<NeteaseSong>((await PlayList.GetAllItemsAsync())?.Select(t => (NeteaseSong)t));
tempSong = SongsList;
}
}

[RelayCommand]
public async Task SubscribePlaylistAsync()
{
if (PlayList.Subscribed==false)
{
await _provider.LikeProvidableItemAsync($"pl{PlayList.ActualId}", null);
}
else
{
await _provider.UnlikeProvidableItemAsync($"pl{PlayList.ActualId}", null);
}
OnPropertyChanged(nameof(PlayList));
}
[RelayCommand]
public void ToggleSortOrder()
{
SortOrder = (SortOrder + 1) % 3;
SortSongListOrder(true);
}

[RelayCommand]
public void SortSongListOrder(bool reload = false)
{
if (SortOrder == 0)
{
if(!reload) return;
SongsList = tempSong;
OnPropertyChanged(nameof(SongsList));
return;
}
switch (SortTypes)
{
case "SongName":
SongsList = new ObservableCollection<NeteaseSong>(SortOrder == 1 ? SongsList.OrderBy(song => song.Name) : SongsList.OrderByDescending(song => song.Name));
break;
case "Artist":
SongsList = new ObservableCollection<NeteaseSong>(SortOrder == 1 ? SongsList.OrderBy(song => song.Artists.FirstOrDefault()?.Name) : SongsList.OrderByDescending(song => song.Artists.FirstOrDefault()?.Name));
break;
case "Album":
SongsList = new ObservableCollection<NeteaseSong>(SortOrder == 1 ? SongsList.OrderBy(song => song.Album?.Name) : SongsList.OrderByDescending(song => song.Album?.Name));
break;
default:
SongsList = tempSong;
OnPropertyChanged(nameof(SongsList));
break;
}

}
}
6 changes: 4 additions & 2 deletions src/HyPlayer.App/Views/Controls/Dialogs/SignInDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
<TextBox
x:Name="TextBoxAccount"
BorderThickness="0"
PlaceholderText="手机 / 邮箱" />
PlaceholderText="手机 / 邮箱"
TabIndex="1"/>
<PasswordBox
x:Name="TextBoxPassword"
BorderThickness="0"
PlaceholderText="密码" />
PlaceholderText="密码"
TabIndex="2"/>
<TextBlock
VerticalAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
mc:Ignorable="d">

<Grid>
<ListView x:Name="SongContainer">
<ListView x:Name="SongContainer"
ItemsSource="{x:Bind ViewModel.SongsList ,Mode=OneWay}"
IsItemClickEnabled="True"
ItemClick="SongItemOnClick">
<ListView.Header>
<ContentControl
x:Name="HeaderPanel"
Expand All @@ -22,7 +25,77 @@
<ListView.Footer>
<ContentControl Content="{x:Bind Footer}" />
</ListView.Footer>

<ListView.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem
x:Name="FlyoutItemPlay"
Text="立即播放">
<MenuFlyoutItem.Icon>
<SymbolIcon Symbol="Play" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="FlyoutItemAddToPlaylist"
Text="添加到播放列表">
<MenuFlyoutItem.Icon>
<SymbolIcon Symbol="MusicInfo" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutSeparator />
<MenuFlyoutItem
x:Name="FlyoutItemSinger"
Text="歌手">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE716;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="FlyoutItemAlbum"
Text="专辑">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE93C;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutSeparator />
<MenuFlyoutItem
x:Name="FlyoutItemComments"
Text="评论">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8F2;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="FlyoutItemDownload"
Text="下载">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE118;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="BtnMV"
Text="视频">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE173;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="FlyoutCollection"
Text="收藏">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE1DA;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="Btn_Del"
Foreground="Red"
Text="删除"
Visibility="{Binding ElementName=SongListRoot, Path=IsMySongList}">
<MenuFlyoutItem.Icon>
<FontIcon Foreground="Red" Glyph="&#xE107;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
</MenuFlyout>
</ListView.ContextFlyout>
<ListView.ItemTemplate>
<DataTemplate x:DataType="netease:NeteaseSong">
<Grid Margin="12,8">
Expand All @@ -37,12 +110,12 @@
Grid.Column="1"
VerticalAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
Text="{x:Bind Artists, Converter={StaticResource StringListToStringConverter}}" />
Text="{x:Bind Artists, Converter={StaticResource ArtistListToStringConverter}}" />
<TextBlock
Grid.Column="2"
VerticalAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
Text="{x:Bind Album}" />
Text="{x:Bind Album.Name}" />
<Button
Grid.Column="3"
Height="32"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using System.Runtime.InteropServices;
using CommunityToolkit.WinUI.UI;
using HyPlayer.NeteaseProvider.Models;
using HyPlayer.ViewModels;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
Expand All @@ -31,7 +38,7 @@ public sealed partial class SongListView : UserControl

public static readonly DependencyProperty FooterProperty = DependencyProperty.Register(
"Footer", typeof(UIElement), typeof(SongListView), new PropertyMetadata(default(UIElement)));

public NeteasePlaylistViewModel ViewModel;
public string ListSource
{
get => (string)GetValue(ListSourceProperty);
Expand All @@ -58,5 +65,24 @@ public SongListView()
{
this.InitializeComponent();
}


public void Update()
{
this.Bindings.Update();
}

private void SongItemOnClick(object sender, ItemClickEventArgs e)
{
var song = (NeteaseSong)e.ClickedItem;
Debug.WriteLine($"Clicking on {song.Name}");
//TODO: Play the song
}

public async void ScrollToIndex(int index)
{
SongContainer.SelectedItem = ViewModel.SongsList[index];
await SongContainer.SmoothScrollIntoViewWithIndexAsync(index, ScrollItemPlacement.Top, false, true);
}
}
}
5 changes: 3 additions & 2 deletions src/HyPlayer.App/Views/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@
LeaderBoardName="{x:Bind Name}"
PlayCount="{x:Bind PlayCount, Converter={StaticResource CountHumanizerConverter}}"
Style="{ThemeResource DefaultTopChartButtonStyle}"
UseSystemFocusVisuals="True" />
CommandParameter="{x:Bind}"
Click="HomePageTopChart_OnClick"/>
</DataTemplate>

<DataTemplate x:Key="HomePagePeronalFMTemplate" x:DataType="models:NeteaseSong">
Expand Down Expand Up @@ -702,7 +703,7 @@
Height="140"
Margin="12,4"
DesiredWidth="240"
IsItemClickEnabled="True"
IsItemClickEnabled="False"
ItemClick="OnPlaylistItemClicked"
ItemHeight="128"
ItemTemplate="{StaticResource HomePageTopChartTemplate}"
Expand Down
Loading

0 comments on commit e5b3333

Please sign in to comment.