Exemple #1
0
        private void CreateOrUpdateLayout()
        {
            foreach (IVirtualizable virtualizableChild in (Collection <IVirtualizable>) this.VirtualizableChildren)
            {
                virtualizableChild.ChangeState(VirtualizableState.Unloaded);
            }
            this.VirtualizableChildren.Clear();
            if (this._thumbs.Count == 0)
            {
                return;
            }
            List <Rect> layout = RectangleLayoutHelper.CreateLayout(new Size(this.Width, this.DesiredHeight), this._thumbs.Select <ThumbsItem.Thumb, Size>((Func <ThumbsItem.Thumb, Size>)(t => new Size(t.Width, t.Height))).ToList <Size>(), 4.0);

            layout.Max <Rect>((Func <Rect, double>)(r => r.Left + r.Width));
            int index = 0;

            foreach (Rect rect1 in layout)
            {
                Rect               rect           = rect1;
                Thickness          margin         = new Thickness(rect.Left, rect.Top, 0.0, 0.0);
                ThumbsItem.Thumb   currentThumb   = this._thumbs[index];
                bool               blackRectOnTop = !string.IsNullOrEmpty(currentThumb.Label);
                bool               flag           = !string.IsNullOrEmpty(currentThumb.LabelLarge);
                VirtualizableImage virtImage      = new VirtualizableImage(rect.Width, rect.Height, margin, currentThumb.GetProperSrc(rect.Width, rect.Height), new Action <VirtualizableImage>(this.Image_Tap), index.ToString(), false, !this._isMessage, Stretch.UniformToFill, (Brush)null, -1.0, blackRectOnTop, false);
                this.VirtualizableChildren.Add((IVirtualizable)virtImage);
                if (currentThumb.Video != null)
                {
                    this.VirtualizableChildren.Add((IVirtualizable) new UCItem(rect.Width, margin, (Func <UserControlVirtualizable>)(() =>
                    {
                        return((UserControlVirtualizable) new VideoNewsItemDescUC()
                        {
                            Width = rect.Width,
                            Height = rect.Height,
                            DataContext = (object)new VideoNewsItemDescViewModel(currentThumb.Video, rect.Width > 460.0)
                        });
                    }), (Func <double>)(() => rect.Height), (Action <UserControlVirtualizable>)null, 0.0, false));
                    virtImage.Tag2 = "NotAPreview";
                }
                else if (currentThumb.GifDoc != null)
                {
                    UCItem ucItem = new UCItem(rect.Width, margin, (Func <UserControlVirtualizable>)(() =>
                    {
                        bool isOneItem = layout.Count == 1;
                        InplaceGifViewerViewModel gifViewerViewModel = new InplaceGifViewerViewModel(currentThumb.GifDoc, false, this._isCommentThumbItem || this._isMessage, isOneItem);
                        if (isOneItem)
                        {
                            return (UserControlVirtualizable) new InplaceGifViewerUC()
                            {
                                Width        = rect.Width,
                                Height       = rect.Height,
                                VM           = gifViewerViewModel,
                                gifOverlayUC =
                                {
                                    OnTap = (Action)(() => this.Image_Tap(virtImage))
                                }
                            }
                        }
                        ;
                        return((UserControlVirtualizable) new GifOverlayUC()
                        {
                            Width = rect.Width,
                            Height = rect.Height,
                            DataContext = (object)gifViewerViewModel,
                            OnTap = (Action)(() => this.Image_Tap(virtImage))
                        });
                    }), (Func <double>)(() => rect.Height), (Action <UserControlVirtualizable>)null, 0.0, false);
                    virtImage.OverlayControl = (object)ucItem;
                    this.VirtualizableChildren.Add((IVirtualizable)ucItem);
                }
                else if (currentThumb.Album != null || currentThumb.MarketAlbum != null)
                {
                    this.VirtualizableChildren.Add((IVirtualizable) new UCItem(rect.Width, margin, (Func <UserControlVirtualizable>)(() =>
                    {
                        return((UserControlVirtualizable) new AlbumNewsItemDescUC()
                        {
                            Width = rect.Width,
                            Height = rect.Height,
                            DataContext = (object)(currentThumb.Album != null ? new AlbumNewsItemDescViewModel(currentThumb.Album, rect.Width > 460.0) : new AlbumNewsItemDescViewModel(currentThumb.MarketAlbum, rect.Width > 460.0))
                        });
                    }), (Func <double>)(() => rect.Height), (Action <UserControlVirtualizable>)null, 0.0, false));
                    virtImage.Tag2 = "NotAPreview";
                }
                else if (blackRectOnTop)
                {
                    if (flag)
                    {
                        this.VirtualizableChildren.Add((IVirtualizable) new TextItem(rect.Width - 12.0, new Thickness(rect.Left + 12.0, rect.Top + rect.Height - 69.0, 0.0, 0.0), this._thumbs[index].LabelLarge, false, 25.33, "Segoe WP", 27.0, new SolidColorBrush(Colors.White), false, null));
                        double          width      = rect.Width - 12.0;
                        Thickness       textMargin = new Thickness(rect.Left + 12.0, rect.Top + rect.Height - 37.0, 0.0, 0.0);
                        string          label      = this._thumbs[index].Label;
                        int             num1       = 0;
                        double          fontSize   = 20.0;
                        string          fontFamily = "Segoe WP";
                        double          lineHeight = 22.0;
                        SolidColorBrush foreground = new SolidColorBrush(Colors.White);
                        double          num2       = 0.6;
                        foreground.Opacity = num2;
                        int    num3  = 0;
                        object local = null;
                        this.VirtualizableChildren.Add((IVirtualizable) new TextItem(width, textMargin, label, num1 != 0, fontSize, fontFamily, lineHeight, foreground, num3 != 0, (Action)local));
                    }
                    else
                    {
                        this.VirtualizableChildren.Add((IVirtualizable) new TextItem(rect.Width - 12.0, new Thickness(rect.Left + 12.0, rect.Top + rect.Height - 37.0, 0.0, 0.0), this._thumbs[index].Label, false, 20.0, "Segoe WP", 22.0, new SolidColorBrush(Colors.White), false, null));
                    }
                    virtImage.Tag2 = "NotAPreview";
                }
                ++index;
            }
            if (this.CurrentState != VirtualizableState.Unloaded)
            {
                foreach (IVirtualizable virtualizableChild in (Collection <IVirtualizable>) this.VirtualizableChildren)
                {
                    virtualizableChild.ChangeState(this.CurrentState);
                }
            }
            double num;

            if (layout.Count <= 0)
            {
                num = 0.0;
            }
            else
            {
                Rect   rect = layout.Last <Rect>();
                double top  = rect.Top;
                rect = layout.Last <Rect>();
                double height = rect.Height;
                num = top + height;
            }
            this._height = num;
        }
