feature: favorite illusts

This commit is contained in:
Tsanie Lily 2020-05-07 16:22:59 +08:00
parent 8cf9ae288b
commit 7757fc2e01
4 changed files with 54 additions and 19 deletions

View File

@ -13,6 +13,8 @@ namespace Pixiview.Illust
InitializeComponent(); InitializeComponent();
} }
protected override bool IsFavoriteVisible => false;
protected override void OnAppearing() protected override void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
@ -20,17 +22,6 @@ namespace Pixiview.Illust
StartLoad(true); StartLoad(true);
} }
protected override void OnDisappearing()
{
base.OnDisappearing();
var illusts = Illusts;
if (illusts != null)
{
illusts.Clear();
}
}
protected override IEnumerable<IllustItem> DoGetIllustList(IllustItem[] data, ICommand command) protected override IEnumerable<IllustItem> DoGetIllustList(IllustItem[] data, ICommand command)
{ {
return data.Select(i => return data.Select(i =>

View File

@ -62,6 +62,8 @@ namespace Pixiview.Illust
public List<IllustItem> Favorites { get; } = new List<IllustItem>(); public List<IllustItem> Favorites { get; } = new List<IllustItem>();
protected virtual bool IsFavoriteVisible => true;
#endregion #endregion
protected bool loaded; protected bool loaded;
@ -256,6 +258,7 @@ namespace Pixiview.Illust
Padding = new Thickness(8, 0, 8, 8), Padding = new Thickness(8, 0, 8, 8),
Children = Children =
{ {
// user icon
new CircleImage new CircleImage
{ {
WidthRequest = 30, WidthRequest = 30,
@ -263,14 +266,31 @@ namespace Pixiview.Illust
Aspect = Aspect.AspectFill Aspect = Aspect.AspectFill
} }
.Binding(Image.SourceProperty, nameof(IllustItem.ProfileImage)), .Binding(Image.SourceProperty, nameof(IllustItem.ProfileImage)),
// user name
new Label new Label
{ {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center,
LineBreakMode = LineBreakMode.TailTruncation, LineBreakMode = LineBreakMode.TailTruncation,
FontSize = StyleDefinition.FontSizeMicro FontSize = StyleDefinition.FontSizeMicro
} }
.Binding(Label.TextProperty, nameof(IllustItem.UserName)) .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) .GridRow(2)
@ -296,6 +316,13 @@ namespace Pixiview.Illust
var data = DoGetIllustList(illustData, commandIllustImageTapped).Where(i => i != null); var data = DoGetIllustList(illustData, commandIllustImageTapped).Where(i => i != null);
var collection = new IllustCollection(data); var collection = new IllustCollection(data);
if (IsFavoriteVisible)
{
foreach (var item in collection)
{
item.IsFavorite = Favorites.Any(i => i.Id == item.Id);
}
}
Illusts = collection; Illusts = collection;
Loading = false; Loading = false;
@ -389,6 +416,8 @@ namespace Pixiview.Illust
nameof(ProfileImage), typeof(ImageSource), typeof(IllustItem)); nameof(ProfileImage), typeof(ImageSource), typeof(IllustItem));
public static readonly BindableProperty ImageHeightProperty = BindableProperty.Create( public static readonly BindableProperty ImageHeightProperty = BindableProperty.Create(
nameof(ImageHeight), typeof(GridLength), typeof(IllustItem), GridLength.Auto); nameof(ImageHeight), typeof(GridLength), typeof(IllustItem), GridLength.Auto);
public static readonly BindableProperty IsFavoriteProperty = BindableProperty.Create(
nameof(IsFavorite), typeof(bool), typeof(IllustItem));
public ImageSource Image public ImageSource Image
{ {
@ -400,12 +429,16 @@ namespace Pixiview.Illust
get => (ImageSource)GetValue(ProfileImageProperty); get => (ImageSource)GetValue(ProfileImageProperty);
set => SetValue(ProfileImageProperty, value); set => SetValue(ProfileImageProperty, value);
} }
[JsonProperty]
public GridLength ImageHeight public GridLength ImageHeight
{ {
get => (GridLength)GetValue(ImageHeightProperty); get => (GridLength)GetValue(ImageHeightProperty);
set => SetValue(ImageHeightProperty, value); set => SetValue(ImageHeightProperty, value);
} }
public bool IsFavorite
{
get => (bool)GetValue(IsFavoriteProperty);
set => SetValue(IsFavoriteProperty, value);
}
public ICommand IllustTapped { get; set; } public ICommand IllustTapped { get; set; }
[JsonProperty] [JsonProperty]
@ -428,6 +461,12 @@ namespace Pixiview.Illust
public int Height { get; set; } public int Height { get; set; }
[JsonProperty] [JsonProperty]
public int PageCount { get; set; } 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 string PageCountText => $"{StyleDefinition.IconLayer} {PageCount}";
public bool IsPageVisible => PageCount > 1; public bool IsPageVisible => PageCount > 1;

View File

@ -155,12 +155,15 @@ namespace Pixiview.Illust
{ {
base.OnDisappearing(); base.OnDisappearing();
var favorite = new IllustFavorite if (collectionPage is IllustDataCollectionPage)
{ {
LastFavoriteUtc = DateTime.UtcNow, var favorite = new IllustFavorite
Illusts = collectionPage.Favorites.ToArray() {
}; LastFavoriteUtc = DateTime.UtcNow,
Stores.SaveFavoritesIllusts(favorite); Illusts = collectionPage.Favorites.ToArray()
};
Stores.SaveFavoritesIllusts(favorite);
}
Screen.SetHomeIndicatorAutoHidden(Shell.Current, false); Screen.SetHomeIndicatorAutoHidden(Shell.Current, false);
} }
@ -257,11 +260,13 @@ namespace Pixiview.Illust
if (index < 0) if (index < 0)
{ {
collectionPage.Favorites.Insert(0, IllustItem); collectionPage.Favorites.Insert(0, IllustItem);
IllustItem.IsFavorite = true;
SetValue(IsFavoriteProperty, fontIconLove); SetValue(IsFavoriteProperty, fontIconLove);
} }
else else
{ {
collectionPage.Favorites.RemoveAt(index); collectionPage.Favorites.RemoveAt(index);
IllustItem.IsFavorite = false;
SetValue(IsFavoriteProperty, fontIconNotLove); SetValue(IsFavoriteProperty, fontIconNotLove);
} }
} }

View File

@ -90,7 +90,7 @@ namespace Pixiview.UI.Theme
Add(FontIconSparkles, GetSolidIcon(StyleDefinition.IconSparkles, solidFontFamily, mainColor)); Add(FontIconSparkles, GetSolidIcon(StyleDefinition.IconSparkles, solidFontFamily, mainColor));
Add(FontIconOrder, GetSolidIcon(StyleDefinition.IconOrder, solidFontFamily, mainColor)); Add(FontIconOrder, GetSolidIcon(StyleDefinition.IconOrder, solidFontFamily, mainColor));
Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, 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(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, (string)this[IconRegularFontFamily], mainColor));
Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily, mainColor)); Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily, mainColor));
Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily, mainColor)); Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily, mainColor));