feature: search in ranking page
This commit is contained in:
parent
8249ba09ce
commit
f6575f61e6
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
@ -17,6 +16,7 @@ namespace Pixiview.Illust
|
|||||||
public interface IIllustCollectionPage
|
public interface IIllustCollectionPage
|
||||||
{
|
{
|
||||||
List<IllustItem> Favorites { get; }
|
List<IllustItem> Favorites { get; }
|
||||||
|
IllustCollection IllustCollection { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class IllustDataCollectionPage : IllustCollectionPage<IllustData> { }
|
public abstract class IllustDataCollectionPage : IllustCollectionPage<IllustData> { }
|
||||||
@ -61,6 +61,7 @@ namespace Pixiview.Illust
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<IllustItem> Favorites { get; } = new List<IllustItem>();
|
public List<IllustItem> Favorites { get; } = new List<IllustItem>();
|
||||||
|
public IllustCollection IllustCollection { get; set; }
|
||||||
|
|
||||||
protected virtual bool IsFavoriteVisible => true;
|
protected virtual bool IsFavoriteVisible => true;
|
||||||
|
|
||||||
@ -122,14 +123,7 @@ namespace Pixiview.Illust
|
|||||||
columns = 2;
|
columns = 2;
|
||||||
break;
|
break;
|
||||||
case Orientation.PortraitUpsideDown:
|
case Orientation.PortraitUpsideDown:
|
||||||
if (DeviceInfo.Idiom == DeviceIdiom.Phone)
|
columns = isPhone ? 4 : 2;
|
||||||
{
|
|
||||||
columns = 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
columns = 2;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Orientation.Unknown:
|
case Orientation.Unknown:
|
||||||
case Orientation.LandscapeLeft:
|
case Orientation.LandscapeLeft:
|
||||||
@ -323,6 +317,7 @@ namespace Pixiview.Illust
|
|||||||
item.IsFavorite = Favorites.Any(i => i.Id == item.Id);
|
item.IsFavorite = Favorites.Any(i => i.Id == item.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
IllustCollection = collection;
|
||||||
Illusts = collection;
|
Illusts = collection;
|
||||||
Loading = false;
|
Loading = false;
|
||||||
|
|
||||||
@ -361,7 +356,7 @@ namespace Pixiview.Illust
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IllustCollection : ObservableCollection<IllustItem>
|
public class IllustCollection : List<IllustItem>
|
||||||
{
|
{
|
||||||
private static readonly object sync = new object();
|
private static readonly object sync = new object();
|
||||||
private static IllustCollection empty;
|
private static IllustCollection empty;
|
||||||
|
@ -3,19 +3,28 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:i="clr-namespace:Pixiview.Illust"
|
xmlns:i="clr-namespace:Pixiview.Illust"
|
||||||
xmlns:u="clr-namespace:Pixiview.UI"
|
xmlns:u="clr-namespace:Pixiview.UI"
|
||||||
|
xmlns:r="clr-namespace:Pixiview.Resources"
|
||||||
x:Class="Pixiview.Illust.RankingPage"
|
x:Class="Pixiview.Illust.RankingPage"
|
||||||
BackgroundColor="{DynamicResource WindowColor}">
|
BackgroundColor="{DynamicResource WindowColor}">
|
||||||
<ContentPage.ToolbarItems>
|
<ContentPage.ToolbarItems>
|
||||||
<ToolbarItem Order="Primary" Clicked="Refresh_Clicked"
|
<ToolbarItem Order="Primary" Clicked="Refresh_Clicked"
|
||||||
IconImageSource="{DynamicResource FontIconRefresh}"/>
|
IconImageSource="{DynamicResource FontIconRefresh}"/>
|
||||||
</ContentPage.ToolbarItems>
|
</ContentPage.ToolbarItems>
|
||||||
<Grid>
|
<Grid Padding="{Binding PageTopMargin}">
|
||||||
<ScrollView HorizontalOptions="Fill">
|
<ScrollView HorizontalOptions="Fill">
|
||||||
<u:FlowLayout ItemsSource="{Binding Illusts}"
|
<u:FlowLayout ItemsSource="{Binding Illusts}"
|
||||||
HorizontalOptions="Fill" Column="{Binding Columns}"
|
HorizontalOptions="Fill" Column="{Binding Columns}"
|
||||||
Margin="16" RowSpacing="16" ColumnSpacing="16"
|
Margin="16, 10, 16, 16" RowSpacing="16" ColumnSpacing="16"
|
||||||
ItemTemplate="{StaticResource cardView}"/>
|
ItemTemplate="{StaticResource cardView}"/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
<SearchBar Placeholder="{r:Text Search}" VerticalOptions="Start"
|
||||||
|
Margin="0, -46, 0, 0" HeightRequest="50"
|
||||||
|
BackgroundColor="{DynamicResource WindowColor}"
|
||||||
|
CancelButtonColor="{DynamicResource SubTextColor}"
|
||||||
|
Text="{Binding Keywords, Mode=TwoWay}"
|
||||||
|
SearchButtonPressed="SearchBar_SearchButtonPressed"
|
||||||
|
Unfocused="SearchBar_Unfocused"
|
||||||
|
/>
|
||||||
<Frame HasShadow="False" Margin="0" Padding="20" CornerRadius="8"
|
<Frame HasShadow="False" Margin="0" Padding="20" CornerRadius="8"
|
||||||
IsVisible="{Binding Loading}"
|
IsVisible="{Binding Loading}"
|
||||||
HorizontalOptions="Center" VerticalOptions="Center"
|
HorizontalOptions="Center" VerticalOptions="Center"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Pixiview.UI;
|
||||||
using Pixiview.Utils;
|
using Pixiview.Utils;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
@ -9,8 +10,23 @@ namespace Pixiview.Illust
|
|||||||
{
|
{
|
||||||
public partial class RankingPage : IllustDataCollectionPage
|
public partial class RankingPage : IllustDataCollectionPage
|
||||||
{
|
{
|
||||||
|
public static readonly BindableProperty KeywordsProperty = BindableProperty.Create(
|
||||||
|
nameof(Keywords), typeof(string), typeof(RankingPage));
|
||||||
|
|
||||||
|
public string Keywords
|
||||||
|
{
|
||||||
|
get => (string)GetValue(KeywordsProperty);
|
||||||
|
set => SetValue(KeywordsProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Thickness totalBarOffset;
|
||||||
|
private readonly Thickness navigationBarOffset;
|
||||||
|
|
||||||
public RankingPage()
|
public RankingPage()
|
||||||
{
|
{
|
||||||
|
totalBarOffset = new Thickness(0, AppShell.TotalBarOffset.Top + 50, 0, 0);
|
||||||
|
navigationBarOffset = new Thickness(0, AppShell.NavigationBarOffset.Top + 50, 0, 0);
|
||||||
|
|
||||||
Resources.Add("cardView", GetCardViewTemplate());
|
Resources.Add("cardView", GetCardViewTemplate());
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
@ -26,6 +42,34 @@ namespace Pixiview.Illust
|
|||||||
loaded = false;
|
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)
|
protected override IEnumerable<IllustItem> DoGetIllustList(IllustData data, ICommand command)
|
||||||
{
|
{
|
||||||
return data.body.page.ranking.items.Select(i =>
|
return data.body.page.ranking.items.Select(i =>
|
||||||
@ -62,5 +106,34 @@ namespace Pixiview.Illust
|
|||||||
}
|
}
|
||||||
StartLoad(true);
|
StartLoad(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SearchBar_SearchButtonPressed(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var key = Keywords;
|
||||||
|
if (key != null)
|
||||||
|
{
|
||||||
|
key = key.Trim().ToLower();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(key))
|
||||||
|
{
|
||||||
|
Illusts = IllustCollection;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var list = IllustCollection.Where(i =>
|
||||||
|
(i.UserName != null && i.UserName.ToLower().Contains(key)) ||
|
||||||
|
(i.Title != null && i.Title.ToLower().Contains(key)));
|
||||||
|
Illusts = new IllustCollection(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SearchBar_Unfocused(object sender, FocusEventArgs e)
|
||||||
|
{
|
||||||
|
if (!e.IsFocused)
|
||||||
|
{
|
||||||
|
SearchBar_SearchButtonPressed(sender, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,6 @@ namespace Pixiview.Illust
|
|||||||
nameof(IsPageVisible), typeof(bool), typeof(ViewIllustPage));
|
nameof(IsPageVisible), typeof(bool), typeof(ViewIllustPage));
|
||||||
public static readonly BindableProperty IllustItemProperty = BindableProperty.Create(
|
public static readonly BindableProperty IllustItemProperty = BindableProperty.Create(
|
||||||
nameof(IllustItem), typeof(IllustItem), typeof(ViewIllustPage));
|
nameof(IllustItem), typeof(IllustItem), typeof(ViewIllustPage));
|
||||||
public static readonly BindableProperty PageTopMarginProperty = BindableProperty.Create(
|
|
||||||
nameof(PageTopMargin), typeof(Thickness), typeof(ViewIllustPage));
|
|
||||||
|
|
||||||
public ImageSource IsFavorite => (ImageSource)GetValue(IsFavoriteProperty);
|
public ImageSource IsFavorite => (ImageSource)GetValue(IsFavoriteProperty);
|
||||||
|
|
||||||
@ -48,11 +46,6 @@ namespace Pixiview.Illust
|
|||||||
get => (IllustItem)GetValue(IllustItemProperty);
|
get => (IllustItem)GetValue(IllustItemProperty);
|
||||||
set => SetValue(IllustItemProperty, value);
|
set => SetValue(IllustItemProperty, value);
|
||||||
}
|
}
|
||||||
public Thickness PageTopMargin
|
|
||||||
{
|
|
||||||
get => (Thickness)GetValue(PageTopMarginProperty);
|
|
||||||
private set => SetValue(PageTopMarginProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int CurrentPage { get; private set; }
|
public int CurrentPage { get; private set; }
|
||||||
|
|
||||||
@ -119,32 +112,6 @@ namespace Pixiview.Illust
|
|||||||
Task.Run(DoLoadImages);
|
Task.Run(DoLoadImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnOrientationChanged(Orientation orientation)
|
|
||||||
{
|
|
||||||
switch (orientation)
|
|
||||||
{
|
|
||||||
case Orientation.Portrait:
|
|
||||||
PageTopMargin = AppShell.TotalBarOffset;
|
|
||||||
break;
|
|
||||||
case Orientation.PortraitUpsideDown:
|
|
||||||
if (DeviceInfo.Idiom == DeviceIdiom.Phone)
|
|
||||||
{
|
|
||||||
PageTopMargin = AppShell.NavigationBarOffset;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PageTopMargin = AppShell.TotalBarOffset;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Orientation.Unknown:
|
|
||||||
case Orientation.LandscapeLeft:
|
|
||||||
case Orientation.LandscapeRight:
|
|
||||||
default:
|
|
||||||
PageTopMargin = AppShell.NavigationBarOffset;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnAppearing()
|
protected override void OnAppearing()
|
||||||
{
|
{
|
||||||
base.OnAppearing();
|
base.OnAppearing();
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
<Recommends>推荐</Recommends>
|
<Recommends>推荐</Recommends>
|
||||||
<ByUser>按用户</ByUser>
|
<ByUser>按用户</ByUser>
|
||||||
<Ranking>排行榜</Ranking>
|
<Ranking>排行榜</Ranking>
|
||||||
|
<Search>搜索</Search>
|
||||||
<Favorites>收藏夹</Favorites>
|
<Favorites>收藏夹</Favorites>
|
||||||
<Option>选项</Option>
|
<Option>选项</Option>
|
||||||
<Preview>预览</Preview>
|
<Preview>预览</Preview>
|
||||||
|
@ -1,18 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
using Pixiview.UI.Theme;
|
using Pixiview.UI.Theme;
|
||||||
using Pixiview.Utils;
|
using Pixiview.Utils;
|
||||||
|
using Xamarin.Essentials;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Pixiview.UI
|
namespace Pixiview.UI
|
||||||
{
|
{
|
||||||
public class AdaptedPage : ContentPage
|
public class AdaptedPage : ContentPage
|
||||||
{
|
{
|
||||||
|
public static readonly BindableProperty PageTopMarginProperty = BindableProperty.Create(
|
||||||
|
nameof(PageTopMargin), typeof(Thickness), typeof(AdaptedPage));
|
||||||
|
|
||||||
|
public Thickness PageTopMargin
|
||||||
|
{
|
||||||
|
get => (Thickness)GetValue(PageTopMarginProperty);
|
||||||
|
protected set => SetValue(PageTopMarginProperty, value);
|
||||||
|
}
|
||||||
public Orientation CurrentOrientation { get; private set; }
|
public Orientation CurrentOrientation { get; private set; }
|
||||||
|
|
||||||
public event EventHandler Load;
|
public event EventHandler Load;
|
||||||
public event EventHandler Unload;
|
public event EventHandler Unload;
|
||||||
public event EventHandler<OrientationEventArgs> OrientationChanged;
|
public event EventHandler<OrientationEventArgs> OrientationChanged;
|
||||||
|
|
||||||
|
protected readonly bool isPhone = DeviceInfo.Idiom == DeviceIdiom.Phone;
|
||||||
|
|
||||||
public AdaptedPage()
|
public AdaptedPage()
|
||||||
{
|
{
|
||||||
SetDynamicResource(Screen.StatusBarStyleProperty, ThemeBase.StatusBarStyle);
|
SetDynamicResource(Screen.StatusBarStyleProperty, ThemeBase.StatusBarStyle);
|
||||||
@ -31,6 +42,21 @@ namespace Pixiview.UI
|
|||||||
|
|
||||||
public virtual void OnOrientationChanged(Orientation orientation)
|
public virtual void OnOrientationChanged(Orientation orientation)
|
||||||
{
|
{
|
||||||
|
switch (orientation)
|
||||||
|
{
|
||||||
|
case Orientation.Portrait:
|
||||||
|
PageTopMargin = AppShell.TotalBarOffset;
|
||||||
|
break;
|
||||||
|
case Orientation.PortraitUpsideDown:
|
||||||
|
PageTopMargin = isPhone ? AppShell.NavigationBarOffset : AppShell.TotalBarOffset;
|
||||||
|
break;
|
||||||
|
case Orientation.Unknown:
|
||||||
|
case Orientation.LandscapeLeft:
|
||||||
|
case Orientation.LandscapeRight:
|
||||||
|
default:
|
||||||
|
PageTopMargin = AppShell.NavigationBarOffset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
OrientationChanged?.Invoke(this, new OrientationEventArgs { CurrentOrientation = orientation });
|
OrientationChanged?.Invoke(this, new OrientationEventArgs { CurrentOrientation = orientation });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace Pixiview.UI.Theme
|
|||||||
Add(WindowColor, Color.Black);
|
Add(WindowColor, Color.Black);
|
||||||
Add(TextColor, Color.White);
|
Add(TextColor, Color.White);
|
||||||
Add(SubTextColor, Color.LightGray);
|
Add(SubTextColor, Color.LightGray);
|
||||||
Add(MainColor, Color.FromRgb(0x33, 0x33, 0x33));
|
Add(MainColor, Color.FromRgb(0x11, 0x11, 0x11));
|
||||||
Add(MainTextColor, Color.White);
|
Add(MainTextColor, Color.White);
|
||||||
Add(SubColor, Color.FromRgb(0x33, 0x33, 0x33));
|
Add(SubColor, Color.FromRgb(0x33, 0x33, 0x33));
|
||||||
Add(MaskColor, Color.FromRgba(0xff, 0xff, 0xff, 0x50));
|
Add(MaskColor, Color.FromRgba(0xff, 0xff, 0xff, 0x50));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user