fixing story traversal

This commit is contained in:
Roy Yang 2012-08-01 12:41:02 -07:00
parent c2c0512471
commit e351f67a2b
11 changed files with 125 additions and 60 deletions

View file

@ -167,7 +167,7 @@
[self fetchFeedDetail:self.feedPage+1 withCallback:callback];
}
- (void)fetchFeedDetail:(int)page withCallback:(void(^)())callback {
- (void)fetchFeedDetail:(int)page withCallback:(void(^)())callback {
NSString *theFeedDetailURL;
if (!self.pageFetching && !self.pageFinished) {
@ -409,7 +409,10 @@
FeedDetailTableCell *cell = (FeedDetailTableCell *)[self.storyTitlesTable cellForRowAtIndexPath:indexPath];
[self loadStory:cell atRow:indexPath.row];
// found the story, reset the two flags.
appDelegate.tryFeedStoryId = nil;
appDelegate.inFindingStoryMode = NO;
}
}
}

View file

@ -101,7 +101,6 @@ static CGFloat *psColors = nil;
if (self.highlighted || self.selected) {
// top border
UIColor *blue = UIColorFromRGB(0x6eadf5);
NSLog(@"self.bounds.size.height is %f", self.bounds.size.height);
CGContextSetStrokeColor(context, CGColorGetComponents([blue CGColor]));
CGContextBeginPath(context);

View file

@ -19,7 +19,8 @@
#define NB_DEFAULT_MASTER_WIDTH 270
#define NB_DEFAULT_STORY_TITLE_HEIGHT 1024 - 640
#define NB_DEFAULT_SLIDER_INTERVAL 0.4
#define NB_DEFAULT_SLIDER_INTERVAL 0.35
#define NB_DEFAULT_SLIDER_INTERVAL_OUT 0.35
#define NB_DEFAULT_SHARE_HEIGHT 120
#define NB_DEFAULT_STORY_TITLE_SNAP_THRESHOLD 60
@ -439,6 +440,7 @@
[self transitionFromShareView];
}
[self.storyDetailViewController clearStory];
self.feedDetailIsVisible = NO;
CGRect vb = [self.view bounds];
@ -452,8 +454,8 @@
self.dashboardViewController.view.frame = CGRectMake(NB_DEFAULT_MASTER_WIDTH + 1, 0, vb.size.width - NB_DEFAULT_MASTER_WIDTH - 1, vb.size.height);
self.masterNavigationController.view.frame = CGRectMake(-NB_DEFAULT_MASTER_WIDTH, 0, NB_DEFAULT_MASTER_WIDTH, vb.size.height);
float smallTimeInterval = NB_DEFAULT_SLIDER_INTERVAL * NB_DEFAULT_MASTER_WIDTH / vb.size.width;
float largeTimeInterval = NB_DEFAULT_SLIDER_INTERVAL * ( vb.size.width - NB_DEFAULT_MASTER_WIDTH) / vb.size.width;
float smallTimeInterval = NB_DEFAULT_SLIDER_INTERVAL_OUT * NB_DEFAULT_MASTER_WIDTH / vb.size.width;
float largeTimeInterval = NB_DEFAULT_SLIDER_INTERVAL_OUT * ( vb.size.width - NB_DEFAULT_MASTER_WIDTH) / vb.size.width;
[UIView animateWithDuration:smallTimeInterval delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.masterNavigationController.view.frame = CGRectMake(0, 0, NB_DEFAULT_MASTER_WIDTH, vb.size.height);

View file

@ -362,7 +362,7 @@
if (social) {
feed = [self.dictSocialFeeds objectForKey:feedId];
self.isSocialView = YES;
self.InFindingStoryMode = YES;
self.inFindingStoryMode = YES;
if (feed == nil) {
feed = user;
@ -575,6 +575,7 @@
}
- (void)hideStoryDetailView {
[self.storyDetailViewController clearStory];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.masterContainerViewController transitionFromFeedDetail];
} else {
@ -701,7 +702,12 @@
if (feedId) {
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
feed = [self.dictFeeds objectForKey:feedIdStr];
if (self.isSocialView) {
feed = [self.dictSocialFeeds objectForKey:feedIdStr];
} else {
feed = [self.dictFeeds objectForKey:feedIdStr];
}
} else {
feed = self.activeFeed;
}
@ -793,8 +799,6 @@
[otherFriendFeeds removeObject:feedId];
// NSLog(@"otherFriendFeeds is %@", otherFriendFeeds);
} else {
feedId = [self.activeStory objectForKey:@"story_feed_id"];
feedIdStr = [NSString stringWithFormat:@"%@",feedId];
@ -857,7 +861,7 @@
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [feed objectForKey:@"id"]];
NSMutableDictionary *newStory = [story mutableCopy];
[newStory setValue:[NSNumber numberWithInt:1] forKey:@"read_status"];
[story setValue:[NSNumber numberWithInt:1] forKey:@"read_status"];
self.visibleUnreadCount -= 1;
if (![self.recentlyReadFeeds containsObject:[newStory objectForKey:@"story_feed_id"]]) {
@ -867,17 +871,23 @@
NSMutableDictionary *newFeed = [feed mutableCopy];
int score = [NewsBlurAppDelegate computeStoryScore:[story objectForKey:@"intelligence"]];
if (score > 0) {
int unreads = MAX(0, [[feed objectForKey:@"ps"] intValue] - 1);
int unreads = MAX(0, [[newFeed objectForKey:@"ps"] intValue] - 1);
[newFeed setValue:[NSNumber numberWithInt:unreads] forKey:@"ps"];
} else if (score == 0) {
int unreads = MAX(0, [[feed objectForKey:@"nt"] intValue] - 1);
int unreads = MAX(0, [[newFeed objectForKey:@"nt"] intValue] - 1);
[newFeed setValue:[NSNumber numberWithInt:unreads] forKey:@"nt"];
} else if (score < 0) {
int unreads = MAX(0, [[feed objectForKey:@"ng"] intValue] - 1);
int unreads = MAX(0, [[newFeed objectForKey:@"ng"] intValue] - 1);
[newFeed setValue:[NSNumber numberWithInt:unreads] forKey:@"ng"];
}
[self.dictFeeds setValue:newFeed forKey:feedIdStr];
if (self.isSocialView) {
[self.dictSocialFeeds setValue:newFeed forKey:feedIdStr];
} else {
[self.dictFeeds setValue:newFeed forKey:feedIdStr];
}
self.activeFeed = newFeed;
}
- (void)markActiveFeedAllRead {

View file

@ -134,7 +134,7 @@
// reload the data and then set the highlight again
[self.feedTitlesTable reloadData];
[self redrawUnreadCounts];
[self.feedTitlesTable selectRowAtIndexPath:self.currentRowAtIndexPath
animated:NO
scrollPosition:UITableViewScrollPositionNone];

View file

@ -64,6 +64,7 @@
- (void)changeWebViewWidth:(int)width;
- (void)showUserProfile:(NSString *)userId xCoordinate:(int)x yCoordinate:(int)y width:(int)width height:(int)height;
- (void)initStory;
- (void)clearStory;
- (void)showShareHUD;
- (void)showFindingStoryHUD;

View file

@ -121,6 +121,7 @@
}
- (void)transitionFromFeedDetail {
[self performSelector:@selector(clearStory) withObject:self afterDelay:0.35];
[appDelegate.masterContainerViewController transitionFromFeedDetail];
}
@ -178,6 +179,10 @@
[self.loadingIndicator stopAnimating];
}
- (void)clearStory {
[self.webView loadHTMLString:@"<html><head></head><body></body></html>" baseURL:nil];
}
- (void)viewDidDisappear:(BOOL)animated {
// Class viewClass = [appDelegate.navigationController.visibleViewController class];
// if (viewClass == [appDelegate.feedDetailViewController class] ||
@ -219,9 +224,10 @@
NSDictionary *user = [self getUser:[[share_user_ids objectAtIndex:i] intValue]];
NSString *avatar = [NSString stringWithFormat:@
"<div class=\"NB-story-share-profile\"><div class=\"NB-user-avatar\">"
"<a class=\"NB-show-profile\" href=\"http://ios.newsblur.com/show-profile/%@\"><img src=\"%@\" /></a>"
"<a id=\"NB-user-share-bar-%@\" class=\"NB-show-profile\" href=\"http://ios.newsblur.com/show-profile/%@\"><img src=\"%@\" /></a>"
"</div></div>",
[user objectForKey:@"user_id"],
[user objectForKey:@"user_id"],
[user objectForKey:@"photo_url"]];
avatarString = [avatarString stringByAppendingString:avatar];
}
@ -629,7 +635,7 @@
footerString
];
// NSLog(@"\n\n\n\nhtmlString:\n\n\n%@\n\n\n", htmlString);
NSLog(@"\n\n\n\nhtmlString:\n\n\n%@\n\n\n", htmlString);
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
@ -863,8 +869,13 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
if ([appDelegate.tryFeedCategory isEqualToString:@"comment_like"] ||
[appDelegate.tryFeedCategory isEqualToString:@"comment_reply"]) {
NSString *currentUserId = [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"user_id"]];
NSString *jsFlashString = [[NSString alloc] initWithFormat:@"slideToComment('%@', true);", currentUserId];
NSString *jsFlashString = [[NSString alloc] initWithFormat:@"slideToComment('%@', true, true);", currentUserId];
[self.webView stringByEvaluatingJavaScriptFromString:jsFlashString];
} else if ([appDelegate.tryFeedCategory isEqualToString:@"story_reshare"]) {
NSString *blurblogUserId = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"social_user_id"]];
NSString *jsFlashString = [[NSString alloc] initWithFormat:@"slideToComment('%@', true);", blurblogUserId];
[self.webView stringByEvaluatingJavaScriptFromString:jsFlashString];
}
appDelegate.tryFeedCategory = nil;
}
@ -890,7 +901,34 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
}
- (void)setNextPreviousButtons {
NSLog(@"the unread count is %i", appDelegate.unreadCount);
NSLog(@"\n\n\n\n\nin setNextPreviousButtons\n");
// setting up the PREV BUTTON
int readStoryCount = [appDelegate.readStories count];
NSLog(@"readStoryCount is %i", readStoryCount);
if (readStoryCount == 0 ||
(readStoryCount == 1 &&
[appDelegate.readStories lastObject] == [appDelegate.activeStory objectForKey:@"id"])) {
[buttonPrevious setStyle:UIBarButtonItemStyleBordered];
[buttonPrevious setTitle:@"Previous"];
[buttonPrevious setEnabled:NO];
} else {
[buttonPrevious setStyle:UIBarButtonItemStyleBordered];
[buttonPrevious setTitle:@"Previous"];
[buttonPrevious setEnabled:YES];
}
// setting up the NEXT STORY BUTTON
int activeLocation = appDelegate.locationOfActiveStory;
NSLog(@"[appDelegate.activeFeedStoryLocations count] is %i", [appDelegate.activeFeedStoryLocations count]);
if (activeLocation >= ([appDelegate.activeFeedStoryLocations count] - 1)) {
self.buttonNextStory.enabled = NO;
} else {
self.buttonNextStory.enabled = YES;
}
// setting up the NEXT UNREAD STORY BUTTON
NSLog(@"unreadStoryCount is %i", [appDelegate unreadCount]);
int nextIndex = [appDelegate indexOfNextUnreadStory];
int unreadCount = [appDelegate unreadCount];
if (nextIndex == -1 && unreadCount > 0) {
@ -904,28 +942,6 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
[buttonNext setTitle:@"Next Unread"];
}
int readStoryCount = [appDelegate.readStories count];
if (readStoryCount == 0 ||
(readStoryCount == 1 &&
[appDelegate.readStories lastObject] == [appDelegate.activeStory objectForKey:@"id"])) {
[buttonPrevious setStyle:UIBarButtonItemStyleBordered];
[buttonPrevious setTitle:@"Previous"];
[buttonPrevious setEnabled:NO];
} else {
[buttonPrevious setStyle:UIBarButtonItemStyleBordered];
[buttonPrevious setTitle:@"Previous"];
[buttonPrevious setEnabled:YES];
}
int activeLocation = appDelegate.locationOfActiveStory;
if (activeLocation >= ([appDelegate.activeFeedStoryLocations count] - 1)) {
self.buttonNextStory.enabled = NO;
} else {
self.buttonNextStory.enabled = YES;
}
float unreads = (float)[appDelegate unreadCount];
float total = [appDelegate originalStoryCount];
float progress = (total - unreads) / total;
@ -1147,11 +1163,11 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
animated:YES];
[appDelegate hideStoryDetailView];
} else {
[self showStory];
[appDelegate setActiveStory:[[appDelegate activeFeedStories]
objectAtIndex:nextIndex]];
[appDelegate pushReadStory:[appDelegate.activeStory objectForKey:@"id"]];
[self setActiveStory];
[self showStory];;
[appDelegate changeActiveFeedDetailRow];
[UIView beginAnimations:nil context:nil];

View file

@ -255,10 +255,12 @@
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [[activity objectForKey:@"with_user"] objectForKey:@"id"]];
NSString *contentIdStr = [NSString stringWithFormat:@"%@", [activity objectForKey:@"content_id"]];
[appDelegate loadTryFeedDetailView:feedIdStr withStory:contentIdStr isSocial:YES withUser:self.userProfile];
appDelegate.tryFeedCategory = category;
} else if ([category isEqualToString:@"sharedstory"]) {
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"id"]];
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [self.userProfile objectForKey:@"id"]];
NSString *contentIdStr = [NSString stringWithFormat:@"%@", [activity objectForKey:@"content_id"]];
[appDelegate loadTryFeedDetailView:feedIdStr withStory:contentIdStr isSocial:YES withUser:self.userProfile];
appDelegate.tryFeedCategory = category;
} else if ([category isEqualToString:@"feedsub"]) {
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [activity objectForKey:@"feed_id"]];
NSString *contentIdStr = nil;

