Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
收藏可以加载了
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed Apr 23, 2019
1 parent 01ca3d3 commit b0917b2
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 2 deletions.
108 changes: 108 additions & 0 deletions PixivFSUWP/Data/BookmarkIllustsCollection.cs
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;
}
}
}
}

1 change: 1 addition & 0 deletions PixivFSUWP/Data/OverAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static class OverAll
public const string refreshTokenResource = "PixivFSUWPRefreshToken";

public static RecommendIllustsCollection RecommendList { get; private set; } = new RecommendIllustsCollection();
public static BookmarkIllustsCollection BookmarkList { get; set; }

public static void RefreshRecommendList()
{
Expand Down
1 change: 1 addition & 0 deletions PixivFSUWP/Data/RecommendIllustsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void ResumeLoading()

protected async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
{
if (!HasMoreItems) return new LoadMoreItemsResult() { Count = 0 };
try
{
LoadMoreItemsResult toret = new LoadMoreItemsResult() { Count = 0 };
Expand Down
1 change: 1 addition & 0 deletions PixivFSUWP/IllustDetailPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<TextBlock x:Name="txtAuthorAccount" Margin="10,0" Grid.Row="1" Grid.Column="1" FontSize="14" Foreground="Gray" VerticalAlignment="Top"/>
</Grid>
<TextBlock x:Name="txtCaption" Margin="15,15,15,0" Height="Auto" TextWrapping="WrapWholeWords"/>
<TextBlock x:Name="txtCommentTitle" Margin="15,15,15,0" Height="Auto" FontSize="20" FontWeight="Bold"/>
</StackPanel>
</ScrollViewer>
</Page>
3 changes: 2 additions & 1 deletion PixivFSUWP/IllustDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ private async Task loadContent()
txtBookmarkStatus.Text = illust.TotalBookmarks.ToString();
txtAuthor.Text = illust.Author;
txtAuthorAccount.Text = string.Format("@{0}", illust.AuthorAccount);
txtCaption.Text = illust.Caption.Replace("<br />", "\n");
txtCaption.Text = (illust.Caption == "") ? "暂无简介" : illust.Caption.Replace("<br />", "\n");
txtCommentTitle.Text = string.Format("评论 - 共{0}条", illust.TotalComments);
int counter = 0;
foreach (var i in illust.OriginalUrls)
{
Expand Down
2 changes: 2 additions & 0 deletions PixivFSUWP/LoginPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ private async void Login()
vault.Add(new PasswordCredential(passwordResource, username, password));
vault.Add(new PasswordCredential(refreshTokenResource, username, Data.OverAll.GlobalBaseAPI.refresh_token));
}
//登陆完毕后加载默认的收藏集合
BookmarkList = new Data.BookmarkIllustsCollection();
Frame.Navigate(typeof(MainPage));
}
else btnTrouble.Visibility = Visibility.Visible;
Expand Down
2 changes: 1 addition & 1 deletion PixivFSUWP/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ private async void NavControl_SelectionChanged(NavigationView sender, Navigation
switch (sender.MenuItems.IndexOf(args.SelectedItem))
{
case 0:
//Data.OverAll.RefreshRecommendList();
ContentFrame.Navigate(typeof(WaterfallPage), WaterfallPage.ListContent.Recommend);
NavPlaceholder.IsEnabled = false;
await Task.Delay(TimeSpan.FromMilliseconds(350));
NavSeparator.Visibility = Visibility.Collapsed;
NavPlaceholder.Visibility = Visibility.Collapsed;
break;
case 1:
ContentFrame.Navigate(typeof(WaterfallPage), WaterfallPage.ListContent.Bookmark);
NavPlaceholder.IsEnabled = false;
await Task.Delay(TimeSpan.FromMilliseconds(350));
NavSeparator.Visibility = Visibility.Collapsed;
Expand Down
1 change: 1 addition & 0 deletions PixivFSUWP/PixivFSUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<Compile Include="Controls\WaterfallContentPanel.cs" />
<Compile Include="Controls\WaterfallListView.cs" />
<Compile Include="Data\BigImageDetail.cs" />
<Compile Include="Data\BookmarkIllustsCollection.cs" />
<Compile Include="Data\IllustDetail.cs" />
<Compile Include="Data\RecommendIllustsCollection.cs" />
<Compile Include="Data\OverAll.cs" />
Expand Down
4 changes: 4 additions & 0 deletions PixivFSUWP/WaterfallPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
WaterfallListView.ItemsSource = Data.OverAll.RecommendList;
Data.OverAll.RecommendList.ResumeLoading();
break;
case ListContent.Bookmark:
WaterfallListView.ItemsSource = Data.OverAll.BookmarkList;
Data.OverAll.BookmarkList.ResumeLoading();
break;
}
}

Expand Down

0 comments on commit b0917b2

Please sign in to comment.