Пример #1
0
        public void when_Refresh_is_called_and_IsNotifying_is_false_then_Reset_event_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = false;

            var bindableCollection = new BindableCollection <int>(testSchedulerProvider);

            var items = Enumerable.Range(0, 1).ToList();

            bindableCollection.AddRange(items);

            bindableCollection.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Reset)
                {
                    result = true;
                }
            };

            bindableCollection.IsNotifying = false;

            bindableCollection.Refresh();

            Assert.That(result, Is.False);
        }
        private void CalculateHeroesPlayed(HearthStatsDbContext context, Expression <Func <ArenaSession, bool> > filter)
        {
            var arenas = context.ArenaSessions.Where(filter);

            heroesPlayed.IsNotifying = false;
            heroesPlayed.Clear();

            var total = arenas.Count();

            if (total == 0)
            {
                return;
            }

            var heroestats = arenas.GroupBy(x => x.Hero).Where(x => x.Any()).Select(
                x => new
            {
                x.Key,
                x.Key.ClassName,
                Count = x.Count()
            }).ToList();

            foreach (var hero in heroestats)
            {
                if (hero.Count > 0)
                {
                    heroesPlayed.Add(new StatModel(string.Format("{0}: {1}", hero.ClassName, hero.Count), (float)hero.Count / total * 100, hero.Key.GetBrush()));
                }
            }

            heroesPlayed.IsNotifying = true;
            heroesPlayed.Refresh();
        }
Пример #3
0
        public void RefreshUsesDispatcherToFireEvents()
        {
            var collection = new BindableCollection <Element>();

            bool propertyChangedRaised = false;

            ((INotifyPropertyChanged)collection).PropertyChanged += (o, e) => propertyChangedRaised = true;
            bool collectionChangingRaised = false;

            collection.CollectionChanging += (o, e) => collectionChangingRaised = true;
            bool collectionChangedRaised = false;

            collection.CollectionChanged += (o, e) => collectionChangedRaised = true;

            var dispatcher = new TestDispatcher();

            Execute.Dispatcher = dispatcher;

            collection.Refresh();

            Assert.False(propertyChangedRaised);
            Assert.False(collectionChangingRaised);
            Assert.False(collectionChangedRaised);
            Assert.NotNull(dispatcher.SendAction);

            dispatcher.SendAction();

            Assert.True(propertyChangedRaised);
            Assert.True(collectionChangingRaised);
            Assert.True(collectionChangedRaised);
        }
Пример #4
0
        private void CalculateHeroesPlayed(HearthStatsDbContext context, Expression <Func <GameResult, bool> > filter)
        {
            var games = context.Games;

            heroesPlayed.Clear();
            opponentHeroesPlayed.Clear();
            var total = games.Where(filter).Count();

            if (total == 0)
            {
                return;
            }
            var heroestats = games
                             .Where(filter)
                             .GroupBy(x => x.Hero)
                             .Where(x => x.Any())
                             .Select(
                x => new
            {
                x.Key,
                x.Key.ClassName,
                Count = x.Count()
            }).ToList();

            var oppheroestats = games
                                .Where(filter)
                                .GroupBy(x => x.OpponentHero)
                                .Where(x => x.Any())
                                .Select(
                x => new
            {
                x.Key,
                x.Key.ClassName,
                Count = x.Count()
            }).ToList();

            heroesPlayed.IsNotifying = false;
            foreach (var hero in heroestats)
            {
                // float count = games.Where(filter).Count(x => x.Hero != null && x.Hero.Key == hero.Key);
                if (hero.Count > 0)
                {
                    heroesPlayed.Add(new StatModel(string.Format("{0}: {1}", hero.ClassName, hero.Count), (float)hero.Count / total * 100, hero.Key.GetBrush()));
                }
            }
            heroesPlayed.IsNotifying = true;
            heroesPlayed.Refresh();

            opponentHeroesPlayed.IsNotifying = false;
            foreach (var hero in oppheroestats)
            {
                //count = games.Where(filter).Count(x => x.OpponentHero != null && x.OpponentHero.Key == hero.Key);
                if (hero.Count > 0)
                {
                    opponentHeroesPlayed.Add(new StatModel(string.Format("{0}: {1}", hero.ClassName, hero.Count), (float)hero.Count / total * 100, hero.Key.GetBrush()));
                }
            }
            opponentHeroesPlayed.IsNotifying = true;
            opponentHeroesPlayed.Refresh();
        }
