public void HandleDownloadEvent(LibraryBookView bookView)
 {
     if (DownloadEvent != null)
     {
         DownloadEvent(bookView);
     }
 }
        void HandleDownloadEvent(LibraryBookView bookView)
        {
            try
            {
                if (!downloadAnimation)
                {
                    downloadAnimation = true;

                    // Remove from collectionView
                    bookView.RemoveFromSuperview();

                    // Add to the current view at exact position
                    NSIndexPath indexPath = dataSource.GetIndexPath(bookView.LibraryBook.ID);
                    UICollectionViewLayoutAttributes attributes = collectionView.GetLayoutAttributesForItem(indexPath);
                    bookView.Frame = new CGRect(attributes.Frame.X + collectionView.Frame.X, attributes.Frame.Y - collectionView.ContentOffset.Y, attributes.Frame.Width, attributes.Frame.Height);
                    this.View.AddSubview(bookView);

                    // Fly Animation
                    CGPoint startPoint = new CGPoint(bookView.Frame.X + bookView.Frame.Width / 2, bookView.Frame.Y + bookView.Frame.Height / 2);
                    CGPoint endPoint   = new CGPoint(Settings.MyBooksTabLocation.X + 76f / 2f, this.View.Frame.Bottom + 55f / 2f);

                    UIView.Animate(0.75d, delegate
                    {
                        bookView.Transform = CGAffineTransform.MakeScale(0.1f, 0.1f);
                        bookView.Center    = endPoint;
                        bookView.Alpha     = 0.5f;

                        // Prepare my own keypath animation for the layer position
                        CGPath animationPath = CreatePath(startPoint, endPoint);
                        CAKeyFrameAnimation keyFrameAnimation = CAKeyFrameAnimation.GetFromKeyPath("position");
                        keyFrameAnimation.Path = animationPath;

                        // Copy properties from UIView's animation
                        CAAnimation autoAnimation        = bookView.Layer.AnimationForKey("position");
                        keyFrameAnimation.Duration       = autoAnimation.Duration;
                        keyFrameAnimation.FillMode       = autoAnimation.FillMode;
                        keyFrameAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

                        // Replace UIView's animation with my animation
                        bookView.Layer.AddAnimation(keyFrameAnimation, keyFrameAnimation.KeyPath);
                    }, delegate
                    {
                        this.InvokeOnMainThread(delegate
                        {
                            UpdateCollectionView(bookView);
                        });
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("LibraryViewController - HandleDownloadEvent: {0}", ex.ToString());
            }
        }
        void HandleOverviewDownloadEvent(Book book)
        {
            this.DismissCurrentPopinControllerAnimated(true);

            LibraryBookView bookView = dataSource.GetLibraryBookView(book.ID);

            if (bookView != null)
            {
                HandleDownloadEvent(bookView);
            }
        }
        private void UpdateCollectionView(LibraryBookView bookView)
        {
            if (dataSource != null && dataSource.BookList != null && dataSource.BookList.Count > 0)
            {
                try
                {
                    bookView.RemoveFromSuperview();

                    Book book = bookView.LibraryBook.Copy();
                    book.Status = Book.BookStatus.PENDING2DOWNLOAD;

                    // Add the book to the device
                    BooksOnDeviceAccessor.AddBook(book);

                    // Start the download
                    BookUpdater.CheckBooks2Download();

                    // Update available badge
                    UpdateAvailableBadge();

                    // Remove from the list
                    List <Book> newBookList = new List <Book>(dataSource.BookList);
                    int         removeIdx   = dataSource.GetBookIndex(book.ID);
                    newBookList.RemoveAt(removeIdx);

                    collectionView.PerformBatchUpdates(delegate
                    {
                        foreach (Book b in dataSource.BookList)
                        {
                            if (b.ID != book.ID)
                            {
                                NSIndexPath fromIndexPath = dataSource.GetIndexPath(b.ID);
                                int toRow = newBookList.IndexOf(b);
                                if (fromIndexPath != null && fromIndexPath.Row >= 0 && toRow >= 0)
                                {
                                    NSIndexPath toIndexPath = NSIndexPath.FromRowSection(toRow, 0);
                                    collectionView.MoveItem(fromIndexPath, toIndexPath);
                                }
                            }
                        }
                    }, delegate
                    {
                        downloadAnimation = false;

                        RefreshTable();
                    });
                }
                catch (Exception ex)
                {
                    Logger.WriteLineDebugging("LibraryViewController - UpdateCollectionView: {0}", ex.ToString());
                }
            }
        }
        private void UpdateDictionary()
        {
            indexDictionary.Clear();

            int row = 0;

            foreach (Book book in BookList)
            {
                LibraryBookView bookView = new LibraryBookView(book, parentVC);
                indexDictionary.Add(NSIndexPath.FromRowSection(row, 0), bookView);
                row++;
            }
        }