mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Adding long press gesture to folder titles. Also adding mark as read by day to folders.
This commit is contained in:
parent
f415de8c13
commit
49c0b4cddb
5 changed files with 107 additions and 32 deletions
|
@ -13,12 +13,17 @@
|
|||
|
||||
@class NewsBlurAppDelegate;
|
||||
|
||||
@interface FolderTitleView : UIView {
|
||||
@interface FolderTitleView : UIView
|
||||
<UIGestureRecognizerDelegate,
|
||||
UIActionSheetDelegate> {
|
||||
NewsBlurAppDelegate *appDelegate;
|
||||
}
|
||||
|
||||
@property (assign, nonatomic) int section;
|
||||
@property (nonatomic) NewsBlurAppDelegate *appDelegate;
|
||||
@property (nonatomic) UnreadCountView *unreadCount;
|
||||
@property (nonatomic) UIButton *invisibleHeaderButton;
|
||||
|
||||
- (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer;
|
||||
|
||||
@end
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import "NewsBlurAppDelegate.h"
|
||||
#import "NewsBlurViewController.h"
|
||||
#import "FolderTitleView.h"
|
||||
#import "UnreadCountView.h"
|
||||
|
||||
|
@ -16,6 +17,7 @@
|
|||
@synthesize appDelegate;
|
||||
@synthesize section;
|
||||
@synthesize unreadCount;
|
||||
@synthesize invisibleHeaderButton;
|
||||
|
||||
- (void)setNeedsDisplay {
|
||||
[unreadCount setNeedsDisplay];
|
||||
|
@ -123,7 +125,7 @@
|
|||
NSForegroundColorAttributeName: textColor,
|
||||
NSParagraphStyleAttributeName: paragraphStyle}];
|
||||
|
||||
UIButton *invisibleHeaderButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
invisibleHeaderButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
invisibleHeaderButton.frame = CGRectMake(0, 0, customView.frame.size.width, customView.frame.size.height);
|
||||
invisibleHeaderButton.alpha = .1;
|
||||
invisibleHeaderButton.tag = section;
|
||||
|
@ -210,6 +212,53 @@
|
|||
} else {
|
||||
[self addSubview:customView];
|
||||
}
|
||||
|
||||
UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc]
|
||||
initWithTarget:self action:@selector(handleLongPress:)];
|
||||
longpress.minimumPressDuration = 1.0;
|
||||
longpress.delegate = self;
|
||||
[self addGestureRecognizer:longpress];
|
||||
}
|
||||
|
||||
- (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
|
||||
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) return;
|
||||
if (section < 2) return;
|
||||
|
||||
NSString *folderTitle = [appDelegate.dictFoldersArray objectAtIndex:section];
|
||||
|
||||
UIActionSheet *markReadSheet = [[UIActionSheet alloc] initWithTitle:folderTitle
|
||||
delegate:self
|
||||
cancelButtonTitle:@"Cancel"
|
||||
destructiveButtonTitle:@"Mark folder as read"
|
||||
otherButtonTitles:@"1 day", @"3 days", @"7 days", @"14 days", nil];
|
||||
markReadSheet.accessibilityValue = folderTitle;
|
||||
[markReadSheet showInView:appDelegate.feedsViewController.view];
|
||||
}
|
||||
|
||||
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
|
||||
NSString *folderTitle = actionSheet.accessibilityValue;
|
||||
NSArray *feedIds = [appDelegate.dictFolders objectForKey:folderTitle];
|
||||
|
||||
switch (buttonIndex) {
|
||||
case 0:
|
||||
[appDelegate.feedsViewController markFeedsRead:feedIds cutoffDays:0];
|
||||
break;
|
||||
case 1:
|
||||
[appDelegate.feedsViewController markFeedsRead:feedIds cutoffDays:1];
|
||||
break;
|
||||
case 2:
|
||||
[appDelegate.feedsViewController markFeedsRead:feedIds cutoffDays:3];
|
||||
break;
|
||||
case 3:
|
||||
[appDelegate.feedsViewController markFeedsRead:feedIds cutoffDays:7];
|
||||
break;
|
||||
case 4:
|
||||
[appDelegate.feedsViewController markFeedsRead:feedIds cutoffDays:14];
|
||||
break;
|
||||
}
|
||||
|
||||
[appDelegate.feedsViewController sectionUntappedOutside:invisibleHeaderButton];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -88,6 +88,8 @@ UIActionSheetDelegate> {
|
|||
- (void)finishRefreshingFeedList:(ASIHTTPRequest *)request;
|
||||
- (void)didSelectSectionHeader:(UIButton *)button;
|
||||
- (IBAction)selectIntelligence;
|
||||
- (void)markFeedRead:(NSString *)feedId cutoffDays:(NSInteger)days;
|
||||
- (void)markFeedsRead:(NSArray *)feedIds cutoffDays:(NSInteger)days;
|
||||
- (void)requestFailedMarkStoryRead:(ASIFormDataRequest *)request;
|
||||
- (void)finishMarkAllAsRead:(ASIHTTPRequest *)request;
|
||||
- (void)didCollapseFolder:(UIButton *)button;
|
||||
|
|
|
@ -764,10 +764,13 @@ static const CGFloat kFolderTitleHeight = 28.0f;
|
|||
- (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
|
||||
CGPoint p = [gestureRecognizer locationInView:self.feedTitlesTable];
|
||||
NSIndexPath *indexPath = [self.feedTitlesTable indexPathForRowAtPoint:p];
|
||||
|
||||
|
||||
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) return;
|
||||
if (indexPath == nil) return;
|
||||
|
||||
FeedTableCell *cell = (FeedTableCell *)[self.feedTitlesTable cellForRowAtIndexPath:indexPath];
|
||||
if (!cell.highlighted) return;
|
||||
|
||||
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:indexPath.section];
|
||||
id feedId = [[appDelegate.dictFolders objectForKey:folderName] objectAtIndex:indexPath.row];
|
||||
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
||||
|
@ -1168,6 +1171,44 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Mark Feeds as read
|
||||
|
||||
- (void)markFeedRead:(NSString *)feedId cutoffDays:(NSInteger)days {
|
||||
[self markFeedsRead:@[feedId] cutoffDays:days];
|
||||
}
|
||||
|
||||
- (void)markFeedsRead:(NSArray *)feedIds cutoffDays:(NSInteger)days {
|
||||
NSTimeInterval cutoffTimestamp = [[NSDate date] timeIntervalSince1970];
|
||||
cutoffTimestamp -= (days * 60*60*24);
|
||||
|
||||
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_feed_as_read",
|
||||
NEWSBLUR_URL];
|
||||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
||||
for (NSString *feedId in feedIds) {
|
||||
[request addPostValue:feedId forKey:@"feed_id"];
|
||||
}
|
||||
if (days) {
|
||||
[request setPostValue:[NSNumber numberWithInteger:cutoffTimestamp]
|
||||
forKey:@"cutoff_timestamp"];
|
||||
}
|
||||
[request setDidFinishSelector:@selector(finishMarkAllAsRead:)];
|
||||
[request setDidFailSelector:@selector(requestFailedMarkStoryRead:)];
|
||||
[request setUserInfo:@{@"feeds": feedIds,
|
||||
@"cutoffTimestamp": [NSNumber numberWithInteger:cutoffTimestamp]}];
|
||||
[request setDelegate:self];
|
||||
[request startAsynchronous];
|
||||
|
||||
if (!days) {
|
||||
for (NSString *feedId in feedIds) {
|
||||
[appDelegate markFeedAllRead:feedId];
|
||||
}
|
||||
} else {
|
||||
// [self showRefreshNotifier];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)requestFailedMarkStoryRead:(ASIFormDataRequest *)request {
|
||||
[appDelegate markStoriesRead:nil
|
||||
inFeeds:[request.userInfo objectForKey:@"feeds"]
|
||||
|
@ -1183,35 +1224,13 @@ heightForHeaderInSection:(NSInteger)section {
|
|||
}
|
||||
|
||||
if ([[request.userInfo objectForKey:@"cutoffTimestamp"] integerValue]) {
|
||||
[self refreshFeedList:[[request.userInfo objectForKey:@"feeds"] objectAtIndex:0]];
|
||||
}
|
||||
[appDelegate markFeedReadInCache:[request.userInfo objectForKey:@"feeds"]];
|
||||
}
|
||||
|
||||
- (void)markFeedRead:(NSString *)feedId cutoffDays:(NSInteger)days {
|
||||
NSTimeInterval cutoffTimestamp = [[NSDate date] timeIntervalSince1970];
|
||||
cutoffTimestamp -= (days * 60*60*24);
|
||||
|
||||
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_feed_as_read",
|
||||
NEWSBLUR_URL];
|
||||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
||||
[request setPostValue:feedId forKey:@"feed_id"];
|
||||
if (days) {
|
||||
[request setPostValue:[NSNumber numberWithInteger:cutoffTimestamp]
|
||||
forKey:@"cutoff_timestamp"];
|
||||
}
|
||||
[request setDidFinishSelector:@selector(finishMarkAllAsRead:)];
|
||||
[request setDidFailSelector:@selector(requestFailedMarkStoryRead:)];
|
||||
[request setUserInfo:@{@"feeds": @[feedId],
|
||||
@"cutoffTimestamp": [NSNumber numberWithInteger:cutoffTimestamp]}];
|
||||
[request setDelegate:self];
|
||||
[request startAsynchronous];
|
||||
|
||||
if (!days) {
|
||||
[appDelegate markFeedAllRead:feedId];
|
||||
id feed;
|
||||
if ([[request.userInfo objectForKey:@"feeds"] count] == 1) {
|
||||
feed = [[request.userInfo objectForKey:@"feeds"] objectAtIndex:0];
|
||||
}
|
||||
[self refreshFeedList:feed];
|
||||
} else {
|
||||
// [self showRefreshNotifier];
|
||||
[appDelegate markFeedReadInCache:[request.userInfo objectForKey:@"feeds"]];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#import <SystemConfiguration/SystemConfiguration.h>
|
||||
#import <MobileCoreServices/MobileCoreServices.h>
|
||||
|
||||
//#define DEBUG 1
|
||||
#define DEBUG 1
|
||||
|
||||
#ifdef DEBUG
|
||||
#define BACKGROUND_REFRESH_SECONDS -5
|
||||
|
|
Loading…
Add table
Reference in a new issue