fix: reload favorites after modified

This commit is contained in:
Tsanie Lily 2020-05-16 17:27:14 +08:00
parent 8a471b6272
commit 02ae52d5cc
4 changed files with 50 additions and 10 deletions

View File

@ -21,6 +21,24 @@ namespace Pixiview.Illust
protected override ActivityIndicator LoadingIndicator => activityLoading;
protected override bool IsDelayLoading => true;
protected override void OnAppearing()
{
if (lastUpdated != LastUpdated)
{
StartLoad();
}
else
{
var favorites = Stores.Favorites;
if (favorites.Changed)
{
favorites.Reload();
lastUpdated = default;
StartLoad();
}
}
}
protected override IEnumerable<IllustItem> DoGetIllustList(IllustItem[] data)
{
return data;

View File

@ -695,12 +695,6 @@ namespace Pixiview.Illust
}
}
public class IllustFavorite
{
public DateTime LastFavoriteUtc { get; set; }
public List<IllustItem> Illusts { get; set; }
}
public enum IllustType
{
Illust = 0,

View File

@ -135,8 +135,7 @@ namespace Pixiview.Illust
fontIconLove = (ImageSource)Application.Current.Resources[ThemeBase.FontIconLove];
fontIconNotLove = (ImageSource)Application.Current.Resources[ThemeBase.FontIconNotLove];
var favorites = Stores.Favorites;
FavoriteIcon = favorites.Any(i => i.Id == illust.Id)
FavoriteIcon = Stores.Favorites.Any(i => i.Id == illust.Id)
? fontIconLove
: fontIconNotLove;

View File

@ -49,8 +49,9 @@ namespace Pixiview.Utils
}
}
public static List<IllustItem> Favorites => GetFavoriteObject().Illusts;
public static FavoriteList Favorites => GetFavoriteObject().Illusts;
public static string FavoritesPath => Path.Combine(PersonalFolder, favoriteFile);
public static DateTime FavoritesLastUpdated { get; set; } = DateTime.Now;
private static IllustFavorite favoriteObject;
@ -69,7 +70,7 @@ namespace Pixiview.Utils
{
favoriteObject = new IllustFavorite
{
Illusts = new List<IllustItem>()
Illusts = new FavoriteList()
};
}
}
@ -450,6 +451,34 @@ namespace Pixiview.Utils
}
}
public class IllustFavorite
{
public DateTime LastFavoriteUtc { get; set; }
public FavoriteList Illusts { get; set; }
}
public class FavoriteList : List<IllustItem>
{
public bool Changed { get; private set; }
public new void Insert(int index, IllustItem item)
{
base.Insert(index, item);
Changed = true;
}
public new void RemoveAt(int index)
{
base.RemoveAt(index);
Changed = true;
}
public void Reload()
{
Changed = false;
}
}
public static class Configs
{
public const string IsOnR18Key = "is_on_r18";