diff --git a/Pixiview/Illust/IllustCollectionPage.cs b/Pixiview/Illust/IllustCollectionPage.cs index d50a112..41f9100 100644 --- a/Pixiview/Illust/IllustCollectionPage.cs +++ b/Pixiview/Illust/IllustCollectionPage.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; using System.Windows.Input; @@ -17,6 +16,7 @@ namespace Pixiview.Illust public interface IIllustCollectionPage { List Favorites { get; } + IllustCollection IllustCollection { get; set; } } public abstract class IllustDataCollectionPage : IllustCollectionPage { } @@ -61,6 +61,7 @@ namespace Pixiview.Illust } public List Favorites { get; } = new List(); + public IllustCollection IllustCollection { get; set; } protected virtual bool IsFavoriteVisible => true; @@ -122,14 +123,7 @@ namespace Pixiview.Illust columns = 2; break; case Orientation.PortraitUpsideDown: - if (DeviceInfo.Idiom == DeviceIdiom.Phone) - { - columns = 4; - } - else - { - columns = 2; - } + columns = isPhone ? 4 : 2; break; case Orientation.Unknown: case Orientation.LandscapeLeft: @@ -323,6 +317,7 @@ namespace Pixiview.Illust item.IsFavorite = Favorites.Any(i => i.Id == item.Id); } } + IllustCollection = collection; Illusts = collection; Loading = false; @@ -361,7 +356,7 @@ namespace Pixiview.Illust #endregion } - public class IllustCollection : ObservableCollection + public class IllustCollection : List { private static readonly object sync = new object(); private static IllustCollection empty; diff --git a/Pixiview/Illust/RankingPage.xaml b/Pixiview/Illust/RankingPage.xaml index 491deab..5c9369f 100644 --- a/Pixiview/Illust/RankingPage.xaml +++ b/Pixiview/Illust/RankingPage.xaml @@ -3,19 +3,28 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:i="clr-namespace:Pixiview.Illust" xmlns:u="clr-namespace:Pixiview.UI" + xmlns:r="clr-namespace:Pixiview.Resources" x:Class="Pixiview.Illust.RankingPage" BackgroundColor="{DynamicResource WindowColor}"> - + + (string)GetValue(KeywordsProperty); + set => SetValue(KeywordsProperty, value); + } + + private readonly Thickness totalBarOffset; + private readonly Thickness navigationBarOffset; + 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()); InitializeComponent(); } @@ -26,6 +42,34 @@ 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 DoGetIllustList(IllustData data, ICommand command) { return data.body.page.ranking.items.Select(i => @@ -62,5 +106,34 @@ namespace Pixiview.Illust } 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); + } + } } } diff --git a/Pixiview/Illust/ViewIllustPage.xaml.cs b/Pixiview/Illust/ViewIllustPage.xaml.cs index 4497750..1cc5c1a 100644 --- a/Pixiview/Illust/ViewIllustPage.xaml.cs +++ b/Pixiview/Illust/ViewIllustPage.xaml.cs @@ -23,8 +23,6 @@ namespace Pixiview.Illust nameof(IsPageVisible), typeof(bool), typeof(ViewIllustPage)); public static readonly BindableProperty IllustItemProperty = BindableProperty.Create( 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); @@ -48,11 +46,6 @@ namespace Pixiview.Illust get => (IllustItem)GetValue(IllustItemProperty); set => SetValue(IllustItemProperty, value); } - public Thickness PageTopMargin - { - get => (Thickness)GetValue(PageTopMarginProperty); - private set => SetValue(PageTopMarginProperty, value); - } public int CurrentPage { get; private set; } @@ -119,32 +112,6 @@ namespace Pixiview.Illust 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() { base.OnAppearing(); diff --git a/Pixiview/Resources/Languages/zh-CN.xml b/Pixiview/Resources/Languages/zh-CN.xml index 1ae7584..7f595a9 100644 --- a/Pixiview/Resources/Languages/zh-CN.xml +++ b/Pixiview/Resources/Languages/zh-CN.xml @@ -7,6 +7,7 @@ 推荐 按用户 排行榜 + 搜索 收藏夹 预览 diff --git a/Pixiview/UI/AdaptedPage.cs b/Pixiview/UI/AdaptedPage.cs index 74f3c0a..453cbe5 100644 --- a/Pixiview/UI/AdaptedPage.cs +++ b/Pixiview/UI/AdaptedPage.cs @@ -1,18 +1,29 @@ using System; using Pixiview.UI.Theme; using Pixiview.Utils; +using Xamarin.Essentials; using Xamarin.Forms; namespace Pixiview.UI { 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 event EventHandler Load; public event EventHandler Unload; public event EventHandler OrientationChanged; + protected readonly bool isPhone = DeviceInfo.Idiom == DeviceIdiom.Phone; + public AdaptedPage() { SetDynamicResource(Screen.StatusBarStyleProperty, ThemeBase.StatusBarStyle); @@ -31,6 +42,21 @@ namespace Pixiview.UI 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 }); } diff --git a/Pixiview/UI/Theme/DarkTheme.cs b/Pixiview/UI/Theme/DarkTheme.cs index 987718e..5a8247c 100644 --- a/Pixiview/UI/Theme/DarkTheme.cs +++ b/Pixiview/UI/Theme/DarkTheme.cs @@ -31,7 +31,7 @@ namespace Pixiview.UI.Theme Add(WindowColor, Color.Black); Add(TextColor, Color.White); Add(SubTextColor, Color.LightGray); - Add(MainColor, Color.FromRgb(0x33, 0x33, 0x33)); + Add(MainColor, Color.FromRgb(0x11, 0x11, 0x11)); Add(MainTextColor, Color.White); Add(SubColor, Color.FromRgb(0x33, 0x33, 0x33)); Add(MaskColor, Color.FromRgba(0xff, 0xff, 0xff, 0x50));