public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) { var cell = (PageCell)collectionView.DequeueReusableCell(cellID, indexPath); var page = list[indexPath.Row]; if (page != null) { cell.PageID = page.ID; if (page.ID != StringRef.Empty || page.ChapterID != StringRef.Empty) { String url = DownloadedFilesCache.BuildCachedFilePath(page.URL); if (!String.IsNullOrEmpty(url)) { CGPDFDocument pdfDoc = CGPDFDocument.FromFile(url); if (pdfDoc != null) { CGPDFPage pdfPage = pdfDoc.GetPage(1); UIImage image = ImageHelper.PDF2Image(pdfPage, 150, UIScreen.MainScreen.Scale); // THIS IS REQUIRED TO SKIP iCLOUD BACKUP SkipBackup2iCloud.SetAttribute(url); if (image != null) { cell.Image = image; } } } } } return cell; }
void RequestFinish(NSObject sender) { try { ASIHTTPRequest request = sender as ASIHTTPRequest; if (request != null) { // THIS IS REQUIRED TO SKIP iCLOUD BACKUP SkipBackup2iCloud.SetAttribute(request.DownloadDestinationPath); if (dataSource != null) { dataSource.UpdateImage(request.Url.AbsoluteString); } if (boc != null) { boc.UpdateCover(request.Url.AbsoluteString); } } } catch (Exception ex) { Logger.WriteLineDebugging("LibraryViewController - RequestFinish: {0}", ex.ToString()); } }
public static void RequestDidFinish(NSObject sender) { try { ASIHTTPRequest request = sender as ASIHTTPRequest; if (request != null) { // THIS IS REQUIRED TO SKIP iCLOUD BACKUP SkipBackup2iCloud.SetAttribute(request.DownloadDestinationPath); // Removed from the list if succeeded re-downloading if (CurrentBook.FailedURLs != null) { if (CurrentBook.FailedURLs.Contains(request.Url.AbsoluteString)) { CurrentBook.FailedURLs.Remove(request.Url.AbsoluteString); } } CurrentBook.DownloadCount += 1; DownloadReporter.UpdateProgress(); } } catch (Exception ex) { Logger.WriteLineDebugging("BookUpdater - RequestDidFinish: {0}", ex.ToString()); } }
private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false) { try { // activityIndicator UIActivityIndicatorView activityIndicator = new UIActivityIndicatorView(); activityIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.White; activityIndicator.StartAnimating(); activityIndicator.HidesWhenStopped = true; activityIndicator.Frame = new RectangleF((this.Frame.Width / 2) - 10, (this.Frame.Height / 2) - 10, 20, 20); this.AddSubview(activityIndicator); // Generate pdf thumbnail Page page = null; Annotation annotation = null; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate { page = BooksOnDeviceAccessor.GetPage(bookID, pageID); if (String.IsNullOrEmpty(text)) { annotation = BooksOnDeviceAccessor.GetAnnotation(bookID, pageID); } }; worker.RunWorkerCompleted += delegate { this.InvokeOnMainThread(delegate { activityIndicator.StopAnimating(); if (page != null) { String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL); if (!String.IsNullOrEmpty(localPath)) { CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath); if (pdfDoc != null) { CGPDFPage pdfPage = pdfDoc.GetPage(1); if (pdfPage != null) { UIImage pdfImg = PDFConverter.Transform2Image(pdfPage, this.Frame.Width); // pageView UIImageView pageView = new UIImageView(); pageView.Frame = new RectangleF(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height); // If this is annotation thumbnail, draw annotation overlay on top of pdf if (annotation != null) { Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((UInt32)page.PageNumber - 1, annotation); if (dictionary != null) { foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary) { // Create full size annotation UIImage annImg = DrawAnnotation(item.Key, item.Value); if (annImg != null) { // Scale down the annotation image annImg = annImg.Scale(new SizeF(pdfImg.Size.Width, pdfImg.Size.Height)); // Overlap pdfImg and annImg pdfImg = Overlap(pdfImg, annImg); } } } } pageView.Image = pdfImg; this.AddSubview(pageView); // THIS IS REQUIRED TO SKIP iCLOUD BACKUP SkipBackup2iCloud.SetAttribute(localPath); // Add ribbon if this is bookmark thumbnail if (bookmark) { UIImageView ribbon = new UIImageView(); ribbon.Image = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"); ribbon.Frame = new RectangleF(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f); this.AddSubview(ribbon); } // Do not add text if this is annotation thumbnail if (!String.IsNullOrEmpty(text)) { // titleLabel UILabel titleLabel = new UILabel(); titleLabel.Frame = new RectangleF(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42); titleLabel.Font = UIFont.SystemFontOfSize(16f); titleLabel.BackgroundColor = UIColor.Clear; titleLabel.TextColor = eBriefingAppearance.DarkGrayColor; titleLabel.Lines = 2; titleLabel.LineBreakMode = UILineBreakMode.TailTruncation; titleLabel.TextAlignment = UITextAlignment.Center; titleLabel.Text = text; this.AddSubview(titleLabel); } } } } } }); }; worker.RunWorkerAsync(); } catch (Exception ex) { Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString()); } }
async private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false) { try { // spinner RTSpinKitView spinner = eBriefingAppearance.GenerateBounceSpinner(); spinner.Center = this.Center; this.AddSubview(spinner); // Generate pdf thumbnail Page page = await eBriefingService.Run(() => BooksOnDeviceAccessor.GetPage(bookID, pageID)); Annotation annotation = null; if (String.IsNullOrEmpty(text)) { annotation = await eBriefingService.Run(() => BooksOnDeviceAccessor.GetAnnotation(bookID, pageID)); } spinner.StopAnimating(); if (page != null) { String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL); if (!String.IsNullOrEmpty(localPath)) { CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath); if (pdfDoc != null) { CGPDFPage pdfPage = pdfDoc.GetPage(1); if (pdfPage != null) { UIImage pdfImg = ImageHelper.PDF2Image(pdfPage, this.Frame.Width, UIScreen.MainScreen.Scale); // pageView UIImageView pageView = new UIImageView(); pageView.Frame = new CGRect(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height); // If this is annotation thumbnail, draw annotation overlay on top of pdf if (annotation != null) { Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((nuint)page.PageNumber - 1, annotation); if (dictionary != null) { foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary) { // Create full size annotation UIImage annImg = ImageHelper.DrawPSPDFAnnotation(item.Key, item.Value); if (annImg != null) { // Scale down the annotation image annImg = annImg.Scale(new CGSize(pdfImg.Size.Width, pdfImg.Size.Height)); // Overlap pdfImg and annImg pdfImg = ImageHelper.Overlap(pdfImg, annImg, CGPoint.Empty, CGPoint.Empty, UIScreen.MainScreen.Scale); } } } } pageView.Image = pdfImg; this.AddSubview(pageView); if (pdfImg.Size.Height < this.Frame.Height) { this.BackgroundColor = UIColor.Clear; } // THIS IS REQUIRED TO SKIP iCLOUD BACKUP SkipBackup2iCloud.SetAttribute(localPath); // Add ribbon if this is bookmark thumbnail if (bookmark) { UIImageView ribbon = new UIImageView(); ribbon.Image = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"); ribbon.Frame = new CGRect(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f); this.AddSubview(ribbon); } // Do not add text if this is annotation thumbnail if (!String.IsNullOrEmpty(text)) { // titleLabel UILabel titleLabel = eBriefingAppearance.GenerateLabel(16); titleLabel.Frame = new CGRect(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42); titleLabel.Lines = 2; titleLabel.LineBreakMode = UILineBreakMode.TailTruncation; titleLabel.TextAlignment = UITextAlignment.Center; titleLabel.Text = text; this.AddSubview(titleLabel); } } } } } } catch (Exception ex) { Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString()); } }