Exemple #2
0
 private void ReadThumbsListFromAttachments()
 {
     if (this._attachments == null)
     {
         return;
     }
     this._thumbs.Clear();
     List <Attachment> .Enumerator enumerator = this._attachments.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             Attachment       current = enumerator.Current;
             ThumbsItem.Thumb thumb1  = (ThumbsItem.Thumb)null;
             if (current.type == "photo")
             {
                 Photo photo = current.photo;
                 if (photo != null)
                 {
                     thumb1 = ThumbsItem.ConvertPhotoToThumb(photo, current);
                 }
             }
             else if (current.type == "album")
             {
                 Photo thumb2 = current.album.thumb;
                 if (thumb2 != null)
                 {
                     thumb1 = ThumbsItem.ConvertPhotoToAlbumThumb(thumb2, current);
                 }
                 else
                 {
                     thumb1 = new ThumbsItem.Thumb(current)
                     {
                         Width  = this.Width,
                         Height = (double)(int)(this.Width * 2.0 / 3.0)
                     }
                 };
             }
             else if (current.type == "market_album")
             {
                 Photo photo = current.market_album.photo;
                 if (photo != null)
                 {
                     thumb1 = ThumbsItem.ConvertPhotoToAlbumThumb(photo, current);
                 }
                 else
                 {
                     thumb1 = new ThumbsItem.Thumb(current)
                     {
                         Width  = this.Width,
                         Height = (double)(int)(this.Width * 2.0 / 3.0)
                     }
                 };
             }
             else if (current.type == "video")
             {
                 VKClient.Common.Backend.DataObjects.Video video = current.video;
                 if (video != null)
                 {
                     thumb1 = new ThumbsItem.Thumb(current)
                     {
                         Width  = this.Width,
                         Height = (double)(int)(this.Width * 9.0 / 16.0),
                         BigSrc = string.IsNullOrWhiteSpace(video.image_big) ? video.image_medium : video.image_big
                     }
                 }
                 ;
             }
             else if (current.type == "doc")
             {
                 Doc doc = current.doc;
                 if (doc != null && doc.IsVideoGif)
                 {
                     Photo photoPreview = doc.ConvertToPhotoPreview();
                     thumb1 = new ThumbsItem.Thumb(current)
                     {
                         Width  = (double)photoPreview.width,
                         Height = (double)photoPreview.height,
                         BigSrc = photoPreview.src_xbig
                     };
                 }
             }
             if (thumb1 != null)
             {
                 this._thumbs.Add(thumb1);
             }
         }
     }
     finally
     {
         enumerator.Dispose();
     }
 }
