完成粉丝页面

croire 2 years ago
parent 60813ce903
commit 05b678e2b8

@ -72,7 +72,7 @@
<Setter Property="Background" Value="#FFFFFFFF" />
<Setter Property="BorderBrush" Value="#FFD7DDE4" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Width" Value="30" />
<Setter Property="MinWidth" Value="30" />
<Setter Property="Height" Value="30" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
@ -136,6 +136,7 @@
Style="{StaticResource pagerButton}"
Visibility="{Binding FirstVisibility}">
<TextBlock
Padding="10,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
@ -174,6 +175,7 @@
Style="{StaticResource pagerButton}"
Visibility="{Binding PreviousSecondVisibility}">
<TextBlock
Padding="10,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
@ -200,6 +202,7 @@
Style="{StaticResource pagerButton}"
Visibility="{Binding PreviousFirstVisibility}">
<TextBlock
Padding="10,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
@ -239,6 +242,7 @@
Style="{StaticResource pagerButton}"
Visibility="{Binding NextFirstVisibility}">
<TextBlock
Padding="10,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
@ -265,6 +269,7 @@
Style="{StaticResource pagerButton}"
Visibility="{Binding NextSecondVisibility}">
<TextBlock
Padding="10,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
@ -303,6 +308,7 @@
Style="{StaticResource pagerButton}"
Visibility="{Binding LastVisibility}">
<TextBlock
Padding="10,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"

@ -103,6 +103,8 @@
<system:String x:Key="FriendFollower">粉丝</system:String>
<system:String x:Key="FollowingWait">请稍等,马上就好~</system:String>
<system:String x:Key="FollowerWait">请稍等,马上就好~</system:String>
<system:String x:Key="AllFollowing">全部关注</system:String>
<system:String x:Key="WhisperFollowing">悄悄关注</system:String>

@ -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<FriendInfo> contents;
public ObservableCollection<FriendInfo> 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<FriendInfo>();
#endregion
}
@ -21,5 +100,140 @@ namespace DownKyi.ViewModels.Friends
#endregion
private void LoadContent(List<RelationFollowInfo> 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<RelationFollowInfo> 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;
}
/// <summary>
/// 初始化页面数据
/// </summary>
private void InitView()
{
ContentVisibility = Visibility.Collapsed;
LoadingVisibility = Visibility.Visible;
NoDataVisibility = Visibility.Collapsed;
Contents.Clear();
}
/// <summary>
/// 导航到页面时执行
/// </summary>
/// <param name="navigationContext"></param>
public override void OnNavigatedTo(NavigationContext navigationContext)
{
base.OnNavigatedTo(navigationContext);
// 传入mid
long parameter = navigationContext.Parameters.GetValue<long>("mid");
if (parameter == 0)
{
return;
}
mid = parameter;
// 是否是从PageFriends的headerTable的item点击进入的
// true表示加载PageFriends后第一次进入此页面
// false表示从headerTable的item点击进入的
bool isFirst = navigationContext.Parameters.GetValue<bool>("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;
}
}
}
}

@ -8,10 +8,146 @@
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<UserControl.Resources>
<converter:CountConverter x:Key="CountConverter" Count="1" />
<Style x:Key="ContentListStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid
Name="nameUserPanel"
Width="400"
Height="80"
Margin="15,15,10,5"
Cursor="Hand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding UserCommand}" CommandParameter="{Binding DataContext.PageName, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Image
Grid.Column="0"
Width="64"
Height="64"
Source="{Binding Header}">
<Image.Clip>
<EllipseGeometry
Center="32,32"
RadiusX="32"
RadiusY="32" />
</Image.Clip>
</Image>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Foreground="{DynamicResource BrushTextDark}"
Text="{Binding Name}"
TextTrimming="CharacterEllipsis"
TextWrapping="WrapWithOverflow" />
<TextBlock
Grid.Row="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
FontSize="12"
Foreground="{DynamicResource BrushTextGrey2}"
Text="{Binding Sign}"
TextTrimming="CharacterEllipsis"
TextWrapping="WrapWithOverflow"
ToolTip="{Binding Sign}" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<TextBlock Text="粉丝" />
<Grid Grid.Column="1" Visibility="{Binding ContentVisibility}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<ListBox
x:Name="nameContents"
Grid.Row="0"
BorderThickness="0"
ItemContainerStyle="{StaticResource ContentListStyle}"
ItemsSource="{Binding Contents}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ContentsCommand}" CommandParameter="{Binding ElementName=nameContents, Path=SelectedItems}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Style>
<Style TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Border
x:Name="Bd"
Padding="0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer Focusable="False">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Style>
</ListBox>
<custom:CustomPager
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
DataContext="{Binding Pager}" />
</Grid>
<!-- 加载gif -->
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical"
Visibility="{Binding LoadingVisibility}">
<ContentControl
Width="40"
Height="40"
Content="{Binding Loading}" />
<TextBlock
Margin="0,10,0,0"
FontSize="14"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource FollowerWait}" />
</StackPanel>
<!-- 没有数据提示 -->
<Image
Width="256"
Height="256"
Source="/DownKyi;component/Resources/no-data.png"
Visibility="{Binding NoDataVisibility}" />
</Grid>
</UserControl>

@ -11,7 +11,6 @@
<converter:CountConverter x:Key="CountConverter" Count="1" />
<Style x:Key="ContentListStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding IsSelected}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">

Loading…
Cancel
Save