Exemple #1
0
 public void HandleShowMenuEvent(BookshelfBookView bookView, bool isFavorite)
 {
     if (ShowMenuEvent != null)
     {
         ShowMenuEvent(bookView, isFavorite);
     }
 }
 private void GetBookViewAndUpdateCollectionView(String bookID)
 {
     if (dataSource != null)
     {
         BookshelfBookView bookView = dataSource.GetBookshelfBookView(collectionView, bookID);
         if (bookView != null)
         {
             UpdateCollectionView(bookView);
         }
     }
 }
Exemple #3
0
        private void UpdateDictionary()
        {
            if (indexDictionary != null)
            {
                indexDictionary.Clear();
            }
            int row = 0;

            foreach (Book book in BookList)
            {
                BookshelfBookView bookView = new BookshelfBookView(book, updateMenu, parentVC);
                indexDictionary.Add(NSIndexPath.FromRowSection(row, 0), bookView);
                row++;
            }
        }
        private void UpdateCollectionView(BookshelfBookView bookView)
        {
            if (dataSource != null && dataSource.BookList != null && dataSource.BookList.Count > 0)
            {
                try
                {
                    bookView.RemoveFromSuperview();

                    Book book = bookView.BookshelfBook.Copy();

                    // 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
                    {
                        RefreshTable();
                    });
                }
                catch (Exception ex)
                {
                    Logger.WriteLineDebugging("BookshelfViewController - UpdateCollectionView: {0}", ex.ToString());
                }
            }
        }
        void HandleShowMenuEvent(BookshelfBookView bookView, bool isFavorite)
        {
            PopoverMenuController pmc = new PopoverMenuController(bookView, isFavorite);

            if (bookView.BookshelfBook.Status == Book.BookStatus.DOWNLOADED)
            {
                pmc.View.Frame = new CGRect(0, 0, bookView.Frame.Width, 88);
            }
            else
            {
                pmc.View.Frame = new CGRect(0, 0, bookView.Frame.Width, 44);
            }

            pmc.FavoriteEvent += delegate
            {
                HideMenuPopover();

                dataSource.UpdateFavorite(bookView.BookshelfBook.ID, !isFavorite);

                if (this.Title != StringRef.myBooks)
                {
                    UpdateCollectionView(bookView);
                }
            };
            pmc.RemoveBookEvent += delegate
            {
                HideMenuPopover();

                UIAlertView alert = new UIAlertView(StringRef.confirmation, "Are you sure you want to remove this book from the Bookshelf?", null, StringRef.no, StringRef.yes);
                alert.Dismissed += (object sender, UIButtonEventArgs e) =>
                {
                    if (e.ButtonIndex == 1)
                    {
                        BooksOnDeviceAccessor.MarkAsRemovedBook(bookView.BookshelfBook);
                        BookRemover.RemoveBookInCache(bookView.BookshelfBook);
                        BookRemover.RemoveBook(bookView.BookshelfBook);
                        UpdateCollectionView(bookView);
                    }
                };
                alert.Show();
            };
            pmc.CancelDownloadEvent += delegate
            {
                HideMenuPopover();

                UIAlertView alert = new UIAlertView(StringRef.confirmation, "Are you sure you want to cancel the download for this book?", null, StringRef.no, StringRef.yes);
                alert.Dismissed += (object sender, UIButtonEventArgs e) =>
                {
                    if (e.ButtonIndex == 1)
                    {
                        if (bookView.BookshelfBook.Status != Book.BookStatus.DOWNLOADED)
                        {
                            CancelDownload(bookView.BookshelfBook);
                        }
                    }
                };
                alert.Show();
            };

            menuViewController             = new UIPopoverController(pmc);
            menuViewController.DidDismiss += (object sender, EventArgs e) =>
            {
                HideMenuPopover();
            };
            menuViewController.SetPopoverContentSize(new CGSize(pmc.View.Frame.Width, pmc.View.Frame.Height), true);
            menuViewController.PresentFromRect(bookView.Frame, bookView, UIPopoverArrowDirection.Any, true);
        }
Exemple #6
0
 public PopoverMenuController(BookshelfBookView bookView, bool isFavorite) : base(UITableViewStyle.Plain)
 {
     this.bookView   = bookView;
     this.isFavorite = isFavorite;
 }
Exemple #7
0
 void HandleShowMenuEvent(BookshelfBookView bookView, bool isFavorite)
 {
     dataSource.HandleShowMenuEvent(bookView, isFavorite);
 }