fix: favorites sync logic

This commit is contained in:
Tsanie Lily 2020-05-19 14:06:12 +08:00
parent dda2c48fa6
commit 22536ea395
5 changed files with 70 additions and 70 deletions

View File

@ -154,6 +154,21 @@ namespace Pixiview.Illust
}); });
} }
private void CloseLoading(Action next = null)
{
var offset = 16 - IndicatorMarginTop;
activityLoading.Animate("margin", top =>
{
activityLoading.Margin = new Thickness(0, top, 0, offset);
},
16 - offset, loadingOffset - offset, easing: Easing.CubicIn, finished: (v, r) =>
{
IsLoading = false;
next?.Invoke();
});
}
private async void ConfirmNext(IllustItem[] list) private async void ConfirmNext(IllustItem[] list)
{ {
var cancel = ResourceHelper.Cancel; var cancel = ResourceHelper.Cancel;
@ -182,33 +197,41 @@ namespace Pixiview.Illust
{ {
var b = nows[i]; var b = nows[i];
var bookmarkId = b.BookmarkId; var bookmarkId = b.BookmarkId;
if (!string.IsNullOrEmpty(bookmarkId)) var bookmark = list.FirstOrDefault(f => f.Id == b.Id);
if (bookmark == null)
{ {
var bookmark = list.FirstOrDefault(f => f.Id == b.Id); if (!string.IsNullOrEmpty(bookmarkId))
if (bookmark == null)
{ {
// not exists in remote any more // not exists in remote any more
App.DebugPrint($"remove bookmark ({bookmarkId}) - {b.Id}: {b.Title}"); App.DebugPrint($"remove bookmark ({bookmarkId}) - {b.Id}: {b.Title}");
nows.RemoveAt(i); nows.RemoveAt(i);
} }
else if (bookmarkId != bookmark.BookmarkId) }
{ else if (bookmarkId != bookmark.BookmarkId)
// update bookmark id {
App.DebugPrint($"change bookmark ({bookmarkId}) to ({bookmark.BookmarkId}) - {b.Id}: {b.Title}"); // update bookmark id
b.BookmarkId = bookmark.BookmarkId; App.DebugPrint($"change bookmark ({bookmarkId}) to ({bookmark.BookmarkId}) - {b.Id}: {b.Title}");
} b.BookmarkId = bookmark.BookmarkId;
} }
} }
// add bookmarks that exists in remote only // add bookmarks that exists in remote only
list = list.Where(f => !nows.Any(i => i.Id == f.Id)).ToArray(); var news = list.Where(f => !nows.Any(i => i.Id == f.Id)).ToArray();
for (var i = 0; i < list.Length; i++) if (news.Length > 0)
{ {
var item = list[i]; for (var i = 0; i < news.Length; i++)
App.DebugPrint($"add bookmark ({item.BookmarkId}) - {item.Id}: {item.Title}"); {
item.Image = StyleDefinition.DownloadBackground; var item = news[i];
App.DebugPrint($"add bookmark ({item.BookmarkId}) - {item.Id}: {item.Title}");
item.Image = StyleDefinition.DownloadBackground;
}
nows.InsertRange(0, news);
}
else
{
CloseLoading();
return;
} }
nows.InsertRange(0, list);
} }
else else
{ {
@ -236,15 +259,8 @@ namespace Pixiview.Illust
MainThread.BeginInvokeOnMainThread(() => MainThread.BeginInvokeOnMainThread(() =>
{ {
var offset = 16 - IndicatorMarginTop; CloseLoading(() =>
activityLoading.Animate("margin", top =>
{ {
activityLoading.Margin = new Thickness(0, top, 0, offset);
},
16 - offset, loadingOffset - offset, easing: Easing.CubicIn, finished: (v, r) =>
{
IsLoading = false;
flag = false; flag = false;
lastUpdated = default; lastUpdated = default;
StartLoad(); StartLoad();

View File

@ -710,11 +710,11 @@ namespace Pixiview.Illust
public IllustCollection() : base() public IllustCollection() : base()
{ {
running = true; Running = true;
} }
public IllustCollection(IEnumerable<IllustItem> illusts) : base(illusts) public IllustCollection(IEnumerable<IllustItem> illusts) : base(illusts)
{ {
running = true; Running = true;
} }
public void AddRange(List<IllustItem> items) public void AddRange(List<IllustItem> items)
@ -736,26 +736,7 @@ namespace Pixiview.Illust
} }
} }
private readonly object sync = new object(); public bool Running { get; set; }
private bool running;
public bool Running
{
get
{
lock (sync)
{
return running;
}
}
set
{
lock (sync)
{
running = value;
}
}
}
} }
public enum IllustType public enum IllustType

View File

@ -143,7 +143,16 @@ namespace Pixiview.UI
private class Tap : IDisposable private class Tap : IDisposable
{ {
public static bool IsBusy => _instance?.isBusy == true; public static bool IsBusy
{
get
{
lock (sync)
{
return _instance?.isBusy == true;
}
}
}
private static readonly object sync = new object(); private static readonly object sync = new object();
private static readonly Tap _instance = new Tap(); private static readonly Tap _instance = new Tap();
@ -163,10 +172,7 @@ namespace Pixiview.UI
public void Dispose() public void Dispose()
{ {
lock (sync) isBusy = false;
{
isBusy = false;
}
} }
} }
} }

View File

@ -100,10 +100,15 @@ namespace Pixiview.Utils
{ {
if (toExclusive <= from) if (toExclusive <= from)
{ {
if (complete != null)
{
ThreadPool.QueueUserWorkItem(o => complete());
}
return null; return null;
} }
var task = new ParallelTask(from, toExclusive, maxCount, action, complete); var task = new ParallelTask(from, toExclusive, maxCount, action, complete);
Task.Run(task.Start); //Task.Run(task.Start);
ThreadPool.QueueUserWorkItem(task.Start);
return task; return task;
} }
@ -134,24 +139,21 @@ namespace Pixiview.Utils
this.complete = complete; this.complete = complete;
} }
private void Start() private void Start(object o)
{ {
for (int i = from; i < to; i++) for (int i = from; i < to; i++)
{ {
var index = i; var index = i;
while (true) while (true)
{ {
lock (sync) if (count < max)
{ {
if (count < max) break;
{ }
break; if (disposed)
} {
if (disposed) App.DebugPrint($"parallel task determinate, disposed");
{ return;
App.DebugPrint($"parallel task determinate, disposed");
return;
}
} }
Thread.Sleep(100); Thread.Sleep(100);
} }
@ -165,10 +167,7 @@ namespace Pixiview.Utils
{ {
if (!action(index)) if (!action(index))
{ {
lock (sync) disposed = true;
{
disposed = true;
}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -190,10 +189,7 @@ namespace Pixiview.Utils
public void Dispose() public void Dispose()
{ {
lock (sync) disposed = true;
{
disposed = true;
}
} }
} }

View File

@ -321,6 +321,7 @@ namespace Pixiview.Utils
} }
} }
} }
App.DebugPrint("download over");
} }
} }