Пример #5
0
        private void ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            if (!IsActive || !IsEnabled)
            {
                return;
            }

            try
            {
                var element = sender as FrameworkElement;
                if (element == null)
                {
                    return;
                }

                if (HasPassedThresholds(element.ActualWidth,
                                        e.TotalManipulation.Translation.X,
                                        e.FinalVelocities.LinearVelocity.X))
                {
                    var movedLeft = e.TotalManipulation.Translation.X < 0.0;

                    // Perform the actions
                    var item = (CardViewModel)((FrameworkElement)sender).DataContext;
                    var evt  = new CardMovedToList
                    {
                        Card              = item.OriginalCard,
                        SourceListId      = item.ListId,
                        DestinationListId = movedLeft ? _previousListId : _nextListId
                    };

                    // Animate accordingly
                    AnimateMove(element, movedLeft, () =>
                    {
                        _eventAggregator.Publish(evt);
                        _cardsModel.Remove(item);
                        _cardsModel.Refresh();

                        Complete();
                    });
                }
                else
                {
                    // Cancel action
                    AnimateCancel(element, () =>
                    {
                        UpdateDragCues(element, 0, 0);
                        Complete();
                    });
                }
            }
            finally
            {
                IsActive = false;
                Complete();
            }
        }
Пример #6
0
        private void HoldCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            if (!IsActive)
            {
                return;
            }

            // stop the timer so that we don't try to re-fix this thing after moving to our
            // final destination.
            _dispatcherTimer.Stop();

            var dragIndex      = _currentIndex;
            var targetItem     = _pointIndex.Get(_currentIndex);
            var targetLocation = targetItem.Position.Top - _scrollViewer.VerticalOffset;
            var transform      = _dragImage.GetVerticalOffset().Transform;

            transform.Animate(null, targetLocation, CompositeTransform.TranslateYProperty, 200, 0, completed: () =>
            {
                // reshow the hidden item
                if (_cardView != null)
                {
                    _cardView.Opacity = 1.0;
                }

                // fade out the dragged image
                if (_dragImage != null)
                {
                    _dragImage.Animate(null, 0.0, UIElement.OpacityProperty, 700, 0,
                                       completed: () => { _dragImage.Visibility = Visibility.Collapsed; });
                }

                Complete();

                if (dragIndex == _initialIndex)
                {
                    return;
                }

                // move the dragged item
                if (_cardView == null)
                {
                    return;
                }

                var item = (CardViewModel)_cardView.DataContext;

                _cardsModel.Remove(item);
                _cardsModel.Insert(dragIndex, item);
                _cardsModel.Refresh();

                // fire off the event for subscribers
                _eventAggregator.Publish(CardPriorityChanged.Create(item.Id, dragIndex, _cardsModel.ToList()));
            });

            IsActive = false;
        }
Пример #7
0
        private async Task LoadInitialData()
        {
            var data = await GlobalData.GetAsync();

            heroes.IsNotifying = false;
            // empty hero for 'all'
            heroes.Add(new Hero(""));
            heroes.AddRange(data.Heroes.OrderBy(x => x.Name));
            heroes.IsNotifying = true;
            heroes.Refresh();
        }
Пример #8
0
        public void RefreshFiresPropertyChanged()
        {
            var collection = new BindableCollection <Element>(new[] { new Element() });

            var changedProperties = new List <string>();

            ((INotifyPropertyChanged)collection).PropertyChanged += (o, e) => changedProperties.Add(e.PropertyName);

            collection.Refresh();

            Assert.That(changedProperties, Is.EquivalentTo(new[] { "Count", "Item[]" }));
        }
