This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tobiichiamane
committed
Apr 23, 2019
1 parent
01ca3d3
commit b0917b2
Showing
9 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using PixivFSCS; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Windows.Foundation; | ||
using Windows.UI.Xaml.Data; | ||
using FSharp.Data; | ||
using System.Web; | ||
|
||
namespace PixivFSUWP.Data | ||
{ | ||
public class BookmarkIllustsCollection : ObservableCollection<ViewModels.WaterfallItemViewModel>, ISupportIncrementalLoading | ||
{ | ||
readonly string userID; | ||
string nexturl = "begin"; | ||
bool _busy = false; | ||
bool _emergencyStop = false; | ||
EventWaitHandle pause = new ManualResetEvent(true); | ||
|
||
public BookmarkIllustsCollection(string UserID) | ||
{ | ||
userID = UserID; | ||
} | ||
|
||
public BookmarkIllustsCollection() : this(OverAll.GlobalBaseAPI.user_id) { } | ||
|
||
public bool HasMoreItems | ||
{ | ||
get => nexturl != ""; | ||
} | ||
|
||
public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count) | ||
{ | ||
if (_busy) | ||
throw new InvalidOperationException("Only one operation in flight at a time"); | ||
_busy = true; | ||
return AsyncInfo.Run((c) => LoadMoreItemsAsync(c, count)); | ||
} | ||
|
||
public void StopLoading() | ||
{ | ||
if (_busy) | ||
{ | ||
_emergencyStop = true; | ||
ResumeLoading(); | ||
} | ||
} | ||
|
||
public void PauseLoading() | ||
{ | ||
pause.Reset(); | ||
} | ||
|
||
public void ResumeLoading() | ||
{ | ||
pause.Set(); | ||
} | ||
|
||
protected async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count) | ||
{ | ||
if (!HasMoreItems) return new LoadMoreItemsResult() { Count = 0 }; | ||
try | ||
{ | ||
LoadMoreItemsResult toret = new LoadMoreItemsResult() { Count = 0 }; | ||
JsonValue recommendres = null; | ||
if (nexturl == "begin") | ||
recommendres = await Task.Run(() => new PixivFS | ||
.PixivAppAPI(OverAll.GlobalBaseAPI) | ||
.csfriendly_user_bookmarks_illust(userID)); | ||
else | ||
{ | ||
Uri next = new Uri(nexturl); | ||
string getparam(string param) => HttpUtility.ParseQueryString(next.Query).Get(param); | ||
recommendres = await Task.Run(() => new PixivFS | ||
.PixivAppAPI(OverAll.GlobalBaseAPI) | ||
.csfriendly_user_bookmarks_illust(userID, getparam("restrict"), | ||
getparam("filter"), getparam("max_bookmark_id"))); | ||
} | ||
nexturl = recommendres.Item("next_url").AsString(); | ||
foreach (var recillust in recommendres.Item("illusts").AsArray()) | ||
{ | ||
if (_emergencyStop) | ||
{ | ||
_emergencyStop = false; | ||
return toret; | ||
} | ||
await Task.Run(() => pause.WaitOne()); | ||
Data.WaterfallItem recommendi = Data.WaterfallItem.FromJsonValue(recillust); | ||
var recommendmodel = ViewModels.WaterfallItemViewModel.FromItem(recommendi); | ||
await recommendmodel.LoadImageAsync(); | ||
Add(recommendmodel); | ||
toret.Count++; | ||
} | ||
return toret; | ||
} | ||
finally | ||
{ | ||
_busy = false; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters