From 05b678e2b898298a6d1b2b9798905b3c95b72d9f Mon Sep 17 00:00:00 2001
From: croire <1432593898@qq.com>
Date: Sat, 5 Nov 2022 21:30:47 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=B2=89=E4=B8=9D=E9=A1=B5?=
=?UTF-8?q?=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DownKyi/CustomControl/CustomPager.xaml | 8 +-
DownKyi/Languages/Default.xaml | 2 +
.../Friends/ViewFollowerViewModel.cs | 216 +++++++++++++++++-
DownKyi/Views/Friends/ViewFollower.xaml | 140 +++++++++++-
DownKyi/Views/Friends/ViewFollowing.xaml | 1 -
5 files changed, 362 insertions(+), 5 deletions(-)
diff --git a/DownKyi/CustomControl/CustomPager.xaml b/DownKyi/CustomControl/CustomPager.xaml
index 499752c..2b512f2 100644
--- a/DownKyi/CustomControl/CustomPager.xaml
+++ b/DownKyi/CustomControl/CustomPager.xaml
@@ -72,7 +72,7 @@
-
+
@@ -136,6 +136,7 @@
Style="{StaticResource pagerButton}"
Visibility="{Binding FirstVisibility}">
粉丝
请稍等,马上就好~
+ 请稍等,马上就好~
+
全部关注
悄悄关注
diff --git a/DownKyi/ViewModels/Friends/ViewFollowerViewModel.cs b/DownKyi/ViewModels/Friends/ViewFollowerViewModel.cs
index 2e337a9..5e91eaa 100644
--- a/DownKyi/ViewModels/Friends/ViewFollowerViewModel.cs
+++ b/DownKyi/ViewModels/Friends/ViewFollowerViewModel.cs
@@ -1,4 +1,18 @@
-using Prism.Events;
+using DownKyi.Core.BiliApi.Users;
+using DownKyi.Core.BiliApi.Users.Models;
+using DownKyi.Core.Settings.Models;
+using DownKyi.Core.Settings;
+using DownKyi.Core.Storage;
+using DownKyi.CustomControl;
+using DownKyi.ViewModels.PageViewModels;
+using Prism.Events;
+using Prism.Regions;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Media.Imaging;
namespace DownKyi.ViewModels.Friends
{
@@ -6,14 +20,79 @@ namespace DownKyi.ViewModels.Friends
{
public const string Tag = "PageFriendsFollower";
+ // mid
+ private long mid = -1;
+
+ // 每页数量,暂时在此写死,以后在设置中增加选项
+ private readonly int NumberInPage = 20;
+
+ public bool IsEnabled = true;
+
#region 页面属性申明
+ private string pageName = ViewFriendsViewModel.Tag;
+ public string PageName
+ {
+ get => pageName;
+ set => SetProperty(ref pageName, value);
+ }
+
+ private Visibility contentVisibility;
+ public Visibility ContentVisibility
+ {
+ get => contentVisibility;
+ set => SetProperty(ref contentVisibility, value);
+ }
+
+ private GifImage loading;
+ public GifImage Loading
+ {
+ get => loading;
+ set => SetProperty(ref loading, value);
+ }
+
+ private Visibility loadingVisibility;
+ public Visibility LoadingVisibility
+ {
+ get => loadingVisibility;
+ set => SetProperty(ref loadingVisibility, value);
+ }
+
+ private Visibility noDataVisibility;
+ public Visibility NoDataVisibility
+ {
+ get => noDataVisibility;
+ set => SetProperty(ref noDataVisibility, value);
+ }
+
+ private CustomPagerViewModel pager;
+ public CustomPagerViewModel Pager
+ {
+ get => pager;
+ set => SetProperty(ref pager, value);
+ }
+
+ private ObservableCollection contents;
+ public ObservableCollection Contents
+ {
+ get => contents;
+ set => SetProperty(ref contents, value);
+ }
+
#endregion
public ViewFollowerViewModel(IEventAggregator eventAggregator) : base(eventAggregator)
{
#region 属性初始化
+ // 初始化loading gif
+ Loading = new GifImage(Properties.Resources.loading);
+ Loading.StartAnimate();
+ LoadingVisibility = Visibility.Collapsed;
+ NoDataVisibility = Visibility.Collapsed;
+
+ Contents = new ObservableCollection();
+
#endregion
}
@@ -21,5 +100,140 @@ namespace DownKyi.ViewModels.Friends
#endregion
+ private void LoadContent(List contents)
+ {
+ ContentVisibility = Visibility.Visible;
+ LoadingVisibility = Visibility.Collapsed;
+ NoDataVisibility = Visibility.Collapsed;
+ foreach (var item in contents)
+ {
+ StorageHeader storageHeader = new StorageHeader();
+ BitmapImage header = storageHeader.GetHeaderThumbnail(item.Mid, item.Name, item.Face, 64, 64);
+ App.PropertyChangeAsync(new Action(() =>
+ {
+ Contents.Add(new FriendInfo(eventAggregator) { Mid = item.Mid, Header = header, Name = item.Name, Sign = item.Sign });
+ }));
+ }
+ }
+
+ private async void UpdateContent(int current)
+ {
+ // 是否正在获取数据
+ // 在所有的退出分支中都需要设为true
+ IsEnabled = false;
+
+ Contents.Clear();
+ ContentVisibility = Visibility.Collapsed;
+ LoadingVisibility = Visibility.Visible;
+ NoDataVisibility = Visibility.Collapsed;
+
+ RelationFollow data = null;
+ List contents = null;
+ await Task.Run(() =>
+ {
+ data = UserRelation.GetFollowers(mid, current, NumberInPage);
+ if (data != null && data.List != null && data.List.Count > 0)
+ {
+ contents = data.List;
+ }
+ if (contents == null) { return; }
+
+ LoadContent(contents);
+ });
+
+ if (data == null || contents == null)
+ {
+ ContentVisibility = Visibility.Collapsed;
+ LoadingVisibility = Visibility.Collapsed;
+ NoDataVisibility = Visibility.Visible;
+ }
+ else
+ {
+ UserInfoSettings userInfo = SettingsManager.GetInstance().GetUserInfo();
+ if (userInfo != null && userInfo.Mid == mid)
+ {
+ Pager.Count = (int)Math.Ceiling((double)data.Total / NumberInPage);
+ }
+ else
+ {
+ int page = (int)Math.Ceiling((double)data.Total / NumberInPage);
+ if (page > 5)
+ {
+ Pager.Count = 5;
+ }
+ else
+ {
+ Pager.Count = page;
+ }
+ }
+
+ ContentVisibility = Visibility.Visible;
+ LoadingVisibility = Visibility.Collapsed;
+ NoDataVisibility = Visibility.Collapsed;
+ }
+
+ IsEnabled = true;
+ }
+
+ private void OnCountChanged_Pager(int count) { }
+
+ private bool OnCurrentChanged_Pager(int old, int current)
+ {
+ if (!IsEnabled)
+ {
+ //Pager.Current = old;
+ return false;
+ }
+
+ UpdateContent(current);
+
+ return true;
+ }
+
+ ///
+ /// 初始化页面数据
+ ///
+ private void InitView()
+ {
+ ContentVisibility = Visibility.Collapsed;
+ LoadingVisibility = Visibility.Visible;
+ NoDataVisibility = Visibility.Collapsed;
+
+ Contents.Clear();
+ }
+
+ ///
+ /// 导航到页面时执行
+ ///
+ ///
+ public override void OnNavigatedTo(NavigationContext navigationContext)
+ {
+ base.OnNavigatedTo(navigationContext);
+
+ // 传入mid
+ long parameter = navigationContext.Parameters.GetValue("mid");
+ if (parameter == 0)
+ {
+ return;
+ }
+ mid = parameter;
+
+ // 是否是从PageFriends的headerTable的item点击进入的
+ // true表示加载PageFriends后第一次进入此页面
+ // false表示从headerTable的item点击进入的
+ bool isFirst = navigationContext.Parameters.GetValue("isFirst");
+ if (isFirst)
+ {
+ InitView();
+
+ //UpdateContent(1);
+
+ // 页面选择
+ Pager = new CustomPagerViewModel(1, (int)Math.Ceiling((double)1 / NumberInPage));
+ Pager.CurrentChanged += OnCurrentChanged_Pager;
+ Pager.CountChanged += OnCountChanged_Pager;
+ Pager.Current = 1;
+ }
+ }
}
}
diff --git a/DownKyi/Views/Friends/ViewFollower.xaml b/DownKyi/Views/Friends/ViewFollower.xaml
index b426740..d5b5a0d 100644
--- a/DownKyi/Views/Friends/ViewFollower.xaml
+++ b/DownKyi/Views/Friends/ViewFollower.xaml
@@ -8,10 +8,146 @@
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DownKyi/Views/Friends/ViewFollowing.xaml b/DownKyi/Views/Friends/ViewFollowing.xaml
index 846df92..bec5253 100644
--- a/DownKyi/Views/Friends/ViewFollowing.xaml
+++ b/DownKyi/Views/Friends/ViewFollowing.xaml
@@ -11,7 +11,6 @@