Files
Pixiview/Pixiview/Illust/RecommendsPage.xaml.cs

81 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Pixiview.Utils;
using Xamarin.Forms;
namespace Pixiview.Illust
{
public partial class RecommendsPage : IllustDataCollectionPage
{
public static readonly BindableProperty SegmentIndexProperty = BindableProperty.Create(
nameof(SegmentIndex), typeof(int), typeof(RecommendsPage), propertyChanged: OnSegmentIndexPropertyChanged);
private static void OnSegmentIndexPropertyChanged(BindableObject obj, object oldValue, object newValue)
{
var page = (RecommendsPage)obj;
Task.Run(() => page.DoLoadIllusts());
}
public int SegmentIndex
{
get => (int)GetValue(SegmentIndexProperty);
set => SetValue(SegmentIndexProperty, value);
}
public RecommendsPage()
{
Resources.Add("cardView", GetCardViewTemplate());
InitializeComponent();
}
protected override IEnumerable<IllustItem> DoGetIllustList(IllustData data, ICommand command)
{
if (SegmentIndex == 1)
{
// by user
return data.body.page.recommendUser.SelectMany(i => i.illustIds)
.Select(id =>
{
var item = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == id)?.ConvertToItem();
if (item != null)
{
item.IllustTapped = command;
}
return item;
});
}
else
{
// recommends
return data.body.page.recommend.Select(id =>
{
var item = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == id)?.ConvertToItem();
if (item != null)
{
item.IllustTapped = command;
}
return item;
});
}
}
protected override IllustData DoLoadIllustData(bool force)
{
var illustData = Stores.LoadIllustData(force);
return illustData;
}
private void Refresh_Clicked(object sender, EventArgs e)
{
if (IsLoading)
{
return;
}
StartLoad(true);
}
}
}