diff --git a/Pixiview.Android/Properties/AndroidManifest.xml b/Pixiview.Android/Properties/AndroidManifest.xml index 2390d4e..ab7e634 100644 --- a/Pixiview.Android/Properties/AndroidManifest.xml +++ b/Pixiview.Android/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + diff --git a/Pixiview.iOS.OpenExtension/Info.plist b/Pixiview.iOS.OpenExtension/Info.plist index ffb57f4..2107d99 100644 --- a/Pixiview.iOS.OpenExtension/Info.plist +++ b/Pixiview.iOS.OpenExtension/Info.plist @@ -31,6 +31,6 @@ CFBundleShortVersionString 1.0.524 CFBundleVersion - 15 + 16 diff --git a/Pixiview.iOS/Info.plist b/Pixiview.iOS/Info.plist index d9a0ab7..98e6103 100644 --- a/Pixiview.iOS/Info.plist +++ b/Pixiview.iOS/Info.plist @@ -81,7 +81,7 @@ CFBundleShortVersionString 1.0.524 CFBundleVersion - 15 + 16 CFBundleDevelopmentRegion China diff --git a/Pixiview/Illust/FavoritesPage.xaml.cs b/Pixiview/Illust/FavoritesPage.xaml.cs index f4329b0..4e50fd6 100644 --- a/Pixiview/Illust/FavoritesPage.xaml.cs +++ b/Pixiview/Illust/FavoritesPage.xaml.cs @@ -87,8 +87,9 @@ namespace Pixiview.Illust base.OnUnload(); } - protected override IEnumerable DoGetIllustList(IllustItem[] data) + protected override IEnumerable DoGetIllustList(IllustItem[] data, out int tag) { + tag = startIndex; return data; } @@ -431,7 +432,8 @@ namespace Pixiview.Illust } } return true; - }, () => + }, + complete: () => { Stores.SaveFavoritesIllusts(); diff --git a/Pixiview/Illust/IllustCollectionPage.cs b/Pixiview/Illust/IllustCollectionPage.cs index a4ff6b4..a0351fc 100644 --- a/Pixiview/Illust/IllustCollectionPage.cs +++ b/Pixiview/Illust/IllustCollectionPage.cs @@ -77,13 +77,16 @@ namespace Pixiview.Illust protected double topOffset; protected string lastError; + private readonly object sync = new object(); + private readonly Queue tasks; private T illustData; - private ParallelTask task; public IllustCollectionPage() { commandIllustImageTapped = new Command(OnIllustImageTapped); commandUserTapped = new Command(OnIllustUserItemTapped); + tasks = new Queue(); + BindingContext = this; } @@ -117,10 +120,15 @@ namespace Pixiview.Illust public override void OnUnload() { - if (task != null) + lock (sync) { - task.Dispose(); - task = null; + while (tasks.TryDequeue(out var task)) + { + if (task != null) + { + task.Dispose(); + } + } } InvalidateCollection(); Illusts = null; @@ -195,7 +203,7 @@ namespace Pixiview.Illust #endregion protected abstract T DoLoadIllustData(bool force); - protected abstract IEnumerable DoGetIllustList(T data); + protected abstract IEnumerable DoGetIllustList(T data, out int tag); protected virtual IllustCollection GetIllustsLoadedCollection(IllustCollection collection, bool bottom) { @@ -614,7 +622,7 @@ namespace Pixiview.Illust } var r18 = Configs.IsOnR18; - var data = DoGetIllustList(illustData).Where(i => i != null && (r18 || !i.IsRestrict)); + var data = DoGetIllustList(illustData, out int tag).Where(i => i != null && (r18 || !i.IsRestrict)); var collection = new IllustCollection(data); var favorites = Stores.Favorites; @@ -655,19 +663,31 @@ namespace Pixiview.Illust } DoIllustsLoaded(collection, bottom); - DoLoadImages(collection); + DoLoadImages(collection, tag); } - void DoLoadImages(IllustCollection collection) + private void DoLoadImages(IllustCollection collection, int tag) { - if (task != null) + lock (sync) { - task.Dispose(); - task = null; + if (tasks.TryPeek(out var peek)) + { + if (peek.TagIndex >= tag) + { + App.DebugPrint($"tasks expired ({tasks.Count}), peek: {peek.TagIndex}, now: {tag}, will be disposing."); + while (tasks.TryPeek(out var t)) + { + if (t != null) + { + t.Dispose(); + } + } + } + } } var list = collection.Where(i => i.Image == null || i.ProfileImage == null).ToArray(); - task = ParallelTask.Start("collection.load", 0, list.Length, Configs.MaxThreads, i => + var task = ParallelTask.Start("collection.load", 0, list.Length, Configs.MaxThreads, i => { if (!collection.Running) { @@ -695,7 +715,12 @@ namespace Pixiview.Illust } } return true; - }); + }, tagIndex: tag); + + lock (sync) + { + tasks.Enqueue(task); + } } #endregion diff --git a/Pixiview/Illust/MainPage.xaml.cs b/Pixiview/Illust/MainPage.xaml.cs index 32d1098..9440cac 100644 --- a/Pixiview/Illust/MainPage.xaml.cs +++ b/Pixiview/Illust/MainPage.xaml.cs @@ -57,8 +57,9 @@ namespace Pixiview.Illust } #endif - protected override IEnumerable DoGetIllustList(IllustData data) + protected override IEnumerable DoGetIllustList(IllustData data, out int tag) { + tag = 0; if (data.body == null) { return null; diff --git a/Pixiview/Illust/RankingPage.xaml.cs b/Pixiview/Illust/RankingPage.xaml.cs index 19b428e..eb78819 100644 --- a/Pixiview/Illust/RankingPage.xaml.cs +++ b/Pixiview/Illust/RankingPage.xaml.cs @@ -162,8 +162,9 @@ namespace Pixiview.Illust } } - protected override IEnumerable DoGetIllustList(IllustRankingData data) + protected override IEnumerable DoGetIllustList(IllustRankingData data, out int tag) { + tag = currentPage; if (lastQueryKey != null && lastQueryKey.StartsWith(segmentDates[3])) { return data.contents.Where(i => i.illust_type == "0").Select(i => i.ConvertToItem()); diff --git a/Pixiview/Illust/RecommendsPage.xaml.cs b/Pixiview/Illust/RecommendsPage.xaml.cs index 5ce3f1c..5b0aeee 100644 --- a/Pixiview/Illust/RecommendsPage.xaml.cs +++ b/Pixiview/Illust/RecommendsPage.xaml.cs @@ -198,8 +198,9 @@ namespace Pixiview.Illust } } - protected override IEnumerable DoGetIllustList(IllustData data) + protected override IEnumerable DoGetIllustList(IllustData data, out int tag) { + tag = 0; if (data.body == null) { return null; diff --git a/Pixiview/Illust/RelatedIllustsPage.xaml.cs b/Pixiview/Illust/RelatedIllustsPage.xaml.cs index 91c2b8f..5324422 100644 --- a/Pixiview/Illust/RelatedIllustsPage.xaml.cs +++ b/Pixiview/Illust/RelatedIllustsPage.xaml.cs @@ -39,8 +39,9 @@ namespace Pixiview.Illust protected override bool IsAutoReload => false; protected override ActivityIndicator LoadingIndicator => activityLoading; - protected override IEnumerable DoGetIllustList(IllustRecommendsData data) + protected override IEnumerable DoGetIllustList(IllustRecommendsData data, out int tag) { + tag = startIndex; if (data.body == null) { return null; diff --git a/Pixiview/Illust/UserIllustPage.xaml.cs b/Pixiview/Illust/UserIllustPage.xaml.cs index 4a08915..b1a0fb5 100644 --- a/Pixiview/Illust/UserIllustPage.xaml.cs +++ b/Pixiview/Illust/UserIllustPage.xaml.cs @@ -51,8 +51,9 @@ namespace Pixiview.Illust protected override bool IsAutoReload => false; protected override ActivityIndicator LoadingIndicator => activityLoading; - protected override IEnumerable DoGetIllustList(IllustUserData data) + protected override IEnumerable DoGetIllustList(IllustUserData data, out int tag) { + tag = startIndex; if (data.body == null) { return null; diff --git a/Pixiview/Utils/Extensions.cs b/Pixiview/Utils/Extensions.cs index b81ced3..c5184cf 100644 --- a/Pixiview/Utils/Extensions.cs +++ b/Pixiview/Utils/Extensions.cs @@ -96,7 +96,7 @@ namespace Pixiview.Utils public class ParallelTask : IDisposable { - public static ParallelTask Start(string tag, int from, int toExclusive, int maxCount, Predicate action, Action complete = null) + public static ParallelTask Start(string tag, int from, int toExclusive, int maxCount, Predicate action, int tagIndex = -1, Action complete = null) { if (toExclusive <= from) { @@ -106,7 +106,7 @@ namespace Pixiview.Utils } return null; } - var task = new ParallelTask(tag, from, toExclusive, maxCount, action, complete); + var task = new ParallelTask(tag, from, toExclusive, maxCount, action, tagIndex, complete); return task.Start(); } @@ -114,6 +114,7 @@ namespace Pixiview.Utils private int count; private bool disposed; + public int TagIndex { get; private set; } private readonly string tag; private readonly int max; private readonly int from; @@ -121,7 +122,7 @@ namespace Pixiview.Utils private readonly Predicate action; private readonly Action complete; - private ParallelTask(string tag, int from, int to, int maxCount, Predicate action, Action complete) + private ParallelTask(string tag, int from, int to, int maxCount, Predicate action, int tagIndex, Action complete) { if (maxCount <= 0) { @@ -132,6 +133,7 @@ namespace Pixiview.Utils { throw new ArgumentOutOfRangeException(nameof(from)); } + TagIndex = tagIndex; this.tag = tag; this.from = from; this.to = to; diff --git a/Pixiview/Utils/Stores.cs b/Pixiview/Utils/Stores.cs index 426c2a7..289d0e9 100644 --- a/Pixiview/Utils/Stores.cs +++ b/Pixiview/Utils/Stores.cs @@ -721,7 +721,7 @@ namespace Pixiview.Utils public const string FavoriteTypeKey = "favorite_type"; public const int MaxPageThreads = 3; - public const int MaxThreads = 4; + public const int MaxThreads = 8; public const string Referer = "https://www.pixiv.net/"; public const string RefererIllust = "https://www.pixiv.net/artworks/{0}"; public const string RefererIllustRanking = "https://www.pixiv.net/ranking.php?{0}"; diff --git a/Pixiview/Utils/Ugoira.cs b/Pixiview/Utils/Ugoira.cs index b793ba6..5ab814b 100644 --- a/Pixiview/Utils/Ugoira.cs +++ b/Pixiview/Utils/Ugoira.cs @@ -294,7 +294,7 @@ namespace Pixiview.Utils downloadTask.Dispose(); downloadTask = null; } - downloadTask = ParallelTask.Start("ugoira.download", 0, inSegs.Count, 2, i => + downloadTask = ParallelTask.Start("ugoira.download", 0, inSegs.Count, 3, i => { var seg = inSegs[i]; #if DEBUG