diff --git a/NonsPlayer.Core/Contracts/Adapters/IAccountAdapter.cs b/NonsPlayer.Core/Contracts/Adapters/IAccountAdapter.cs index 516eb3f..5cbe766 100644 --- a/NonsPlayer.Core/Contracts/Adapters/IAccountAdapter.cs +++ b/NonsPlayer.Core/Contracts/Adapters/IAccountAdapter.cs @@ -11,16 +11,12 @@ public interface IAccountAdapter : ISubAdapter List CreatedPlaylists { get; set; } List SavedPlaylists { get; set; } - string Key { get; set; } - Task GetQrCodeUrlAsync(); + Task> GetQrCodeUrlAsync(); Task CheckLoginAsync(string key); - - Task GetAccountAsync(string token); - + IAccount GetAccount(); Task GetTokenAsync(string response); - - Task GetUserPlaylists(); - Task GetFavoritePlaylist(); + Task GetUserPlaylists(); + Task GetFavoritePlaylist(); } public class QrCodeResult diff --git a/NonsPlayer.Core/Contracts/Models/Nons/IAccount.cs b/NonsPlayer.Core/Contracts/Models/Nons/IAccount.cs index 642330f..7de8daf 100644 --- a/NonsPlayer.Core/Contracts/Models/Nons/IAccount.cs +++ b/NonsPlayer.Core/Contracts/Models/Nons/IAccount.cs @@ -4,8 +4,16 @@ namespace NonsPlayer.Core.Contracts.Models.Nons; public interface IAccount : INonsModel { - string NickName { get; set; } + string Name { get; set; } string Token { get; set; } - string FaceUrl { get; set; } + string AvatarUrl { get; set; } bool IsLoggedIn { get; set; } + string CacheAvatarId => Id + "_avatar"; + string CacheSmallAvatarId => CacheAvatarId + "_small"; + string CacheMiddleAvatarId => CacheAvatarId + "_middle"; + string Key { get; set; } + + Task LoginByToken(string token); + Task GetAvatarUrl(); + Task Refresh(); } \ No newline at end of file diff --git a/NonsPlayer.Core/Resources/LocalSettings.cs b/NonsPlayer.Core/Resources/LocalSettings.cs index df24ed2..e14a425 100644 --- a/NonsPlayer.Core/Resources/LocalSettings.cs +++ b/NonsPlayer.Core/Resources/LocalSettings.cs @@ -10,35 +10,29 @@ namespace NonsPlayer.Core.Resources { public class LocalSettings { - [JsonIgnore] - public string DataPath { get; set; } + [JsonIgnore] public string DataPath { get; set; } - [JsonIgnore] - public string ConfigFilePath; + [JsonIgnore] public string ConfigFilePath; - [JsonPropertyName("adapter_path")] - public string AdapterPath { get; set; } + [JsonPropertyName("adapter_path")] public string AdapterPath { get; set; } - [JsonPropertyName("plugin_path")] - public string PluginPath { get; set; } + [JsonPropertyName("plugin_path")] public string PluginPath { get; set; } - [JsonPropertyName("data_path")] - public string Data { get; set; } + [JsonPropertyName("data_path")] public string Data { get; set; } - [JsonPropertyName("theme")] - public string Theme { get; set; } + [JsonPropertyName("theme")] public string Theme { get; set; } - [JsonPropertyName("volume")] - public double Volume { get; set; } + [JsonPropertyName("volume")] public double Volume { get; set; } - [JsonPropertyName("default_adapter")] - public string DefaultAdapter { get; set; } + [JsonPropertyName("adapter_account_tokens")] + public Dictionary AdapterAccountTokens { get; set; } + + [JsonPropertyName("default_adapter")] public string DefaultAdapter { get; set; } [JsonPropertyName("disabled_adapters")] public string DisabledAdapters { get; set; } - [JsonPropertyName("disabled_plugins")] - public string DisabledPlugins { get; set; } + [JsonPropertyName("disabled_plugins")] public string DisabledPlugins { get; set; } public LocalSettings() { @@ -49,10 +43,10 @@ public LocalSettings() Data = DataPath + "/Data"; Theme = "Light"; Volume = 50; + AdapterAccountTokens = new Dictionary(); DefaultAdapter = string.Empty; DisabledAdapters = string.Empty; DisabledPlugins = string.Empty; } - } } \ No newline at end of file diff --git a/NonsPlayer/App.xaml b/NonsPlayer/App.xaml index de62c8f..f88d734 100644 --- a/NonsPlayer/App.xaml +++ b/NonsPlayer/App.xaml @@ -17,6 +17,7 @@ + diff --git a/NonsPlayer/App.xaml.cs b/NonsPlayer/App.xaml.cs index 4900aa5..9b5a6a5 100644 --- a/NonsPlayer/App.xaml.cs +++ b/NonsPlayer/App.xaml.cs @@ -74,6 +74,8 @@ public App() services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -131,6 +133,14 @@ public App() ConfigManager.Instance.LoadConfig(); AdapterService.Instance.AdapterLoadFailed += OnAdapterLoadFailed; AdapterService.Instance.Init(); + foreach (var key in ConfigManager.Instance.Settings.AdapterAccountTokens.Keys) + { + var adapter = AdapterService.Instance.GetAdapter(key); + if (adapter != null) + { + adapter.Account.GetAccount().LoginByToken(ConfigManager.Instance.Settings.AdapterAccountTokens[key]); + } + } UnhandledException += App_UnhandledException; GetService().Init(); GetService().Init(); diff --git a/NonsPlayer/Components/ViewModels/LoginCardViewModel.cs b/NonsPlayer/Components/ViewModels/LoginCardViewModel.cs new file mode 100644 index 0000000..ad5deda --- /dev/null +++ b/NonsPlayer/Components/ViewModels/LoginCardViewModel.cs @@ -0,0 +1,14 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Microsoft.UI.Xaml; +using NonsPlayer.Core.Contracts.Adapters; +using NonsPlayer.Core.Nons; +using NonsPlayer.Core.Services; +using NonsPlayer.Helpers; + +namespace NonsPlayer.Components.ViewModels; + +[INotifyPropertyChanged] +public partial class LoginCardViewModel +{ +} \ No newline at end of file diff --git a/NonsPlayer/Components/Views/Login/LoginQrCard.xaml b/NonsPlayer/Components/Views/Login/LoginQrCard.xaml new file mode 100644 index 0000000..0be5c16 --- /dev/null +++ b/NonsPlayer/Components/Views/Login/LoginQrCard.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/NonsPlayer/Components/Views/Login/LoginQrCard.xaml.cs b/NonsPlayer/Components/Views/Login/LoginQrCard.xaml.cs new file mode 100644 index 0000000..0b3735e --- /dev/null +++ b/NonsPlayer/Components/Views/Login/LoginQrCard.xaml.cs @@ -0,0 +1,128 @@ +using System.Drawing.Imaging; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Imaging; +using NonsPlayer.Components.ViewModels; +using NonsPlayer.Core.Contracts.Adapters; +using NonsPlayer.Core.Contracts.Models.Nons; +using NonsPlayer.Core.Services; +using NonsPlayer.Helpers; +using QRCoder; + +namespace NonsPlayer.Components.Views; + +[INotifyPropertyChanged] +public sealed partial class LoginQrCard : UserControl +{ + [ObservableProperty] private ImageBrush qrCode; + [ObservableProperty] private string qrCodeState; + private IAccount account; + private IAdapter adapter; + private CancellationTokenSource tokenSource; + private CancellationToken cancellationToken; + public LoginQrCard() + { + ViewModel = App.GetService(); + InitializeComponent(); + QrCodeState = "QrCodeState_Waiting".GetLocalized(); + tokenSource = new(); + cancellationToken = tokenSource.Token; + } + public LoginCardViewModel ViewModel { get; } + + public IAdapter Adapter + { + set + { + adapter = value; + account = adapter.Account.GetAccount(); + Init(); + } + } + + private async void Init() + { + if (account != null) + { + if (account.IsLoggedIn) + { + await RefreshAccountInfo().ConfigureAwait(false); + } + else + { + await GetQrCode(); + await CheckKey().ConfigureAwait(false); + } + } + + } + + private async Task GetQrCode() + { + var data = await adapter.Account.GetQrCodeUrlAsync(); + if (data.Item1 == null) return; + account.Key = data.Item2; + var qrCodeImage = new QRCode(new QRCodeGenerator().CreateQrCode( + new PayloadGenerator.Url(data.Item1.ToString()).ToString(), + QRCodeGenerator.ECCLevel.M)).GetGraphic(10); + var ms = new MemoryStream(); + qrCodeImage.Save(ms, ImageFormat.Png); + ms.Seek(0, SeekOrigin.Begin); + var result = new BitmapImage(); + result.SetSource(ms.AsRandomAccessStream()); + + DispatcherQueue.TryEnqueue(() => + { + QrCode = new ImageBrush + { + ImageSource = result + }; + QrCodeState = "QrCodeState_Waiting".GetLocalized(); + }); + + } + + private async Task CheckKey() + { + // ظά״̬ + await Task.Run(async () => + { + while (!cancellationToken.IsCancellationRequested) + { + var result = await adapter.Account.CheckLoginAsync(account.Key); + if (result.Status == QrCodeStatus.Timeout) + { + await GetQrCode(); + } + else if (result.Status == QrCodeStatus.Scanned) + { + DispatcherQueue.TryEnqueue(() => { QrCodeState = "QrCodeState_Scanned".GetLocalized(); }); + } + else if (result.Status == QrCodeStatus.Confirmed) + { + // ά¼ɹ + DispatcherQueue.TryEnqueue(() => { QrCodeState = "QrCodeState_Done".GetLocalized(); }); + account = result.Account; + ConfigManager.Instance.Settings.AdapterAccountTokens.Add(adapter.GetMetadata().Name, account.Token); + ConfigManager.Instance.SaveConfig(); + break; + } + + await Task.Delay(1000); + } + }); + } + + private async Task RefreshAccountInfo() + { + + } + + private void LoginQrCard_OnUnloaded(object sender, RoutedEventArgs e) + { + tokenSource.Cancel(); + } +} \ No newline at end of file diff --git a/NonsPlayer/Components/Views/Login/LoginTokenCard.xaml b/NonsPlayer/Components/Views/Login/LoginTokenCard.xaml new file mode 100644 index 0000000..f0c73ec --- /dev/null +++ b/NonsPlayer/Components/Views/Login/LoginTokenCard.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/NonsPlayer/Components/Views/Login/LoginTokenCard.xaml.cs b/NonsPlayer/Components/Views/Login/LoginTokenCard.xaml.cs new file mode 100644 index 0000000..1fb3cbb --- /dev/null +++ b/NonsPlayer/Components/Views/Login/LoginTokenCard.xaml.cs @@ -0,0 +1,30 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Imaging; +using NonsPlayer.Components.ViewModels; +using NonsPlayer.Core.Contracts.Adapters; +using NonsPlayer.Core.Contracts.Models.Nons; +using NonsPlayer.Helpers; + +namespace NonsPlayer.Components.Views; + +[INotifyPropertyChanged] +public sealed partial class LoginTokenCard : UserControl +{ + private IAccount account; + private IAdapter adapter; + public LoginTokenCard() + { + ViewModel = App.GetService(); + InitializeComponent(); + } + public LoginCardViewModel ViewModel { get; } + + public IAdapter Adapter + { + set => adapter = value; + } +} \ No newline at end of file diff --git a/NonsPlayer/Models/AccountStateModel.cs b/NonsPlayer/Models/AccountStateModel.cs deleted file mode 100644 index b39da75..0000000 --- a/NonsPlayer/Models/AccountStateModel.cs +++ /dev/null @@ -1,30 +0,0 @@ -using CommunityToolkit.Mvvm.ComponentModel; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Media.Imaging; -using NonsPlayer.Helpers; - -namespace NonsPlayer.ViewModels; - -[INotifyPropertyChanged] -public partial class AccountStateModel -{ - [ObservableProperty] private ImageBrush face; - [ObservableProperty] private string faceUrl; - [ObservableProperty] private string name; - - [ObservableProperty] private string uid; - - public static AccountStateModel Instance { get; } = new(); - - partial void OnFaceUrlChanged(string value) - { - ServiceHelper.DispatcherQueue.TryEnqueue(() => - { - Face = new ImageBrush - { - ImageSource = new BitmapImage(new Uri(value)) - }; - }); - OnPropertyChanged(nameof(Face)); - } -} \ No newline at end of file diff --git a/NonsPlayer/Models/LoginModel.cs b/NonsPlayer/Models/LoginModel.cs new file mode 100644 index 0000000..a04b3e4 --- /dev/null +++ b/NonsPlayer/Models/LoginModel.cs @@ -0,0 +1,15 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Imaging; +using NonsPlayer.Core.Contracts.Adapters; +using NonsPlayer.Core.Contracts.Models.Nons; +using NonsPlayer.Helpers; + +namespace NonsPlayer.Models; + +public partial class LoginModel +{ + public IAccount Account; + public IAdapter Adapter; +} \ No newline at end of file diff --git a/NonsPlayer/NonsPlayer.csproj b/NonsPlayer/NonsPlayer.csproj index 9671a2a..6ae12a8 100644 --- a/NonsPlayer/NonsPlayer.csproj +++ b/NonsPlayer/NonsPlayer.csproj @@ -61,6 +61,14 @@ Always + + $(DefaultXamlRuntime) + Designer + + + $(DefaultXamlRuntime) + Designer + $(DefaultXamlRuntime) Designer @@ -176,7 +184,10 @@ + + + @@ -209,6 +220,9 @@ $(DefaultXamlRuntime) MSBuild:Compile + + $(DefaultXamlRuntime) + @@ -229,5 +243,6 @@ + diff --git a/NonsPlayer/Services/PageService.cs b/NonsPlayer/Services/PageService.cs index f6d89d8..1bbe94e 100644 --- a/NonsPlayer/Services/PageService.cs +++ b/NonsPlayer/Services/PageService.cs @@ -28,6 +28,8 @@ public PageService() Configure(); Configure(); Configure(); + Configure(); + Configure(); } public Type GetPageType(string key) diff --git a/NonsPlayer/Strings/zh-cn/Resources.resw b/NonsPlayer/Strings/zh-cn/Resources.resw index c293b99..6153520 100644 --- a/NonsPlayer/Strings/zh-cn/Resources.resw +++ b/NonsPlayer/Strings/zh-cn/Resources.resw @@ -135,8 +135,8 @@ https://github.com/Miaoyww/NonsPlayer 设置页面 超链接文本 Github链接 - - Settings + + 设置 Page title for SettingsPage @@ -429,4 +429,16 @@ 尝试登录后可用 + + 登录成功 + + + 请在手机上确认登录 + + + 扫描二维码登录 + + + 输入Token以登录 + \ No newline at end of file diff --git a/NonsPlayer/Styles/FlipView.xaml b/NonsPlayer/Styles/FlipView.xaml new file mode 100644 index 0000000..4fd7344 --- /dev/null +++ b/NonsPlayer/Styles/FlipView.xaml @@ -0,0 +1,40 @@ + + + + + \ No newline at end of file diff --git a/NonsPlayer/Styles/Resource.xaml b/NonsPlayer/Styles/Resource.xaml index 3d95dcd..c3cda11 100644 --- a/NonsPlayer/Styles/Resource.xaml +++ b/NonsPlayer/Styles/Resource.xaml @@ -9,5 +9,5 @@ 45,80,45,100 #3D3D3D #FFFFFF - #F5F3F2 + #F1F1F1 \ No newline at end of file diff --git a/NonsPlayer/ViewModels/Pages/LoginViewModel.cs b/NonsPlayer/ViewModels/Pages/LoginViewModel.cs deleted file mode 100644 index b45e0df..0000000 --- a/NonsPlayer/ViewModels/Pages/LoginViewModel.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System.Drawing.Imaging; -using CommunityToolkit.Mvvm.ComponentModel; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Media.Imaging; -using Newtonsoft.Json.Linq; -using NonsPlayer.Core.Nons; -using NonsPlayer.Helpers; -using QRCoder; - -namespace NonsPlayer.ViewModels; - -public partial class LoginViewModel : ObservableObject -{ - [ObservableProperty] private string key; - [ObservableProperty] private ImageBrush qrCode; - [ObservableProperty] private string text; - - public async void Init() - { - Text = "扫描二维码登录"; - await GetQrCode(); - checkKey(); - } - - public async Task GetQrCode() - { - // if (key == null) - // key = (await Apis.Login.QRCode.Key(getCurrentTimestamp(), NonsCore.Instance))["unikey"].ToString(); - // - // var qrCodeImage = - // new QRCode(new QRCodeGenerator().CreateQrCode( - // new PayloadGenerator.Url($"http://music.163.com/login?codekey={key}").ToString(), - // QRCodeGenerator.ECCLevel.M)).GetGraphic(10); - // var ms = new MemoryStream(); - // qrCodeImage.Save(ms, ImageFormat.Png); - // ms.Seek(0, SeekOrigin.Begin); - // var result = new BitmapImage(); - // result.SetSource(ms.AsRandomAccessStream()); - // QrCode = new ImageBrush - // { - // ImageSource = result - // }; - } - - private async Task checkKey() - { - // // 重复检查二维码状态 - // await Task.Run(async () => - // { - // while (true) - // { - // var result = await Apis.Login.QRCode.Check(key, NonsCore.Instance); - // var code = int.Parse(JObject.Parse(result.Content)["code"].ToString()); - // if (code == 800) - // { - // // 二维码过期 - // await GetQrCode(); - // } - // else if (code == 802) - // { - // // 二维码已确认 - // ServiceHelper.DispatcherQueue.TryEnqueue(() => { Text = "请在手机上确认登录"; }); - // } - // else if (code == 803) - // { - // // 二维码登录成功 - // ServiceHelper.DispatcherQueue.TryEnqueue(() => { Text = "登录成功"; }); - // foreach (var cookieItem in result.Cookies) - // if (cookieItem.Name == "MUSIC_U") - // Account.Instance.LoginByToken(cookieItem.Value); - // - // ServiceHelper.DispatcherQueue.TryEnqueue(() => - // { - // ServiceHelper.NavigationService.NavigateTo(typeof(PersonalCenterViewModel).FullName!); - // }); - // break; - // } - // - // await Task.Delay(1000); - // } - // }); - } - - private string getCurrentTimestamp() - { - return ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds().ToString(); - } -} \ No newline at end of file diff --git a/NonsPlayer/ViewModels/Pages/MainPages/PersonalCenterViewModel.cs b/NonsPlayer/ViewModels/Pages/MainPages/PersonalCenterViewModel.cs index ae295e8..273ca91 100644 --- a/NonsPlayer/ViewModels/Pages/MainPages/PersonalCenterViewModel.cs +++ b/NonsPlayer/ViewModels/Pages/MainPages/PersonalCenterViewModel.cs @@ -14,30 +14,6 @@ public PersonalCenterViewModel(INavigationService navigationService) NavigationService = navigationService; } - public AccountStateModel AccountStateModel => AccountStateModel.Instance; - - public string Greeting - { - //TODO: 应用一言 https://developer.hitokoto.cn/ - get - { - var hour = DateTime.Now.Hour; - switch (hour) - { - case int n when n >= 0 && n < 6: - return "Greetings_MidNight".GetLocalized(); - case int n when n >= 6 && n < 12: - return "Greetings_Morning".GetLocalized(); - case int n when n >= 12 && n < 14: - return "Greetings_Noon".GetLocalized(); - case int n when n >= 14 && n < 18: - return "Greetings_Afternoon".GetLocalized(); - default: - return "Greetings_Night".GetLocalized(); - } - } - } - public INavigationService NavigationService { get; } public void PersonalCenterPage_OnLoaded(object sender, RoutedEventArgs e) diff --git a/NonsPlayer/ViewModels/Pages/PersonalPages/LoginViewModel.cs b/NonsPlayer/ViewModels/Pages/PersonalPages/LoginViewModel.cs new file mode 100644 index 0000000..6cf0dde --- /dev/null +++ b/NonsPlayer/ViewModels/Pages/PersonalPages/LoginViewModel.cs @@ -0,0 +1,41 @@ +using System.Collections.ObjectModel; +using System.Drawing.Imaging; +using CommunityToolkit.Mvvm.ComponentModel; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Imaging; +using Newtonsoft.Json.Linq; +using NonsPlayer.Contracts.ViewModels; +using NonsPlayer.Core.Contracts.Adapters; +using NonsPlayer.Core.Contracts.Models.Nons; +using NonsPlayer.Core.Nons; +using NonsPlayer.Helpers; +using NonsPlayer.Models; +using QRCoder; + +namespace NonsPlayer.ViewModels; + +public partial class LoginViewModel : ObservableObject, INavigationAware +{ + public ObservableCollection LoginModels; + [ObservableProperty] private string platForm; + [ObservableProperty] private ImageBrush avatar; + + public IAdapter Adapter; + + public async void OnNavigatedTo(object parameter) + { + Adapter = parameter as IAdapter; + if (Adapter != null) + { + PlatForm = Adapter.GetMetadata().DisplayPlatform; + Avatar = await CacheHelper.GetImageBrushAsync( + Adapter.Account.GetAccount().CacheAvatarId, + await Adapter.Account.GetAccount().GetAvatarUrl()); + } + } + + public void OnNavigatedFrom() + { + } +} \ No newline at end of file diff --git a/NonsPlayer/ViewModels/Pages/PersonalPages/PersonalLibaryViewModel.cs b/NonsPlayer/ViewModels/Pages/PersonalPages/PersonalLibaryViewModel.cs new file mode 100644 index 0000000..746b036 --- /dev/null +++ b/NonsPlayer/ViewModels/Pages/PersonalPages/PersonalLibaryViewModel.cs @@ -0,0 +1,21 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using NonsPlayer.Contracts.ViewModels; +using NonsPlayer.Core.Contracts.Adapters; + +namespace NonsPlayer.ViewModels; + +public partial class PersonalLibaryViewModel : ObservableRecipient, INavigationAware +{ + public PersonalLibaryViewModel() + { + } + + public void OnNavigatedTo(object parameter) + { + var adapter = parameter as IAdapter; + } + + public void OnNavigatedFrom() + { + } +} diff --git a/NonsPlayer/ViewModels/ShellViewModel.cs b/NonsPlayer/ViewModels/ShellViewModel.cs index 9f8a2e2..04f7852 100644 --- a/NonsPlayer/ViewModels/ShellViewModel.cs +++ b/NonsPlayer/ViewModels/ShellViewModel.cs @@ -28,8 +28,6 @@ public ShellViewModel(INavigationService navigationService) NavigationService.Navigated += OnNavigated; } - public AccountStateModel AccountStateModel => AccountStateModel.Instance; - public bool IsBackEnabled { get => _isBackEnabled; diff --git a/NonsPlayer/Views/Pages/LoginPage.xaml b/NonsPlayer/Views/Pages/LoginPage.xaml deleted file mode 100644 index a0d75a8..0000000 --- a/NonsPlayer/Views/Pages/LoginPage.xaml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NonsPlayer/Views/Pages/LoginPage.xaml.cs b/NonsPlayer/Views/Pages/LoginPage.xaml.cs deleted file mode 100644 index 4afa202..0000000 --- a/NonsPlayer/Views/Pages/LoginPage.xaml.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.UI.Xaml.Controls; -using NonsPlayer.ViewModels; - -namespace NonsPlayer.Views.Pages; - -public sealed partial class LoginPage : Page -{ - //TODO: 为适配器提供 - public LoginPage() - { - ViewModel = App.GetService(); - InitializeComponent(); - ViewModel.Init(); - } - - public LoginViewModel ViewModel { get; } -} \ No newline at end of file diff --git a/NonsPlayer/Views/Pages/MainPages/PersonalCenterPage.xaml b/NonsPlayer/Views/Pages/MainPages/PersonalCenterPage.xaml index aa29d81..a4cdb6c 100644 --- a/NonsPlayer/Views/Pages/MainPages/PersonalCenterPage.xaml +++ b/NonsPlayer/Views/Pages/MainPages/PersonalCenterPage.xaml @@ -8,27 +8,13 @@ Loaded="{x:Bind ViewModel.PersonalCenterPage_OnLoaded}"> - - - - - - - - - - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/NonsPlayer/Views/Pages/MainPages/PersonalCenterPage.xaml.cs b/NonsPlayer/Views/Pages/MainPages/PersonalCenterPage.xaml.cs index ce79fa1..b26af99 100644 --- a/NonsPlayer/Views/Pages/MainPages/PersonalCenterPage.xaml.cs +++ b/NonsPlayer/Views/Pages/MainPages/PersonalCenterPage.xaml.cs @@ -1,5 +1,12 @@ -using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Text; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media.Animation; +using NonsPlayer.Contracts.ViewModels; +using NonsPlayer.Core.Contracts.Adapters; +using NonsPlayer.Core.Services; +using NonsPlayer.Helpers; using NonsPlayer.ViewModels; +using TagLib.Id3v2; namespace NonsPlayer.Views.Pages; @@ -9,7 +16,62 @@ public PersonalCenterPage() { ViewModel = App.GetService(); InitializeComponent(); + RefreshInfo(); } public PersonalCenterViewModel ViewModel { get; } + + private void RefreshInfo() + { + SelectorBar.Items.Clear(); + var adapters = AdapterService.Instance.GetAdaptersByType(ISubAdapterEnum.Account); + foreach (var adapter in adapters) + { + var metaData = adapter.GetMetadata(); + SelectorBar.Items.Add( + new SelectorBarItem + { + Text = metaData.DisplayPlatform, + Tag = adapter, + FontSize = 20, + FontWeight = FontWeights.Bold + }); + } + + SelectorBar.Items.Add(new() + { + Text = "SettingsText".GetLocalized(), + Tag = "setting" + }); + } + + private async void SelectorBar_OnSelectionChanged(SelectorBar sender, SelectorBarSelectionChangedEventArgs args) + { + var selectedItem = sender.SelectedItem as SelectorBarItem; + var currentSelectedIndex = sender.Items.IndexOf(selectedItem); + if (selectedItem.Tag is string) + { + return; + } + + var adapter = selectedItem.Tag as IAdapter; + if (adapter.Account.GetAccount().IsLoggedIn) + { + Navigate(typeof(PersonalLibaryPage), adapter); + } + else + { + Navigate(typeof(LoginPage), adapter); + } + } + + private void Navigate(Type pageType, object parameter) + { + var navigated = ContentFrame.Navigate(pageType, parameter); + var vmBeforeNavigation = ContentFrame.GetPageViewModel(); + if (navigated) + { + if (vmBeforeNavigation is INavigationAware navigationAware) navigationAware.OnNavigatedTo(parameter); + } + } } \ No newline at end of file diff --git a/NonsPlayer/Views/Pages/PersonalPages/LoginPage.xaml b/NonsPlayer/Views/Pages/PersonalPages/LoginPage.xaml new file mode 100644 index 0000000..13ac5a8 --- /dev/null +++ b/NonsPlayer/Views/Pages/PersonalPages/LoginPage.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NonsPlayer/Views/Pages/PersonalPages/LoginPage.xaml.cs b/NonsPlayer/Views/Pages/PersonalPages/LoginPage.xaml.cs new file mode 100644 index 0000000..6f7b473 --- /dev/null +++ b/NonsPlayer/Views/Pages/PersonalPages/LoginPage.xaml.cs @@ -0,0 +1,47 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using NonsPlayer.Contracts.ViewModels; +using NonsPlayer.Core.Contracts.Models.Nons; +using NonsPlayer.ViewModels; + +namespace NonsPlayer.Views.Pages; + +[INotifyPropertyChanged] +public sealed partial class LoginPage : Page +{ + [ObservableProperty] private bool previousButtonEnable; + + public LoginPage() + { + ViewModel = App.GetService(); + InitializeComponent(); + CheckButtonEnable(); + } + + public LoginViewModel ViewModel { get; } + + private void NextButton_Clicked(object sender, RoutedEventArgs e) + { + LoginCardView.SelectedIndex = 1; + if (LoginCardView.SelectedIndex == 1) PreviousButtonEnable = true; + } + + private void PreviousButton_Clicked(object sender, RoutedEventArgs e) + { + LoginCardView.SelectedIndex = 0; + if (LoginCardView.SelectedIndex == 0) PreviousButtonEnable = false; + + } + + private void LoginCardView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + CheckButtonEnable(); + } + + private void CheckButtonEnable() + { + if (LoginCardView.SelectedIndex == 0) PreviousButtonEnable = false; + if (LoginCardView.SelectedIndex == 1) PreviousButtonEnable = true; + } +} \ No newline at end of file diff --git a/NonsPlayer/Views/Pages/PersonalPages/PersonalLibaryPage.xaml b/NonsPlayer/Views/Pages/PersonalPages/PersonalLibaryPage.xaml new file mode 100644 index 0000000..ff94d7d --- /dev/null +++ b/NonsPlayer/Views/Pages/PersonalPages/PersonalLibaryPage.xaml @@ -0,0 +1,12 @@ + + + + + + diff --git a/NonsPlayer/Views/Pages/PersonalPages/PersonalLibaryPage.xaml.cs b/NonsPlayer/Views/Pages/PersonalPages/PersonalLibaryPage.xaml.cs new file mode 100644 index 0000000..88678fb --- /dev/null +++ b/NonsPlayer/Views/Pages/PersonalPages/PersonalLibaryPage.xaml.cs @@ -0,0 +1,19 @@ +using Microsoft.UI.Xaml.Controls; + +using NonsPlayer.ViewModels; + +namespace NonsPlayer.Views; + +public sealed partial class PersonalLibaryPage : Page +{ + public PersonalLibaryViewModel ViewModel + { + get; + } + + public PersonalLibaryPage() + { + ViewModel = App.GetService(); + InitializeComponent(); + } +}