View file

@ -0,0 +1,5 @@
<html><head><link rel="stylesheet" type="text/css" href="reader.css" ><link rel="stylesheet" type="text/css" href="storyDetailView.css" ><meta name="viewport" id="viewport" content="width=753, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/></head><body id="story_pane" class="NB-ipad-wide"> <div class="NB-header"><div class="NB-header-inner"><div class="NB-story-date">5:49am</div><div class="NB-story-title">The Schienenzeppelin or rail zeppelin was an experimental...</div><div class="NB-story-author"></div></div></div> <div class="NB-san-serif" id="NB-font-style"> <div class="NB-medium" id="NB-font-size"> <div class="NB-story"><img src="http://25.media.tumblr.com/tumblr_m80az25BbX1qz4vmto1_500.jpg" /><br /><br /><blockquote>
<p><em>The <a href="http://en.wikipedia.org/wiki/Schienenzeppelin" target="_blank">Schienenzeppelin or rail zeppelin</a> was an experimental railcar which resembled a zeppelin airship in appearance. It was designed and developed by the German aircraft engineer Franz Kruckenberg in 1929. Propulsion was by means of a propeller located at the rear, <strong>it accelerated the railcar to 230.2 km/h (143.0 mph) setting the land speed record for a petrol powered rail vehicle</strong>.</em></p>
</blockquote>
<p>Wow.</p></div> </div> </div> <div class='NB-share-header'></div><div class='NB-share-wrapper'><div class='NB-share-inner-wrapper'><div id="NB-share-button-id" class='NB-share-button NB-button'><div><a href="http://ios.newsblur.com/share">Post to Blurblog</a></div></div></div></div> <div id="NB-comments-wrapper"> <div class="NB-feed-story-comments"><div class="NB-story-comments-shares-teaser-wrapper"><div class="NB-story-comments-shares-teaser"><div class="NB-right">Shared by 2 people</div><div class="NB-story-share-profiles NB-story-share-profiles-public"></div><div class="NB-story-share-label">Shared by: </div><div class="NB-story-share-profiles NB-story-share-profiles-friends"><div class="NB-story-share-profile"><div class="NB-user-avatar"><a id="NB-user-share-bar-27551" class="NB-show-profile" href="http://ios.newsblur.com/show-profile/27551"><img src="http://graph.facebook.com/1702670/picture" /></a></div></div><div class="NB-story-share-profile"><div class="NB-user-avatar"><a id="NB-user-share-bar-32601" class="NB-show-profile" href="http://ios.newsblur.com/show-profile/32601"><img src="http://www.gravatar.com/avatar/fe66f260795c73ef4add39866445a861" /></a></div></div></div></div></div><div class="NB-story-comment" id="NB-user-comment-27551"><div class="NB-user-avatar"><a class="NB-show-profile" href="http://ios.newsblur.com/show-profile/27551"><img src="http://graph.facebook.com/1702670/picture" /></a></div><div class="NB-story-comment-author-container"> <div class="NB-story-comment-username">roy</div> <div class="NB-story-comment-date">12 hours ago</div> <div class="NB-story-comment-reply-button NB-button"> <div class="NB-story-comment-reply-button-wrapper"> <a href="http://ios.newsblur.com/reply/27551/roy">Reply</a> </div> </div> <div class="NB-story-comment-edit-button NB-story-comment-share-edit-button NB-button"><div class="NB-story-comment-edit-button-wrapper"><a href="http://ios.newsblur.com/edit-share/27551">Edit</a></div></div> </div><div class="NB-story-comment-content">I can&#039;t believe that thing actually worked. Those Germans and their engines!</div><div class="NB-story-comment-replies"><div class="NB-story-comment-reply" id="NB-user-comment-5018e405f01b3059f3000007"> <a class="NB-show-profile" href="http://ios.newsblur.com/show-profile/13"> <img class="NB-user-avatar NB-story-comment-reply-photo" src="http://a0.twimg.com/profile_images/1382021023/Campeche_Steps_normal.jpg" /> </a> <div class="NB-story-comment-username NB-story-comment-reply-username">samuel</div> <div class="NB-story-comment-date NB-story-comment-reply-date">10 hours ago</div> <div class="NB-story-comment-reply-content">143 mph on land in 1929?!?</div></div><div class="NB-story-comment-reply" id="NB-user-comment-50191ec5f01b302cc1000001"> <a class="NB-show-profile" href="http://ios.newsblur.com/show-profile/23766"> <img class="NB-user-avatar NB-story-comment-reply-photo" src="http://www.gravatar.com/avatar/b81436883b4b34c863b52fca89461ba1" /> </a> <div class="NB-story-comment-username NB-story-comment-reply-username">Courtney</div> <div class="NB-story-comment-date NB-story-comment-reply-date">6 hours ago</div> <div class="NB-story-comment-reply-content">I&#039;m just fixated on that gigantic propeller and how close those people are standing to it. </div></div></div></div></div> </div> <script src="zepto.js"></script><script src="storyDetailView.js"></script></body></html>

