Handling gestures for entering original view.

This commit is contained in:
Samuel Clay 2014-02-03 18:54:50 -08:00
parent 0620af0674
commit 7b8c0d957e
11 changed files with 65 additions and 23 deletions

View file

@ -1771,7 +1771,7 @@ heightForRowAtIndexPath:(NSIndexPath *)indexPath {
options:kNilOptions options:kNilOptions
error:&error]; error:&error];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul);
dispatch_async(queue, ^{ dispatch_async(queue, ^{
for (id feed_id in results) { for (id feed_id in results) {
NSMutableDictionary *feed = [[appDelegate.dictActiveFeeds objectForKey:feed_id] mutableCopy]; NSMutableDictionary *feed = [[appDelegate.dictActiveFeeds objectForKey:feed_id] mutableCopy];

View file

@ -744,11 +744,11 @@
// NSLog(@"Original frame: %@", NSStringFromCGRect(self.originalViewController.view.frame)); // NSLog(@"Original frame: %@", NSStringFromCGRect(self.originalViewController.view.frame));
CGRect feedDetailFrame = self.feedDetailViewController.view.frame; CGRect feedDetailFrame = self.feedDetailViewController.view.frame;
feedDetailFrame.origin.x = -1 * (1-percentage) * feedDetailFrame.size.width/6; feedDetailFrame.origin.x = -1 * (1-percentage) * 100;
self.feedDetailViewController.view.frame = feedDetailFrame; self.feedDetailViewController.view.frame = feedDetailFrame;
CGRect storyNavFrame = self.storyNavigationController.view.frame; CGRect storyNavFrame = self.storyNavigationController.view.frame;
storyNavFrame.origin.x = -1 * (1-percentage) * feedDetailFrame.size.width/6; storyNavFrame.origin.x = -1 * (1-percentage) * 100;
self.storyNavigationController.view.frame = storyNavFrame; self.storyNavigationController.view.frame = storyNavFrame;
} else { } else {
CGRect originalNavFrame = self.originalNavigationController.view.frame; CGRect originalNavFrame = self.originalNavigationController.view.frame;
@ -758,11 +758,11 @@
// NSLog(@"Original frame: %@", NSStringFromCGRect([[[[self.originalNavigationController viewControllers] objectAtIndex:0] view] frame])); // NSLog(@"Original frame: %@", NSStringFromCGRect([[[[self.originalNavigationController viewControllers] objectAtIndex:0] view] frame]));
CGRect feedDetailFrame = self.masterNavigationController.view.frame; CGRect feedDetailFrame = self.masterNavigationController.view.frame;
feedDetailFrame.origin.x = -1 * (1-percentage) * feedDetailFrame.size.width/6; feedDetailFrame.origin.x = -1 * (1-percentage) * 100;
self.masterNavigationController.view.frame = feedDetailFrame; self.masterNavigationController.view.frame = feedDetailFrame;
CGRect storyNavFrame = self.storyNavigationController.view.frame; CGRect storyNavFrame = self.storyNavigationController.view.frame;
storyNavFrame.origin.x = NB_DEFAULT_MASTER_WIDTH - 1 + -1 * (1-percentage) * feedDetailFrame.size.width/6; storyNavFrame.origin.x = NB_DEFAULT_MASTER_WIDTH - 1 + -1 * (1-percentage) * 100;
self.storyNavigationController.view.frame = storyNavFrame; self.storyNavigationController.view.frame = storyNavFrame;
} }

View file

@ -192,8 +192,8 @@
[window makeKeyAndVisible]; [window makeKeyAndVisible];
// [self performSelectorOnMainThread:@selector(showSplashView) withObject:nil waitUntilDone:NO]; // [self performSelectorOnMainThread:@selector(showSplashView) withObject:nil waitUntilDone:NO];
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0xE0E3DB)]; [[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0xE3E6E0)];
[[UIToolbar appearance] setBarTintColor:UIColorFromRGB(0xE0E3DB)]; [[UIToolbar appearance] setBarTintColor: UIColorFromRGB(0xE3E6E0)];
[[UISegmentedControl appearance] setTintColor:UIColorFromRGB(0x8F918B)]; [[UISegmentedControl appearance] setTintColor:UIColorFromRGB(0x8F918B)];
// [[UISegmentedControl appearance] setBackgroundColor:UIColorFromRGB(0x8F918B)]; // [[UISegmentedControl appearance] setBackgroundColor:UIColorFromRGB(0x8F918B)];
@ -2976,7 +2976,7 @@
- (void)flushQueuedReadStories:(BOOL)forceCheck withCallback:(void(^)())callback { - (void)flushQueuedReadStories:(BOOL)forceCheck withCallback:(void(^)())callback {
if (self.hasQueuedReadStories || forceCheck) { if (self.hasQueuedReadStories || forceCheck) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,
(unsigned long)NULL), ^(void) { (unsigned long)NULL), ^(void) {
[self.database inTransaction:^(FMDatabase *db, BOOL *rollback) { [self.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
NSMutableDictionary *hashes = [NSMutableDictionary dictionary]; NSMutableDictionary *hashes = [NSMutableDictionary dictionary];

View file

@ -522,7 +522,6 @@ static UIFont *userLabelFont;
forKey:userKey]; forKey:userKey];
} }
NSLog(@"Setting dictSocialFeeds");
appDelegate.dictSocialFeeds = socialDict; appDelegate.dictSocialFeeds = socialDict;
[self loadAvatars]; [self loadAvatars];
@ -1536,7 +1535,7 @@ heightForHeaderInSection:(NSInteger)section {
} }
- (void)loadAvatars { - (void)loadAvatars {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul);
dispatch_async(queue, ^{ dispatch_async(queue, ^{
for (NSString *feed_id in [appDelegate.dictSocialFeeds allKeys]) { for (NSString *feed_id in [appDelegate.dictSocialFeeds allKeys]) {
NSDictionary *feed = [appDelegate.dictSocialFeeds objectForKey:feed_id]; NSDictionary *feed = [appDelegate.dictSocialFeeds objectForKey:feed_id];
@ -1569,7 +1568,7 @@ heightForHeaderInSection:(NSInteger)section {
options:kNilOptions options:kNilOptions
error:&error]; error:&error];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul);
dispatch_async(queue, ^{ dispatch_async(queue, ^{
for (id feed_id in results) { for (id feed_id in results) {
NSMutableDictionary *feed = [[appDelegate.dictFeeds objectForKey:feed_id] mutableCopy]; NSMutableDictionary *feed = [[appDelegate.dictFeeds objectForKey:feed_id] mutableCopy];

View file

@ -12,7 +12,8 @@
@class NewsBlurAppDelegate; @class NewsBlurAppDelegate;
@interface OriginalStoryViewController : BaseViewController @interface OriginalStoryViewController : BaseViewController
<UIActionSheetDelegate, UITextFieldDelegate, UIWebViewDelegate> { <UIActionSheetDelegate, UITextFieldDelegate, UIWebViewDelegate,
UIGestureRecognizerDelegate> {
NewsBlurAppDelegate *appDelegate; NewsBlurAppDelegate *appDelegate;
NSString *activeUrl; NSString *activeUrl;

View file

@ -108,13 +108,12 @@
if ([recognizer state] == UIGestureRecognizerStateEnded || if ([recognizer state] == UIGestureRecognizerStateEnded ||
[recognizer state] == UIGestureRecognizerStateCancelled) { [recognizer state] == UIGestureRecognizerStateCancelled) {
CGFloat velocity = [recognizer velocityInView:recognizer.view].x; CGFloat velocity = [recognizer velocityInView:recognizer.view].x;
if (percentage > 0.25 && velocity > 0) { if ((percentage > 0.25 && velocity > 0) ||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { (percentage > 0.05 && velocity > 1000)) {
[appDelegate.masterContainerViewController transitionFromOriginalView]; NSLog(@"Original velocity ESCAPED: %f (at %.2f%%)", velocity, percentage*100);
} else { [self transitionToFeedDetail:recognizer];
}
} else { } else {
NSLog(@"Original velocity: %f (at %.2f%%)", velocity, percentage*100);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[appDelegate.masterContainerViewController transitionToOriginalView:NO]; [appDelegate.masterContainerViewController transitionToOriginalView:NO];
} else { } else {
@ -124,6 +123,14 @@
} }
} }
- (void)transitionToFeedDetail:(UIGestureRecognizer *)recognizer {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[appDelegate.masterContainerViewController transitionFromOriginalView];
} else {
}
}
- (void)loadInitialStory { - (void)loadInitialStory {
[self loadAddress:nil]; [self loadAddress:nil];
titleView.text = [[appDelegate activeStory] objectForKey:@"story_title"]; titleView.text = [[appDelegate activeStory] objectForKey:@"story_title"];

View file

@ -14,7 +14,7 @@
@class ASIHTTPRequest; @class ASIHTTPRequest;
@interface StoryDetailViewController : BaseViewController @interface StoryDetailViewController : BaseViewController
<UIScrollViewDelegate> { <UIScrollViewDelegate, UIGestureRecognizerDelegate> {
NewsBlurAppDelegate *appDelegate; NewsBlurAppDelegate *appDelegate;
NSString *activeStoryId; NSString *activeStoryId;

View file

@ -62,7 +62,7 @@
error:nil]; error:nil];
self.webView.scalesPageToFit = YES; self.webView.scalesPageToFit = YES;
self.webView.multipleTouchEnabled = NO; // self.webView.multipleTouchEnabled = NO;
[self.webView.scrollView setDelaysContentTouches:NO]; [self.webView.scrollView setDelaysContentTouches:NO];
[self.webView.scrollView setDecelerationRate:UIScrollViewDecelerationRateNormal]; [self.webView.scrollView setDecelerationRate:UIScrollViewDecelerationRateNormal];
@ -71,6 +71,10 @@
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:nil]; context:nil];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(showOriginalStory:)];
[self.webView addGestureRecognizer:pinchGesture];
self.pageIndex = -2; self.pageIndex = -2;
self.inTextView = NO; self.inTextView = NO;
} }
@ -1049,6 +1053,37 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
return YES; return YES;
} }
- (void)showOriginalStory:(UIGestureRecognizer *)gesture {
NSURL *url = [NSURL URLWithString:[appDelegate.activeStory
objectForKey:@"story_permalink"]];
[appDelegate.masterContainerViewController hidePopover];
if (!gesture) {
[appDelegate showOriginalStory:url];
return;
}
if ([gesture isKindOfClass:[UIPinchGestureRecognizer class]] &&
gesture.state == UIGestureRecognizerStateChanged &&
[gesture numberOfTouches] >= 2) {
CGPoint touch1 = [gesture locationOfTouch:0 inView:self.view];
CGPoint touch2 = [gesture locationOfTouch:1 inView:self.view];
CGPoint slope = CGPointMake(touch2.x-touch1.x, touch2.y-touch1.y);
CGFloat distance = sqrtf(slope.x*slope.x + slope.y*slope.y);
CGFloat scale = [(UIPinchGestureRecognizer *)gesture scale];
NSLog(@"Gesture: %f - %f", [(UIPinchGestureRecognizer *)gesture scale], distance);
if ((distance < 150 && scale <= 1.5) ||
(distance < 500 && scale <= 1.2)) {
return;
}
[appDelegate showOriginalStory:url];
gesture.enabled = NO;
gesture.enabled = YES;
}
}
- (void)showUserProfile:(NSString *)userId xCoordinate:(int)x yCoordinate:(int)y width:(int)width height:(int)height { - (void)showUserProfile:(NSString *)userId xCoordinate:(int)x yCoordinate:(int)y width:(int)width height:(int)height {
CGRect frame = CGRectZero; CGRect frame = CGRectZero;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

View file

@ -112,7 +112,7 @@ static NSMutableDictionary *imageCache;
} }
+ (void)saveimagesToDisk { + (void)saveimagesToDisk {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0);
dispatch_async(queue, ^{ dispatch_async(queue, ^{
for (NSString *filename in [imageCache allKeys]) { for (NSString *filename in [imageCache allKeys]) {

View file

@ -154,7 +154,7 @@
return; return;
} }
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,
(unsigned long)NULL), ^{ (unsigned long)NULL), ^{
NSString *storyHash = [[request userInfo] objectForKey:@"story_hash"]; NSString *storyHash = [[request userInfo] objectForKey:@"story_hash"];

View file

@ -78,7 +78,7 @@
NSLog(@"Failed fetch all unreads."); NSLog(@"Failed fetch all unreads.");
[lock signal]; [lock signal];
}]; }];
request.successCallbackQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, request.successCallbackQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,
(unsigned long)NULL); (unsigned long)NULL);
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[request start]; [request start];