Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement double tap feature request #73. #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Classes/Controllers/CommentListController.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@
CommentTableCell *expandedCell;
}

@property (nonatomic, retain) DetailsHeaderView *detailsHeaderView;
@property (nonatomic) BOOL goesDirectlyToArticle;

@end
7 changes: 7 additions & 0 deletions Classes/Controllers/CommentListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ - (void)clearSavedCompletion;

@implementation CommentListController

@synthesize detailsHeaderView, goesDirectlyToArticle;

#pragma mark - Lifecycle

- (void)finishedLoading {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controllers/EntryListController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 46 additions & 3 deletions Classes/Controllers/EntryListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

#import "CommentListController.h"

@interface EntryListController (PrivateMethods)
-(void)doubleTap:(UISwipeGestureRecognizer*)tap;
-(void)singleTap:(UISwipeGestureRecognizer*)tap;
@end


@implementation EntryListController

#pragma mark - Lifecycle
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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];
Expand Down
7 changes: 4 additions & 3 deletions Classes/Controllers/SubmissionListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down