Major refactor of ios feed list. No longer relies on fragile locations dictionary.

This commit is contained in:
Samuel Clay 2012-12-20 12:08:35 -08:00
parent 223bd26721
commit f826f1da31
5 changed files with 106 additions and 359 deletions

View file

@ -245,6 +245,8 @@
NSString *theFeedDetailURL; NSString *theFeedDetailURL;
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
if (!appDelegate.activeFeed) return;
if (callback || (!self.pageFetching && !self.pageFinished)) { if (callback || (!self.pageFetching && !self.pageFinished)) {
self.feedPage = page; self.feedPage = page;
@ -287,6 +289,7 @@
[self informError:[request error]]; [self informError:[request error]];
}]; }];
[request setCompletionBlock:^(void) { [request setCompletionBlock:^(void) {
if (!appDelegate.activeFeed) return;
[self finishedLoadingFeed:request]; [self finishedLoadingFeed:request];
if (callback) { if (callback) {
callback(); callback();
@ -882,7 +885,7 @@
- (void)markFeedsReadWithAllStories:(BOOL)includeHidden { - (void)markFeedsReadWithAllStories:(BOOL)includeHidden {
NSLog(@"mark feeds read: %d %d", appDelegate.isRiverView, includeHidden); NSLog(@"mark feeds read: %d %d", appDelegate.isRiverView, includeHidden);
if ([appDelegate.activeFolder isEqualToString:@"everything"]) { if (appDelegate.isRiverView && [appDelegate.activeFolder isEqualToString:@"everything"]) {
// Mark folder as read // Mark folder as read
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_all_as_read", NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_all_as_read",
NEWSBLUR_URL]; NEWSBLUR_URL];

View file

@ -17,16 +17,17 @@
@class NewsBlurAppDelegate; @class NewsBlurAppDelegate;
@interface NewsBlurViewController : BaseViewController @interface NewsBlurViewController : BaseViewController
<UITableViewDelegate, UITableViewDataSource, <UITableViewDelegate, UITableViewDataSource,
UIAlertViewDelegate, PullToRefreshViewDelegate, UIAlertViewDelegate, PullToRefreshViewDelegate,
ASIHTTPRequestDelegate, NSCacheDelegate, ASIHTTPRequestDelegate, NSCacheDelegate,
WEPopoverControllerDelegate, WEPopoverControllerDelegate,
UIPopoverControllerDelegate> { UIPopoverControllerDelegate> {
NewsBlurAppDelegate *appDelegate; NewsBlurAppDelegate *appDelegate;
NSMutableDictionary * activeFeedLocations; NSMutableDictionary * activeFeedLocations;
NSMutableDictionary *visibleFeeds;
NSMutableDictionary *stillVisibleFeeds; NSMutableDictionary *stillVisibleFeeds;
NSMutableDictionary *visibleFolders;
BOOL viewShowingAllFeeds; BOOL viewShowingAllFeeds;
PullToRefreshView *pull; PullToRefreshView *pull;
NSDate *lastUpdate; NSDate *lastUpdate;
@ -49,8 +50,8 @@
@property (nonatomic) IBOutlet UISlider * feedScoreSlider; @property (nonatomic) IBOutlet UISlider * feedScoreSlider;
@property (nonatomic) IBOutlet UIBarButtonItem * homeButton; @property (nonatomic) IBOutlet UIBarButtonItem * homeButton;
@property (nonatomic) NSMutableDictionary *activeFeedLocations; @property (nonatomic) NSMutableDictionary *activeFeedLocations;
@property (nonatomic) NSMutableDictionary *visibleFeeds;
@property (nonatomic) NSMutableDictionary *stillVisibleFeeds; @property (nonatomic) NSMutableDictionary *stillVisibleFeeds;
@property (nonatomic) NSMutableDictionary *visibleFolders;
@property (nonatomic, readwrite) BOOL viewShowingAllFeeds; @property (nonatomic, readwrite) BOOL viewShowingAllFeeds;
@property (nonatomic) PullToRefreshView *pull; @property (nonatomic) PullToRefreshView *pull;
@property (nonatomic) NSDate *lastUpdate; @property (nonatomic) NSDate *lastUpdate;
@ -70,15 +71,14 @@
- (void)didSelectSectionHeader:(UIButton *)button; - (void)didSelectSectionHeader:(UIButton *)button;
- (IBAction)selectIntelligence; - (IBAction)selectIntelligence;
- (void)didCollapseFolder:(UIButton *)button; - (void)didCollapseFolder:(UIButton *)button;
- (BOOL)isFeedVisible:(id)feedId;
- (void)changeToAllMode; - (void)changeToAllMode;
- (void)updateFeedsWithIntelligence:(int)previousLevel newLevel:(int)newLevel; - (void)calculateFeedLocations;
- (void)calculateFeedLocations:(BOOL)markVisible;
- (IBAction)sectionTapped:(UIButton *)button; - (IBAction)sectionTapped:(UIButton *)button;
- (IBAction)sectionUntapped:(UIButton *)button; - (IBAction)sectionUntapped:(UIButton *)button;
- (IBAction)sectionUntappedOutside:(UIButton *)button; - (IBAction)sectionUntappedOutside:(UIButton *)button;
- (void)redrawUnreadCounts; - (void)redrawUnreadCounts;
+ (int)computeMaxScoreForFeed:(NSDictionary *)feed; + (int)computeMaxScoreForFeed:(NSDictionary *)feed;
- (void)switchSitesUnread;
- (void)loadFavicons; - (void)loadFavicons;
- (void)loadAvatars; - (void)loadAvatars;
- (void)saveAndDrawFavicons:(ASIHTTPRequest *)request; - (void)saveAndDrawFavicons:(ASIHTTPRequest *)request;

View file

@ -48,7 +48,6 @@ static const CGFloat kFolderTitleHeight = 28;
@synthesize homeButton; @synthesize homeButton;
@synthesize intelligenceControl; @synthesize intelligenceControl;
@synthesize activeFeedLocations; @synthesize activeFeedLocations;
@synthesize visibleFeeds;
@synthesize stillVisibleFeeds; @synthesize stillVisibleFeeds;
@synthesize viewShowingAllFeeds; @synthesize viewShowingAllFeeds;
@synthesize pull; @synthesize pull;
@ -137,19 +136,13 @@ static const CGFloat kFolderTitleHeight = 28;
[MBProgressHUD hideHUDForView:appDelegate.storyPageControl.view animated:NO]; [MBProgressHUD hideHUDForView:appDelegate.storyPageControl.view animated:NO];
if (appDelegate.activeFeed || appDelegate.isRiverView) { if (appDelegate.activeFeed || appDelegate.isRiverView) {
[self.feedTitlesTable beginUpdates];
[self.feedTitlesTable
reloadRowsAtIndexPaths:[self.feedTitlesTable indexPathsForVisibleRows]
withRowAnimation:UITableViewRowAnimationNone];
[self.feedTitlesTable endUpdates];
NSInteger previousLevel = [self.intelligenceControl selectedSegmentIndex] - 1; NSInteger previousLevel = [self.intelligenceControl selectedSegmentIndex] - 1;
NSInteger newLevel = [appDelegate selectedIntelligence]; NSInteger newLevel = [appDelegate selectedIntelligence];
if (newLevel != previousLevel) { if (newLevel != previousLevel) {
[appDelegate setSelectedIntelligence:newLevel]; [appDelegate setSelectedIntelligence:newLevel];
if (!self.viewShowingAllFeeds) { [self calculateFeedLocations];
[self updateFeedsWithIntelligence:previousLevel newLevel:newLevel]; [self.feedTitlesTable beginUpdates];
} [self.feedTitlesTable endUpdates];
[self redrawUnreadCounts]; [self redrawUnreadCounts];
} }
} }
@ -311,7 +304,6 @@ static const CGFloat kFolderTitleHeight = 28;
// NSLog(@"results are %@", results); // NSLog(@"results are %@", results);
[MBProgressHUD hideHUDForView:self.view animated:YES]; [MBProgressHUD hideHUDForView:self.view animated:YES];
self.stillVisibleFeeds = [NSMutableDictionary dictionary]; self.stillVisibleFeeds = [NSMutableDictionary dictionary];
self.visibleFeeds = [NSMutableDictionary dictionary];
[pull finishedLoading]; [pull finishedLoading];
[self loadFavicons]; [self loadFavicons];
@ -467,19 +459,14 @@ static const CGFloat kFolderTitleHeight = 28;
[appDelegate.dictFoldersArray insertObject:@"saved_stories" atIndex:appDelegate.dictFoldersArray.count]; [appDelegate.dictFoldersArray insertObject:@"saved_stories" atIndex:appDelegate.dictFoldersArray.count];
} }
if (self.viewShowingAllFeeds) {
[self calculateFeedLocations:NO];
} else {
[self calculateFeedLocations:YES];
}
// test for empty // test for empty
if ([[appDelegate.dictFeeds allKeys] count] == 0 && if ([[appDelegate.dictFeeds allKeys] count] == 0 &&
[[appDelegate.dictSocialFeeds allKeys] count] == 0) { [[appDelegate.dictSocialFeeds allKeys] count] == 0) {
appDelegate.hasNoSites = YES; appDelegate.hasNoSites = YES;
} }
[self calculateFeedLocations];
[self.feedTitlesTable reloadData]; [self.feedTitlesTable reloadData];
// assign categories for FTUX // assign categories for FTUX
@ -597,122 +584,6 @@ static const CGFloat kFolderTitleHeight = 28;
} }
} }
- (void)switchSitesUnread {
NSDictionary *feed;
NSInteger intelligenceLevel = [appDelegate selectedIntelligence];
NSMutableArray *indexPaths = [NSMutableArray array];
NSMutableDictionary *oldSectionRows = [NSMutableDictionary dictionary];
NSMutableDictionary *switchingSectionRows = [NSMutableDictionary dictionary];
for (int section=0; section < [self numberOfSectionsInTableView:self.feedTitlesTable]; section++) {
[oldSectionRows setObject:[NSNumber numberWithInt:[self.feedTitlesTable
numberOfRowsInSection:section]]
forKey:[NSNumber numberWithInt:section]];
}
// if show all sites, calculate feeds and mark visible
if (self.viewShowingAllFeeds) {
[self calculateFeedLocations:NO];
}
// NSLog(@"View showing all: %d and %@", self.viewShowingAllFeeds, self.stillVisibleFeeds);
for (int s=0; s < [appDelegate.dictFoldersArray count]; s++) {
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:s];
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
NSArray *originalFolder = [appDelegate.dictFolders objectForKey:folderName];
for (int f=0; f < [activeFolderFeeds count]; f++) {
int location = [[activeFolderFeeds objectAtIndex:f] intValue];
id feedId = [originalFolder objectAtIndex:location];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:f inSection:s];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
if ([appDelegate isSocialFeed:feedIdStr]) {
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
} else {
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
}
int maxScore = [NewsBlurViewController computeMaxScoreForFeed:feed];
// BOOL isUser = [[NSString stringWithFormat:@"%@", feedId]
// isEqualToString:
// [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"id"]]];
// if unread
if (!self.viewShowingAllFeeds) {
if (maxScore < intelligenceLevel) {
[indexPaths addObject:indexPath];
}
} else if (self.viewShowingAllFeeds && ![self.stillVisibleFeeds objectForKey:feedIdStr]) {
if (maxScore < intelligenceLevel) {
[indexPaths addObject:indexPath];
}
}
}
}
// if show unreads, calculate feeds and mark visible
if (!self.viewShowingAllFeeds) {
[self calculateFeedLocations:YES];
}
// Count the rows that will be deleted/inserted and ensure it matches
// the table's count, just in case they are incorrect.
for (NSIndexPath *rowPath in indexPaths) {
NSNumber *section = [NSNumber numberWithInt:rowPath.section];
[switchingSectionRows setObject:[NSNumber numberWithInt:[[switchingSectionRows objectForKey:section] intValue] + 1]
forKey:section];
}
BOOL correct = YES;
for (int section=0; section < [self numberOfSectionsInTableView:self.feedTitlesTable]; section++) {
int newRows = [self tableView:self.feedTitlesTable numberOfRowsInSection:section];
int oldRows = [[oldSectionRows objectForKey:[NSNumber numberWithInt:section]] intValue];
int difference = [[switchingSectionRows objectForKey:[NSNumber numberWithInt:section]] intValue];
if (!self.viewShowingAllFeeds) {
difference = difference * -1;
}
if (oldRows + difference != newRows) {
correct = NO;
break;
}
}
NSArray *visiblePaths = [self.feedTitlesTable indexPathsForVisibleRows];
NSIndexPath *middleRow = [visiblePaths objectAtIndex:0];
// If the row counts don't match up, no animation is possible. Instead of crashing
// just reload the table. Loss of animation, but better than crashing.
if (!correct) {
[self.feedTitlesTable reloadData];
} else {
[self.feedTitlesTable beginUpdates];
if ([indexPaths count] > 0) {
if (self.viewShowingAllFeeds) {
[self.feedTitlesTable insertRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationNone];
} else {
[self.feedTitlesTable deleteRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationNone];
}
}
[self.feedTitlesTable endUpdates];
}
NSIndexPath *newMiddleRow = [NSIndexPath indexPathForItem:0 inSection:middleRow.section];
[self.feedTitlesTable scrollToRowAtIndexPath:newMiddleRow atScrollPosition:UITableViewScrollPositionTop animated:YES];
// CGRect middleRect = [self.feedTitlesTable rectForRowAtIndexPath:middleRow];
// CGPoint offset = CGPointMake(middleRect.origin.x, middleRect.origin.y);
// [self.feedTitlesTable setContentOffset:offset animated:YES];
// Forget still visible feeds, since they won't be populated when
// all feeds are showing, and shouldn't be populated after this
// hide/show runs.
self.stillVisibleFeeds = [NSMutableDictionary dictionary];
[self redrawUnreadCounts];
}
#pragma mark - #pragma mark -
#pragma mark Table View - Feed List #pragma mark Table View - Feed List
@ -734,7 +605,7 @@ static const CGFloat kFolderTitleHeight = 28;
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:section]; NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:section];
return [[self.activeFeedLocations objectForKey:folderName] count]; return [[appDelegate.dictFolders objectForKey:folderName] count];
} }
- (UITableViewCell *)tableView:(UITableView *)tableView - (UITableViewCell *)tableView:(UITableView *)tableView
@ -757,12 +628,13 @@ static const CGFloat kFolderTitleHeight = 28;
return cell; return cell;
} }
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:indexPath.section];
NSDictionary *feed; id feedId = [[appDelegate.dictFolders objectForKey:folderName] objectAtIndex:indexPath.row];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
BOOL isSocial = [appDelegate isSocialFeed:feedIdStr];
NSString *CellIdentifier; NSString *CellIdentifier;
if (indexPath.section == 0 || indexPath.section == 1) {
if (indexPath.section == 0) {
CellIdentifier = @"BlurblogCellIdentifier"; CellIdentifier = @"BlurblogCellIdentifier";
} else { } else {
CellIdentifier = @"FeedCellIdentifier"; CellIdentifier = @"FeedCellIdentifier";
@ -776,21 +648,14 @@ static const CGFloat kFolderTitleHeight = 28;
cell.appDelegate = appDelegate; cell.appDelegate = appDelegate;
} }
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:indexPath.section]; if (![self isFeedVisible:feedId]) {
NSArray *feeds = [appDelegate.dictFolders objectForKey:folderName]; return cell;
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
int location = [[activeFolderFeeds objectAtIndex:indexPath.row] intValue];
id feedId = [feeds objectAtIndex:location];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
BOOL isSocial = [appDelegate isSocialFeed:feedIdStr];
if (isSocial) {
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
cell.feedFavicon = [Utilities getImage:feedIdStr isSocial:YES];
} else {
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
cell.feedFavicon = [Utilities getImage:feedIdStr];
} }
NSDictionary *feed = isSocial ?
[appDelegate.dictSocialFeeds objectForKey:feedIdStr] :
[appDelegate.dictFeeds objectForKey:feedIdStr];
cell.feedFavicon = [Utilities getImage:feedIdStr isSocial:isSocial];
cell.feedTitle = [feed objectForKey:@"feed_title"]; cell.feedTitle = [feed objectForKey:@"feed_title"];
cell.positiveCount = [[feed objectForKey:@"ps"] intValue]; cell.positiveCount = [[feed objectForKey:@"ps"] intValue];
cell.neutralCount = [[feed objectForKey:@"nt"] intValue]; cell.neutralCount = [[feed objectForKey:@"nt"] intValue];
@ -812,7 +677,6 @@ static const CGFloat kFolderTitleHeight = 28;
// set the current row pointer // set the current row pointer
self.currentRowAtIndexPath = indexPath; self.currentRowAtIndexPath = indexPath;
NSDictionary *feed;
NSString *folderName; NSString *folderName;
if (indexPath.section == 0) { if (indexPath.section == 0) {
folderName = @"river_global"; folderName = @"river_global";
@ -823,12 +687,9 @@ static const CGFloat kFolderTitleHeight = 28;
} else { } else {
folderName = [appDelegate.dictFoldersArray objectAtIndex:indexPath.section]; folderName = [appDelegate.dictFoldersArray objectAtIndex:indexPath.section];
} }
NSArray *feeds = [appDelegate.dictFolders objectForKey:folderName]; id feedId = [[appDelegate.dictFolders objectForKey:folderName] objectAtIndex:indexPath.row];
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
int location = [[activeFolderFeeds objectAtIndex:indexPath.row] intValue];
id feedId = [feeds objectAtIndex:location];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId]; NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
NSDictionary *feed;
if ([appDelegate isSocialFeed:feedIdStr]) { if ([appDelegate isSocialFeed:feedIdStr]) {
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr]; feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
appDelegate.isSocialView = YES; appDelegate.isSocialView = YES;
@ -880,6 +741,11 @@ static const CGFloat kFolderTitleHeight = 28;
return 0; return 0;
} }
id feedId = [[appDelegate.dictFolders objectForKey:folderName] objectAtIndex:indexPath.row];
if (![self isFeedVisible:feedId]) {
return 0;
}
if ([folderName isEqualToString:@"river_blurblogs"] || if ([folderName isEqualToString:@"river_blurblogs"] ||
[folderName isEqualToString:@"river_global"]) { // blurblogs [folderName isEqualToString:@"river_global"]) { // blurblogs
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
@ -924,12 +790,9 @@ static const CGFloat kFolderTitleHeight = 28;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:section]; NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:section];
// if ([[folder stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
// return 0;
// }
int rows = [tableView.dataSource tableView:tableView numberOfRowsInSection:section]; BOOL visibleFeeds = [[self.visibleFolders objectForKey:folderName] boolValue];
if (rows == 0 && section != 2 && section != 0 && folderName != @"saved_stories") { if (!visibleFeeds && section != 2 && section != 0 && folderName != @"saved_stories") {
return 0; return 0;
} }
@ -1021,9 +884,9 @@ static const CGFloat kFolderTitleHeight = 28;
} }
[userPreferences synchronize]; [userPreferences synchronize];
[self.feedTitlesTable beginUpdates];
[self.feedTitlesTable reloadSections:[NSIndexSet indexSetWithIndex:button.tag] [self.feedTitlesTable reloadSections:[NSIndexSet indexSetWithIndex:button.tag]
withRowAnimation:UITableViewRowAnimationFade]; withRowAnimation:UITableViewRowAnimationFade];
[self.feedTitlesTable beginUpdates];
[self.feedTitlesTable endUpdates]; [self.feedTitlesTable endUpdates];
// Scroll to section header if collapse causes it to scroll far off screen // Scroll to section header if collapse causes it to scroll far off screen
@ -1042,6 +905,29 @@ static const CGFloat kFolderTitleHeight = 28;
} }
- (BOOL)isFeedVisible:(id)feedId {
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
BOOL isSocial = [appDelegate isSocialFeed:feedIdStr];
NSDictionary *feed = isSocial ?
[appDelegate.dictSocialFeeds objectForKey:feedIdStr] :
[appDelegate.dictFeeds objectForKey:feedIdStr];
NSIndexPath *stillVisible = [self.stillVisibleFeeds objectForKey:feedIdStr];
if (!stillVisible &&
appDelegate.selectedIntelligence >= 1 &&
[[feed objectForKey:@"ps"] intValue] <= 0) {
return NO;
} else if (!stillVisible &&
!self.viewShowingAllFeeds &&
([[feed objectForKey:@"ps"] intValue] <= 0 &&
[[feed objectForKey:@"nt"] intValue] <= 0)) {
return NO;
}
return YES;
}
- (void)changeToAllMode { - (void)changeToAllMode {
[self.intelligenceControl setSelectedSegmentIndex:0]; [self.intelligenceControl setSelectedSegmentIndex:0];
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
@ -1055,172 +941,56 @@ static const CGFloat kFolderTitleHeight = 28;
hud.mode = MBProgressHUDModeText; hud.mode = MBProgressHUDModeText;
hud.removeFromSuperViewOnHide = YES; hud.removeFromSuperViewOnHide = YES;
NSIndexPath *topRow = [[self.feedTitlesTable indexPathsForVisibleRows] objectAtIndex:0];
int selectedSegmentIndex = [self.intelligenceControl selectedSegmentIndex]; int selectedSegmentIndex = [self.intelligenceControl selectedSegmentIndex];
self.stillVisibleFeeds = [NSMutableDictionary dictionary];
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
int direction;
if (selectedSegmentIndex == 0) { if (selectedSegmentIndex == 0) {
hud.labelText = @"All Stories"; hud.labelText = @"All Stories";
[userPreferences setInteger:-1 forKey:@"selectedIntelligence"]; [userPreferences setInteger:-1 forKey:@"selectedIntelligence"];
[userPreferences synchronize]; [userPreferences synchronize];
if (appDelegate.selectedIntelligence != 0) { direction = -1;
int previousLevel = appDelegate.selectedIntelligence;
[appDelegate setSelectedIntelligence:0];
[self updateFeedsWithIntelligence:previousLevel newLevel:0];
[self redrawUnreadCounts];
}
self.viewShowingAllFeeds = YES; self.viewShowingAllFeeds = YES;
[self switchSitesUnread]; [appDelegate setSelectedIntelligence:0];
} else if(selectedSegmentIndex == 1) { } else if(selectedSegmentIndex == 1) {
// NSString *unreadStr = [NSString stringWithFormat:@"%i Unread Stories", appDelegate.allUnreadCount];
hud.labelText = @"Unread Stories"; hud.labelText = @"Unread Stories";
[userPreferences setInteger:0 forKey:@"selectedIntelligence"]; [userPreferences setInteger:0 forKey:@"selectedIntelligence"];
[userPreferences synchronize]; [userPreferences synchronize];
if (appDelegate.selectedIntelligence != 0) { direction = self.viewShowingAllFeeds ? 1 : -1;
int previousLevel = appDelegate.selectedIntelligence;
[appDelegate setSelectedIntelligence:0];
[self updateFeedsWithIntelligence:previousLevel newLevel:0];
[self redrawUnreadCounts];
}
self.viewShowingAllFeeds = NO; self.viewShowingAllFeeds = NO;
[self switchSitesUnread]; [appDelegate setSelectedIntelligence:0];
} else { } else {
hud.labelText = @"Focus Stories"; hud.labelText = @"Focus Stories";
[userPreferences setInteger:1 forKey:@"selectedIntelligence"]; [userPreferences setInteger:1 forKey:@"selectedIntelligence"];
[userPreferences synchronize]; [userPreferences synchronize];
if (self.viewShowingAllFeeds == YES) { direction = 1;
self.viewShowingAllFeeds = NO; self.viewShowingAllFeeds = NO;
[self switchSitesUnread];
}
[appDelegate setSelectedIntelligence:1]; [appDelegate setSelectedIntelligence:1];
[self updateFeedsWithIntelligence:0 newLevel:1];
[self redrawUnreadCounts];
} }
[self calculateFeedLocations];
[self.feedTitlesTable reloadData];
NSIndexPath *newMiddleRow;
if ([self.feedTitlesTable numberOfRowsInSection:topRow.section] == 0) {
newMiddleRow = [[self.feedTitlesTable indexPathsForVisibleRows] objectAtIndex:0];
} else {
newMiddleRow = [NSIndexPath indexPathForRow:0 inSection:topRow.section];
}
[self.feedTitlesTable scrollToRowAtIndexPath:newMiddleRow
atScrollPosition:UITableViewScrollPositionTop
animated:NO];
[self.feedTitlesTable
reloadRowsAtIndexPaths:[self.feedTitlesTable indexPathsForVisibleRows]
withRowAnimation:direction == 1 ? UITableViewRowAnimationLeft : UITableViewRowAnimationRight];
[self redrawUnreadCounts];
[hud hide:YES afterDelay:0.5]; [hud hide:YES afterDelay:0.5];
// [self.feedTitlesTable reloadData];
}
- (void)updateFeedsWithIntelligence:(int)previousLevel newLevel:(int)newLevel {
NSMutableArray *insertIndexPaths = [NSMutableArray array];
NSMutableArray *deleteIndexPaths = [NSMutableArray array];
NSMutableDictionary *addToVisibleFeeds = [NSMutableDictionary dictionary];
if (newLevel <= previousLevel) {
[self calculateFeedLocations:NO];
}
for (int s=0; s < [appDelegate.dictFoldersArray count]; s++) {
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:s];
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
NSArray *originalFolder = [appDelegate.dictFolders objectForKey:folderName];
// if (s == 9) {
// NSLog(@"Section %d: %@. %d to %d", s, folderName, previousLevel, newLevel);
// }
for (int f=0; f < [originalFolder count]; f++) {
NSNumber *feedId = [originalFolder objectAtIndex:f];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
NSDictionary *feed;
// BOOL isUser = [feedIdStr isEqualToString:
// [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"id"]]];
if ([appDelegate isSocialFeed:feedIdStr]) {
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
} else {
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
}
int maxScore = [NewsBlurViewController computeMaxScoreForFeed:feed];
// if (s == 9) {
// NSLog(@"MaxScore: %d for %@ (%@/%@/%@). Visible: %@", maxScore,
// [feed objectForKey:@"feed_title"],
// [feed objectForKey:@"ng"], [feed objectForKey:@"nt"], [feed objectForKey:@"ng"],
// [self.visibleFeeds objectForKey:feedIdStr]);
// }
if ([self.visibleFeeds objectForKey:feedIdStr]) {
if (maxScore < newLevel) {
for (int l=0; l < [activeFolderFeeds count]; l++) {
if ([originalFolder objectAtIndex:[[activeFolderFeeds objectAtIndex:l] intValue]] == feedId) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:l inSection:s];
[deleteIndexPaths addObject:indexPath];
if ([self.stillVisibleFeeds objectForKey:feedIdStr]) {
[self.stillVisibleFeeds removeObjectForKey:feedIdStr];
}
break;
}
}
}
} else {
if (maxScore >= newLevel) {
for (int l=0; l < [activeFolderFeeds count]; l++) {
if ([originalFolder objectAtIndex:[[activeFolderFeeds objectAtIndex:l] intValue]] == feedId) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:l inSection:s];
[addToVisibleFeeds setObject:[NSNumber numberWithBool:YES] forKey:feedIdStr];
[insertIndexPaths addObject:indexPath];
break;
}
}
}
}
}
}
for (id feedIdStr in addToVisibleFeeds) {
[self.visibleFeeds setObject:[addToVisibleFeeds objectForKey:feedIdStr] forKey:feedIdStr];
}
for (id feedIdStr in [self.stillVisibleFeeds allKeys]) {
NSDictionary *feed;
if ([appDelegate isSocialFeed:feedIdStr]) {
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
} else {
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
}
int maxScore = [NewsBlurViewController computeMaxScoreForFeed:feed];
if (previousLevel != newLevel && maxScore < newLevel) {
[deleteIndexPaths addObject:[self.stillVisibleFeeds objectForKey:feedIdStr]];
[self.stillVisibleFeeds removeObjectForKey:feedIdStr];
[self.visibleFeeds removeObjectForKey:feedIdStr];
}
}
if (newLevel > previousLevel) {
[self calculateFeedLocations:NO];
}
@try {
[self.feedTitlesTable beginUpdates];
if ([deleteIndexPaths count] > 0) {
[self.feedTitlesTable deleteRowsAtIndexPaths:deleteIndexPaths
withRowAnimation:UITableViewRowAnimationNone];
}
if ([insertIndexPaths count] > 0) {
[self.feedTitlesTable insertRowsAtIndexPaths:insertIndexPaths
withRowAnimation:UITableViewRowAnimationNone];
}
[self.feedTitlesTable endUpdates];
}
@catch (NSException *exception) {
NSLog(@"Exception: %@", exception);
[self.feedTitlesTable reloadData];
}
// scrolls to the top and fixes header rendering bug
CGPoint offsetOne = CGPointMake(0, 1);
CGPoint offset = CGPointMake(0, 0);
[self.feedTitlesTable setContentOffset:offsetOne animated:NO];
[self.feedTitlesTable setContentOffset:offset animated:NO];
[self calculateFeedLocations:YES];
} }
- (void)redrawUnreadCounts { - (void)redrawUnreadCounts {
@ -1234,54 +1004,26 @@ static const CGFloat kFolderTitleHeight = 28;
} }
} }
- (void)calculateFeedLocations:(BOOL)markVisible { - (void)calculateFeedLocations {
NSDictionary *feed;
self.activeFeedLocations = [NSMutableDictionary dictionary]; self.activeFeedLocations = [NSMutableDictionary dictionary];
if (markVisible) { self.visibleFolders = [NSMutableDictionary dictionary];
self.visibleFeeds = [NSMutableDictionary dictionary];
}
for (NSString *folderName in appDelegate.dictFoldersArray) { for (NSString *folderName in appDelegate.dictFoldersArray) {
if ([folderName isEqualToString:@"river_global"]) continue; if ([folderName isEqualToString:@"river_global"]) continue;
NSArray *folder = [appDelegate.dictFolders objectForKey:folderName]; NSArray *folder = [appDelegate.dictFolders objectForKey:folderName];
NSMutableArray *feedLocations = [NSMutableArray array]; NSMutableArray *feedLocations = [NSMutableArray array];
for (int f = 0; f < [folder count]; f++) { for (int f = 0; f < [folder count]; f++) {
id feedId = [folder objectAtIndex:f]; id feedId = [folder objectAtIndex:f];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId]; if ([self isFeedVisible:feedId]) {
if ([folderName isEqualToString:@"river_blurblogs"]){
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
} else {
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
}
// BOOL isUser = [[NSString stringWithFormat:@"%@", feedId]
// isEqualToString:
// [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"id"]]];
if (self.viewShowingAllFeeds) {
NSNumber *location = [NSNumber numberWithInt:f]; NSNumber *location = [NSNumber numberWithInt:f];
[feedLocations addObject:location]; [feedLocations addObject:location];
} else { if (![[self.visibleFolders objectForKey:folderName] boolValue]) {
int maxScore = [NewsBlurViewController computeMaxScoreForFeed:feed]; [self.visibleFolders setObject:[NSNumber numberWithBool:YES] forKey:folderName];
// if ([folderName isEqualToString:@"river_blurblogs"]){
// NSLog(@"Computing score for %@: %d in %d (markVisible: %d)",
// [feed objectForKey:@"feed_title"], maxScore, appDelegate.selectedIntelligence, markVisible);
// }
if (maxScore >= appDelegate.selectedIntelligence) {
NSNumber *location = [NSNumber numberWithInt:f];
[feedLocations addObject:location];
if (markVisible) {
[self.visibleFeeds setObject:[NSNumber numberWithBool:YES] forKey:feedIdStr];
}
} }
} }
} }
[self.activeFeedLocations setObject:feedLocations forKey:folderName]; [self.activeFeedLocations setObject:feedLocations forKey:folderName];
} }
// NSLog(@"Active feed locations %@", self.activeFeedLocations);
} }
+ (int)computeMaxScoreForFeed:(NSDictionary *)feed { + (int)computeMaxScoreForFeed:(NSDictionary *)feed {
@ -1447,8 +1189,10 @@ static const CGFloat kFolderTitleHeight = 28;
for (int l=0; l < [activeFolderFeeds count]; l++) { for (int l=0; l < [activeFolderFeeds count]; l++) {
if ([[originalFolder objectAtIndex:[[activeFolderFeeds objectAtIndex:l] intValue]] intValue] == [feed intValue]) { if ([[originalFolder objectAtIndex:[[activeFolderFeeds objectAtIndex:l] intValue]] intValue] == [feed intValue]) {
indexPath = [NSIndexPath indexPathForRow:l inSection:s]; indexPath = [NSIndexPath indexPathForRow:l inSection:s];
break;
} }
} }
if (indexPath) break;
} }
if (indexPath) { if (indexPath) {
[self.stillVisibleFeeds setObject:indexPath forKey:feedIdStr]; [self.stillVisibleFeeds setObject:indexPath forKey:feedIdStr];

View file

@ -5,7 +5,7 @@
<key>application-identifier</key> <key>application-identifier</key>
<string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string> <string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string>
<key>get-task-allow</key> <key>get-task-allow</key>
<true/> <false/>
<key>keychain-access-groups</key> <key>keychain-access-groups</key>
<array> <array>
<string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string> <string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string>

Binary file not shown.