From cd976658fdc663f40f816901be8b03560bce5d3b Mon Sep 17 00:00:00 2001 From: YukinoShary Date: Sun, 31 May 2020 04:36:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=85=B3=E4=BA=8E=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=BB=93=E6=9E=9C=E9=A1=B5=E7=9A=84=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PixivFSUWP/Data/OverAll.cs | 20 ++++++++++++++++++++ PixivFSUWP/MainPage.xaml.cs | 2 +- PixivFSUWP/SearchPage.xaml.cs | 29 ++++++++++++++++++++++++++--- PixivFSUWP/SearchResultPage.xaml.cs | 16 ++-------------- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/PixivFSUWP/Data/OverAll.cs b/PixivFSUWP/Data/OverAll.cs index 330d232..83560bb 100644 --- a/PixivFSUWP/Data/OverAll.cs +++ b/PixivFSUWP/Data/OverAll.cs @@ -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(); @@ -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 DownloadImage(string Uri) { diff --git a/PixivFSUWP/MainPage.xaml.cs b/PixivFSUWP/MainPage.xaml.cs index 2ff3840..e02d0c6 100644 --- a/PixivFSUWP/MainPage.xaml.cs +++ b/PixivFSUWP/MainPage.xaml.cs @@ -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 { } diff --git a/PixivFSUWP/SearchPage.xaml.cs b/PixivFSUWP/SearchPage.xaml.cs index f82abf7..b804939 100644 --- a/PixivFSUWP/SearchPage.xaml.cs +++ b/PixivFSUWP/SearchPage.xaml.cs @@ -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 上介绍了“空白页”项模板 @@ -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(); } } @@ -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")); } @@ -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() }; @@ -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(); diff --git a/PixivFSUWP/SearchResultPage.xaml.cs b/PixivFSUWP/SearchResultPage.xaml.cs index f4b42ca..2ed16d4 100644 --- a/PixivFSUWP/SearchResultPage.xaml.cs +++ b/PixivFSUWP/SearchResultPage.xaml.cs @@ -30,16 +30,6 @@ namespace PixivFSUWP /// 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() @@ -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; }