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
YukinoShary committed May 30, 2020
1 parent 463af07 commit cd97665
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
20 changes: 20 additions & 0 deletions PixivFSUWP/Data/OverAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ public static class OverAll
public static BookmarkIllustsCollection BookmarkList { get; private set; }
public static FollowingIllustsCollection FollowingList { get; private set; }
public static RankingIllustsCollection RankingList { get; private set; }
public static SearchResultIllustsCollection SearchResultList { get; private set; }
public static MainPage TheMainPage { get; set; }

public struct SearchParam
{
public string Word;
public string SearchTarget;
public string Sort;
public string Duration;
}

public static void RefreshRecommendList()
{
RecommendList?.StopLoading();
Expand All @@ -57,6 +66,17 @@ public static void RefreshRankingList()
RankingList = new RankingIllustsCollection();
}

public static void NewSearchResultList(SearchParam param)
{
SearchResultList?.StopLoading();
SearchResultList = new SearchResultIllustsCollection(param.Word, param.SearchTarget, param.Sort, param.Duration);
}

public static void SearchResultStop()
{
SearchResultList?.StopLoading();
}

//携带缓存的图像下载
public static async Task<MemoryStream> DownloadImage(string Uri)
{
Expand Down
2 changes: 1 addition & 1 deletion PixivFSUWP/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private async void BtnSearch_Click(object sender, RoutedEventArgs e)
if (ContentFrame.Content is SearchPage)
await (ContentFrame.Content as SearchPage).ShowSearch();
else
ContentFrame.Navigate(typeof(SearchPage));
ContentFrame.Navigate(typeof(SearchPage),ContentFrame);
}
//吞掉异常,这个异常没有意义
catch { }
Expand Down
29 changes: 26 additions & 3 deletions PixivFSUWP/SearchPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using PixivFSUWP.Interfaces;
using static PixivFSUWP.Data.OverAll;
using Windows.Data.Json;
using PixivFSUWP.Data;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

Expand Down Expand Up @@ -50,10 +51,10 @@ public void SetBackFlag(bool value)
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
(resultFrame.Content as SearchResultPage)?.ItemsSource?.StopLoading();
if (!_backflag)
{
Data.Backstack.Default.Push(typeof(SearchPage), null);
Data.OverAll.SearchResultList?.PauseLoading();
((Frame.Parent as Grid)?.Parent as MainPage)?.UpdateNavButtonState();
}
}
Expand Down Expand Up @@ -87,6 +88,27 @@ async Task loadContents()
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e?.Parameter is Frame)
{
_ = loadContents();
SearchResultList?.StopLoading();
}
else
{
resultFrame.Navigate(typeof(SearchResultPage));
(resultFrame.Content as SearchResultPage).ItemsSource.CollectionChanged += ItemsSource_CollectionChanged;
grdSearchPanel.Visibility = Visibility.Collapsed;
if (txtWord.Text.Trim() != lastWord || cbSearchTarget.SelectedIndex != lastIndex1 ||
cbSort.SelectedIndex != lastIndex2 || cbDuration.SelectedIndex != lastIndex3)
{
lastWord = txtWord.Text.Trim();
lastIndex1 = cbSearchTarget.SelectedIndex;
lastIndex2 = cbSort.SelectedIndex;
lastIndex3 = cbDuration.SelectedIndex;
searchProgressRing.IsActive = true;
searchProgressRing.Visibility = Visibility.Visible;
}
}
((Frame.Parent as Grid)?.Parent as MainPage)?.SelectNavPlaceholder(GetResourceString("SearchPagePlain"));
}

Expand Down Expand Up @@ -117,7 +139,7 @@ private async void TxtWord_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQ
{
if (resultFrame.Content != null)
(resultFrame.Content as SearchResultPage).ItemsSource.CollectionChanged -= ItemsSource_CollectionChanged;
var param = new SearchResultPage.SearchParam()
var param = new OverAll.SearchParam()
{
Word = txtWord.Text.Trim()
};
Expand Down Expand Up @@ -157,7 +179,8 @@ private async void TxtWord_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQ
param.Duration = "within_last_month";
break;
}
resultFrame.Navigate(typeof(SearchResultPage), param);
OverAll.NewSearchResultList(param);
resultFrame.Navigate(typeof(SearchResultPage));
(resultFrame.Content as SearchResultPage).ItemsSource.CollectionChanged += ItemsSource_CollectionChanged;
}
storyFade.Begin();
Expand Down
16 changes: 2 additions & 14 deletions PixivFSUWP/SearchResultPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ namespace PixivFSUWP
/// </summary>
public sealed partial class SearchResultPage : Page
{
public struct SearchParam
{
public string Word;
public string SearchTarget;
public string Sort;
public string Duration;
}

SearchParam param;

public SearchResultIllustsCollection ItemsSource;

public SearchResultPage()
Expand All @@ -50,16 +40,14 @@ public SearchResultPage()
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.Parameter is SearchParam) param = (SearchParam)e.Parameter;
ItemsSource = new SearchResultIllustsCollection(param.Word, param.SearchTarget,
param.Sort, param.Duration);
ItemsSource = Data.OverAll.SearchResultList;
Data.OverAll.SearchResultList.ResumeLoading();
WaterfallListView.ItemsSource = ItemsSource;
}

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
ItemsSource?.StopLoading();
ItemsSource = null;
}

Expand Down

0 comments on commit cd97665

Please sign in to comment.