View file

@ -285,6 +285,15 @@ del {
max-width: none !important;
}
#story_pane .NB-story-comments-shares-teaser.NB-highlighted {
-webkit-transition: background-color .6s linear;
background-color: #FBE5C7;
}
#story_pane .NB-story-comments-shares-teaser {
-webkit-transition: background-color .6s linear;
}
#story_pane .NB-story-comment-reply.NB-highlighted {
background-color: #FBE5C7;
padding-left: 50px;

View file

@ -46,25 +46,43 @@ function setImage(img) {
}
function slideToComment(commentId, highlight) {
var commentString = 'NB-user-comment-' + commentId;
setTimeout(function(){
var commentString = 'NB-user-comment-' + commentId;
var shareString = 'NB-user-share-bar-' + commentId;
//Get comment
var $comment = $('#' + commentString);
if ($comment.length) {
$.scroll($comment.offset().top - 32, 1000);
} else {
var $shareBar = $('#' + shareString);
if ($shareBar.length) {
$.scroll($shareBar.offset().top - 32, 1000);
} else {
var $shareButton =$("#NB-share-button-id");
$.scroll($shareButton.offset().top - 32, 1000);
}
}
//Get comment
var $comment = $('#' + commentString);
if ($comment.length) {
$.scroll($comment.offset().top - 32, 1000);
} else {
var shareButton = document.getElementById("NB-share-button-id");
$.scroll($('#NB-share-button-id').offset().top - 32, 1000);
}
if (highlight) {
if ($comment.length) {
setTimeout(function(){
$comment.addClass('NB-highlighted');
setTimeout(function(){
$comment.removeClass('NB-highlighted');
}, 2000);
}, 1000);
} else if ($shareBar.length) {
if (highlight) {
setTimeout(function(){
$('#' + commentString).addClass('NB-highlighted');
setTimeout(function(){
$('#' + commentString).removeClass('NB-highlighted');
}, 2000);
}, 1000);
}
setTimeout(function(){
$(".NB-story-comments-shares-teaser").addClass('NB-highlighted');
setTimeout(function(){
$(".NB-story-comments-shares-teaser").removeClass('NB-highlighted');
}, 2000);
}, 1000);
}
}
}, 500);
}
function findPos(obj) {