private void ProcessRecentGifs()
        {
            var recent = _stickersService.GetRecentGifs();

            BeginOnUIThread(() =>
            {
                SavedGifs.ReplaceWith(MosaicMedia.Calculate(recent));
            });
        }
Beispiel #2
0
 public void Handle(UpdateSavedAnimations update)
 {
     ProtoService.Send(new GetSavedAnimations(), result =>
     {
         if (result is Animations animation)
         {
             BeginOnUIThread(() => SavedGifs.ReplaceWith(MosaicMedia.Calculate(animation.AnimationsValue.ToList())));
         }
     });
 }
Beispiel #3
0
        public IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint phase)
        {
            return(AsyncInfo.Run(async token =>
            {
                if (_userId == null)
                {
                    var bot = await _protoService.SendAsync(new SearchPublicChat(_protoService.Options.AnimationSearchBotUsername));
                    if (bot is Chat chat && chat.Type is ChatTypePrivate privata)
                    {
                        _userId = privata.UserId;
                    }
                }

                if (_userId != null)
                {
                    var response = await _protoService.SendAsync(new GetInlineQueryResults(_userId.Value, 0, null, _query, _offset));
                    if (response is InlineQueryResults results)
                    {
                        _offset = results.NextOffset;
                        _hasMoreItems = _offset.Length > 0;

                        var mosaic = MosaicMedia.Calculate(results.Results.ToList());

                        foreach (var item in mosaic)
                        {
                            Add(item);
                        }
                    }
                    else
                    {
                        _hasMoreItems = false;
                    }
                }
                else
                {
                    _hasMoreItems = false;
                }

                return new LoadMoreItemsResult();
            }));
        }
Beispiel #4
0
        public override async Task <IList <MosaicMediaRow> > LoadDataAsync()
        {
            if (_nextOffset != null)
            {
                var response = await _protoService.SendAsync(new GetInlineQueryResults(_botUserId, _chatId, _location, _query, _nextOffset));

                if (response is InlineQueryResults results)
                {
                    _results    = results;
                    _nextOffset = string.IsNullOrEmpty(results.NextOffset) ? null : results.NextOffset;

                    foreach (var item in results.Results)
                    {
                        _queryIds[item] = results.InlineQueryId;
                    }

                    return(MosaicMedia.Calculate(results.Results.ToList()));
                }
            }

            return(new MosaicMediaRow[0]);
        }
        protected override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
        {
            if (context.ItemCount < 1)
            {
                return(new Size(0, 0));
            }

            // Item size is 96 + 2px of margin

            var state = context.LayoutState as MosaicLayoutState;

            if (state.LayoutRects.Count < 1)
            {
                state.LayoutRects.Clear();
                state.ActualWidth = availableSize.Width;

                var items = GetItems(context);

                var mosaic = MosaicMedia.Calculate(items);
                var top    = 0d;

                foreach (var row in mosaic)
                {
                    var left = 0d;

                    foreach (var item in row)
                    {
                        state.LayoutRects.Add(new Rect(left, top, item.Width, 98));
                        left += item.Width;
                    }

                    top += 98;
                }

                state.Rows         = mosaic;
                state.ExtentHeight = top - 2;
            }

            if (state.LayoutRects.Count < 1)
            {
                return(new Size(0, 0));
            }

            var firstRowIndex = Math.Min(Math.Max((int)(context.RealizationRect.Y / 98) - 1, 0), state.Rows.Count - 1);
            var lastRowIndex  = Math.Max(Math.Min((int)(context.RealizationRect.Bottom / 98) + 1, state.Rows.Count - 1), 0);

            var firstItemIndex = state.Rows[firstRowIndex][0].Index;
            var lastItemIndex  = state.Rows[lastRowIndex].Last().Index;

            var availableWidth = availableSize.Width + 2;

            for (int i = firstItemIndex; i <= lastItemIndex; i++)
            {
                var container = context.GetOrCreateElementAt(i);
                container.Measure(new Size(
                                      state.LayoutRects[i].Width * availableWidth,
                                      state.LayoutRects[i].Height));
            }

            state.FirstRealizedIndex = firstItemIndex;
            state.LastRealizedIndex  = lastItemIndex;

            // Report this as the desired size for the layout
            return(new Size(availableSize.Width, state.ExtentHeight));
        }