feature: segments control
This commit is contained in:
@@ -67,6 +67,8 @@ namespace Pixiview.Illust
|
||||
|
||||
#endregion
|
||||
|
||||
protected Thickness totalBarOffset;
|
||||
protected Thickness navigationBarOffset;
|
||||
protected bool loaded;
|
||||
|
||||
private T illustData;
|
||||
@@ -297,7 +299,7 @@ namespace Pixiview.Illust
|
||||
|
||||
#region - Illust Tasks -
|
||||
|
||||
void DoLoadIllusts(bool force = false)
|
||||
protected void DoLoadIllusts(bool force = false, bool skipImage = false)
|
||||
{
|
||||
illustData = DoLoadIllustData(force);
|
||||
if (illustData == null)
|
||||
@@ -321,7 +323,10 @@ namespace Pixiview.Illust
|
||||
Illusts = collection;
|
||||
Loading = false;
|
||||
|
||||
DoLoadImages(collection);
|
||||
if (!skipImage)
|
||||
{
|
||||
DoLoadImages(collection);
|
||||
}
|
||||
}
|
||||
|
||||
void DoLoadImages(IllustCollection collection)
|
||||
|
@@ -23,8 +23,7 @@
|
||||
CancelButtonColor="{DynamicResource SubTextColor}"
|
||||
Text="{Binding Keywords, Mode=TwoWay}"
|
||||
SearchButtonPressed="SearchBar_SearchButtonPressed"
|
||||
Unfocused="SearchBar_Unfocused"
|
||||
/>
|
||||
Unfocused="SearchBar_Unfocused"/>
|
||||
<Frame HasShadow="False" Margin="0" Padding="20" CornerRadius="8"
|
||||
IsVisible="{Binding Loading}"
|
||||
HorizontalOptions="Center" VerticalOptions="Center"
|
||||
|
@@ -19,9 +19,6 @@ namespace Pixiview.Illust
|
||||
set => SetValue(KeywordsProperty, value);
|
||||
}
|
||||
|
||||
private readonly Thickness totalBarOffset;
|
||||
private readonly Thickness navigationBarOffset;
|
||||
|
||||
public RankingPage()
|
||||
{
|
||||
totalBarOffset = new Thickness(0, AppShell.TotalBarOffset.Top + 50, 0, 0);
|
||||
|
@@ -11,13 +11,26 @@
|
||||
<ToolbarItem Order="Primary" Clicked="Refresh_Clicked"
|
||||
IconImageSource="{DynamicResource FontIconRefresh}"/>
|
||||
</ContentPage.ToolbarItems>
|
||||
<Grid>
|
||||
<Grid Padding="{Binding PageTopMargin}">
|
||||
<ScrollView HorizontalOptions="Fill">
|
||||
<u:FlowLayout ItemsSource="{Binding Illusts}"
|
||||
HorizontalOptions="Fill" Column="{Binding Columns}"
|
||||
Margin="16" RowSpacing="16" ColumnSpacing="16"
|
||||
Margin="16, 6, 16, 16" RowSpacing="16" ColumnSpacing="16"
|
||||
ItemTemplate="{StaticResource cardView}"/>
|
||||
</ScrollView>
|
||||
<Grid Margin="0, -40, 0, 0" VerticalOptions="Start" HeightRequest="40">
|
||||
<u:SegmentedControl VerticalOptions="Center" HorizontalOptions="Center"
|
||||
HeightRequest="30"
|
||||
BackgroundColor="{DynamicResource WindowColor}"
|
||||
TintColor="{DynamicResource SubTextColor}"
|
||||
SelectedTextColor="{DynamicResource TextColor}"
|
||||
SelectedSegmentIndex="{Binding SegmentIndex, Mode=TwoWay}">
|
||||
<u:SegmentedControl.Children>
|
||||
<u:SegmentedControlOption Text="{r:Text Recommends}"/>
|
||||
<u:SegmentedControlOption Text="{r:Text ByUser}"/>
|
||||
</u:SegmentedControl.Children>
|
||||
</u:SegmentedControl>
|
||||
</Grid>
|
||||
<Frame HasShadow="False" Margin="0" Padding="20" CornerRadius="8"
|
||||
IsVisible="{Binding Loading}"
|
||||
HorizontalOptions="Center" VerticalOptions="Center"
|
||||
|
@@ -2,16 +2,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using Pixiview.UI;
|
||||
using Pixiview.Utils;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Pixiview.Illust
|
||||
{
|
||||
public partial class RecommendsPage : IllustDataCollectionPage
|
||||
{
|
||||
public bool ByUser { get; set; }
|
||||
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;
|
||||
page.DoLoadIllusts();
|
||||
}
|
||||
|
||||
public int SegmentIndex
|
||||
{
|
||||
get => (int)GetValue(SegmentIndexProperty);
|
||||
set => SetValue(SegmentIndexProperty, value);
|
||||
}
|
||||
|
||||
private IllustData illustData;
|
||||
|
||||
public RecommendsPage()
|
||||
{
|
||||
totalBarOffset = new Thickness(0, AppShell.TotalBarOffset.Top + 40, 0, 0);
|
||||
navigationBarOffset = new Thickness(0, AppShell.NavigationBarOffset.Top + 40, 0, 0);
|
||||
|
||||
Resources.Add("cardView", GetCardViewTemplate());
|
||||
InitializeComponent();
|
||||
}
|
||||
@@ -27,10 +47,39 @@ namespace Pixiview.Illust
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
public override void OnOrientationChanged(Orientation orientation)
|
||||
{
|
||||
int columns;
|
||||
switch (orientation)
|
||||
{
|
||||
case Orientation.Portrait:
|
||||
columns = 2;
|
||||
PageTopMargin = totalBarOffset;
|
||||
break;
|
||||
case Orientation.PortraitUpsideDown:
|
||||
columns = isPhone ? 4 : 2;
|
||||
PageTopMargin = isPhone ? navigationBarOffset : totalBarOffset;
|
||||
break;
|
||||
case Orientation.Unknown:
|
||||
case Orientation.LandscapeLeft:
|
||||
case Orientation.LandscapeRight:
|
||||
default:
|
||||
columns = 4;
|
||||
PageTopMargin = navigationBarOffset;
|
||||
break;
|
||||
}
|
||||
if (Columns != columns)
|
||||
{
|
||||
App.DebugPrint($"ranking page, change columns to {columns}");
|
||||
Columns = columns;
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<IllustItem> DoGetIllustList(IllustData data, ICommand command)
|
||||
{
|
||||
if (ByUser)
|
||||
if (SegmentIndex == 1)
|
||||
{
|
||||
// by user
|
||||
return data.body.page.recommendUser.SelectMany(i => i.illustIds)
|
||||
.Select(id =>
|
||||
{
|
||||
@@ -44,6 +93,7 @@ namespace Pixiview.Illust
|
||||
}
|
||||
else
|
||||
{
|
||||
// recommends
|
||||
return data.body.page.recommend.Select(id =>
|
||||
{
|
||||
var item = data.body.thumbnails.illust.FirstOrDefault(l => l.illustId == id)?.ConvertToItem();
|
||||
@@ -58,7 +108,12 @@ namespace Pixiview.Illust
|
||||
|
||||
protected override IllustData DoLoadIllustData(bool force)
|
||||
{
|
||||
return Stores.LoadIllustData(force);
|
||||
if (illustData != null && !force)
|
||||
{
|
||||
return illustData;
|
||||
}
|
||||
illustData = Stores.LoadIllustData(force);
|
||||
return illustData;
|
||||
}
|
||||
|
||||
private void Refresh_Clicked(object sender, EventArgs e)
|
||||
|
@@ -187,14 +187,14 @@ namespace Pixiview.Illust
|
||||
item.OriginalUrl = p.urls.original;
|
||||
}
|
||||
|
||||
DoLoadImage(0);
|
||||
DoLoadImage(0, true);
|
||||
if (items.Length > 1)
|
||||
{
|
||||
DoLoadImage(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoLoadImage(int index)
|
||||
private void DoLoadImage(int index, bool force = false)
|
||||
{
|
||||
var items = Illusts;
|
||||
if (index < 0 || index >= items.Length)
|
||||
@@ -204,10 +204,13 @@ namespace Pixiview.Illust
|
||||
}
|
||||
|
||||
var item = items[index];
|
||||
if (item.Loading || (index > 0 && item.Image != null))
|
||||
if (!force)
|
||||
{
|
||||
App.DebugPrint($"skipped, loading or already loaded, index: {index}, loading: {item.Loading}");
|
||||
return;
|
||||
if (item.Loading || (index > 0 && item.Image != null))
|
||||
{
|
||||
App.DebugPrint($"skipped, loading or already loaded, index: {index}, loading: {item.Loading}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
item.Loading = true;
|
||||
var image = Stores.LoadPreviewImage(item.PreviewUrl);
|
||||
|
Reference in New Issue
Block a user