feature: favorite illusts
This commit is contained in:
parent
8cf9ae288b
commit
7757fc2e01
@ -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<IllustItem> DoGetIllustList(IllustItem[] data, ICommand command)
|
||||
{
|
||||
return data.Select(i =>
|
||||
|
@ -62,6 +62,8 @@ namespace Pixiview.Illust
|
||||
|
||||
public List<IllustItem> Favorites { get; } = new List<IllustItem>();
|
||||
|
||||
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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user