예제 #1
0
        public void Sort(UICollectionView collectionView)
        {
            if (dataType == DataType.CHAPTERS)
            {
                (list as List <Chapter>).Reverse();

                collectionView.PerformBatchUpdates(delegate
                {
                    for (int i = 0; i < (list as List <Chapter>).Count; i++)
                    {
                        NSIndexPath fromIndexPath = indexDictionary[(list as List <Chapter>)[i].ID];
                        NSIndexPath toIndexPath   = NSIndexPath.FromRowSection(i, 0);
                        collectionView.MoveItem(fromIndexPath, toIndexPath);
                    }
                }, delegate
                {
                    collectionView.ReloadData();
                });
            }
            else if (dataType == DataType.BOOKMARKS)
            {
                (list as List <Bookmark>).Reverse();

                collectionView.PerformBatchUpdates(delegate
                {
                    for (int i = 0; i < (list as List <Bookmark>).Count; i++)
                    {
                        NSIndexPath fromIndexPath = indexDictionary[(list as List <Bookmark>)[i].PageID];
                        NSIndexPath toIndexPath   = NSIndexPath.FromRowSection(i, 0);
                        collectionView.MoveItem(fromIndexPath, toIndexPath);
                    }
                }, delegate
                {
                    collectionView.ReloadData();
                });
            }
            else
            {
                (list as List <Annotation>).Reverse();

                collectionView.PerformBatchUpdates(delegate
                {
                    for (int i = 0; i < (list as List <Annotation>).Count; i++)
                    {
                        NSIndexPath fromIndexPath = indexDictionary[(list as List <Annotation>)[i].PageID];
                        NSIndexPath toIndexPath   = NSIndexPath.FromRowSection(i, 0);
                        collectionView.MoveItem(fromIndexPath, toIndexPath);
                    }
                }, delegate
                {
                    collectionView.ReloadData();
                });
            }
        }
        void Move(NotifyCollectionChangedEventArgs args)
        {
            var oldPath = NSIndexPath.Create(0, args.OldStartingIndex);
            var newPath = NSIndexPath.Create(0, args.NewStartingIndex);

            _collectionView.MoveItem(oldPath, newPath);
        }
        void Move(NotifyCollectionChangedEventArgs args)
        {
            var count = args.NewItems.Count;

            if (count == 1)
            {
                // For a single item, we can use MoveItem and get the animation
                var oldPath = NSIndexPath.Create(_section, args.OldStartingIndex);
                var newPath = NSIndexPath.Create(_section, args.NewStartingIndex);

                Update(() => CollectionView.MoveItem(oldPath, newPath), args);
                return;
            }

            var start = Math.Min(args.OldStartingIndex, args.NewStartingIndex);
            var end   = Math.Max(args.OldStartingIndex, args.NewStartingIndex) + count;

            Update(() => CollectionView.ReloadItems(CreateIndexesFrom(start, end)), args);
        }
예제 #4
0
        public void Execute()
        {
            // If we have incremental diffs, animate them in the collection view
            _collectionView.PerformBatchUpdates(() =>
            {
                // For indexes to make sense, updates must be in this order:
                // delete, insert, reload, move
                if (_changes.RemovedIndexes?.Count > 0)
                {
                    var result = new List <NSIndexPath>();
                    _changes.RemovedIndexes.EnumerateIndexes((nuint idx, ref bool stop) =>
                                                             result.Add(NSIndexPath.FromItemSection((nint)idx, _sectionIndex)));

                    _collectionView.DeleteItems(result.ToArray());
                }

                if (_changes.InsertedIndexes?.Count > 0)
                {
                    var result = new List <NSIndexPath>();

                    _changes.InsertedIndexes.EnumerateIndexes((nuint idx, ref bool stop) =>
                                                              result.Add(NSIndexPath.FromItemSection((nint)idx, _sectionIndex)));

                    _collectionView.InsertItems(result.ToArray());
                }

                if (_changes.ChangedIndexes?.Count > 0)
                {
                    var result = new List <NSIndexPath>();
                    _changes.ChangedIndexes.EnumerateIndexes((nuint idx, ref bool stop) =>
                                                             result.Add(NSIndexPath.FromItemSection((nint)idx, _sectionIndex)));

                    _collectionView.ReloadItems(result.ToArray());
                }

                _changes.EnumerateMoves((fromIndex, toIndex) =>
                {
                    _collectionView.MoveItem(NSIndexPath.FromItemSection((nint)fromIndex, _sectionIndex),
                                             NSIndexPath.FromItemSection((nint)toIndex, _sectionIndex));
                });
            }, null);
        }