//Check if there are images and the preview image is included private void CheckTextBlockForPreviewImage(DependencyObject SearchElement, string ItemImageLink, ref int ItemImagecount, ref bool FoundPreviewImage) { try { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(SearchElement); i++) { try { DependencyObject child = VisualTreeHelper.GetChild(SearchElement, i); if (child.GetType() == typeof(grid_item_image)) { ItemImagecount++; grid_item_image frameworkElement = child as grid_item_image; BitmapImage bitmapSource = frameworkElement.item_source.Source as BitmapImage; string CompareBitmapLink = Regex.Replace(bitmapSource.UriSource.ToString(), @"^(?:http(?:s)?://)?(?:www(?:[0-9]+)?\.)?", string.Empty, RegexOptions.IgnoreCase).ToLower(); string CompareItemImageLink = Regex.Replace(ItemImageLink, @"^(?:http(?:s)?://)?(?:www(?:[0-9]+)?\.)?", string.Empty, RegexOptions.IgnoreCase).ToLower(); //Debug.WriteLine("Comparing image: " + CompareBitmapLink + " vs " + CompareItemImageLink); if (CompareBitmapLink == CompareItemImageLink) { FoundPreviewImage = true; break; } } else { //Debug.WriteLine("No image, checking if there is a sub image."); CheckTextBlockForPreviewImage(child, ItemImageLink, ref ItemImagecount, ref FoundPreviewImage); } } catch { } } } catch { } }
private void GenerateWebview(Span addSpan, HtmlNode htmlNode) { try { //Check if webview limit reached if (vWebViewAdded == vWebViewLimit) { grid_item_webview webView = new grid_item_webview(); webView.item_status.Text = "Webview not loaded,\nlimit has been reached."; InlineUIContainer iui = new InlineUIContainer(); iui.Child = webView; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Check if media loading is allowed if (!AppVariables.LoadMedia) { grid_item_webview webView = new grid_item_webview(); webView.item_status.Text = "Webview not loaded,\nnetwork is not available."; InlineUIContainer iui = new InlineUIContainer(); iui.Child = webView; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Check if device is low on memory if (AVFunctions.DevMemoryAvailableMB() < 200) { grid_item_webview webView = new grid_item_webview(); webView.item_status.Text = "Webview not loaded,\ndevice is low on memory."; InlineUIContainer iui = new InlineUIContainer(); iui.Child = webView; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Check if low bandwidth mode is enabled if ((bool)AppVariables.ApplicationSettings["LowBandwidthMode"]) { grid_item_image img = new grid_item_image(); img.item_status.Text = "Webview not loaded,\nlow bandwidth mode."; img.IsHitTestVisible = false; InlineUIContainer iui = new InlineUIContainer(); iui.Child = img; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Create item webview string WebLink = htmlNode.Attributes["src"].Value; if (!string.IsNullOrWhiteSpace(WebLink)) { Debug.WriteLine("Opening webview: " + WebLink); grid_item_webview webView = new grid_item_webview(); webView.item_source.Source = new Uri(WebLink); webView.item_source.ContainsFullScreenElementChanged += webview_Full_ContainsFullScreenElementChanged; webView.item_source.NewWindowRequested += webview_Full_NewWindowRequested; InlineUIContainer iui = new InlineUIContainer(); iui.Child = webView; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); //Update the webview count vWebViewAdded++; } } catch { } }
private async Task GenerateImage(Span addSpan, HtmlNode htmlNode) { try { //Decode the image source link string sourceUri = string.Empty; if (htmlNode.Attributes["src"] != null) { sourceUri = WebUtility.HtmlDecode(htmlNode.Attributes["src"].Value); sourceUri = WebUtility.UrlDecode(sourceUri); } else if (htmlNode.Attributes["srcset"] != null) { sourceUri = WebUtility.HtmlDecode(htmlNode.Attributes["srcset"].Value); sourceUri = WebUtility.UrlDecode(sourceUri); } //Split an image srcset link Regex RegexSourceset = new Regex(@"(?:\s+\d+[wx])(?:,\s+)?"); IEnumerable <string> ImageSources = RegexSourceset.Split(sourceUri).Where(x => x != string.Empty); if (ImageSources.Any()) { sourceUri = ImageSources.LastOrDefault(); } //Split http(s):// tags from uri if (sourceUri.Contains("https://") && sourceUri.LastIndexOf("https://") <= 20) { sourceUri = sourceUri.Substring(sourceUri.LastIndexOf("https://")); } if (sourceUri.Contains("http://") && sourceUri.LastIndexOf("http://") <= 20) { sourceUri = sourceUri.Substring(sourceUri.LastIndexOf("http://")); } //Check if image needs to be blocked if (string.IsNullOrWhiteSpace(sourceUri) || AppVariables.BlockedListUrl.Any(sourceUri.ToLower().Contains)) { Debug.WriteLine("Blocked image: " + sourceUri); return; } //Check if device is low on memory if (AVFunctions.DevMemoryAvailableMB() < 100) { grid_item_image img = new grid_item_image(); img.item_status.Text = "Image not loaded,\ndevice is low on memory."; img.IsHitTestVisible = false; InlineUIContainer iui = new InlineUIContainer(); iui.Child = img; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Check if media is a gif(v) file bool ImageIsGif = sourceUri.ToLower().Contains(".gif"); bool ImageIsSvg = sourceUri.ToLower().Contains(".svg"); //Check if low bandwidth mode is enabled if (ImageIsGif && (bool)AppVariables.ApplicationSettings["LowBandwidthMode"]) { grid_item_image img = new grid_item_image(); img.item_status.Text = "Gif not loaded,\nlow bandwidth mode."; img.IsHitTestVisible = false; InlineUIContainer iui = new InlineUIContainer(); iui.Child = img; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Create item image Debug.WriteLine("Adding image: " + sourceUri); SvgImageSource SvgImage = null; BitmapImage BitmapImage = null; if (ImageIsSvg) { SvgImage = await AVImage.LoadSvgImage(sourceUri); } else { BitmapImage = await AVImage.LoadBitmapImage(sourceUri, true); } if (SvgImage != null || BitmapImage != null) { grid_item_image img = new grid_item_image(); img.MaxHeight = AppVariables.MaximumItemImageHeight; if (SvgImage != null) { img.item_source.Source = SvgImage; } if (BitmapImage != null) { img.value_item_image = BitmapImage; } //Get and set alt from the image if (vImageShowAlt && htmlNode.Attributes["alt"] != null) { string AltText = Process.ProcessItemTextSummary(htmlNode.Attributes["alt"].Value, false, false); if (!string.IsNullOrWhiteSpace(AltText)) { img.item_description.Text = AltText; img.item_description.Visibility = Visibility.Visible; //Enable or disable text selection if ((bool)AppVariables.ApplicationSettings["ItemTextSelection"]) { img.item_description.IsTextSelectionEnabled = true; } else { img.item_description.IsTextSelectionEnabled = false; } } } InlineUIContainer iui = new InlineUIContainer(); iui.Child = img; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); } else { grid_item_image img = new grid_item_image(); img.item_status.Text = "Image is not available,\nopen item in browser to view it."; img.IsHitTestVisible = false; InlineUIContainer iui = new InlineUIContainer(); iui.Child = img; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } } catch { } }
private void GenerateVideo(Span addSpan, HtmlNode htmlNode) { try { //Check if media loading is allowed if (!AppVariables.LoadMedia) { grid_item_video video = new grid_item_video(); video.item_status.Text = "Video not loaded,\nnetwork is not available."; InlineUIContainer iui = new InlineUIContainer(); iui.Child = video; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Check if device is low on memory if (AVFunctions.DevMemoryAvailableMB() < 200) { grid_item_video video = new grid_item_video(); video.item_status.Text = "Video not loaded,\ndevice is low on memory."; InlineUIContainer iui = new InlineUIContainer(); iui.Child = video; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Check if low bandwidth mode is enabled if ((bool)AppVariables.ApplicationSettings["LowBandwidthMode"]) { grid_item_image img = new grid_item_image(); img.item_status.Text = "Video not loaded,\nlow bandwidth mode."; img.IsHitTestVisible = false; InlineUIContainer iui = new InlineUIContainer(); iui.Child = img; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); return; } //Create item video string VideoString = htmlNode.Attributes["src"].Value; if (!string.IsNullOrWhiteSpace(VideoString)) { Debug.WriteLine("Opening video: " + VideoString); grid_item_video video = new grid_item_video(); video.item_source.Source = new Uri(VideoString); //Check if media is a gif(v) file if (VideoString.ToLower().Contains(".gif")) { video.item_source.AutoPlay = true; video.item_source.MediaEnded += delegate { video.item_source.Position = new TimeSpan(); video.item_source.Play(); }; } else { video.item_source.AutoPlay = false; } InlineUIContainer iui = new InlineUIContainer(); iui.Child = video; addSpan.Inlines.Add(iui); //addSpan.Inlines.Add(new LineBreak()); } } catch { } }