/// <summary> /// 更新布局,获取最新资讯 /// </summary> /// <param name="page">频道数据</param> /// <returns></returns> public async Task UpdateLayout(CustomPage page, bool isForceRefresh = false) { AllFeeds.Clear(); LoadingRing.IsActive = true; JustNoReadSwitch.IsEnabled = false; AllReadButton.Visibility = Visibility.Collapsed; LastCacheTimeContainer.Visibility = Visibility.Collapsed; NoDataTipContainer.Visibility = Visibility.Collapsed; AllReadTipContainer.Visibility = Visibility.Collapsed; _sourceData = page; PageNameTextBlock.Text = _sourceData.Name; FeedCollection.Clear(); var feed = new List <RssSchema>(); if (NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable) { var schema = await IOTools.GetSchemaFromPage(_sourceData); foreach (var item in schema) { feed.Add(item); } bool isAutoCache = Convert.ToBoolean(AppTools.GetLocalSetting(AppSettings.AutoCacheWhenOpenChannel, "False")); if (isAutoCache && feed.Count > 0) { await IOTools.AddCachePage(null, page); } } else { if (MainPage.Current._isCacheAlert) { new PopupToast(AppTools.GetReswLanguage("Tip_WatchingCache")).ShowPopup(); MainPage.Current._isCacheAlert = false; } var data = await IOTools.GetLocalCache(page); feed = data.Item1; _lastCacheTime = data.Item2; if (_lastCacheTime > 0) { LastCacheTimeContainer.Visibility = Visibility.Visible; LastCacheTimeBlock.Text = AppTools.TimeStampToDate(_lastCacheTime).ToString("HH:mm"); } } if (feed != null && feed.Count > 0) { AllFeeds = feed; await FeedInit(); } else { NoDataTipContainer.Visibility = Visibility.Visible; } JustNoReadSwitch.IsEnabled = true; LoadingRing.IsActive = false; }
private async void CacheAllButton_Click(object sender, RoutedEventArgs e) { if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable) { new PopupToast(AppTools.GetReswLanguage("Tip_FailedWithoutInternet"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); return; } CacheAllButton.IsEnabled = false; CacheProgressBar.Visibility = Visibility.Visible; var list = new List <Channel>(); foreach (var item in MainPage.Current.Categories) { foreach (var cha in item.Channels) { list.Add(cha); } } var pageList = MainPage.Current.CustomPages; if (list.Count > 0) { try { CacheProgressBar.Maximum = list.Count + pageList.Count; int channelCount = 0; int pageCount = 0; var tasks = new Task[2]; tasks[0] = Task.Run(async() => { await IOTools.AddCacheChannel(async(count) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { channelCount = count; CacheProgressBar.Value = channelCount + pageCount; }); }, list.ToArray()); }); tasks[1] = Task.Run(async() => { await IOTools.AddCachePage(async(count) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { pageCount = count; CacheProgressBar.Value = channelCount + pageCount; }); }, pageList.ToArray()); }); await Task.WhenAll(tasks); new PopupToast(AppTools.GetReswLanguage("Tip_CacheSuccess")).ShowPopup(); } catch (Exception ex) { new PopupToast(ex.Message).ShowPopup(); } } CacheSizeTextBlock.Text = await IOTools.GetCacheSize(); CacheAllButton.IsEnabled = true; CacheProgressBar.Visibility = Visibility.Collapsed; }