Пример #9
0
        private void LoadTextTemplates()
        {
            var tpls = repository.ToList(q => q.OrderBy(x => x.Filename));

            templates.IsNotifying = false;
            foreach (var tpl in tpls)
            {
                var model = new TextFileModel();
                model.InjectFrom(tpl);
                templates.Add(model);
            }
            templates.IsNotifying = true;
            templates.Refresh();
        }
 public WorkingHoursViewModel()
 {
     _timer          = new DispatcherTimer();
     _timer.Tick    += new EventHandler(timer_tick);
     _timer.Interval = new TimeSpan(0, 0, 1);
     _timer.Start();
     _selectedDate     = DateTime.Now;
     Employees         = new BindableCollection <EmployeeModel>();
     _selectedEmployee = Employees.First();
     Hours             = new BindableCollection <HoursModel>();
     Hours.Refresh();
     YearMonths.Refresh();
     MessageQueue = new SnackbarMessageQueue(TimeSpan.FromMilliseconds(5000));
 }
Пример #11
0
        public void RefreshFiresCollectionChanged()
        {
            var collection = new BindableCollection <Element>(new[] { new Element() });

            var changedEvents = new List <NotifyCollectionChangedEventArgs>();

            collection.CollectionChanged += (o, e) => changedEvents.Add(e);

            collection.Refresh();

            Assert.AreEqual(1, changedEvents.Count);
            var changedEvent = changedEvents[0];

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvent.Action);
        }
Пример #12
0
        //private string IsRepeat(bool mathProp, bool Letter, ShapeData data, BindableCollection<ShapeData> given)
        //{
        //    string result = string.Empty;

        //    var repeatMath = 0;
        //    var repeatLetter = 0;

        //    if (mathProp == true)
        //    {
        //        foreach (var item in given)
        //        {
        //            if (item.MathematicalProperty.Name == data.MathematicalProperty.Name)
        //            {
        //                repeatMath++;
        //                if (repeatMath == 1)
        //                {
        //                    repeatMath = 0;
        //                    return data.MathematicalProperty.Name;
        //                }
        //            }
        //        }
        //    }
        //    if (Letter == true)
        //    {
        //        foreach (var item in given)
        //        {
        //            if (item.Letter == data.Letter)
        //            {
        //                repeatLetter++;
        //                if (repeatLetter == 1)
        //                {
        //                    repeatLetter = 0;
        //                    return data.Letter;
        //                }
        //            }
        //        }
        //    }
        //
        //    return result;
        //}

        private string SetLetter(BindableCollection <ShapeData> Collection, int par, List <TextBoxDropDownModel> props,
                                 string Letter)
        {
            var textBox = new TextBoxDropDownModel();

            if (Collection.Count > par)
            {
                var shapeData = Collection[par];

                var Prop = props[par];

                if (shapeData != null)
                {
                    Prop.Name = shapeData.Letter;


                    if (shapeData.MyVisibility == Visibility.Collapsed)
                    {
                        textBox.Name = Letter;

                        shapeData.Letter = Letter;

                        Collection[par] = shapeData;

                        props[par] = textBox;
                    }
                }

                Formatting(shapeData);

                //shapeData.IsRepeat = IsRepeat(true, false, shapeData, GivenInput);

                //if (shapeData.IsRepeat)
                //{
                //    RemoveShapeHelp(GivenInput, shapeData, MathProps, LetterProps);
                //}

                Collection.Refresh();

                Figures = da.BrushLine(GivenInput, FindInput, "#5983EB", "#33AF63", Figures);

                return(Prop.Name);
            }


            return(null);
        }
Пример #13
0
        public LibraryPageViewModel(IContext context)
            : base(context)
        {
            Importer = Context.Services.Utilise <ImporterService>();
            Player   = Context.Services.Utilise <PlayerService>();

            Folders = new BindableCollection <LibraryFolder>();
            Folders.Add(new LibraryFolder("Now Playing", Player.CurrentPlaylist.ToList()));
            Folders.Add(new LibraryFolder("All Tracks", Player.TracksCollection));
            Folders.Add(new LibraryFolder("Recent", Player.GetRecentTracks()));
            Folders.Add(new LibraryFolder("Unheard", Player.GetUnheardTracks()));
            Folders.Add(new LibraryFolder("Favourites", Player.GetFavouriteTracks()));

            _searchFolder = new LibraryFolder("Search", null, isEnabled: false);
            Folders.Add(_searchFolder);

            Folders.Refresh();
        }
