void HandleDidRenderPageViewEvent(PSPDFPageView pageView) { Page page = BooksOnDeviceAccessor.GetPage(book.ID, (int)pageView.Page + 1); if (page != null) { // Set current page id for Dashboard menu button action Settings.CurrentPageID = page.ID; // Clear the pageview foreach (UIView subview in pageView) { if (subview.Tag == -1) { subview.RemoveFromSuperview(); break; } } // bookmark Bookmark bookmark = BooksOnDeviceAccessor.GetBookmark(book.ID, page.ID); // bookmarkButton UIButton bookmarkButton = GenerateBookmarkButton(pageView, page, bookmark); bookmarkButton.Tag = -1; pageView.AddSubview(bookmarkButton); UpdateBookmarkLocation(bookmarkButton); } }
public static void SaveBookmark(Book book, String pageID, String text) { Bookmark bookmark = BooksOnDeviceAccessor.GetBookmark(book.ID, pageID); if (bookmark == null) { if (!String.IsNullOrEmpty(text)) { bookmark = GenerateBookmarkObj(book, pageID, text); Add(bookmark); } } else { if (String.IsNullOrEmpty(text)) { Remove(book.ID, pageID); } else { bookmark = GenerateBookmarkObj(book, pageID, text); Update(bookmark); } } BooksOnDeviceAccessor.UpdateUserModifiedDate(book); }
private static void PullBookmarksWork(Book book) { List <Bookmark> sBookmarks = SaveMyStuff.GetMyBookmarks(book.ID); if (sBookmarks != null && sBookmarks.Count > 0) { foreach (var sBookmark in sBookmarks) { Bookmark dBookmark = BooksOnDeviceAccessor.GetBookmark(book.ID, sBookmark.PageID); if (dBookmark == null) { // This is a new bookmark from the server BooksOnDeviceAccessor.AddBookmark(sBookmark); } else { if (dBookmark.ModifiedUtc <= sBookmark.ModifiedUtc) { if (sBookmark.Removed) { // Remove bookmark if the bookmark on the cloud has 'Removed' checked BooksOnDeviceAccessor.RemoveBookmark(dBookmark.BookID, dBookmark.PageID); } else { BooksOnDeviceAccessor.UpdateBookmark(sBookmark); } } } } } }
private UIButton GenerateBookmarkButton(PSPDFPageView pageView, Page page, Bookmark bookmark) { UIButton button = UIButton.FromType(UIButtonType.Custom); // Image if (bookmark == null) { button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_add.png"), UIControlState.Normal); button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_add.png"), UIControlState.Highlighted); } else { button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"), UIControlState.Normal); button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"), UIControlState.Highlighted); } button.Frame = new CGRect(30, 0, button.CurrentBackgroundImage.Size.Width, button.CurrentBackgroundImage.Size.Height); // Action button.TouchUpInside += (object sender, EventArgs e) => { UIAlertView alertView = new UIAlertView("Bookmark", "Please enter bookmark title and press Save.", null, StringRef.cancel, "Save"); alertView.AlertViewStyle = UIAlertViewStyle.PlainTextInput; alertView.GetTextField(0).ReturnKeyType = UIReturnKeyType.Done; alertView.GetTextField(0).Placeholder = "Bookmark Title"; // Show bookmark title if already exist bookmark = BooksOnDeviceAccessor.GetBookmark(book.ID, page.ID); if (bookmark != null) { alertView.GetTextField(0).Text = bookmark.Title; } alertView.Dismissed += delegate(object sender1, UIButtonEventArgs e1) { if (e1.ButtonIndex == 1) { String text = alertView.GetTextField(0).Text; BookmarkUpdater.SaveBookmark(book, page.ID, text); if (String.IsNullOrEmpty(text)) { RemoveBookmarkFromBookmarkParser(this.Page); button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_add.png"), UIControlState.Normal); button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_add.png"), UIControlState.Highlighted); } else { AddBookmarkToBookmarkParser(this.Page); button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"), UIControlState.Normal); button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"), UIControlState.Highlighted); } } }; alertView.WillDismiss += delegate { alertView.GetTextField(0).ResignFirstResponder(); }; alertView.Show(); }; return(button); }
static void HandleGetMyBookmarksEvent(String bookID, List <Bookmark> sBookmarks, bool lastItem) { try { List <Bookmark> dBookmarks = BooksOnDeviceAccessor.GetBookmarks(bookID); if (dBookmarks != null && dBookmarks.Count > 0) { foreach (Bookmark dBookmark in dBookmarks) { if (sBookmarks != null && sBookmarks.Count > 0) { foreach (Bookmark sBookmark in sBookmarks) { if (dBookmark.PageID == sBookmark.PageID) { if (dBookmark.ModifiedUtc < sBookmark.ModifiedUtc) { if (sBookmark.Removed) { // Remove bookmark if bookmark on the cloud has 'Removed' checked BooksOnDeviceAccessor.RemoveBookmark(dBookmark.BookID, dBookmark.PageID); } else { // Update bookmark if bookmark on the cloud has the latest ModifiedUtc dBookmark.BookVersion = sBookmark.BookVersion; dBookmark.Title = sBookmark.Title; dBookmark.ModifiedUtc = sBookmark.ModifiedUtc; BooksOnDeviceAccessor.UpdateBookmark(dBookmark); } } break; } } } } } // Add bookmark if the bookmark is not on the device if (sBookmarks != null && sBookmarks.Count > 0) { foreach (Bookmark sBookmark in sBookmarks) { if (!sBookmark.Removed) { if (BooksOnDeviceAccessor.GetBookmark(sBookmark.BookID, sBookmark.PageID) == null) { BooksOnDeviceAccessor.AddBookmark(sBookmark); } } } } // Check if syncing is done if (cancelled) { SetReceive(true); CheckReceiveDone(); } else { if (lastItem) { SaveMyStuff.GetMyBookmarksEvent -= HandleGetMyBookmarksEvent; receiveBookmarks = true; CheckReceiveDone(); } } } catch (Exception ex) { SetReceive(true); CheckReceiveDone(); Logger.WriteLineDebugging("CloudSync - HandleGetMyBookmarksEvent: {0}", ex.ToString()); } }