gelbooru source

This commit is contained in:
2021-08-10 21:46:38 +08:00
parent 8f8cfaca54
commit 24f39a2e27
8 changed files with 104 additions and 30 deletions

View File

@ -12,12 +12,7 @@ namespace Gallery.Resources.UI
{
public abstract class GalleryCollectionPage : GalleryScrollableCollectionPage<GalleryItem[]>
{
protected readonly IGallerySource source;
public GalleryCollectionPage(IGallerySource source)
{
this.source = source;
}
public GalleryCollectionPage(IGallerySource source) : base(source) { }
}
public interface IGalleryCollectionPage
@ -59,15 +54,46 @@ namespace Gallery.Resources.UI
set => SetValue(IsBottomLoadingProperty, value);
}
public IGallerySource Source { get; }
public GalleryCollection GalleryCollection { get; set; }
public DateTime LastUpdated
{
get
{
if (App.RefreshTimes.TryGetValue(Source.Route, out var time))
{
#if DEBUG
Log.Print($"get last updated time for: {Source.Route}, {time}");
#endif
return time;
}
#if DEBUG
Log.Print($"cannot get last updated time for: {Source.Route}");
#endif
return default;
}
set
{
#if DEBUG
Log.Print($"set last updated time for: {Source.Route} to {value}");
#endif
App.RefreshTimes[Source.Route] = value;
}
}
protected virtual ActivityIndicator LoadingIndicator => null;
protected virtual double IndicatorMarginTop => 16;
protected bool Expired => lastUpdated == default || (DateTime.Now - lastUpdated).TotalMinutes > EXPIRED_MINUTES;
protected bool Expired
{
get
{
var lastUpdated = LastUpdated;
return lastUpdated == default || (DateTime.Now - lastUpdated).TotalMinutes > EXPIRED_MINUTES;
}
}
protected readonly Command<GalleryItem> commandGalleryItemTapped;
protected DateTime lastUpdated;
protected double topOffset;
protected string lastError;
@ -75,8 +101,9 @@ namespace Gallery.Resources.UI
private readonly Stack<ParallelTask> tasks = new();
private T galleryData;
public GalleryCollectionPage()
public GalleryCollectionPage(IGallerySource source)
{
Source = source;
commandGalleryItemTapped = new Command<GalleryItem>(OnGalleryItemTapped);
}
@ -107,14 +134,14 @@ namespace Gallery.Resources.UI
}
InvalidateCollection();
Gallery = null;
lastUpdated = default;
LastUpdated = default;
}
protected override void OnAppearing()
{
base.OnAppearing();
if (lastUpdated == default)
if (Expired)
{
StartLoading();
}
@ -391,9 +418,9 @@ namespace Gallery.Resources.UI
Log.Error("gallery.load", "failed to load gallery data.");
return;
}
if (force)
if (force || Expired)
{
lastUpdated = DateTime.Now;
LastUpdated = DateTime.Now;
}
var data = DoGetGalleryList(galleryData, out int tag).Where(i => i != null);
@ -469,6 +496,8 @@ namespace Gallery.Resources.UI
private double lastRefreshY = double.MinValue;
private double offset;
public GalleryScrollableCollectionPage(IGallerySource source) : base(source) { }
protected bool IsScrollingDown(double y)
{
if (y > lastScrollY)