diff --git a/KFEpubKit iOS/KFViewController.m b/KFEpubKit iOS/KFViewController.m index d6aa224..fb154c6 100644 --- a/KFEpubKit iOS/KFViewController.m +++ b/KFEpubKit iOS/KFViewController.m @@ -7,23 +7,116 @@ // #import "KFViewController.h" +#import "KFEpubController.h" +#import "KFEpubContentModel.h" + +@interface KFViewController () + + +@property (weak, nonatomic) IBOutlet UIWebView *webView; + +@property (nonatomic, strong) KFEpubController *epubController; + +@property (nonatomic, strong) KFEpubContentModel *contentModel; + +@property (nonatomic) NSUInteger spineIndex; -@interface KFViewController () @end + @implementation KFViewController + - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. + NSURL *epubURL = [[NSBundle mainBundle] URLForResource:@"tolstoy-war-and-peace" withExtension:@"epub"]; + + NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; + + self.epubController = [[KFEpubController alloc] initWithEpubURL:epubURL andDestinationFolder:documentsURL]; + self.epubController.delegate = self; + [self.epubController openAsynchronous:YES]; + + UISwipeGestureRecognizer *swipeRecognizer; + swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)]; + swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight; + swipeRecognizer.delegate = self; + [self.webView addGestureRecognizer:swipeRecognizer]; + + swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)]; + swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; + swipeRecognizer.delegate = self; + [self.webView addGestureRecognizer:swipeRecognizer]; +} + + +- (void)didSwipeRight:(UIGestureRecognizer *)recognizer +{ + if (self.spineIndex > 1) + { + self.spineIndex--; + [self updateContentForSpineIndex:self.spineIndex]; + } +} + + +- (void)didSwipeLeft:(UIGestureRecognizer *)recognizer +{ + if (self.spineIndex < self.contentModel.spine.count) + { + self.spineIndex++; + [self updateContentForSpineIndex:self.spineIndex]; + } +} + + +#pragma mark Epub Contents + + +- (void)updateContentForSpineIndex:(NSUInteger)currentSpineIndex +{ + NSString *contentFile = self.contentModel.manifest[self.contentModel.spine[currentSpineIndex]][@"href"]; + NSURL *contentURL = [self.epubController.epubContentBaseURL URLByAppendingPathComponent:contentFile]; + NSLog(@"content URL :%@", contentURL); + + NSURLRequest *request = [[NSURLRequest alloc] initWithURL:contentURL]; + [self.webView loadRequest:request]; +} + + +#pragma mark KFEpubControllerDelegate Methods + + +- (void)epubController:(KFEpubController *)controller willOpenEpub:(NSURL *)epubURL +{ + NSLog(@"will open epub"); +} + + +- (void)epubController:(KFEpubController *)controller didOpenEpub:(KFEpubContentModel *)contentModel +{ + NSLog(@"opened: %@", contentModel.metaData[@"title"]); + self.contentModel = contentModel; + self.spineIndex = 4; + [self updateContentForSpineIndex:self.spineIndex]; +} + + +- (void)epubController:(KFEpubController *)controller didFailWithError:(NSError *)error +{ + NSLog(@"epubController:didFailWithError: %@", error.description); } -- (void)didReceiveMemoryWarning + +#pragma mark - UIGestureRecognizerDelegate Methods + + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + return YES; } + @end diff --git a/KFEpubKit iOS/en.lproj/KFViewController_iPhone.xib b/KFEpubKit iOS/en.lproj/KFViewController_iPhone.xib index a2822e9..ddfd08b 100644 --- a/KFEpubKit iOS/en.lproj/KFViewController_iPhone.xib +++ b/KFEpubKit iOS/en.lproj/KFViewController_iPhone.xib @@ -1,18 +1,20 @@ - 1536 - 12A269 - 2835 - 1187 - 624.00 + 1552 + 12D78 + 3084 + 1187.37 + 626.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 1919 + 2083 + IBNSLayoutConstraint IBProxyObject IBUIView + IBUIWebView com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -33,10 +35,24 @@ 274 + + + + 274 + {320, 548} + + _NS:9 + + 1 + MSAxIDEAA + + IBCocoaTouchFramework + 1 + YES + + {{0, 20}, {320, 548}} - - 3 MC43NQA @@ -76,6 +92,14 @@ 7 + + + webView + + + + 13 + @@ -99,8 +123,100 @@ 6 + + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 4 + 0 + + 4 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 3 + 0 + + 3 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + @@ -108,31 +224,32 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin UIResponder com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 7 - - - - - KFViewController - UIViewController - - IBProjectSource - ./Classes/KFViewController.h - - - + 13 + 0 IBCocoaTouchFramework YES 3 YES - 1919 + 2083 diff --git a/KFEpubKit.xcodeproj/project.pbxproj b/KFEpubKit.xcodeproj/project.pbxproj index 153f82b..f6105d1 100644 --- a/KFEpubKit.xcodeproj/project.pbxproj +++ b/KFEpubKit.xcodeproj/project.pbxproj @@ -50,6 +50,7 @@ 1D7175251769030400CA1E90 /* KFEpubExtractor.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D4FFAD917280EC500AA5D35 /* KFEpubExtractor.m */; }; 1D7175261769030400CA1E90 /* KFEpubKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D4FFB19172983BC00AA5D35 /* KFEpubKit.m */; }; 1D7175271769030400CA1E90 /* KFEpubParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DEB65861727FC6700FDBDC3 /* KFEpubParser.m */; }; + 1D7175281769102500CA1E90 /* tolstoy-war-and-peace.epub in Resources */ = {isa = PBXBuildFile; fileRef = 1D4FFB0A17293ABA00AA5D35 /* tolstoy-war-and-peace.epub */; }; 1DC73F111733FA6900C87195 /* Winnie-the-Pooh.epub in Resources */ = {isa = PBXBuildFile; fileRef = 1DC73F101733FA6900C87195 /* Winnie-the-Pooh.epub */; }; 1DEB65641727E18800FDBDC3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DEB65631727E18800FDBDC3 /* Cocoa.framework */; }; 1DEB656E1727E18800FDBDC3 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1DEB656C1727E18800FDBDC3 /* InfoPlist.strings */; }; @@ -486,6 +487,7 @@ 1D71750E176900FC00CA1E90 /* Default-568h@2x.png in Resources */, 1D717514176900FC00CA1E90 /* KFViewController_iPhone.xib in Resources */, 1D717517176900FC00CA1E90 /* KFViewController_iPad.xib in Resources */, + 1D7175281769102500CA1E90 /* tolstoy-war-and-peace.epub in Resources */, ); runOnlyForDeploymentPostprocessing = 0; };