From e2dbb2606251c98e9bf037a89afdfe5ac9fe085f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Glo=CC=88de?= Date: Thu, 9 Feb 2017 11:26:42 +0100 Subject: [PATCH 1/5] Introduced delegate for rotation change and tap notification --- Source/PDF UI/CPDFDocumentViewController.h | 11 +++++++++-- Source/PDF UI/CPDFDocumentViewController.m | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Source/PDF UI/CPDFDocumentViewController.h b/Source/PDF UI/CPDFDocumentViewController.h index 96268ed..be7d3b2 100644 --- a/Source/PDF UI/CPDFDocumentViewController.h +++ b/Source/PDF UI/CPDFDocumentViewController.h @@ -33,17 +33,24 @@ @class CPDFDocument; @class CContentScrollView; -@class CPreviewBar; @class CPDFPage; +@protocol CPDFDocumentViewControllerDelegate + +@optional +- (void)didTap:(BOOL)thumbnailsVisible; +- (void)didChangeRotation:(UIInterfaceOrientation)orientation andThumbnailsVisible:(BOOL)thumbnailsVisible; + +@end + @interface CPDFDocumentViewController : UIViewController +@property (readwrite, nonatomic, weak) id delegate; @property (readwrite, nonatomic, strong) NSURL *documentURL; @property (readwrite, nonatomic, strong) CPDFDocument *document; @property (readonly, nonatomic, strong) UIPageViewController *pageViewController; @property (readwrite, nonatomic, strong) UIView *backgroundView; -@property (readwrite, nonatomic, assign) BOOL magazineMode; @property (nonatomic) BOOL statusBarHidden; - (BOOL)openPage:(CPDFPage *)inPage; diff --git a/Source/PDF UI/CPDFDocumentViewController.m b/Source/PDF UI/CPDFDocumentViewController.m index a81ac6d..9c1c280 100644 --- a/Source/PDF UI/CPDFDocumentViewController.m +++ b/Source/PDF UI/CPDFDocumentViewController.m @@ -270,15 +270,20 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInte - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [self.renderedPageCache removeAllObjects]; [self populateCache]; + + if([self.delegate respondsToSelector:@selector(didChangeRotation:andThumbnailsVisible:)]) { + [self.delegate didChangeRotation:self.currentInterfaceOrientation andThumbnailsVisible:!self.chromeHidden]; + } } - (void)hideChrome { if (!self.chromeHidden) { [UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{ - self.navigationController.navigationBar.alpha = 0.0; self.previewCollectionView.alpha = 0.0; } completion:^(BOOL finished) { self.chromeHidden = YES; + + [self notifyDidTap]; }]; } } @@ -286,13 +291,20 @@ - (void)hideChrome { - (void)toggleChrome { [UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{ CGFloat newAlpha = 1.0f - (self.chromeHidden ? 0.0f : 1.0f); - self.navigationController.navigationBar.alpha = newAlpha; self.previewCollectionView.alpha = newAlpha; } completion:^(BOOL finished) { self.chromeHidden = !self.chromeHidden; + + [self notifyDidTap]; }]; } +- (void) notifyDidTap { + if([self.delegate respondsToSelector:@selector(didTap:)]) { + [self.delegate didTap:!self.chromeHidden]; + } +} + - (void)resizePageViewControllerForOrientation:(UIInterfaceOrientation)inOrientation { CGRect theBounds = self.view.bounds; CGRect theFrame; From 6e7fc9c14fe7b20d85721916d13535d9cc2f3fe6 Mon Sep 17 00:00:00 2001 From: Kevin Greim Date: Fri, 3 Mar 2017 13:13:14 +0100 Subject: [PATCH 2/5] Fixed all warnings --- Externals/TouchUI/Geometry.m | 2 +- Source/PDF Model/CPDFDocument.m | 2 +- Source/PDF Model/CPDFPage.m | 6 +++--- Source/PDF Model/CPDFStream.m | 4 ++-- Source/PDF UI/CPDFAnnotationView.m | 19 +++++++++++-------- Source/PDF UI/CPDFDocumentViewController.m | 4 ++-- Source/PDF UI/CPreviewCollectionViewCell.m | 2 +- Source/Support/NSURL_Extensions.m | 4 ++-- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Externals/TouchUI/Geometry.m b/Externals/TouchUI/Geometry.m index 1df5571..bcf2ef5 100755 --- a/Externals/TouchUI/Geometry.m +++ b/Externals/TouchUI/Geometry.m @@ -129,7 +129,7 @@ CGRect ScaleAndAlignRectToRect(CGRect inImageRect, CGRect inDestinationRect, EIm NSString *NSStringFromCIntegerPoint(CIntegerPoint inPoint) { -return([NSString stringWithFormat:@"%d,%d", inPoint.x, inPoint.y]); +return([NSString stringWithFormat:@"%ld,%ld", (long)inPoint.x, (long)inPoint.y]); } extern CIntegerPoint CIntegerPointFromString(NSString *inString) diff --git a/Source/PDF Model/CPDFDocument.m b/Source/PDF Model/CPDFDocument.m index 5f12a1b..28258cc 100644 --- a/Source/PDF Model/CPDFDocument.m +++ b/Source/PDF Model/CPDFDocument.m @@ -96,7 +96,7 @@ - (NSString *)title - (CPDFPage *)pageForPageNumber:(NSInteger)inPageNumber { - NSString *theKey = [NSString stringWithFormat:@"page_%d", inPageNumber]; + NSString *theKey = [NSString stringWithFormat:@"page_%ld", (long)inPageNumber]; CPDFPage *thePage = [self.cache objectForKey:theKey]; if (thePage == NULL) { diff --git a/Source/PDF Model/CPDFPage.m b/Source/PDF Model/CPDFPage.m index ddd74fc..a9c42d9 100644 --- a/Source/PDF Model/CPDFPage.m +++ b/Source/PDF Model/CPDFPage.m @@ -59,7 +59,7 @@ - (id)initWithDocument:(CPDFDocument *)inDocument pageNumber:(NSInteger)inPageNu - (NSString *)description { - return([NSString stringWithFormat:@"%@ (#%d, %@)", [super description], self.pageNumber, NSStringFromCGRect(self.mediaBox)]); + return([NSString stringWithFormat:@"%@ (#%ld, %@)", [super description], (long)self.pageNumber, NSStringFromCGRect(self.mediaBox)]); } - (CGPDFPageRef)cg @@ -137,14 +137,14 @@ - (UIImage *)imageWithSize:(CGSize)inSize scale:(CGFloat)inScale - (UIImage *)thumbnail { - NSString *theKey = [NSString stringWithFormat:@"page_%d_image_128x128", self.pageNumber]; + NSString *theKey = [NSString stringWithFormat:@"page_%ld_image_128x128", (long)self.pageNumber]; UIImage *theImage = [self.document.cache objectForKey:theKey]; return(theImage); } - (UIImage *)preview { - NSString *theKey = [NSString stringWithFormat:@"page_%d_image_preview2", self.pageNumber]; + NSString *theKey = [NSString stringWithFormat:@"page_%ld_image_preview2", (long)self.pageNumber]; UIImage *theImage = [self.document.cache objectForKey:theKey]; if (theImage == NULL) { diff --git a/Source/PDF Model/CPDFStream.m b/Source/PDF Model/CPDFStream.m index 4311d70..4be5673 100644 --- a/Source/PDF Model/CPDFStream.m +++ b/Source/PDF Model/CPDFStream.m @@ -46,7 +46,7 @@ - (NSString *)description { CGPDFDataFormat theFormat; NSData *theData = (__bridge_transfer NSData *)CGPDFStreamCopyData(_stream, &theFormat); - return([NSString stringWithFormat:@"%@ (format: %d, length: %d)", [super description], theFormat, theData.length]); + return([NSString stringWithFormat:@"%@ (format: %d, length: %lu)", [super description], theFormat, (unsigned long)theData.length]); } - (NSData *)data @@ -62,7 +62,7 @@ - (NSURL *)fileURLWithPathExtension:(NSString *)inPathExtension size_t theBufferLength = strlen([thePath UTF8String]) + 1; char thePathBuffer[theBufferLength]; strncpy(thePathBuffer, [thePath UTF8String], theBufferLength); - int theFileDescriptor = mkstemps(thePathBuffer, inPathExtension.length + 1); + int theFileDescriptor = mkstemps(thePathBuffer, (int)inPathExtension.length + 1); NSData *theData = self.data; write(theFileDescriptor, theData.bytes, inPathExtension.length + 1); diff --git a/Source/PDF UI/CPDFAnnotationView.m b/Source/PDF UI/CPDFAnnotationView.m index 027e17f..0de0ce2 100644 --- a/Source/PDF UI/CPDFAnnotationView.m +++ b/Source/PDF UI/CPDFAnnotationView.m @@ -35,10 +35,11 @@ #import "PDFUtilities.h" #import "CPDFStream.h" -#import +//#import +#import @interface CPDFAnnotationView () -@property (readwrite, nonatomic, strong) MPMoviePlayerController *moviePlayer; +@property (readwrite, nonatomic, strong) AVPlayer *moviePlayer; @end #pragma mark - @@ -70,17 +71,19 @@ - (void)layoutSubviews if (theURL) { - self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL]; - self.moviePlayer.view.frame = self.bounds; - self.moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [self.moviePlayer prepareToPlay]; - [self addSubview:self.moviePlayer.view]; - + self.moviePlayer = [[AVPlayer alloc]initWithURL:theURL];//[[MPMoviePlayerController alloc] initWithContentURL:theURL]; + AVPlayerViewController* controller = [AVPlayerViewController new]; + controller.allowsPictureInPicturePlayback = false; + controller.player = self.moviePlayer; + [controller.view setFrame:self.bounds]; + + double delayInSeconds = 2.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ // [self.moviePlayer play]; +// [self presentViewController:controller animated:true completion:nil]; }); } } diff --git a/Source/PDF UI/CPDFDocumentViewController.m b/Source/PDF UI/CPDFDocumentViewController.m index d43e31d..1da123f 100644 --- a/Source/PDF UI/CPDFDocumentViewController.m +++ b/Source/PDF UI/CPDFDocumentViewController.m @@ -249,7 +249,7 @@ - (void)viewWillAppear:(BOOL)animated { // select first cell. Both things are required to get the correct behaviour. UICollectionViewCell *cell = [self.previewCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; [cell setSelected:YES]; - [self.previewCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:nil]; + [self.previewCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UICollectionViewScrollPositionNone]; }); } @@ -415,7 +415,7 @@ - (void)populateCache { CGRect theBounds = thePageView.bounds; for (NSInteger thePageNumber = theStartPageNumber; thePageNumber <= theLastPageNumber; ++thePageNumber) { - NSString *theKey = [NSString stringWithFormat:@"%d[%d,%d]", thePageNumber, (int) theBounds.size.width, (int) theBounds.size.height]; + NSString *theKey = [NSString stringWithFormat:@"%d[%d,%d]", (int)thePageNumber, (int) theBounds.size.width, (int) theBounds.size.height]; if ([self.renderedPageCache objectForKey:theKey] == NULL) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ UIImage *theImage = [[self.document pageForPageNumber:thePageNumber] imageWithSize:theBounds.size scale:[UIScreen mainScreen].scale]; diff --git a/Source/PDF UI/CPreviewCollectionViewCell.m b/Source/PDF UI/CPreviewCollectionViewCell.m index 5167cf6..b40144f 100644 --- a/Source/PDF UI/CPreviewCollectionViewCell.m +++ b/Source/PDF UI/CPreviewCollectionViewCell.m @@ -22,7 +22,7 @@ - (instancetype)initWithFrame:(CGRect)frame self.imageView = [[UIImageView alloc] init]; self.imageView.frame = self.frame; self.imageView.contentMode = UIViewContentModeScaleAspectFill; - [self.viewForBaselineLayout addSubview:self.imageView]; + [self.viewForLastBaselineLayout addSubview:self.imageView]; } return self; } diff --git a/Source/Support/NSURL_Extensions.m b/Source/Support/NSURL_Extensions.m index 0ce34f0..c3a2370 100644 --- a/Source/Support/NSURL_Extensions.m +++ b/Source/Support/NSURL_Extensions.m @@ -72,14 +72,14 @@ + (NSString *)queryStringForDictionary:(NSDictionary *)inQueryDictionary for (id subValue in theValue) { NSString *tempSubValue = [subValue description]; - [theQueryComponents addObject:[NSString stringWithFormat:@"%@=%@", theKey, [tempSubValue stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; + [theQueryComponents addObject:[NSString stringWithFormat:@"%@=%@", theKey, [tempSubValue stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]]]; } } else { // this fixes the issue of spaces in values. %@ = [value description] NSString *tempValue = [theValue description]; - [theQueryComponents addObject:[NSString stringWithFormat:@"%@=%@", theKey, [tempValue stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; + [theQueryComponents addObject:[NSString stringWithFormat:@"%@=%@", theKey, [tempValue stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]]]; } } return([theQueryComponents componentsJoinedByString:@"&"]); From 7999c6000ac0c07622e5f3091cff0a5a4c7c12a9 Mon Sep 17 00:00:00 2001 From: Kevin Greim Date: Fri, 17 Mar 2017 11:41:09 +0100 Subject: [PATCH 3/5] AVKit and Bugfixing New: - Uses now AVKit - Bugfixing: If the document has one page and is in landscape the PDF-Reader loads an empty page 0. Bug/Todo: - --- Source/PDF UI/CPDFAnnotationView.m | 5 +---- Source/PDF UI/CPDFDocumentViewController.m | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/PDF UI/CPDFAnnotationView.m b/Source/PDF UI/CPDFAnnotationView.m index 0de0ce2..a43f32e 100644 --- a/Source/PDF UI/CPDFAnnotationView.m +++ b/Source/PDF UI/CPDFAnnotationView.m @@ -35,7 +35,6 @@ #import "PDFUtilities.h" #import "CPDFStream.h" -//#import #import @interface CPDFAnnotationView () @@ -71,7 +70,7 @@ - (void)layoutSubviews if (theURL) { - self.moviePlayer = [[AVPlayer alloc]initWithURL:theURL];//[[MPMoviePlayerController alloc] initWithContentURL:theURL]; + self.moviePlayer = [[AVPlayer alloc]initWithURL:theURL]; AVPlayerViewController* controller = [AVPlayerViewController new]; controller.allowsPictureInPicturePlayback = false; controller.player = self.moviePlayer; @@ -82,8 +81,6 @@ - (void)layoutSubviews double delayInSeconds = 2.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ -// [self.moviePlayer play]; -// [self presentViewController:controller animated:true completion:nil]; }); } } diff --git a/Source/PDF UI/CPDFDocumentViewController.m b/Source/PDF UI/CPDFDocumentViewController.m index 1da123f..00881d7 100644 --- a/Source/PDF UI/CPDFDocumentViewController.m +++ b/Source/PDF UI/CPDFDocumentViewController.m @@ -437,7 +437,7 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl return (NULL); } - if (theNextPageNumber == 0 && UIInterfaceOrientationIsPortrait(self.currentInterfaceOrientation)) { + if (theNextPageNumber == 0 && (UIInterfaceOrientationIsPortrait(self.currentInterfaceOrientation) || self.document.numberOfPages == 1)) { return (NULL); } From 2cfd1a7ccac22af5bb4fd8caadd6456dc33ccda3 Mon Sep 17 00:00:00 2001 From: Kevin Greim Date: Thu, 1 Jun 2017 15:01:16 +0200 Subject: [PATCH 4/5] Strings-File New: - Introduced strings-File Bug/Todo: - --- Source/Library/CLibraryViewController.m | 2 +- Source/Support/iOS-PDF-Reader.strings | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Source/Support/iOS-PDF-Reader.strings diff --git a/Source/Library/CLibraryViewController.m b/Source/Library/CLibraryViewController.m index c2a2f7f..22edb43 100644 --- a/Source/Library/CLibraryViewController.m +++ b/Source/Library/CLibraryViewController.m @@ -64,7 +64,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - self.title = @"Library"; + self.title = LocStringModule(@"STR_TITLE", @"iOS-PDF-Reader"); //@"Library"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidOpenURL:) name:@"applicationDidOpenURL" object:NULL]; diff --git a/Source/Support/iOS-PDF-Reader.strings b/Source/Support/iOS-PDF-Reader.strings new file mode 100644 index 0000000..52bc3aa --- /dev/null +++ b/Source/Support/iOS-PDF-Reader.strings @@ -0,0 +1,9 @@ +/* + iOS-PDF-Reader.strings + DVAG + + Created by Kevin Greim on 01.06.17. + Copyright © 2017 DVAG. All rights reserved. +*/ + +"STR_TITLE" = "Library"; From 177daab71762017f3d6ae41f822c9db6b93c9b13 Mon Sep 17 00:00:00 2001 From: Kevin Greim Date: Wed, 28 Jun 2017 07:43:50 +0200 Subject: [PATCH 5/5] Added import of AVFoundation New: - import AVFoundation --- Source/PDF UI/CPDFAnnotationView.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/PDF UI/CPDFAnnotationView.m b/Source/PDF UI/CPDFAnnotationView.m index a43f32e..1af8e8a 100644 --- a/Source/PDF UI/CPDFAnnotationView.m +++ b/Source/PDF UI/CPDFAnnotationView.m @@ -36,6 +36,7 @@ #import "CPDFStream.h" #import +#import @interface CPDFAnnotationView () @property (readwrite, nonatomic, strong) AVPlayer *moviePlayer;