Пример #14
0
        protected override void OnViewLoaded(object view)
        {
            if (initialized)
            {
                return;
            }
            initialized = true;
            var data = GlobalData.Get();

            heroes.IsNotifying = false;
            // empty hero for 'all'
            heroes.Add(new Hero(""));
            heroes.AddRange(data.Heroes.OrderBy(x => x.Name));
            heroes.IsNotifying = true;
            heroes.Refresh();

            RefreshDecks();
        }
Пример #15
0
        public void addModifiedProfile(PublicProfile profile)
        {
            if (profile.username == _userName)
            {
                _avatarName = profile.avatar;
            }

            IEnumerable <SelectableRoom>        enumSR = _selectableJoinedRooms.Where(x => x.id == "General");
            BindableCollection <SelectableRoom> sRs    = new BindableCollection <SelectableRoom>(enumSR);

            if (sRs.Count() != 1)
            {
                Console.WriteLine("il exite un doublon de general dans les rooms jointes");
            }

            _selectableJoinedRooms[_selectableJoinedRooms.IndexOf(sRs[0])].room.avatars[profile.username] = profile.avatar;
            _selectableJoinedRooms.Refresh();
        }
Пример #16
0
        private void GroupLaps()
        {
            if (isUpdating)
            {
                return;
            }

            foreach (var group in groups)
            {
                group.Clear();
            }

            var      groupings    = laps.GroupByPresented();
            TimeSpan?previousTime = null;

            for (var i = 0; i < groupings.Count; i++)
            {
                var grouping = groupings[i];
                var group    = GetOrAddGroup(i);

                if (grouping.Key != null)
                {
                    grouping.Key.PreviousTime = previousTime;
                    group.Presented           = grouping.Key;
                }

                foreach (var notPresented in grouping)
                {
                    notPresented.PreviousTime = previousTime;
                    group.NotPresented.Add(notPresented);
                }

                if (grouping.Key != null)
                {
                    previousTime = grouping.Key.Time;
                }
            }

            TrimGroups();
            groups.Refresh();

            LastPresented = groups.LastOrDefault(g => g.Presented != null);
        }
Пример #17
0
        private void EnsureInitialized()
        {
            if (initDataLoaded)
            {
                return;
            }
            initDataLoaded = true;

            var data = GlobalData.Get();

            heroes.IsNotifying = false;
            // empty hero for 'all'
            heroes.Add(new Hero(""));
            heroes.AddRange(data.Heroes.OrderBy(x => x.Name));
            heroes.IsNotifying = true;
            heroes.Refresh();

            RefreshDecks();
        }
Пример #18
0
        /* Handlers -----------------------------------------------------------------------------------------------*/

        public void Handle(refreshRoomsEvent message)
        {
            if (!message.joined)
            {
                foreach (SelectableRoom sR in _availableRooms)
                {
                    sR.resetColor();
                    sR.menuVisibility = "Collapsed";
                }

                int selectedRoomIndex = _availableRooms.IndexOf(_availableRooms.Single(i => i.id == message.selectedRoomId));
                _availableRooms[selectedRoomIndex].changeColor("Black");
                _availableRooms[selectedRoomIndex].menuVisibility = "Visible";
                _availableRooms.Refresh();
                _selectedAvailableRoom = message.selectedRoomId;
                NotifyOfPropertyChange(null);
            }
            else
            {
                foreach (SelectableRoom sR in _joinedRooms)
                {
                    sR.resetColor();
                    sR.menuVisibility = "Collapsed";
                }

                int selectedRoomIndex = 0;
                try
                {
                    selectedRoomIndex = _joinedRooms.IndexOf(_joinedRooms.Single(i => i.id == message.selectedRoomId));
                } catch {
                    selectedRoomIndex = _joinedRooms.IndexOf(_joinedRooms.Where(x => x.id == message.selectedRoomId).ToList()[0]);
                }

                _joinedRooms[selectedRoomIndex].changeColor("Black");
                _joinedRooms[selectedRoomIndex].menuVisibility = "Visible";
                _selectedJoinedRoom = message.selectedRoomId;
                _joinedRooms.Refresh();
                NotifyOfPropertyChange(null);
            }
        }
