Exemplo n.º 1
0
        public async void UpdateFile(File file)
        {
            if (!file.Local.IsDownloadingCompleted)
            {
                return;
            }

            if (_stickers.TryGetValue(file.Id, out List <ViewModels.Dialogs.StickerViewModel> items) && items.Count > 0)
            {
                foreach (var item in items)
                {
                    item.UpdateFile(file);

                    var container = Stickers.ContainerFromItem(item) as SelectorItem;
                    if (container == null)
                    {
                        continue;
                    }

                    var content = container.ContentTemplateRoot as Image;
                    content.Source = await PlaceholderHelper.GetWebpAsync(file.Local.Path);
                }
            }

            foreach (MosaicMediaRow line in GifsView.Items)
            {
                var any = false;
                foreach (var item in line)
                {
                    if (item.Item is Animation animation && animation.UpdateFile(file))
                    {
                        any = true;
                    }
Exemplo n.º 2
0
        public void UpdateFile(File file)
        {
            if (_stickers.TryGetValue(file.Id, out List <StickerViewModel> items) && items.Count > 0)
            {
                foreach (var item in items)
                {
                    item.UpdateFile(file);

                    if (item.Thumbnail?.File.Id == file.Id)
                    {
                        var container = Stickers.ContainerFromItem(item) as SelectorItem;
                        if (container == null)
                        {
                            continue;
                        }

                        var content = container.ContentTemplateRoot as Grid;
                        var photo   = content.Children[0] as Image;

                        photo.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path);
                    }
                    else if (item.StickerValue.Id == file.Id)
                    {
                        _handler.ThrottleVisibleItems();
                    }
                }
            }

            if (_stickerSets.TryGetValue(file.Id, out List <StickerSetViewModel> sets) && sets.Count > 0)
            {
                foreach (var item in sets)
                {
                    var cover = item.Thumbnail ?? item.Covers.FirstOrDefault()?.Thumbnail;
                    if (cover == null)
                    {
                        continue;
                    }

                    cover.UpdateFile(file);

                    var container = Toolbar.ContainerFromItem(item) as SelectorItem;
                    if (container == null)
                    {
                        continue;
                    }

                    var content = container.ContentTemplateRoot as Grid;
                    var photo   = content?.Children[0] as Image;

                    if (content == null)
                    {
                        continue;
                    }

                    if (item.IsAnimated)
                    {
                        photo.Source = PlaceholderHelper.GetLottieFrame(file.Local.Path, 0, 36, 36);
                    }
                    else
                    {
                        photo.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path);
                    }
                }
            }

            _zoomer.UpdateFile(file);
        }
Exemplo n.º 3
0
        private async void LoadVisibleStickers()
        {
            var scrollingHost = Stickers.ItemsPanelRoot as ItemsWrapGrid;

            if (scrollingHost == null)
            {
                return;
            }

            if (scrollingHost.FirstVisibleIndex < 0)
            {
                return;
            }

            var lastSet = 0L;

            for (int i = scrollingHost.FirstVisibleIndex; i <= scrollingHost.LastVisibleIndex; i++)
            {
                if (i >= Stickers.Items.Count)
                {
                    return;
                }

                var first = Stickers.Items[i] as ViewModels.Dialogs.StickerViewModel;
                if (first == null || first.SetId == lastSet)
                {
                    continue;
                }

                lastSet = first.SetId;

                var fromItem = Stickers.ContainerFromItem(first);
                if (fromItem == null)
                {
                    continue;
                }

                var header = Stickers.GroupHeaderContainerFromItemContainer(fromItem) as GridViewHeaderItem;
                if (header == null)
                {
                    continue;
                }

                var group = header.Content as ViewModels.Dialogs.StickerSetViewModel;
                if (group == null || group.IsLoaded)
                {
                    continue;
                }

                group.IsLoaded = true;

                Debug.WriteLine("Loading sticker set " + group.Id);

                var response = await ViewModel.ProtoService.SendAsync(new GetStickerSet(group.Id));

                if (response is StickerSet full)
                {
                    group.Update(full);
                    //group.Stickers.RaiseCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset));

                    int j = 0;
                    foreach (var sticker in group.Stickers)
                    {
                        if (sticker.Thumbnail == null)
                        {
                            continue;
                        }

                        //group.Stickers.RaiseCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Move, sticker, j, j));
                        //j++;

                        var container = Stickers.ContainerFromItem(sticker) as SelectorItem;
                        if (container == null)
                        {
                            continue;
                        }

                        var content = container.ContentTemplateRoot as Image;

                        var file = sticker.Thumbnail.Photo;
                        if (file.Local.IsDownloadingCompleted)
                        {
                            var temp = await StorageFile.GetFileFromPathAsync(file.Local.Path);

                            var buffer = await FileIO.ReadBufferAsync(temp);

                            content.Source = WebPImage.DecodeFromBuffer(buffer);
                        }
                        else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
                        {
                            DownloadFile(file.Id, sticker);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public async void UpdateFile(File file)
        {
            if (!file.Local.IsDownloadingCompleted)
            {
                return;
            }

            if (_stickers.TryGetValue(file.Id, out List <ViewModels.Dialogs.StickerViewModel> items) && items.Count > 0)
            {
                var temp = await StorageFile.GetFileFromPathAsync(file.Local.Path);

                var buffer = await FileIO.ReadBufferAsync(temp);

                foreach (var item in items)
                {
                    item.UpdateFile(file);

                    var container = Stickers.ContainerFromItem(item) as SelectorItem;
                    if (container == null)
                    {
                        return;
                    }

                    var content = container.ContentTemplateRoot as Image;
                    content.Source = WebPImage.DecodeFromBuffer(buffer);
                }
            }

            foreach (MosaicMediaRow line in GifsView.Items)
            {
                var any = false;
                foreach (var item in line)
                {
                    if (item.Item is Animation animation && animation.UpdateFile(file))
                    {
                        any = true;
                    }
                }

                if (!any)
                {
                    continue;
                }

                var container = GifsView.ContainerFromItem(line) as SelectorItem;
                if (container == null)
                {
                    continue;
                }

                var content = container.ContentTemplateRoot as MosaicRow;
                if (content == null)
                {
                    continue;
                }

                content.UpdateFile(line, file);
            }

            foreach (ViewModels.Dialogs.StickerSetViewModel stickerSet in Toolbar.Items)
            {
                if (stickerSet.Covers == null)
                {
                    continue;
                }

                var cover = stickerSet.Covers.FirstOrDefault();
                if (cover == null || cover.Thumbnail == null)
                {
                    continue;
                }

                var container = Toolbar.ContainerFromItem(stickerSet) as SelectorItem;
                if (container == null)
                {
                    continue;
                }

                var content = container.ContentTemplateRoot as Image;
                if (content == null)
                {
                    continue;
                }

                if (cover.UpdateFile(file))
                {
                    var temp = await StorageFile.GetFileFromPathAsync(file.Local.Path);

                    var buffer = await FileIO.ReadBufferAsync(temp);

                    content.Source = WebPImage.DecodeFromBuffer(buffer);
                }
            }

            //foreach (ViewModels.Dialogs.StickerViewModel item in Stickers.Items)
            //{
            //    if (item.UpdateFile(file) && file.Local.IsDownloadingCompleted)
            //    {
            //        var container = Stickers.ContainerFromItem(item) as SelectorItem;
            //        if (container == null)
            //        {
            //            continue;
            //        }

            //        var content = container.ContentTemplateRoot as Image;
            //        if (item.Thumbnail.Photo.Id == file.Id)
            //        {
            //            var temp = await StorageFile.GetFileFromPathAsync(file.Local.Path);
            //            var buffer = await FileIO.ReadBufferAsync(temp);

            //            content.Source = WebPImage.DecodeFromBuffer(buffer);
            //        }
            //    }
            //}
        }