diff --git a/Pixiview/Illust/ViewIllustPage.xaml.cs b/Pixiview/Illust/ViewIllustPage.xaml.cs index fb20ea7..01a383e 100644 --- a/Pixiview/Illust/ViewIllustPage.xaml.cs +++ b/Pixiview/Illust/ViewIllustPage.xaml.cs @@ -116,13 +116,15 @@ namespace Pixiview.Illust public IllustItem IllustItem { get; private set; } - private readonly object sync = new object(); private readonly bool saveFavorites; private readonly ImageSource fontIconLove; private readonly ImageSource fontIconNotLove; private IllustUgoiraData ugoiraData; private Ugoira ugoira; + private volatile int downloaded = 0; + private int pageCount; + public ViewIllustPage(IllustItem illust, bool save) { IllustItem = illust; @@ -137,7 +139,11 @@ namespace Pixiview.Illust ? fontIconLove : fontIconNotLove; - ProgressVisible = IsPageVisible = illust != null && illust.PageCount > 1; + if (illust != null) + { + pageCount = illust.PageCount; + ProgressVisible = IsPageVisible = pageCount > 1; + } Resources.Add("carouselView", GetCarouseTemplate()); InitializeComponent(); @@ -335,11 +341,12 @@ namespace Pixiview.Illust illust.CopyToItem(illustItem); MainThread.BeginInvokeOnMainThread(() => { - var pageCount = illustItem.PageCount; + var count = illustItem.PageCount; + pageCount = count; Title = illustItem.Title; - IsPageVisible = pageCount > 1; + IsPageVisible = count > 1; IsAnimateSliderVisible = illustItem.IsAnimeVisible; - ProgressVisible = pageCount > 1; + ProgressVisible = count > 1; }); if (preload.user.TryGetValue(illust.userId, out var user)) { @@ -401,34 +408,32 @@ namespace Pixiview.Illust private void RefreshProgress() { - var illusts = Illusts; - var length = illusts.Length; - if (length <= 1) + if (pageCount <= 1) { return; } - lock (sync) + + downloaded++; + if (downloaded >= pageCount) { - var loading = illusts.Count(i => i.Loading); - if (loading <= 0) + MainThread.BeginInvokeOnMainThread(async () => { - 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); - }); - } + await progress.ProgressTo(1, 250, Easing.CubicIn); + await progress.FadeTo(0, easing: Easing.CubicIn); + ProgressVisible = false; + }); } + else + { + var val = downloaded / (float)pageCount; + App.DebugPrint($"download progress: {val}"); + MainThread.BeginInvokeOnMainThread(() => + { + ViewExtensions.CancelAnimations(progress); + progress.ProgressTo(val, 250, Easing.CubicIn); + }); + } + } private void TapPrevious_Tapped(object sender, EventArgs e)