Пример #19
0
        public MassEditViewModel(Type aType, IEnumerable <object> aDocuments)
        {
            this.aDocuments = aDocuments.ToList();
            this.aType      = aType;
            var properties = aType.GetProperties();

            // find displayname
            List <CustomProperty> aCustomProp = new List <CustomProperty>();

            foreach (var item in properties)
            {
                var column = item.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute;
                if (column == null || column.FieldType == ModelFieldType.Separation ||
                    column.FieldType == ModelFieldType.BaseButton ||
                    column.FieldType == ModelFieldType.Button ||
                    column.FieldType == ModelFieldType.Image ||
                    column.FieldType == ModelFieldType.ImageSide ||
                    column.FieldType == ModelFieldType.OpsButton ||
                    column.FieldType == ModelFieldType.Table ||
                    column.FieldType == ModelFieldType.WeakTable ||
                    column.FieldType == ModelFieldType.ReadOnly ||
                    column.FieldType == ModelFieldType.LienButton)
                {
                    continue;
                }


                string name    = item.Name;
                var    display = item.GetCustomAttribute(typeof(DisplayNameAttribute)) as DisplayNameAttribute;
                if (display != null)
                {
                    name = display.DisplayName;
                }
                aCustomProp.Add(new CustomProperty(item, name));
            }
            Properties = new BindableCollection <CustomProperty>();
            Properties.AddRange(aCustomProp);
            Properties.Refresh();
        }
Пример #20
0
        private static void AddItemsTo(BindableCollection <Node> newParentCollection, IFlatListItem insertPlace, IEnumerable <Node> items)
        {
            var newItems = new List <Node>();
            var position = newParentCollection.IndexOf(insertPlace as Node);

            if (position != -1)
            {
                newItems.AddRange(newParentCollection.Take(position));
                newItems.AddRange(items);
                newItems.AddRange(newParentCollection.Skip(position));
            }
            else
            {
                newItems.AddRange(newParentCollection);
                newItems.AddRange(items);
            }
            newParentCollection.IsNotifying = false;
            newParentCollection.Clear();
            newParentCollection.AddRange(newItems);
            newParentCollection.IsNotifying = true;
            newParentCollection.Refresh();
        }
Пример #21
0
        private string FindButtonHelp(BindableCollection <ShapeData> Collection, int par, List <TextBoxDropDownModel> props,
                                      string MathProp)
        {
            var textBox = new TextBoxDropDownModel();

            //for (int i = 0; i < Collection.Count; i++)
            //{
            //    Collection[i].ShapeId = i;
            //}

            if (Collection.Count > par)
            {
                var shapeData = Collection[par];

                var Prop = props[par];

                Prop = shapeData.MathematicalProperty;

                СheckVisibility(Collection, par);

                if (shapeData.MyVisibility == Visibility.Collapsed)
                {
                    textBox.Name = MathProp;

                    shapeData.MathematicalProperty.Name = MathProp;

                    Collection[par] = shapeData;

                    props[par] = textBox;

                    //Formatting(shapeData);
                }

                Collection.Refresh();

                return(Prop.Name);
            }
            return(null);
        }
        protected override void OnViewLoaded(object view)
        {
            base.OnViewLoaded(view);
            Timetable    = TimetableDataAccess.GetTimetableById(TimetableId);
            LocationList =
                new BindableCollection <LocationModel>(
                    LocationDataAccess.GetAllLocationsPerRoute(Timetable.RouteId)
                    .OrderBy(x => x.Order)
                    .ToList());
            int i = 0;

            foreach (var item in LocationList)
            {
                item.Order = i++;
            }


            SetPeriod();             // sets start and end time at the graph
            Dummy += 1;
            LocationList.Refresh();
            PrepareDataSet();
            TimeGraphUIChanged++;
            TimeGraphUI.Refresh();
        }
