-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating the ViewModel abstract of NeteaseSong and using it to display songlist
- Loading branch information
Showing
10 changed files
with
240 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
refs/HyPlayer.PlayCore/HyPlayer.PlayCore.Abstraction/Models/ProvidableItemBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
namespace HyPlayer.PlayCore.Abstraction.Models; | ||
namespace HyPlayer.PlayCore.Abstraction.Models; | ||
|
||
public abstract class ProvidableItemBase | ||
{ | ||
public required string Name { get; set; } | ||
public string Name { get; set; } = ""; | ||
public string ItemId => $"{ProviderId}{TypeId}{ActualId}"; | ||
public abstract string ProviderId { get; } | ||
public abstract string TypeId { get; } | ||
public required string ActualId { get; set; } | ||
public string ActualId { get; set; } = "0000"; | ||
} | ||
|
||
public interface IProvidableItem { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using HyPlayer.Interfaces.ViewModels; | ||
using HyPlayer.NeteaseProvider.Models; | ||
using HyPlayer.PlayCore.Abstraction.Models.Containers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace HyPlayer.ViewModels | ||
{ | ||
public partial class SongViewModel : ObservableObject, IScopedViewModel | ||
{ | ||
private readonly NeteaseProvider.NeteaseProvider _provider; | ||
|
||
[ObservableProperty] public NeteaseSong _ncmSong; | ||
[ObservableProperty] private string? _songName; | ||
[ObservableProperty] private string? _songId; | ||
[ObservableProperty] private TimeSpan? _duration; | ||
[ObservableProperty] private Uri _coverUri; | ||
[ObservableProperty] private List<PersonBase>? _artists; | ||
[ObservableProperty] private AlbumBase? _album; | ||
[ObservableProperty] private int _loadIndex = -1; | ||
|
||
public SongViewModel(NeteaseProvider.NeteaseProvider provider) | ||
{ | ||
_provider = provider; | ||
} | ||
[RelayCommand] | ||
public void GetSongInfo() | ||
{ | ||
if (NcmSong == null) | ||
{ | ||
SongName = "Song0"; | ||
Duration = new TimeSpan(0); | ||
CoverUri = new Uri("ms-appx:///Assets/Images/StoreLogo.png"); | ||
return; | ||
} | ||
|
||
SongName = NcmSong.Name; | ||
Duration = new TimeSpan(NcmSong.Duration); | ||
CoverUri = new Uri(NcmSong.CoverUrl ?? "ms-appx:///Assets/Images/StoreLogo.png"); | ||
Artists = NcmSong.Artists ?? new List<PersonBase>(); | ||
SongId = NcmSong.ActualId; | ||
Album = NcmSong.Album; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<UserControl | ||
x:Class="HyPlayer.Views.Controls.PlayBar.PlayBar" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:HyPlayer.Views.Controls.PlayBar" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<Grid> | ||
|
||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
|
||
// To learn more about WinUI, the WinUI project structure, | ||
// and more about our project templates, see: http://aka.ms/winui-project-info. | ||
|
||
namespace HyPlayer.Views.Controls.PlayBar | ||
{ | ||
public sealed partial class PlayBar : UserControl | ||
{ | ||
public PlayBar() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/HyPlayer.App/Views/Controls/SingleSongView/SingleSongView.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<local:SingleSongViewBase | ||
x:Class="HyPlayer.Views.Controls.SingleSongView.SingleSongView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:HyPlayer.Views.Controls.SingleSongView" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls" | ||
mc:Ignorable="d"> | ||
|
||
<Grid> | ||
<Grid Margin="12,8"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="5" /> | ||
<ColumnDefinition Width="55" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="45" /> | ||
</Grid.ColumnDefinitions> | ||
<TextBlock x:Name="Index" | ||
Text="{x:Bind ViewModel.LoadIndex}" | ||
FontSize="16" | ||
VerticalAlignment="Center" | ||
HorizontalAlignment="Left" | ||
Margin="-15,0,0,0" | ||
FontWeight="Bold"/> | ||
<controls:ImageEx | ||
x:Name="SongCoverImage" | ||
Width="50" | ||
Height="50" | ||
Stretch="UniformToFill" | ||
EnableLazyLoading="True" | ||
IsCacheEnabled="False" | ||
Margin="6,0,0,0" | ||
CornerRadius="9" | ||
Grid.Column="1" | ||
> | ||
<controls:ImageEx.Source> | ||
<BitmapImage UriSource="{x:Bind ViewModel.CoverUri}" /> | ||
</controls:ImageEx.Source> | ||
</controls:ImageEx> | ||
<TextBlock Margin="5,0,0,0" Grid.Column="2" VerticalAlignment="Center" Text="{x:Bind ViewModel.SongName}" /> | ||
<TextBlock | ||
Grid.Column="3" | ||
VerticalAlignment="Center" | ||
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" | ||
Text="{x:Bind ViewModel.Artists, Converter={StaticResource ArtistListToStringConverter}}" /> | ||
<TextBlock | ||
Grid.Column="4" | ||
VerticalAlignment="Center" | ||
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" | ||
Text="{x:Bind ViewModel.Album.Name}" /> | ||
<Button | ||
Grid.Column="5" | ||
Height="32" | ||
VerticalAlignment="Center" | ||
Background="Transparent" | ||
BorderBrush="Transparent"> | ||
<FontIcon Glyph="" /> | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
</local:SingleSongViewBase> |
56 changes: 56 additions & 0 deletions
56
src/HyPlayer.App/Views/Controls/SingleSongView/SingleSongView.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using HyPlayer.Interfaces.Views; | ||
using HyPlayer.NeteaseProvider.Models; | ||
using HyPlayer.ViewModels; | ||
using HyPlayer.Views.Controls.Netease.SongListView; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
|
||
// To learn more about WinUI, the WinUI project structure, | ||
// and more about our project templates, see: http://aka.ms/winui-project-info. | ||
|
||
namespace HyPlayer.Views.Controls.SingleSongView | ||
{ | ||
public sealed partial class SingleSongView : SingleSongViewBase | ||
{ | ||
public static readonly DependencyProperty SongProperty = DependencyProperty.Register( | ||
"DisplaySong", typeof(NeteaseSong), | ||
typeof(SingleSongView), | ||
new PropertyMetadata(null)); | ||
public NeteaseSong DisplaySong | ||
{ | ||
get => ((NeteaseSong)GetValue(SongProperty)); | ||
set | ||
{ | ||
SetValue(SongProperty, value); | ||
} | ||
} | ||
|
||
public SingleSongView() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
public void SetSong(NeteaseSong song, int loadIndex = -1) | ||
{ | ||
ViewModel.NcmSong = song; | ||
ViewModel.GetSongInfo(); | ||
ViewModel.LoadIndex=loadIndex; ; | ||
Bindings.Update(); | ||
} | ||
} | ||
public class SingleSongViewBase : ReactiveControlBase<SongViewModel> | ||
{ | ||
|
||
} | ||
} |