Beispiel #1
0
 private static void item_image_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
 {
     try
     {
         ImageContainer sender = dependencyObject as ImageContainer;
         if (sender != null)
         {
             sender.item_image_Update(args);
         }
     }
     catch { }
 }
Beispiel #2
0
 private static async void image_linkChanged(BindableObject bindableObject, object oldValue, object newValue)
 {
     try
     {
         ImageContainer sender = bindableObject as ImageContainer;
         if (sender != null)
         {
             await sender.SetImageLink(newValue.ToString());
         }
     }
     catch { }
 }
Beispiel #3
0
        //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(ImageContainer))
                        {
                            ItemImagecount++;
                            ImageContainer frameworkElement = child as ImageContainer;
                            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();
                            //System.Diagnostics.Debug.WriteLine("Comparing image: " + CompareBitmapLink + " vs " + CompareItemImageLink);

                            if (CompareBitmapLink == CompareItemImageLink)
                            {
                                FoundPreviewImage = true;
                                break;
                            }
                        }
                        else
                        {
                            //System.Diagnostics.Debug.WriteLine("No image, checking if there is a sub image.");
                            CheckTextBlockForPreviewImage(child, ItemImageLink, ref ItemImagecount, ref FoundPreviewImage);
                        }
                    }
                    catch { }
                }
            }
            catch { }
        }
Beispiel #4
0
        private async Task GenerateImage(StackPanel addElement, 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))
                {
                    System.Diagnostics.Debug.WriteLine("Blocked image: " + sourceUri);
                    return;
                }

                //Check if device is low on memory
                if (AVFunctions.DevMemoryAvailableMB() < 100)
                {
                    ImageContainer imgLowMemory = new ImageContainer();
                    imgLowMemory.item_status.Text = "Image not loaded,\ndevice is low on memory.";
                    imgLowMemory.IsHitTestVisible = false;

                    addElement.Children.Add(imgLowMemory);
                    //GenerateBreak(addElement);
                    return;
                }

                //Create item image
                System.Diagnostics.Debug.WriteLine("Adding image: " + sourceUri);
                ImageContainer imgContainer = new ImageContainer();
                imgContainer.MaxHeight        = AppVariables.DefaultMediaHeight;
                imgContainer.item_image_Value = sourceUri;

                //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))
                    {
                        imgContainer.item_description.Text       = AltText;
                        imgContainer.item_description.Visibility = Visibility.Visible;
                    }
                }

                addElement.Children.Add(imgContainer);
                //GenerateBreak(addElement);
            }
            catch { }
        }
Beispiel #5
0
        private void GenerateImage(StackLayout addElement, 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;
                }

                //fix
                ////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.IsEnabled = false;

                //    InlineUIContainer iui = new InlineUIContainer();
                //    iui.Child = img;

                //    addElement.Children.Add(iui);
                //    //GenerateBreak(addElement);
                //    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)AppSettingLoad("LowBandwidthMode"))
                {
                    Label img_lowbandwidth = new Label();
                    img_lowbandwidth.Text = "Gif not loaded,\nlow bandwidth mode.";
                    img_lowbandwidth.SetDynamicResource(Label.StyleProperty, "LabelDark");
                    img_lowbandwidth.SetDynamicResource(Label.FontSizeProperty, "TextSizeMedium");

                    addElement.Children.Add(img_lowbandwidth);
                    return;
                }

                //Create item container
                ImageContainer imageContainer = new ImageContainer();
                imageContainer.image_link = sourceUri;

                //Get and set alt from the image
                if (vImageShowAlt && htmlNode.Attributes["alt"] != null)
                {
                    string imageAltText = Process.ProcessItemTextSummary(htmlNode.Attributes["alt"].Value, false, false);
                    if (!string.IsNullOrWhiteSpace(imageAltText))
                    {
                        imageContainer.item_description.Text      = imageAltText;
                        imageContainer.item_description.IsVisible = true;

                        //Fix
                        ////Enable or disable text selection
                        //if ((bool)AppSettingLoad("ItemTextSelection"])
                        //{
                        //    img.item_description.IsTextSelectionEnabled = true;
                        //}
                        //else
                        //{
                        //    img.item_description.IsTextSelectionEnabled = false;
                        //}
                    }
                }

                addElement.Children.Add(imageContainer);
                Debug.WriteLine("Added image: " + sourceUri);
                //GenerateBreak(addElement);
            }
            catch
            {
                Label img_failed = new Label();
                img_failed.Text = "Image is not available,\nopen item in browser to view it.";
                img_failed.SetDynamicResource(Label.StyleProperty, "LabelDark");
                img_failed.SetDynamicResource(Label.FontSizeProperty, "TextSizeMedium");

                addElement.Children.Add(img_failed);
                //GenerateBreak(addElement);
                return;
            }
        }
Beispiel #6
0
        private async Task GenerateImage(StackPanel addElement, 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))
                {
                    System.Diagnostics.Debug.WriteLine("Blocked image: " + sourceUri);
                    return;
                }

                //Check if device is low on memory
                if (AVFunctions.DevMemoryAvailableMB() < 100)
                {
                    ImageContainer img = new ImageContainer();
                    img.item_status.Text = "Image not loaded,\ndevice is low on memory.";
                    img.IsHitTestVisible = false;

                    addElement.Children.Add(img);
                    //GenerateBreak(addElement);
                    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"])
                {
                    ImageContainer img = new ImageContainer();
                    img.item_status.Text = "Gif not loaded,\nlow bandwidth mode.";
                    img.IsHitTestVisible = false;

                    addElement.Children.Add(img);
                    //GenerateBreak(addElement);
                    return;
                }

                //Create item image
                //Fix move image downloading to imagecontainer
                System.Diagnostics.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)
                {
                    ImageContainer img = new ImageContainer();
                    img.MaxHeight = AppVariables.MaximumItemImageHeight;

                    if (SvgImage != null)
                    {
                        img.item_source.Source = SvgImage;
                    }

                    if (BitmapImage != null)
                    {
                        img.item_source.Source = 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;
                        }
                    }

                    addElement.Children.Add(img);
                    //GenerateBreak(addElement);
                }
                else
                {
                    ImageContainer img = new ImageContainer();
                    img.item_status.Text = "Image is not available,\nopen item in browser to view it.";
                    img.IsHitTestVisible = false;

                    addElement.Children.Add(img);
                    //GenerateBreak(addElement);
                    return;
                }
            }
            catch { }
        }