Пример #23
0
        public BindableCollection <Figures> BrushLine(BindableCollection <ShapeData> givenDatas,
                                                      BindableCollection <ShapeData> findDatas, string brush1, string brush2, BindableCollection <Figures> figures)
        {
            BrushConverter brushConverter = new BrushConverter();

            for (var i = 0; i < figures.Count; i++)
            {
                figures[i].Color = brushConverter.ConvertFromString("#DCE1E4") as Brush;
            }

            foreach (var item in givenDatas)
            {
                for (var i = 0; i < figures.Count; i++)
                {
                    if (item.Letter == figures[i].Name)
                    {
                        figures[i].Color = brushConverter.ConvertFromString(brush1) as Brush;
                    }
                }
            }

            foreach (var item in findDatas)
            {
                for (var i = 0; i < figures.Count; i++)
                {
                    if (item.Letter == figures[i].Name)
                    {
                        figures[i].Color = brushConverter.ConvertFromString(brush2) as Brush;
                    }
                }
            }

            figures.Refresh();

            return(figures);
        }
Пример #24
0
        public void when_Refresh_is_called_then_Reset_event_fired()
        {
            var testSchedulerProvider = new TestDispatcherSchedulerProvider();

            var result = false;

            var bindableCollection = new BindableCollection<int>(testSchedulerProvider);

            var items = Enumerable.Range(0, 1).ToList();

            bindableCollection.AddRange(items);

            bindableCollection.CollectionChanged += (sender, args) =>
                                                    {
                                                        if (args.Action == NotifyCollectionChangedAction.Reset)
                                                        {
                                                            result = true;
                                                        }
                                                    };

            bindableCollection.Refresh();

            Assert.That(result, Is.True);
        }
Пример #25
0
        public void RefreshFiresPropertyChanged()
        {
            var collection = new BindableCollection<Element>(new[] { new Element() });

            var changedProperties = new List<string>();
            ((INotifyPropertyChanged)collection).PropertyChanged += (o, e) => changedProperties.Add(e.PropertyName);

            collection.Refresh();

            Assert.That(changedProperties, Is.EquivalentTo(new[] { "Count", "Item[]" }));
        }
Пример #26
0
        public void RefreshFiresCollectionChanged()
        {
            var collection = new BindableCollection<Element>(new[] { new Element() });

            var changedEvents = new List<NotifyCollectionChangedEventArgs>();
            collection.CollectionChanged += (o, e) => changedEvents.Add(e);

            collection.Refresh();

            Assert.AreEqual(1, changedEvents.Count);
            var changedEvent = changedEvents[0];
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvent.Action);
        }
Пример #27
0
        public void RefreshUsesDispatcherToFireEvents()
        {
            var collection = new BindableCollection<Element>();

            bool propertyChangedRaised = false;
            ((INotifyPropertyChanged)collection).PropertyChanged += (o, e) => propertyChangedRaised = true;
            bool collectionChangingRaised = false;
            collection.CollectionChanging += (o, e) => collectionChangingRaised = true;
            bool collectionChangedRaised = false;
            collection.CollectionChanged += (o, e) => collectionChangedRaised = true;

            var dispatcher = new TestDispatcher();
            Execute.Dispatcher = dispatcher;

            collection.Refresh();

            Assert.False(propertyChangedRaised);
            Assert.False(collectionChangingRaised);
            Assert.False(collectionChangedRaised);
            Assert.NotNull(dispatcher.SendAction);

            dispatcher.SendAction();

            Assert.True(propertyChangedRaised);
            Assert.True(collectionChangingRaised);
            Assert.True(collectionChangedRaised);
        }
