From fee511cf335d02a6652cd72fac49ab0724c528be Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Sun, 24 Oct 2021 17:48:54 +0800 Subject: [PATCH] =?UTF-8?q?PagePublicFavorites=E5=BC=80=E5=8F=91=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E4=B8=AD=EF=BC=8C=E5=AE=8C=E6=88=90=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=EF=BC=8C20211024=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/FavoritesMediaResource.cs | 2 +- DownKyi/Models/FavoritesMedia.cs | 72 +++++++- DownKyi/Services/FavoritesService.cs | 44 ++++- DownKyi/Services/IFavoritesService.cs | 4 +- DownKyi/Themes/ColorBrush.xaml | 2 + DownKyi/Themes/Colors/ColorDefault.xaml | 2 + .../ViewPublicFavoritesViewModel.cs | 17 +- DownKyi/Views/ViewPublicFavorites.xaml | 160 +++++++++++++++++- 8 files changed, 283 insertions(+), 20 deletions(-) diff --git a/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaResource.cs b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaResource.cs index bdd30b5..edaa0d7 100644 --- a/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaResource.cs +++ b/DownKyi.Core/BiliApi/Favorites/Models/FavoritesMediaResource.cs @@ -24,7 +24,7 @@ namespace DownKyi.Core.BiliApi.Favorites.Models [JsonProperty("medias")] public List Medias { get; set; } [JsonProperty("has_more")] - public int HasMore { get; set; } + public bool HasMore { get; set; } } } diff --git a/DownKyi/Models/FavoritesMedia.cs b/DownKyi/Models/FavoritesMedia.cs index 666c2b5..562544b 100644 --- a/DownKyi/Models/FavoritesMedia.cs +++ b/DownKyi/Models/FavoritesMedia.cs @@ -1,13 +1,75 @@ using Prism.Mvvm; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Windows.Media.Imaging; namespace DownKyi.Models { public class FavoritesMedia : BindableBase { + public long Avid { get; set; } + public string Bvid { get; set; } + public long UpperMid { get; set; } + + private bool isSelected; + public bool IsSelected + { + get { return isSelected; } + set { SetProperty(ref isSelected, value); } + } + + private int order; + public int Order + { + get { return order; } + set { SetProperty(ref order, value); } + } + + private BitmapImage cover; + public BitmapImage Cover + { + get { return cover; } + set { SetProperty(ref cover, value); } + } + + private string title; + public string Title + { + get { return title; } + set { SetProperty(ref title, value); } + } + + private string playNumber; + public string PlayNumber + { + get { return playNumber; } + set { SetProperty(ref playNumber, value); } + } + + private string danmakuNumber; + public string DanmakuNumber + { + get { return danmakuNumber; } + set { SetProperty(ref danmakuNumber, value); } + } + + private string favoriteNumber; + public string FavoriteNumber + { + get { return favoriteNumber; } + set { SetProperty(ref favoriteNumber, value); } + } + + private string duration; + public string Duration + { + get { return duration; } + set { SetProperty(ref duration, value); } + } + + private string upName; + public string UpName + { + get { return upName; } + set { SetProperty(ref upName, value); } + } } } diff --git a/DownKyi/Services/FavoritesService.cs b/DownKyi/Services/FavoritesService.cs index cc542b7..a619554 100644 --- a/DownKyi/Services/FavoritesService.cs +++ b/DownKyi/Services/FavoritesService.cs @@ -3,7 +3,9 @@ using DownKyi.Core.Storage; using DownKyi.Core.Utils; using DownKyi.Models; using System; -using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading; using System.Windows.Media.Imaging; namespace DownKyi.Services @@ -82,9 +84,45 @@ namespace DownKyi.Services /// /// /// - public List GetFavoritesMediaList(long mediaId) + public void GetFavoritesMediaList(long mediaId, ObservableCollection result) { - throw new NotImplementedException(); + var medias = FavoritesResource.GetAllFavoritesMedia(mediaId); + if (medias.Count == 0) { return; } + + int order = 0; + foreach (var media in medias) + { + order++; + + // 查询、保存封面 + StorageCover storageCover = new StorageCover(); + string coverUrl = media.Cover; + string cover = storageCover.GetCover(media.Id, media.Bvid, -1, coverUrl); + + App.PropertyChangeAsync(new Action(() => + { + FavoritesMedia newMedia = new FavoritesMedia + { + Avid = media.Id, + Bvid = media.Bvid, + Order = order, + Cover = cover == null ? null : new BitmapImage(new Uri(cover)), + Title = media.Title, + PlayNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Play) : "0", + DanmakuNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Danmaku) : "0", + FavoriteNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Collect) : "0", + Duration = Format.FormatDuration2(media.Duration), + UpName = media.Upper != null ? media.Upper.Name : string.Empty, + UpperMid = media.Upper != null ? media.Upper.Mid : -1 + }; + + if (!result.ToList().Exists(t => t.Avid == newMedia.Avid)) + { + result.Add(newMedia); + Thread.Sleep(50); + } + })); + } } } } diff --git a/DownKyi/Services/IFavoritesService.cs b/DownKyi/Services/IFavoritesService.cs index 42e721b..96ec9d8 100644 --- a/DownKyi/Services/IFavoritesService.cs +++ b/DownKyi/Services/IFavoritesService.cs @@ -1,11 +1,11 @@ using DownKyi.Models; -using System.Collections.Generic; +using System.Collections.ObjectModel; namespace DownKyi.Services { public interface IFavoritesService { Favorites GetFavorites(long mediaId); - List GetFavoritesMediaList(long mediaId); + void GetFavoritesMediaList(long mediaId, ObservableCollection result); } } diff --git a/DownKyi/Themes/ColorBrush.xaml b/DownKyi/Themes/ColorBrush.xaml index 64dc369..bc81eda 100644 --- a/DownKyi/Themes/ColorBrush.xaml +++ b/DownKyi/Themes/ColorBrush.xaml @@ -28,6 +28,8 @@ + + diff --git a/DownKyi/Themes/Colors/ColorDefault.xaml b/DownKyi/Themes/Colors/ColorDefault.xaml index b12aca1..fd949c1 100644 --- a/DownKyi/Themes/Colors/ColorDefault.xaml +++ b/DownKyi/Themes/Colors/ColorDefault.xaml @@ -28,6 +28,8 @@ #7FBDBDBD #33BDBDBD + #7F000000 + #FFF4F4F4 #FFF4F4F4 diff --git a/DownKyi/ViewModels/ViewPublicFavoritesViewModel.cs b/DownKyi/ViewModels/ViewPublicFavoritesViewModel.cs index 54240d6..1f268fe 100644 --- a/DownKyi/ViewModels/ViewPublicFavoritesViewModel.cs +++ b/DownKyi/ViewModels/ViewPublicFavoritesViewModel.cs @@ -6,11 +6,9 @@ using DownKyi.Services; using DownKyi.Utils; using Prism.Commands; using Prism.Events; -using Prism.Mvvm; using Prism.Regions; using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Windows; @@ -64,11 +62,11 @@ namespace DownKyi.ViewModels set { SetProperty(ref favorites, value); } } - private List favoritesMedia; - public List FavoritesMedia + private ObservableCollection favoritesMedias; + public ObservableCollection FavoritesMedias { - get { return favoritesMedia; } - set { SetProperty(ref favoritesMedia, value); } + get { return favoritesMedias; } + set { SetProperty(ref favoritesMedias, value); } } private Visibility contentVisibility; @@ -106,6 +104,8 @@ namespace DownKyi.ViewModels Share = NormalIcon.Instance().Share; Share.Fill = DictionaryResource.GetColor("ColorTextGrey2"); + FavoritesMedias = new ObservableCollection(); + #endregion } @@ -202,6 +202,8 @@ namespace DownKyi.ViewModels ContentVisibility = Visibility.Collapsed; NoDataVisibility = Visibility.Collapsed; + + FavoritesMedias.Clear(); } /// @@ -224,6 +226,7 @@ namespace DownKyi.ViewModels NoDataVisibility = Visibility.Collapsed; } + favoritesService.GetFavoritesMediaList(favoritesId, FavoritesMedias); } /// diff --git a/DownKyi/Views/ViewPublicFavorites.xaml b/DownKyi/Views/ViewPublicFavorites.xaml index 68740bc..d768a26 100644 --- a/DownKyi/Views/ViewPublicFavorites.xaml +++ b/DownKyi/Views/ViewPublicFavorites.xaml @@ -281,9 +281,165 @@ Style="{StaticResource BtnStyle}" /> - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +