From 7757fc2e01cf97934abe28c84ce85bd917463407 Mon Sep 17 00:00:00 2001 From: Tsanie Lily Date: Thu, 7 May 2020 16:22:59 +0800 Subject: [PATCH] feature: favorite illusts --- Pixiview/Illust/FavoritesPage.xaml.cs | 13 ++------ Pixiview/Illust/IllustCollectionPage.cs | 43 +++++++++++++++++++++++-- Pixiview/Illust/ViewIllustPage.xaml.cs | 15 ++++++--- Pixiview/UI/Theme/ThemeBase.cs | 2 +- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/Pixiview/Illust/FavoritesPage.xaml.cs b/Pixiview/Illust/FavoritesPage.xaml.cs index 0b0954d..8dda895 100644 --- a/Pixiview/Illust/FavoritesPage.xaml.cs +++ b/Pixiview/Illust/FavoritesPage.xaml.cs @@ -13,6 +13,8 @@ namespace Pixiview.Illust InitializeComponent(); } + protected override bool IsFavoriteVisible => false; + protected override void OnAppearing() { base.OnAppearing(); @@ -20,17 +22,6 @@ namespace Pixiview.Illust StartLoad(true); } - protected override void OnDisappearing() - { - base.OnDisappearing(); - - var illusts = Illusts; - if (illusts != null) - { - illusts.Clear(); - } - } - protected override IEnumerable DoGetIllustList(IllustItem[] data, ICommand command) { return data.Select(i => diff --git a/Pixiview/Illust/IllustCollectionPage.cs b/Pixiview/Illust/IllustCollectionPage.cs index 69ff7d2..d50a112 100644 --- a/Pixiview/Illust/IllustCollectionPage.cs +++ b/Pixiview/Illust/IllustCollectionPage.cs @@ -62,6 +62,8 @@ namespace Pixiview.Illust public List Favorites { get; } = new List(); + protected virtual bool IsFavoriteVisible => true; + #endregion protected bool loaded; @@ -256,6 +258,7 @@ namespace Pixiview.Illust Padding = new Thickness(8, 0, 8, 8), Children = { + // user icon new CircleImage { WidthRequest = 30, @@ -263,14 +266,31 @@ namespace Pixiview.Illust Aspect = Aspect.AspectFill } .Binding(Image.SourceProperty, nameof(IllustItem.ProfileImage)), + + // user name new Label { + HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, LineBreakMode = LineBreakMode.TailTruncation, FontSize = StyleDefinition.FontSizeMicro } .Binding(Label.TextProperty, nameof(IllustItem.UserName)) - .DynamicResource(Label.TextColorProperty, ThemeBase.SubTextColor) + .DynamicResource(Label.TextColorProperty, ThemeBase.SubTextColor), + + // label: favorite + new Label + { + WidthRequest = 26, + HorizontalOptions = LayoutOptions.End, + HorizontalTextAlignment = TextAlignment.End, + VerticalOptions = LayoutOptions.Center, + FontSize = StyleDefinition.FontSizeSmall, + TextColor = StyleDefinition.ColorRedBackground, + Text = StyleDefinition.IconLove + } + .Binding(IsVisibleProperty, nameof(IllustItem.IsFavorite)) + .DynamicResource(Label.FontFamilyProperty, ThemeBase.IconSolidFontFamily) } } .GridRow(2) @@ -296,6 +316,13 @@ namespace Pixiview.Illust var data = DoGetIllustList(illustData, commandIllustImageTapped).Where(i => i != null); var collection = new IllustCollection(data); + if (IsFavoriteVisible) + { + foreach (var item in collection) + { + item.IsFavorite = Favorites.Any(i => i.Id == item.Id); + } + } Illusts = collection; Loading = false; @@ -389,6 +416,8 @@ namespace Pixiview.Illust nameof(ProfileImage), typeof(ImageSource), typeof(IllustItem)); public static readonly BindableProperty ImageHeightProperty = BindableProperty.Create( nameof(ImageHeight), typeof(GridLength), typeof(IllustItem), GridLength.Auto); + public static readonly BindableProperty IsFavoriteProperty = BindableProperty.Create( + nameof(IsFavorite), typeof(bool), typeof(IllustItem)); public ImageSource Image { @@ -400,12 +429,16 @@ namespace Pixiview.Illust get => (ImageSource)GetValue(ProfileImageProperty); set => SetValue(ProfileImageProperty, value); } - [JsonProperty] public GridLength ImageHeight { get => (GridLength)GetValue(ImageHeightProperty); set => SetValue(ImageHeightProperty, value); } + public bool IsFavorite + { + get => (bool)GetValue(IsFavoriteProperty); + set => SetValue(IsFavoriteProperty, value); + } public ICommand IllustTapped { get; set; } [JsonProperty] @@ -428,6 +461,12 @@ namespace Pixiview.Illust public int Height { get; set; } [JsonProperty] public int PageCount { get; set; } + [JsonProperty] + public double ImageHeightValue + { + get => ImageHeight.IsAuto ? -1 : ImageHeight.Value; + set => ImageHeight = value > 0 ? value : GridLength.Auto; + } public string PageCountText => $"{StyleDefinition.IconLayer} {PageCount}"; public bool IsPageVisible => PageCount > 1; diff --git a/Pixiview/Illust/ViewIllustPage.xaml.cs b/Pixiview/Illust/ViewIllustPage.xaml.cs index a42c0c7..4497750 100644 --- a/Pixiview/Illust/ViewIllustPage.xaml.cs +++ b/Pixiview/Illust/ViewIllustPage.xaml.cs @@ -155,12 +155,15 @@ namespace Pixiview.Illust { base.OnDisappearing(); - var favorite = new IllustFavorite + if (collectionPage is IllustDataCollectionPage) { - LastFavoriteUtc = DateTime.UtcNow, - Illusts = collectionPage.Favorites.ToArray() - }; - Stores.SaveFavoritesIllusts(favorite); + var favorite = new IllustFavorite + { + LastFavoriteUtc = DateTime.UtcNow, + Illusts = collectionPage.Favorites.ToArray() + }; + Stores.SaveFavoritesIllusts(favorite); + } Screen.SetHomeIndicatorAutoHidden(Shell.Current, false); } @@ -257,11 +260,13 @@ namespace Pixiview.Illust if (index < 0) { collectionPage.Favorites.Insert(0, IllustItem); + IllustItem.IsFavorite = true; SetValue(IsFavoriteProperty, fontIconLove); } else { collectionPage.Favorites.RemoveAt(index); + IllustItem.IsFavorite = false; SetValue(IsFavoriteProperty, fontIconNotLove); } } diff --git a/Pixiview/UI/Theme/ThemeBase.cs b/Pixiview/UI/Theme/ThemeBase.cs index b675f9e..901f61c 100644 --- a/Pixiview/UI/Theme/ThemeBase.cs +++ b/Pixiview/UI/Theme/ThemeBase.cs @@ -90,7 +90,7 @@ namespace Pixiview.UI.Theme Add(FontIconSparkles, GetSolidIcon(StyleDefinition.IconSparkles, solidFontFamily, mainColor)); Add(FontIconOrder, GetSolidIcon(StyleDefinition.IconOrder, solidFontFamily, mainColor)); Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily, mainColor)); - Add(FontIconLove, GetSolidIcon(StyleDefinition.IconLove, solidFontFamily, mainColor)); + Add(FontIconLove, GetSolidIcon(StyleDefinition.IconLove, solidFontFamily, StyleDefinition.ColorRedBackground)); Add(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, (string)this[IconRegularFontFamily], mainColor)); Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily, mainColor)); Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily, mainColor));