feature: sync favorites

feature: remote bookmark icon
fix: sometimes blank title
This commit is contained in:
2020-05-19 11:40:17 +08:00
parent 01d782660b
commit 32058fe210
14 changed files with 154 additions and 84 deletions

View File

@@ -176,12 +176,37 @@ namespace Pixiview.Illust
else if (result == combine)
{
// combine
var favNow = Stores.GetFavoriteObject();
var nows = favNow.Illusts;
var nows = Stores.GetFavoriteObject().Illusts;
// sync bookmarks from remote
for (var i = nows.Count - 1; i >= 0; i--)
{
var b = nows[i];
var bookmarkId = b.BookmarkId;
if (!string.IsNullOrEmpty(bookmarkId))
{
var bookmark = list.FirstOrDefault(f => f.Id == b.Id);
if (bookmark == null)
{
// not exists in remote any more
App.DebugPrint($"remove bookmark ({bookmarkId}) - {b.Id}: {b.Title}");
nows.RemoveAt(i);
}
else if (bookmarkId != bookmark.BookmarkId)
{
// update bookmark id
App.DebugPrint($"change bookmark ({bookmarkId}) to ({bookmark.BookmarkId}) - {b.Id}: {b.Title}");
b.BookmarkId = bookmark.BookmarkId;
}
}
}
// add bookmarks that exists in remote only
list = list.Where(f => !nows.Any(i => i.Id == f.Id)).ToArray();
for (var i = 0; i < list.Length; i++)
{
list[i].Image = StyleDefinition.DownloadBackground;
var item = list[i];
App.DebugPrint($"add bookmark ({item.BookmarkId}) - {item.Id}: {item.Title}");
item.Image = StyleDefinition.DownloadBackground;
}
nows.InsertRange(0, list);
}

View File

