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
e61425f
commit f543bac
Showing
9 changed files
with
222 additions
and
16 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
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,101 @@ | ||
using FSharp.Data; | ||
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 System.Web; | ||
using Windows.Foundation; | ||
using Windows.UI.Xaml.Data; | ||
|
||
namespace PixivFSUWP.Data | ||
{ | ||
public class CommentsCollection : ObservableCollection<ViewModels.CommentViewModel>, ISupportIncrementalLoading | ||
{ | ||
string nexturl = "begin"; | ||
bool _busy = false; | ||
bool _emergencyStop = false; | ||
EventWaitHandle pause = new ManualResetEvent(true); | ||
readonly string illustid; | ||
|
||
public CommentsCollection(string IllustID) => illustid = IllustID; | ||
|
||
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) | ||
{ | ||
try | ||
{ | ||
if (!HasMoreItems) return new LoadMoreItemsResult() { Count = 0 }; | ||
LoadMoreItemsResult toret = new LoadMoreItemsResult() { Count = 0 }; | ||
JsonValue commentres = null; | ||
if (nexturl == "begin") | ||
commentres = await Task.Run(() => new PixivFS | ||
.PixivAppAPI(OverAll.GlobalBaseAPI) | ||
.csfriendly_illust_comments(illustid, include_total_comments: true)); | ||
else | ||
{ | ||
Uri next = new Uri(nexturl); | ||
string getparam(string param) => HttpUtility.ParseQueryString(next.Query).Get(param); | ||
commentres = await Task.Run(() => new PixivFS | ||
.PixivAppAPI(OverAll.GlobalBaseAPI) | ||
.csfriendly_illust_comments(illustid, getparam("offset"), bool.Parse(getparam("include_total_comments")))); | ||
} | ||
nexturl = commentres.Item("next_url").AsString(); | ||
foreach (var recillust in commentres.Item("comments").AsArray()) | ||
{ | ||
if (_emergencyStop) | ||
{ | ||
_emergencyStop = false; | ||
return toret; | ||
} | ||
await Task.Run(() => pause.WaitOne()); | ||
Data.IllustCommentItem recommendi = Data.IllustCommentItem.FromJsonValue(recillust); | ||
var recommendmodel = ViewModels.CommentViewModel.FromItem(recommendi); | ||
//await recommendmodel.LoadAvatarAsync(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using FSharp.Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PixivFSUWP.Data | ||
{ | ||
public class IllustCommentItem | ||
{ | ||
public string Comment { get; set; } | ||
public string DateTime { get; set; } | ||
public string UserName { get; set; } | ||
public string UserAccount { get; set; } | ||
public string AvatarUrl { get; set; } | ||
|
||
public static IllustCommentItem FromJsonValue(JsonValue Source) | ||
{ | ||
IllustCommentItem toret = new IllustCommentItem(); | ||
toret.Comment = Source.Item("comment").AsString(); | ||
toret.DateTime = Source.Item("date").AsString(); | ||
toret.UserName = Source.Item("user").Item("name").AsString(); | ||
toret.UserAccount = Source.Item("user").Item("account").AsString(); | ||
toret.AvatarUrl = Source.Item("user").Item("profile_image_urls").Item("medium").AsString(); | ||
return toret; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Windows.UI.Xaml.Media.Imaging; | ||
|
||
namespace PixivFSUWP.ViewModels | ||
{ | ||
public class CommentViewModel | ||
{ | ||
public string Comment { get; set; } | ||
public string UserName { get; set; } | ||
public string UserAccount { get; set; } | ||
private string _dateTime { get; set; } | ||
public string AvatarUrl { get; set; } | ||
public BitmapImage Avatar { get; set; } | ||
public string DateTime | ||
{ | ||
get => DateTimeOffset.Parse(_dateTime).LocalDateTime.ToString(); | ||
} | ||
|
||
public async Task LoadAvatarAsync() | ||
=> Avatar = await Data.OverAll.LoadImageAsync(AvatarUrl); | ||
|
||
public static CommentViewModel FromItem(Data.IllustCommentItem Item) | ||
{ | ||
return new CommentViewModel() | ||
{ | ||
Comment = Item.Comment, | ||
UserName = Item.UserName, | ||
UserAccount = "@" + Item.UserAccount, | ||
_dateTime = Item.DateTime, | ||
AvatarUrl = Item.AvatarUrl | ||
}; | ||
} | ||
} | ||
} |