private async Task FeedReInit(RssSchema data) { bool isUnread = Convert.ToBoolean(AppTools.GetLocalSetting(AppSettings.IsJustUnread, "False")); if (!isUnread) { ShowFeeds.Insert(0, _sourceFeed); } ShowFeeds.Remove(data); _sourceFeed = data; LoadingRing.IsActive = true; if (MainPage.Current.ChannelListView.SelectedItem != null) { var selectChannel = MainPage.Current.ChannelListView.SelectedItem as Channel; if (MainPage.Current.ReadableList.Any(c => c.Id == selectChannel.Id)) { DetailWebView.NavigateToString(""); SmartReader.Article article = await SmartReader.Reader.ParseArticleAsync(_sourceFeed.FeedUrl); if (article.IsReadable || !string.IsNullOrEmpty(article.TextContent)) { _sourceFeed.Content = article.Content; } else { new PopupToast(AppTools.GetReswLanguage("Tip_ReadError"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); } } } await UpdateFeed(); LoadingRing.IsActive = false; }
public void HidePopup() { DetailWebView.NavigateToString(""); PopupOut.Begin(); PopupOut.Completed -= PopupOut_Completed; PopupOut.Completed += PopupOut_Completed; }
private void DetailWebView_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args) { LoadingRing.IsActive = false; DetailWebView.Focus(FocusState.Programmatic); if (string.IsNullOrEmpty(TitleBlock.Text)) { TitleBlock.Text = DetailWebView.DocumentTitle; } }
private async void ShareButton_Click(object sender, RoutedEventArgs e) { _tempHtml = await DetailWebView.InvokeScriptAsync("getHtml", new string[] { }); DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView(); dataTransferManager.DataRequested += IndexPage_DataRequested; DataTransferManager.ShowShareUI(); }
/// <summary> /// 获取原网页并解析为可读文本 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ReadabilityButton_Click(object sender, RoutedEventArgs e) { var result = await ReadabilityFromUrl(_sourceFeed.FeedUrl); if (!string.IsNullOrEmpty(_sourceFeed.Content)) { DetailWebView.NavigateToString(await PackageHTML(_sourceFeed.Content)); } }
public async void Init(string title, int id) { _articleId = id; TitleBlock.Text = title; LoadingRing.IsActive = true; string content = await GetArticleContent(); string html = await PackageHTML(content); DetailWebView.NavigateToString(html); }
private async void FontFamilyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!_isInit) { return; } string name = (FontFamilyComboBox.SelectedItem as SystemFont).Name; AppTools.WriteLocalSetting(AppSettings.ReadFontFamily, name); await DetailWebView.InvokeScriptAsync("setFontFamily", new string[] { name }); }
private async void SelectMenu_Mark_Click(object sender, RoutedEventArgs e) { try { await DetailWebView.InvokeScriptAsync("setMark", new string[] { }); } catch (Exception) { new PopupToast(AppTools.GetReswLanguage("Tip_DoNotMarkAgain"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); } }
private async Task UpdateFeed() { ButtonStatusCheck(); TitleTextBlock.Text = _sourceFeed.Title; string html = await PackageHTML(_sourceFeed.Content); LoadingRing.IsActive = true; DetailWebView.NavigateToString(html); bool isSideLocked = Convert.ToBoolean(AppTools.GetLocalSetting(AppSettings.SideListLocked, "False")); if (MainPage.Current.MinsizeHeaderContainer.Visibility == Visibility.Visible && !isSideLocked) { DetailSplitView.IsPaneOpen = false; } MainPage.Current.AddReadId(_sourceFeed.InternalID); await GenerateActivityAsync(_sourceFeed); }
public async Task TranslateArticle(string language) { if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable) { new PopupToast(AppTools.GetReswLanguage("Tip_FailedWithoutInternet"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); return; } string appId = AppTools.GetRoamingSetting(AppSettings.Translate_BaiduAppId, ""); if (string.IsNullOrEmpty(appId)) { var dialog = new Dialog.BaiduTranslateDialog(); await dialog.ShowAsync(); } appId = AppTools.GetRoamingSetting(AppSettings.Translate_BaiduAppId, ""); string appKey = AppTools.GetRoamingSetting(AppSettings.Translate_BaiduKey, ""); if (string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(appKey)) { return; } else { LoadingRing.IsActive = true; string output = await TranslateTools.Translate(_sourceFeed.Content, appId, appKey, "auto", language.ToLower()); if (!string.IsNullOrEmpty(output)) { string html = await PackageHTML(output); DetailWebView.NavigateToString(html); } else { new PopupToast(AppTools.GetReswLanguage("Tip_TranslateFailed"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); } LoadingRing.IsActive = false; } }
private async Task SetFontSize() { if (!_isInit) { return; } string oldSize = AppTools.GetLocalSetting(AppSettings.ReadFontSize, "16"); string size = FontSizeTextBox.Text?.Trim(); if (oldSize == size) { return; } if (string.IsNullOrEmpty(size)) { FontSizeTextBox.Text = oldSize; return; } try { int s = Convert.ToInt32(size); if (s > 0) { await DetailWebView.InvokeScriptAsync("setFontSize", new string[] { s.ToString() }); AppTools.WriteLocalSetting(AppSettings.ReadFontSize, s.ToString()); FontSizeTextBox.Text = s.ToString(); return; } } catch (Exception) { } FontSizeTextBox.Text = oldSize; return; }
private void DetailWebView_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args) { LoadingRing.IsActive = false; DetailWebView.Focus(FocusState.Programmatic); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { if (e.NavigationMode == NavigationMode.Back) { ReadabilityButton.IsEnabled = true; return; } if (e.Parameter != null) { ShowFeeds.Clear(); // 这种情况表明入口点为频道 if (e.Parameter is Tuple <RssSchema, List <RssSchema> > ) { var anim = ConnectedAnimationService.GetForCurrentView().GetAnimation("ForwardConnectedAnimation"); if (anim != null) { anim.TryStart(TitleTextBlock); } LoadingRing.IsActive = true; var data = e.Parameter as Tuple <RssSchema, List <RssSchema> >; bool isUnread = Convert.ToBoolean(AppTools.GetLocalSetting(AppSettings.IsJustUnread, "False")); bool isCollection = Convert.ToBoolean(MainPage.Current.TodoButton.IsChecked) || Convert.ToBoolean(MainPage.Current.StarButton.IsChecked); _sourceFeed = data.Item1; AllFeeds = data.Item2; TitleTextBlock.Text = _sourceFeed.Title; MainPage.Current.AddReadId(_sourceFeed.InternalID); foreach (var item in AllFeeds) { if (item.InternalID != _sourceFeed.InternalID) { if (isUnread && !isCollection && !MainPage.Current.ReadIds.Contains(item.InternalID)) { ShowFeeds.Add(item); } else if (!isUnread || isCollection) { ShowFeeds.Add(item); } } } if (MainPage.Current.ChannelListView.SelectedItem != null) { var selectChannel = MainPage.Current.ChannelListView.SelectedItem as Channel; if (MainPage.Current.ReadableList.Any(c => c.Id == selectChannel.Id)) { SmartReader.Article article = await SmartReader.Reader.ParseArticleAsync(_sourceFeed.FeedUrl); if (article.IsReadable || !string.IsNullOrEmpty(article.TextContent)) { _sourceFeed.Content = article.Content; } else { new PopupToast(AppTools.GetReswLanguage("Tip_ReadError"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); } } } _sourceContent = _sourceFeed.Content; await GenerateActivityAsync(_sourceFeed); } // 这种情况表明入口点是动态卡片 else if (e.Parameter is string[]) { var data = e.Parameter as string[]; _sourceFeed = new RssSchema() { InternalID = data[0], Title = data[1], Content = data[2], FeedUrl = data[3], ImageUrl = data[4], PublishDate = Convert.ToDateTime(data[5]), Summary = data[6], }; _sourceContent = data[2]; LoadingRing.IsActive = true; GridViewButton.Visibility = Visibility.Collapsed; SideListButton.Visibility = Visibility.Collapsed; FeedListView.Visibility = Visibility.Collapsed; Grid.SetColumn(SideControlContainer, 1); MainPage.Current.SideHide(); SideControlContainer.HorizontalAlignment = HorizontalAlignment.Right; SideControlContainer.Margin = new Thickness(0, 0, 10, 0); DetailSplitView.IsPaneOpen = false; } // 入口点是通知 else if (e.Parameter is string) { string url = e.Parameter as string; _sourceFeed = new RssSchema { InternalID = url, FeedUrl = url }; var content = await ReadabilityFromUrl(url); _sourceFeed.Content = content.Content ?? content.TextContent; _sourceFeed.Title = content.Title; _sourceFeed.PublishDate = Convert.ToDateTime(content.PublicationDate).ToLocalTime(); _sourceFeed.ImageUrl = content.FeaturedImage; _sourceContent = content.Content ?? content.TextContent; LoadingRing.IsActive = true; GridViewButton.Visibility = Visibility.Collapsed; SideListButton.Visibility = Visibility.Collapsed; FeedListView.Visibility = Visibility.Collapsed; Grid.SetColumn(SideControlContainer, 1); MainPage.Current.SideHide(); SideControlContainer.HorizontalAlignment = HorizontalAlignment.Right; SideControlContainer.Margin = new Thickness(0, 0, 10, 0); DetailSplitView.IsPaneOpen = false; } ButtonStatusCheck(); TitleTextBlock.Text = _sourceFeed.Title; string html = await PackageHTML(_sourceFeed.Content ?? _sourceFeed.Summary); DetailWebView.NavigateToString(html); string fontFamily = AppTools.GetLocalSetting(AppSettings.ReadFontFamily, "Tw Cen MT"); string fontSize = AppTools.GetLocalSetting(AppSettings.ReadFontSize, "16"); var selectFontFamily = MainPage.Current.SystemFonts.Where(p => p.Name == fontFamily).FirstOrDefault(); FontFamilyComboBox.SelectedItem = selectFontFamily; FontSizeTextBox.Text = fontSize; _isInit = true; } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { DetailWebView.NavigateToString(""); this.UnloadObject(this); base.OnNavigatedFrom(e); }
private async void Menu_ReInit_Click(object sender, RoutedEventArgs e) { string html = await PackageHTML(_sourceContent); DetailWebView.NavigateToString(html); }