@@ -174,7 +174,7 @@ namespace Pixiview.Illust
protected abstract IEnumerable<IllustItem> DoGetIllustList(T data);
protected virtual void OnIllustImageTapped(IllustItem illust)
{
var page = new ViewIllustPage(illust, IsFavoriteVisible);
var page = new ViewIllustPage(illust, true);
Navigation.PushAsync(page);
}
protected virtual IllustCollection GetIllustsLoadedCollection(IllustCollection collection, bool bottom)
@@ -388,9 +388,10 @@ namespace Pixiview.Illust
VerticalOptions = LayoutOptions.Center,
FontSize = StyleDefinition.FontSizeSmall,
TextColor = StyleDefinition.ColorRedBackground,
Text = StyleDefinition.IconLove
IsVisible = false
}
.Binding(IsVisibleProperty, IsFavoriteVisible ? nameof(IllustItem.IsFavorite) : null)
.Binding(Label.TextProperty, ".", converter: new FavoriteIconConverter(IsFavoriteVisible))
.Binding(IsVisibleProperty, ".", converter: new FavoriteVisibleConverter())
.DynamicResource(Label.FontFamilyProperty, ThemeBase.IconSolidFontFamily);
#endregion
@@ -488,7 +489,7 @@ namespace Pixiview.Illust
HeightRequest = 30,
Aspect = Aspect.AspectFill
}
.Binding(Image.SourceProperty, nameof(IllustItem.ProfileImage)),
.Binding(Image.SourceProperty, nameof(IIllustItem.ProfileImage)),
// user name
new Label
@@ -498,7 +499,7 @@ namespace Pixiview.Illust
LineBreakMode = LineBreakMode.TailTruncation,
FontSize = StyleDefinition.FontSizeMicro
}
.Binding(Label.TextProperty, nameof(IllustItem.UserName))
.Binding(Label.TextProperty, nameof(IIllustItem.UserName))
.DynamicResource(Label.TextColorProperty, ThemeBase.SubTextColor)
.GridColumn(1),
@@ -558,17 +559,14 @@ namespace Pixiview.Illust
var data = DoGetIllustList(illustData).Where(i => i != null && (r18 || !i.IsRestrict));
var collection = new IllustCollection(data);
if (IsFavoriteVisible)
var favorites = Stores.Favorites;
foreach (var item in collection)
{
var favorites = Stores.Favorites;
foreach (var item in collection)
if (item.Image == null)
{
if (item.Image == null)
{
item.Image = StyleDefinition.DownloadBackground;
}
item.IsFavorite = favorites.Any(i => i.Id == item.Id);
item.Image = StyleDefinition.DownloadBackground;
}
item.IsFavorite = IsFavoriteVisible && favorites.Any(i => i.Id == item.Id);
}
DoIllustsLoaded(collection, bottom);
@@ -767,15 +765,17 @@ namespace Pixiview.Illust
Anime = 2
}
public interface IIllustUser
public interface IIllustItem
{
string UserId { get; }
string UserName { get; }
ImageSource ProfileImage { get; }
bool IsFavorite { get; }
string BookmarkId { get; }
}
[JsonObject(MemberSerialization.OptIn)]
public class IllustItem : BindableObject, IIllustUser
public class IllustItem : BindableObject, IIllustItem
{
private static IllustItem empty;
public static IllustItem Empty
@@ -798,10 +798,13 @@ namespace Pixiview.Illust
nameof(ImageHeight), typeof(GridLength), typeof(IllustItem), GridLength.Auto);
public static readonly BindableProperty IsFavoriteProperty = BindableProperty.Create(
nameof(IsFavorite), typeof(bool), typeof(IllustItem));
public static readonly BindableProperty BookmarkIdProperty = BindableProperty.Create(
nameof(BookmarkId), typeof(string), typeof(IllustItem));
[JsonProperty]
public string Title { get; set; }
public string RankTitle { get; set; }
public int Rank { get; set; }
public string RankTitle => Rank > 0 ? $"#{Rank} {Title}" : Title;
public ImageSource Image
{
get => (ImageSource)GetValue(ImageProperty);
@@ -827,7 +830,11 @@ namespace Pixiview.Illust
[JsonProperty]
public string Id { get; set; }
[JsonProperty]
public string BookmarkId { get; set; }
public string BookmarkId
{
get => (string)GetValue(BookmarkIdProperty);
set => SetValue(BookmarkIdProperty, value);
}
[JsonProperty]
public DateTime FavoriteDateUtc { get; set; }
[JsonProperty]

View File

@@ -347,7 +347,7 @@ namespace Pixiview.Illust
}
}
public class IllustUserItem : BindableObject, IIllustUser
public class IllustUserItem : BindableObject, IIllustItem
{
//public static readonly BindableProperty Image1Property = BindableProperty.Create(
// nameof(Image1), typeof(ImageSource), typeof(IllustUserItem));
@@ -371,5 +371,8 @@ namespace Pixiview.Illust
public IllustItem Image2Item { get; set; }
public IllustItem Image3Item { get; set; }
public string ProfileUrl { get; set; }
public bool IsFavorite { get; }
public string BookmarkId { get; }
}
}

View File

@@ -20,13 +20,13 @@ namespace Pixiview.Illust
set => SetValue(UserIconProperty, value);
}
public IIllustUser UserItem { get; }
public IIllustItem UserItem { get; }
private int startIndex;
private int nextIndex;
private string[] illustIds;
public UserIllustPage(IIllustUser item)
public UserIllustPage(IIllustItem item)
{
UserItem = item;
UserIcon = item.ProfileImage;

View File

@@ -528,6 +528,10 @@ namespace Pixiview.Illust
{
return;
}
if (!add && string.IsNullOrEmpty(illust.BookmarkId))
{
return;
}
if (Configs.SyncFavType == SyncType.Prompt)
{
var ok = await DisplayAlert(
@@ -551,11 +555,7 @@ namespace Pixiview.Illust
}
else
{
var bookmarkId = illust.BookmarkId;
if (!string.IsNullOrEmpty(bookmarkId))
{
_ = Task.Run(() => Stores.DeleteBookmark(bookmarkId));
}
_ = Task.Run(() => Stores.DeleteBookmark(illust.BookmarkId));
}
}