From 52f5c20a7285140b72c12db0ac00dc95785aa7f3 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Mon, 23 Jul 2012 16:17:49 -0700 Subject: [PATCH] logic for story titles in landscape view and edit reply logic --- media/ios/Classes/FeedDetailViewController.m | 10 ++--- media/ios/Classes/NewsBlurAppDelegate.m | 39 +++++++++---------- media/ios/Classes/ShareViewController.h | 3 +- media/ios/Classes/ShareViewController.m | 28 ++++++++----- media/ios/Classes/StoryDetailViewController.m | 20 ++++++++-- media/ios/sample_text.html | 6 ++- 6 files changed, 66 insertions(+), 40 deletions(-) diff --git a/media/ios/Classes/FeedDetailViewController.m b/media/ios/Classes/FeedDetailViewController.m index d4d97679b..784c807f6 100644 --- a/media/ios/Classes/FeedDetailViewController.m +++ b/media/ios/Classes/FeedDetailViewController.m @@ -460,13 +460,13 @@ cell.imageView.image = resizedSpacer; [cell.imageView addSubview:spinner]; [spinner startAnimating]; - - UIView *topBorder = [[UIView alloc] init]; - topBorder.frame = CGRectMake(0, 0, self.view.frame.size.width, 1); - topBorder.backgroundColor = [UIColor colorWithRed:.9 green:.9 blue:.9 alpha:1.0]; - [cell addSubview:topBorder]; } + UIView *topBorder = [[UIView alloc] init]; + topBorder.frame = CGRectMake(0, 0, self.view.frame.size.width, 1); + topBorder.backgroundColor = [UIColor colorWithRed:.9 green:.9 blue:.9 alpha:1.0]; + [cell addSubview:topBorder]; + return cell; } diff --git a/media/ios/Classes/NewsBlurAppDelegate.m b/media/ios/Classes/NewsBlurAppDelegate.m index ce2f99ec9..4729dc0a9 100644 --- a/media/ios/Classes/NewsBlurAppDelegate.m +++ b/media/ios/Classes/NewsBlurAppDelegate.m @@ -266,32 +266,32 @@ setUsername:(NSString *)username setCommentIndex:(NSString *)commentIndex { self.isShowingShare = YES; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // add shareViewController to storyDetail - [self.storyDetailViewController.view addSubview:self.shareViewController.view]; + [self.storyDetailContainerViewController.view addSubview:self.shareViewController.view]; [self.shareViewController setSiteInfo:type setUserId:userId setUsername:username setCommentIndex:commentIndex]; self.shareViewController.view.frame = CGRectMake(0, - self.storyDetailViewController.view.frame.size.height, - self.storyDetailViewController.view.frame.size.width, + self.storyDetailContainerViewController.view.frame.size.height, + self.storyDetailContainerViewController.view.frame.size.width, 0); - int newShareYCoordinate = self.storyDetailViewController.view.frame.size.height - SHARE_MODAL_HEIGHT; - int newStoryHeight = self.storyDetailViewController.view.frame.size.height - SHARE_MODAL_HEIGHT; + int newShareYCoordinate = self.storyDetailContainerViewController.view.frame.size.height - SHARE_MODAL_HEIGHT; + int newStoryHeight = self.storyDetailContainerViewController.view.frame.size.height - SHARE_MODAL_HEIGHT + 44; - [UIView animateWithDuration:0.35 animations:^{ + [UIView animateWithDuration:0.35 animations:^{ self.shareViewController.view.frame = CGRectMake(0, newShareYCoordinate, - self.storyDetailViewController.view.frame.size.width, + self.storyDetailContainerViewController.view.frame.size.width, SHARE_MODAL_HEIGHT); + self.storyDetailViewController.view.frame = CGRectMake(0, + 0, + self.storyDetailContainerViewController.view.frame.size.width, + newStoryHeight); } completion:^(BOOL finished) { - self.storyDetailViewController.webView.frame = CGRectMake(0, - 0, - self.storyDetailViewController.view.frame.size.width, - newStoryHeight); [self.shareViewController.commentField becomeFirstResponder]; - [self.storyDetailViewController scrolltoBottom]; }]; } else { [self.navigationController presentModalViewController:self.shareViewController animated:YES]; @@ -323,17 +323,16 @@ self.isShowingShare = NO; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { - storyDetailViewController.webView.frame = CGRectMake(0, - 0, - storyDetailViewController.view.frame.size.width, - storyDetailViewController.view.frame.size.height - 44); - + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [UIView animateWithDuration:0.35 animations:^{ shareViewController.view.frame = CGRectMake(0, - storyDetailViewController.view.frame.size.height, - storyDetailViewController.view.frame.size.width, + storyDetailContainerViewController.view.frame.size.height, + storyDetailContainerViewController.view.frame.size.width, 0); + storyDetailViewController.view.frame = CGRectMake(0, + 0, + storyDetailContainerViewController.view.frame.size.width, + storyDetailContainerViewController.view.frame.size.height); } completion:^(BOOL finished) { [shareViewController.view removeFromSuperview]; }]; diff --git a/media/ios/Classes/ShareViewController.h b/media/ios/Classes/ShareViewController.h index 7c2e6e2b7..a1ca64c37 100644 --- a/media/ios/Classes/ShareViewController.h +++ b/media/ios/Classes/ShareViewController.h @@ -30,6 +30,7 @@ - (IBAction)doReplyToComment:(id)sender; - (void)finishAddComment:(ASIHTTPRequest *)request; - (void)finishAddReply:(ASIHTTPRequest *)request; -- (void)replaceStory:(NSDictionary *)newStory; +- (void)requestFailed:(ASIHTTPRequest *)request;- (void)replaceStory:(NSDictionary *)newStory; +- (NSString *) stringByStrippingHTML:(NSString *)s; @end diff --git a/media/ios/Classes/ShareViewController.m b/media/ios/Classes/ShareViewController.m index 52100b053..34a21e089 100644 --- a/media/ios/Classes/ShareViewController.m +++ b/media/ios/Classes/ShareViewController.m @@ -111,6 +111,7 @@ - (void)setSiteInfo:(NSString *)type setUserId:(NSString *)userId setUsername:(NSString *)username setCommentIndex:(NSString *)commentIndex { + if ([type isEqualToString: @"edit-reply"]) { [submitButton setTitle:@"Save"]; facebookButton.hidden = YES; @@ -122,7 +123,7 @@ // get old comment NSArray *replies = [appDelegate.activeComment objectForKey:@"replies"]; int commentIdx = [commentIndex intValue]; - self.commentField.text = [[replies objectAtIndex:commentIdx] objectForKey:@"comments"]; + self.commentField.text = [self stringByStrippingHTML:[[replies objectAtIndex:commentIdx] objectForKey:@"comments"]]; } else if ([type isEqualToString: @"reply"]) { self.activeCommentIndex = -1; [submitButton setTitle:@"Reply"]; @@ -136,7 +137,7 @@ twitterButton.hidden = NO; // get old comment - self.commentField.text = [appDelegate.activeComment objectForKey:@"comments"]; + self.commentField.text = [self stringByStrippingHTML:[appDelegate.activeComment objectForKey:@"comments"]]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [toolbarTitle setTitle:@"Edit Your Comment"]; @@ -211,7 +212,7 @@ if (self.activeCommentIndex != -1) { NSDictionary *activeComment = [[appDelegate.activeComment objectForKey:@"replies"] objectAtIndex:self.activeCommentIndex]; - [request setPostValue:[activeComment objectForKey:@"comments"] forKey:@"original_message"]; + [request setPostValue:[self stringByStrippingHTML:[activeComment objectForKey:@"comments"]] forKey:@"original_message"]; } [request setDelegate:self]; @@ -226,7 +227,6 @@ NSString *responseString = [request responseString]; NSDictionary *results = [[NSDictionary alloc] initWithDictionary:[responseString JSONValue]]; - // add the comment into the activeStory dictionary NSDictionary *comment = [results objectForKey:@"comment"]; NSArray *userProfiles = [results objectForKey:@"user_profiles"]; @@ -285,6 +285,12 @@ [self replaceStory:[results objectForKey:@"story"]]; } +- (void)requestFailed:(ASIHTTPRequest *)request +{ + NSError *error = [request error]; + NSLog(@"Error: %@", error); +} + - (void)replaceStory:(NSDictionary *)newStory { [commentField resignFirstResponder]; [appDelegate hideShareView:YES]; @@ -310,12 +316,6 @@ self.commentField.text = nil; [appDelegate refreshComments]; - -} - -- (void)requestFailed:(ASIHTTPRequest *)request { - NSError *error = [request error]; - NSLog(@"Error: %@", error); } -(void)keyboardWillShowOrHide:(NSNotification*)notification { @@ -360,4 +360,12 @@ }]; } +-(NSString *)stringByStrippingHTML:(NSString *)s { + NSRange r; + + while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound) + s = [s stringByReplacingCharactersInRange:r withString:@""]; + return s; +} + @end diff --git a/media/ios/Classes/StoryDetailViewController.m b/media/ios/Classes/StoryDetailViewController.m index c38a030e0..ec207730a 100644 --- a/media/ios/Classes/StoryDetailViewController.m +++ b/media/ios/Classes/StoryDetailViewController.m @@ -276,6 +276,8 @@ "", [sourceUser objectForKey:@"photo_url"]]; } + + NSString *commentContent = [self textToHtml:[commentDict objectForKey:@"comments"]]; NSString *comment = [NSString stringWithFormat:@ "
" @@ -306,7 +308,7 @@ [user objectForKey:@"username"], userEditButton, userLikeButton, - [commentDict objectForKey:@"comments"], + commentContent, [self getReplies:[commentDict objectForKey:@"replies"] forUserId:[commentDict objectForKey:@"user_id"]]]; return comment; @@ -336,6 +338,8 @@ i // comment number in array ]; } + + NSString *replyContent = [self textToHtml:[replyDict objectForKey:@"comments"]]; NSString *reply = [NSString stringWithFormat:@ "
" @@ -352,7 +356,7 @@ [user objectForKey:@"username"], [replyDict objectForKey:@"publish_date"], userEditButton, - [replyDict objectForKey:@"comments"]]; + replyContent]; repliesString = [repliesString stringByAppendingString:reply]; } repliesString = [repliesString stringByAppendingString:@"
"]; @@ -566,7 +570,11 @@ shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *url = [request URL]; NSArray *urlComponents = [url pathComponents]; - NSString *action = [NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:1]]; + NSString *action = @""; + if ([urlComponents count] > 1) { + action = [NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:1]]; + } + // HACK: Using ios.newsblur.com to intercept the javascript share, reply, and edit events. // the pathComponents do not work correctly unless it is a correctly formed url // Is there a better way? Someone show me the light @@ -757,6 +765,7 @@ shouldStartLoadWithRequest:(NSURLRequest *)request NSString *jsString = [[NSString alloc] initWithFormat:@ "document.getElementById('NB-comments-wrapper').innerHTML = '%@';", commentString]; + NSLog(@"JSSTRING IS %@\n\n\n", jsString); [self.webView stringByEvaluatingJavaScriptFromString:jsString]; } @@ -950,4 +959,9 @@ shouldStartLoadWithRequest:(NSURLRequest *)request [appDelegate showOriginalStory:url]; } +- (NSString *)textToHtml:(NSString*)htmlString { + htmlString = [htmlString stringByReplacingOccurrencesOfString:@"'" withString:@"'"]; + return htmlString; +} + @end diff --git a/media/ios/sample_text.html b/media/ios/sample_text.html index 17d2b350c..79e508a0a 100644 --- a/media/ios/sample_text.html +++ b/media/ios/sample_text.html @@ -8,4 +8,8 @@

The latest reports say the suspect accused of the shooting, which killed 12 and injured over 50, declared himself the Joker to police. That last bit of information is still only coming from an anonymous source. Aurora Police are now attempting to figure out the best approach to enter the suspect’s apartment, which was set with explosives. ”It is a very vexing problem how to enter that apartment safely. I personally have never seen anything like what the pictures show us is in there,” Police Chief Dan Oates told the press.

Anyone looking to help can contact the local Red Cross chapter or volunteer if you’re in the area. You can also help by donating to the Colorado Organization for Victim Assistance. Our thoughts go out to the victims, their friends, family, and the community at large.

UPDATE: TDKR actor, Christian Bale, has released a statement:

-

Words cannot express the horror that I feel. I cannot begin to truly understand the pain and grief of the victims and their loved ones, but my heart goes out to them.

Post to Blurblog
Shared by 1 person
Shared by:
Courtney
1 day ago
reply
like
security theater, tragedy theater, bullshit theater
\ No newline at end of file +

Words cannot express the horror that I feel. I cannot begin to truly understand the pain and grief of the victims and their loved ones, but my heart goes out to them.

Post to Blurblog
Shared by 1 person
Shared by:
Courtney
1 day ago
reply
like
security theater, tragedy theater, bullshit theater
+ + \ No newline at end of file