Пример #28
0
        private void SetInitState()
        {
            CurrentItem = StateService.CurrentPhoto;
            StateService.CurrentPhoto = null;

            if (StateService.CurrentContact != null)
            {
                _currentContact             = StateService.CurrentContact;
                StateService.CurrentContact = null;

                IsWorking = true;
                MTProtoService.GetUserPhotosAsync(_currentContact.ToInputUser(), new TLInt(0), new TLLong(0),
                                                  new TLInt(0),
                                                  photos => Execute.BeginOnUIThread(() =>
                {
                    _currentIndex = 0;
                    _items.Clear();
                    foreach (var photo in photos.Photos)
                    {
                        _items.Add(photo);
                    }

                    GroupedItems.IsNotifying = false;
                    GroupedItems.Clear();
                    if (_items.Count > 1)
                    {
                        GroupedItems.AddRange(_items);
                    }
                    GroupedItems.IsNotifying = true;
                    GroupedItems.Refresh();

                    PreviousItem = _currentIndex + 1 < _items.Count ? _items[_currentIndex + 1] : null;
                    NextItem     = _currentIndex > 0 ? _items[_currentIndex - 1] : null;

                    var view = GetView() as ProfilePhotoViewerView;
                    if (view != null)
                    {
                        view.SetControlContent(0, NextItem);
                        view.SetControlContent(2, PreviousItem);
                        if (_items.Count > 0)
                        {
                            view.ScrollTo(_items[_currentIndex], 0.25);
                        }
                    }

                    IsWorking = false;
                }),
                                                  error => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    Execute.ShowDebugMessage("photos.getUserPhotos error=" + error);
                }));
            }
            else if (StateService.CurrentChat != null)
            {
                _currentChat             = StateService.CurrentChat;
                StateService.CurrentChat = null;

                IsWorking = true;
                MTProtoService.SearchAsync(
                    _currentChat.ToInputPeer(),
                    TLString.Empty,
                    null,
                    new TLInputMessagesFilterChatPhotos(),
                    new TLInt(0),
                    new TLInt(0),
                    new TLInt(0),
                    new TLInt(0),
                    new TLInt(100),
                    new TLInt(0),
                    result => Execute.BeginOnUIThread(() =>
                {
                    _items.Clear();
                    _currentIndex = -1;
                    for (var i = 0; i < result.Messages.Count; i++)
                    {
                        var messageService = result.Messages[i] as TLMessageService;
                        if (messageService != null)
                        {
                            var chatEditPhotoAction = messageService.Action as TLMessageActionChatEditPhoto;
                            if (chatEditPhotoAction != null)
                            {
                                _items.Add(chatEditPhotoAction.Photo);

                                var photo        = chatEditPhotoAction.Photo as TLPhoto;
                                var currentPhoto = CurrentItem as TLPhoto;
                                var chatPhoto    = CurrentItem as TLChatPhoto;
                                if (photo != null &&
                                    currentPhoto != null &&
                                    photo.Id.Value == currentPhoto.Id.Value ||
                                    (chatPhoto != null && ChatPhotoEquals(chatPhoto, photo)))
                                {
                                    _currentIndex = _items.Count - 1;
                                }
                            }
                        }
                    }

                    if (_currentIndex == -1)
                    {
                        if (_items.Count > 0)
                        {
                            _items.Insert(0, CurrentItem);
                            _currentIndex = 0;
                        }
                    }

                    GroupedItems.IsNotifying = false;
                    GroupedItems.Clear();
                    if (_items.Count > 1)
                    {
                        GroupedItems.AddRange(_items);
                    }
                    GroupedItems.IsNotifying = true;
                    GroupedItems.Refresh();

                    PreviousItem = _currentIndex + 1 < _items.Count ? _items[_currentIndex + 1] : null;
                    NextItem     = _currentIndex > 0 ? _items[_currentIndex - 1] : null;

                    var view = GetView() as ProfilePhotoViewerView;
                    if (view != null)
                    {
                        view.SetControlContent(0, NextItem);
                        view.SetControlContent(2, PreviousItem);
                        if (_items.Count > 0)
                        {
                            view.ScrollTo(_items[_currentIndex], 0.25);
                        }
                    }

                    IsWorking = false;
                }),
                    error => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    Execute.ShowDebugMessage("messages.search error=" + error);
                }));
            }
        }