diff --git a/Pixiview/Illust/IllustCollectionPage.cs b/Pixiview/Illust/IllustCollectionPage.cs
index 6be9cb3..557d293 100644
--- a/Pixiview/Illust/IllustCollectionPage.cs
+++ b/Pixiview/Illust/IllustCollectionPage.cs
@@ -61,7 +61,6 @@ namespace Pixiview.Illust
protected double topOffset;
private T illustData;
- private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads };
public IllustCollectionPage()
{
@@ -467,12 +466,13 @@ namespace Pixiview.Illust
void DoLoadImages(IllustCollection collection)
{
- Parallel.ForEach(collection, parallelOptions, illust =>
+ ParallelTask.Start(0, collection.Count, Configs.MaxThreads, i =>
{
if (!collection.Running)
{
- return;
+ return false;
}
+ var illust = collection[i];
if (illust.ImageUrl != null)
{
var url = Configs.GetThumbnailUrl(illust.ImageUrl);
@@ -495,6 +495,7 @@ namespace Pixiview.Illust
illust.ProfileImage = userImage;
}
}
+ return true;
});
}
diff --git a/Pixiview/Illust/ViewIllustPage.xaml b/Pixiview/Illust/ViewIllustPage.xaml
index 8ffad30..7669abe 100644
--- a/Pixiview/Illust/ViewIllustPage.xaml
+++ b/Pixiview/Illust/ViewIllustPage.xaml
@@ -27,6 +27,10 @@
+
+
(double)GetValue(MaximumFrameProperty);
set => SetValue(MaximumFrameProperty, value);
}
+ public bool ProgressVisible
+ {
+ get => (bool)GetValue(ProgressVisibleProperty);
+ set => SetValue(ProgressVisibleProperty, value);
+ }
public IllustItem IllustItem { get; private set; }
- private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads };
+ private readonly object sync = new object();
private readonly bool saveFavorites;
private readonly ImageSource fontIconLove;
private readonly ImageSource fontIconNotLove;
@@ -130,7 +137,7 @@ namespace Pixiview.Illust
? fontIconLove
: fontIconNotLove;
- IsPageVisible = illust != null && illust.PageCount > 1;
+ ProgressVisible = IsPageVisible = illust != null && illust.PageCount > 1;
Resources.Add("carouselView", GetCarouseTemplate());
InitializeComponent();
@@ -328,9 +335,11 @@ namespace Pixiview.Illust
illust.CopyToItem(illustItem);
MainThread.BeginInvokeOnMainThread(() =>
{
+ var pageCount = illustItem.PageCount;
Title = illustItem.Title;
- IsPageVisible = illustItem.PageCount > 1;
+ IsPageVisible = pageCount > 1;
IsAnimateSliderVisible = illustItem.IsAnimeVisible;
+ ProgressVisible = pageCount > 1;
});
if (preload.user.TryGetValue(illust.userId, out var user))
{
@@ -340,15 +349,13 @@ namespace Pixiview.Illust
}
}
- Task.Run(() => DoLoadImage(0, true));
- if (items.Length > 1)
+ ParallelTask.Start(0, items.Length, Configs.MaxPageThreads, i =>
{
- Parallel.For(1, items.Length, parallelOptions, i =>
- {
- DoLoadImage(i);
- });
- }
- else if (illustItem.IsAnimeVisible)
+ DoLoadImage(i, i == 0);
+ return true;
+ });
+
+ if (illustItem.IsAnimeVisible)
{
// anime
ugoiraData = Stores.LoadIllustUgoiraData(illustItem.Id);
@@ -389,6 +396,39 @@ namespace Pixiview.Illust
}
}
item.Loading = false;
+ RefreshProgress();
+ }
+
+ private void RefreshProgress()
+ {
+ var illusts = Illusts;
+ var length = illusts.Length;
+ if (length <= 1)
+ {
+ return;
+ }
+ lock (sync)
+ {
+ var loading = illusts.Count(i => i.Loading);
+ if (loading <= 0)
+ {
+ MainThread.BeginInvokeOnMainThread(async () =>
+ {
+ await progress.ProgressTo(1, 250, Easing.CubicIn);
+ await progress.FadeTo(0, easing: Easing.CubicIn);
+ ProgressVisible = false;
+ });
+ }
+ else
+ {
+ var val = (length - loading) / (float)length;
+ MainThread.BeginInvokeOnMainThread(() =>
+ {
+ ViewExtensions.CancelAnimations(progress);
+ progress.ProgressTo(val, 250, Easing.CubicIn);
+ });
+ }
+ }
}
private void TapPrevious_Tapped(object sender, EventArgs e)
diff --git a/Pixiview/Utils/Stores.cs b/Pixiview/Utils/Stores.cs
index 6acf1d2..7ab234a 100644
--- a/Pixiview/Utils/Stores.cs
+++ b/Pixiview/Utils/Stores.cs
@@ -450,6 +450,7 @@ namespace Pixiview.Utils
public const string QueryTypeKey = "query_type";
public const string QueryDateKey = "query_date";
+ public const int MaxPageThreads = 3;
public const int MaxThreads = 6;
public const string Referer = "https://www.pixiv.net/";
public const string RefererIllust = "https://www.pixiv.net/artworks/{0}";