Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
Fixed a bug in the last commit and in the handling of external links url
Browse files Browse the repository at this point in the history
  • Loading branch information
Xm4s committed Jan 7, 2011
1 parent 195e857 commit b8a6d2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Classes/BakerAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ - (void)saveLastPageReference {
// Save last page references
NSString *lastPageViewed = [NSString stringWithFormat:@"%d", rootViewController.currentPageNumber];
NSString *lastScrollIndex = [rootViewController.currPage stringByEvaluatingJavaScriptFromString:@"window.scrollY;"];

NSUserDefaults *userDefs = [NSUserDefaults standardUserDefaults];

if (lastPageViewed != 0) {
[userDefs setObject:lastPageViewed forKey:@"lastPageViewed"];
NSLog(@"Saved last page viewed: %@", lastPageViewed);
}
[userDefs setObject:lastScrollIndex forKey:@"lastScrollIndex"];


[userDefs setObject:lastScrollIndex forKey:@"lastScrollIndex"];
NSLog(@"Saved last scroll index: %@", lastScrollIndex);
}

Expand Down
25 changes: 15 additions & 10 deletions Classes/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ - (void)initBook:(NSString *)path {
NSString *currPageToLoad = [[NSUserDefaults standardUserDefaults] objectForKey:@"lastPageViewed"];
if (currentPageFirstLoading && currPageToLoad != nil)
currentPageNumber = [currPageToLoad intValue];
if (currentPageNumber == 0)
else
currentPageNumber = 1;

//prevPage.frame = [self frameForPage:currentPageNumber-1];
Expand Down Expand Up @@ -451,10 +451,19 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
if (!url || !URLString)
return NO;

NSArray *URLSections = [URLString componentsSeparatedByString:@"://"];
NSString *URLBody = [URLSections objectAtIndex:1];

NSString *URLScheme = [url scheme];
if (![URLScheme isEqualToString:@"file"] && ![URLScheme isEqualToString:@"book"]) {
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}

NSArray *URLSections = [URLString componentsSeparatedByString:@"://"];
NSString *URLBody = nil;
if ([URLSections count] == 2)
URLBody = [URLSections objectAtIndex:1];
else
return NO;

if ([URLScheme isEqualToString:@"file"]) {

NSString *file = [URLBody stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Expand All @@ -463,19 +472,15 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
[scrollView scrollRectToVisible:[self frameForPage:currentPageNumber] animated:YES];
[self gotoPageDelayer];
}

} else if ([URLScheme isEqualToString:@"book"]) {

if ([URLBody isEqualToString:@"default"] && [[NSFileManager defaultManager] fileExistsAtPath:bundleBookPath]) {
[self initBook:bundleBookPath];
} else {
self.URLDownload = [@"http://" stringByAppendingString:URLBody];
[self downloadBook:nil];
}

} else {

[[UIApplication sharedApplication] openURL:[request URL]];
}
}

return NO;
Expand Down

0 comments on commit b8a6d2e

Please sign in to comment.