From 7154c9303edaec67b952864f1afd0ff6a80ee980 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Sat, 19 May 2012 10:50:49 -0500 Subject: [PATCH] Implement double tap feature request #73. Single tap to go to comments, double tap to go directly to article. --- Classes/Controllers/CommentListController.h | 3 ++ Classes/Controllers/CommentListController.m | 7 +++ Classes/Controllers/EntryListController.h | 2 +- Classes/Controllers/EntryListController.m | 49 +++++++++++++++++-- .../Controllers/SubmissionListController.m | 7 +-- 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Classes/Controllers/CommentListController.h b/Classes/Controllers/CommentListController.h index 4ce6075d..ecbad419 100644 --- a/Classes/Controllers/CommentListController.h +++ b/Classes/Controllers/CommentListController.h @@ -30,4 +30,7 @@ CommentTableCell *expandedCell; } +@property (nonatomic, retain) DetailsHeaderView *detailsHeaderView; +@property (nonatomic) BOOL goesDirectlyToArticle; + @end diff --git a/Classes/Controllers/CommentListController.m b/Classes/Controllers/CommentListController.m index ccf60b94..ed69c327 100644 --- a/Classes/Controllers/CommentListController.m +++ b/Classes/Controllers/CommentListController.m @@ -36,6 +36,8 @@ - (void)clearSavedCompletion; @implementation CommentListController +@synthesize detailsHeaderView, goesDirectlyToArticle; + #pragma mark - Lifecycle - (void)finishedLoading { @@ -322,6 +324,11 @@ - (void)setupHeader { [tableView setTableHeaderView:containerContainer]; suggestedHeaderHeight = [detailsHeaderView bounds].size.height; + + if(self.goesDirectlyToArticle == YES) { + [self.detailsHeaderView touchesEnded:nil withEvent:nil]; + self.goesDirectlyToArticle = NO; + } } #pragma mark - Delegates diff --git a/Classes/Controllers/EntryListController.h b/Classes/Controllers/EntryListController.h index 31190bd6..186e55c4 100644 --- a/Classes/Controllers/EntryListController.h +++ b/Classes/Controllers/EntryListController.h @@ -26,7 +26,7 @@ + (Class)cellClass; - (CGFloat)cellHeightForEntry:(HNEntry *)entry; - (void)configureCell:(UITableViewCell *)cell forEntry:(HNEntry *)entry; -- (void)cellSelected:(UITableViewCell *)cell forEntry:(HNEntry *)entry; +- (void)cellSelected:(UITableViewCell *)cell forEntry:(HNEntry *)entry goesDirectlyToArticle:(BOOL)direct; - (void)deselectWithAnimation:(BOOL)animated; @end diff --git a/Classes/Controllers/EntryListController.m b/Classes/Controllers/EntryListController.m index f06d38a5..6f4524ad 100644 --- a/Classes/Controllers/EntryListController.m +++ b/Classes/Controllers/EntryListController.m @@ -16,6 +16,12 @@ #import "CommentListController.h" +@interface EntryListController (PrivateMethods) +-(void)doubleTap:(UISwipeGestureRecognizer*)tap; +-(void)singleTap:(UISwipeGestureRecognizer*)tap; +@end + + @implementation EntryListController #pragma mark - Lifecycle @@ -43,6 +49,17 @@ - (void)loadView { [tableView addSubview:pullToRefreshView]; [pullToRefreshView setDelegate:self]; + UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)]; + doubleTap.numberOfTapsRequired = 2; + doubleTap.numberOfTouchesRequired = 1; + [tableView addGestureRecognizer:doubleTap]; + + UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)]; + singleTap.numberOfTapsRequired = 1; + singleTap.numberOfTouchesRequired = 1; + [singleTap requireGestureRecognizerToFail:doubleTap]; + [tableView addGestureRecognizer:singleTap]; + [[self view] bringSubviewToFront:statusView]; } @@ -207,17 +224,43 @@ - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSInd } } -- (void)cellSelected:(UITableViewCell *)cell forEntry:(HNEntry *)entry { +- (void)cellSelected:(UITableViewCell *)cell forEntry:(HNEntry *)entry goesDirectlyToArticle:(BOOL)direct { return; } - (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + return; +} + +-(void)singleTap:(UISwipeGestureRecognizer*)tap +{ + if (UIGestureRecognizerStateEnded == tap.state) + { + CGPoint p = [tap locationInView:tap.view]; + NSIndexPath* indexPath = [tableView indexPathForRowAtPoint:p]; + UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; + HNEntry *entry = [self entryAtIndexPath:indexPath]; - UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + + [self cellSelected:cell forEntry:entry goesDirectlyToArticle:NO]; + } +} + +-(void)doubleTap:(UISwipeGestureRecognizer*)tap +{ + if (UIGestureRecognizerStateEnded == tap.state) + { + CGPoint p = [tap locationInView:tap.view]; + NSIndexPath* indexPath = [tableView indexPathForRowAtPoint:p]; + UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; - [self cellSelected:cell forEntry:entry]; + HNEntry *entry = [self entryAtIndexPath:indexPath]; + + [self cellSelected:cell forEntry:entry goesDirectlyToArticle:YES]; + } } + - (void)loadMorePressed { if ([source isLoaded] && ![(HNContainer *) source isLoadingMore]) { [(HNContainer *) source beginLoadingMore]; diff --git a/Classes/Controllers/SubmissionListController.m b/Classes/Controllers/SubmissionListController.m index e2249389..e7d0cc33 100644 --- a/Classes/Controllers/SubmissionListController.m +++ b/Classes/Controllers/SubmissionListController.m @@ -28,9 +28,10 @@ - (void)configureCell:(UITableViewCell *)cell forEntry:(HNEntry *)entry { [cell_ setSubmission:entry]; } -- (void)cellSelected:(UITableViewCell *)cell forEntry:(HNEntry *)entry { - CommentListController *controller = [[CommentListController alloc] initWithSource:entry]; - [[self navigationController] pushController:[controller autorelease] animated:YES]; +- (void)cellSelected:(UITableViewCell *)cell forEntry:(HNEntry *)entry goesDirectlyToArticle:(BOOL)direct { + CommentListController *controller = [[CommentListController alloc] initWithSource:entry]; + controller.goesDirectlyToArticle = direct; + [[self navigationController] pushController:[controller autorelease] animated:YES]; } - (void)deselectWithAnimation:(BOOL)animated {