feature: user illusts page

This commit is contained in:
2020-05-15 00:23:34 +08:00
parent 8cbca8f290
commit 90816bc57e
6 changed files with 109 additions and 24 deletions

View File

@@ -14,9 +14,9 @@ namespace Pixiview.Illust
{
public abstract class FavoriteIllustCollectionPage : IllustCollectionPage<IllustItem[]> { }
public abstract class IllustDataCollectionPage : IllustCollectionPage<IllustData> { }
public abstract class IllustUserDataCollectionPage : IllustCollectionPage<IllustUserData> { }
public abstract class IllustRankingDataCollectionPage : IllustScrollableCollectionPage<IllustRankingData> { }
public abstract class IllustRecommendsCollectionPage : IllustScrollableCollectionPage<IllustRecommendsData> { }
public abstract class IllustUserDataCollectionPage : IllustScrollableCollectionPage<IllustUserData> { }
public interface IIllustCollectionPage
{

View File

@@ -12,8 +12,8 @@
IconImageSource="{DynamicResource FontIconRefresh}"/>
</ContentPage.ToolbarItems>
<Grid>
<ScrollView x:Name="scrollView" Scrolled="ScrollView_Scrolled"
HorizontalOptions="Fill" HorizontalScrollBarVisibility="Never">
<ScrollView x:Name="scrollView" Scrolled="ScrollView_Scrolled"
HorizontalOptions="Fill" HorizontalScrollBarVisibility="Never">
<u:FlowLayout ItemsSource="{Binding Illusts}" MaxHeightChanged="FlowLayout_MaxHeightChanged"
HorizontalOptions="Fill" Column="{Binding Columns}"
Margin="16" RowSpacing="16" ColumnSpacing="16"

View File

@@ -61,7 +61,6 @@ namespace Pixiview.Illust
if (ids.Length == 0 || nextIndex >= illustIds.Length)
{
// done
App.DebugPrint($"download completed: {startIndex}");
startIndex = nextIndex;
}

View File

@@ -6,9 +6,10 @@
x:Class="Pixiview.Illust.UserIllustPage"
BackgroundColor="{DynamicResource WindowColor}">
<Shell.TitleView>
<StackLayout Orientation="Horizontal" Padding="0, 2, 0, 4">
<StackLayout Orientation="Horizontal">
<u:CircleImage Aspect="AspectFill" Source="{Binding UserIcon}"
WidthRequest="{x:OnPlatform Android=40}">
VerticalOptions="Center"
WidthRequest="34" HeightRequest="34" >
<u:CircleImage.Margin>
<OnPlatform x:TypeArguments="Thickness" Android="0, 5, 0, 5"/>
</u:CircleImage.Margin>
@@ -23,8 +24,9 @@
IconImageSource="{DynamicResource FontIconRefresh}"/>
</ContentPage.ToolbarItems>
<Grid>
<ScrollView HorizontalOptions="Fill" HorizontalScrollBarVisibility="Never">
<u:FlowLayout ItemsSource="{Binding Illusts}"
<ScrollView x:Name="scrollView" Scrolled="ScrollView_Scrolled"
HorizontalOptions="Fill" HorizontalScrollBarVisibility="Never">
<u:FlowLayout ItemsSource="{Binding Illusts}" MaxHeightChanged="FlowLayout_MaxHeightChanged"
HorizontalOptions="Fill" Column="{Binding Columns}"
Margin="16" RowSpacing="16" ColumnSpacing="16"
ItemTemplate="{StaticResource cardView}"/>

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Pixiview.UI;
using Pixiview.Utils;
using Xamarin.Forms;
@@ -8,6 +9,8 @@ namespace Pixiview.Illust
{
public partial class UserIllustPage : IllustUserDataCollectionPage
{
private const int STEP = 48;
public static readonly BindableProperty UserIconProperty = BindableProperty.Create(
nameof(UserIcon), typeof(ImageSource), typeof(UserIllustPage));
@@ -19,6 +22,10 @@ namespace Pixiview.Illust
public IIllustUser UserItem { get; }
private int startIndex;
private int nextIndex;
private string[] illustIds;
public UserIllustPage(IIllustUser item)
{
UserItem = item;
@@ -26,6 +33,9 @@ namespace Pixiview.Illust
Resources.Add("cardView", GetCardViewTemplate(true));
InitializeComponent();
startIndex = -1;
nextIndex = 0;
}
protected override IEnumerable<IllustItem> DoGetIllustList(IllustUserData data)
@@ -39,7 +49,56 @@ namespace Pixiview.Illust
protected override IllustUserData DoLoadIllustData(bool force)
{
return Stores.LoadIllustUserData(UserItem.UserId, force);
var userId = UserItem.UserId;
if (startIndex < 0)
{
var init = Stores.LoadIllustUserInitData(userId);
if (init == null || init.body == null)
{
return null;
}
illustIds = init.body.illusts.Keys.OrderByDescending(i => i).ToArray();
startIndex = 0;
}
if (illustIds == null || startIndex >= illustIds.Length)
{
return null;
}
var ids = illustIds.Skip(startIndex).Take(STEP).ToArray();
var data = Stores.LoadIllustUserData(userId, ids, startIndex == 0);
nextIndex = startIndex + STEP;
if (ids.Length == 0 || nextIndex >= illustIds.Length)
{
// done
App.DebugPrint($"download completed: {startIndex}");
startIndex = nextIndex;
}
return data;
}
private void FlowLayout_MaxHeightChanged(object sender, HeightEventArgs e)
{
if (e.ContentHeight > 0)
{
SetOffset(e.ContentHeight - scrollView.Bounds.Height - SCROLL_OFFSET);
}
}
protected override bool CheckRefresh()
{
if (nextIndex > startIndex)
{
startIndex = nextIndex;
return true;
}
return false;
}
private void ScrollView_Scrolled(object sender, ScrolledEventArgs e)
{
var y = e.ScrollY;
OnScrolled(y);
}
private void Refresh_Clicked(object sender, EventArgs e)
@@ -48,6 +107,16 @@ namespace Pixiview.Illust
{
return;
}
// release
var collection = IllustCollection;
if (collection != null)
{
collection.Running = false;
IllustCollection = null;
}
startIndex = -1;
nextIndex = 0;
illustIds = null;
StartLoad(true);
}
}