Exemple #3
0
 private void ReadThumbsListFromAttachments()
 {
     if (this._attachments == null)
     {
         return;
     }
     this._thumbs.Clear();
     foreach (Attachment attachment in this._attachments)
     {
         ThumbsItem.Thumb thumb1 = (ThumbsItem.Thumb)null;
         if (attachment.type == "photo")
         {
             Photo photo = attachment.photo;
             if (photo != null)
             {
                 thumb1 = ThumbsItem.ConvertPhotoToThumb(photo, attachment);
             }
         }
         else if (attachment.type == "album")
         {
             Photo thumb2 = attachment.album.thumb;
             if (thumb2 != null)
             {
                 thumb1 = ThumbsItem.ConvertPhotoToAlbumThumb(thumb2, attachment);
             }
             else
             {
                 thumb1 = new ThumbsItem.Thumb(attachment)
                 {
                     Width  = this.Width,
                     Height = (double)(int)(this.Width * 2.0 / 3.0)
                 }
             };
         }
         else if (attachment.type == "market_album")
         {
             Photo photo = attachment.market_album.photo;
             if (photo != null)
             {
                 thumb1 = ThumbsItem.ConvertPhotoToAlbumThumb(photo, attachment);
             }
             else
             {
                 thumb1 = new ThumbsItem.Thumb(attachment)
                 {
                     Width  = this.Width,
                     Height = (double)(int)(this.Width * 2.0 / 3.0)
                 }
             };
         }
         else if (attachment.type == "video")
         {
             VKClient.Common.Backend.DataObjects.Video video = attachment.video;
             if (video != null)
             {
                 thumb1 = new ThumbsItem.Thumb(attachment)
                 {
                     Width  = this.Width,
                     Height = (double)(int)(this.Width * 9.0 / 16.0),
                     BigSrc = string.IsNullOrWhiteSpace(video.image_big) ? video.image_medium : video.image_big
                 }
             }
             ;
         }
         else if (attachment.type == "doc")
         {
             Doc doc = attachment.doc;
             if (doc != null && doc.IsVideoGif)
             {
                 Photo photoPreview = doc.ConvertToPhotoPreview();
                 thumb1 = new ThumbsItem.Thumb(attachment)
                 {
                     Width  = (double)photoPreview.width,
                     Height = (double)photoPreview.height,
                     BigSrc = photoPreview.src_xbig
                 };
             }
         }
         if (thumb1 != null)
         {
             this._thumbs.Add(thumb1);
         }
     }
 }