2012-06-21 11:53:48 -07:00
|
|
|
//
|
|
|
|
// ShareViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 6/21/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "ShareViewController.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-06-22 22:57:17 -07:00
|
|
|
#import "StoryDetailViewController.h"
|
2012-06-22 11:52:10 -07:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
|
|
|
#import "ASIHTTPRequest.h"
|
2012-06-21 11:53:48 -07:00
|
|
|
|
|
|
|
@implementation ShareViewController
|
|
|
|
|
2012-06-22 22:57:17 -07:00
|
|
|
@synthesize siteFavicon;
|
|
|
|
@synthesize siteInformation;
|
2012-06-22 11:52:10 -07:00
|
|
|
@synthesize commentField;
|
2012-06-21 11:53:48 -07:00
|
|
|
@synthesize appDelegate;
|
|
|
|
|
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
|
|
|
{
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
if (self) {
|
|
|
|
// Custom initialization
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view from its nib.
|
2012-06-22 11:52:10 -07:00
|
|
|
|
|
|
|
commentField.layer.borderWidth = 1.0f;
|
|
|
|
commentField.layer.cornerRadius = 8;
|
|
|
|
commentField.layer.borderColor = [[UIColor grayColor] CGColor];
|
2012-06-21 11:53:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload
|
|
|
|
{
|
2012-06-22 11:52:10 -07:00
|
|
|
[self setCommentField:nil];
|
2012-06-22 22:57:17 -07:00
|
|
|
[self setSiteInformation:nil];
|
|
|
|
[self setSiteFavicon:nil];
|
2012-06-21 11:53:48 -07:00
|
|
|
[super viewDidUnload];
|
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
|
|
|
}
|
|
|
|
|
2012-06-22 22:57:17 -07:00
|
|
|
|
|
|
|
|
2012-06-21 11:53:48 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2012-06-22 22:57:17 -07:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
|
|
|
|
|
|
|
NSString *siteInfoString = [NSString stringWithFormat:@"%@: %@",
|
|
|
|
[appDelegate.activeFeed objectForKey:@"feed_title"],
|
|
|
|
[appDelegate.activeStory objectForKey:@"story_title"]];
|
|
|
|
|
|
|
|
[self.siteInformation setText:siteInfoString];
|
|
|
|
}
|
|
|
|
|
2012-06-21 11:53:48 -07:00
|
|
|
- (void)dealloc {
|
|
|
|
[appDelegate release];
|
2012-06-22 11:52:10 -07:00
|
|
|
[commentField release];
|
2012-06-22 22:57:17 -07:00
|
|
|
[siteInformation release];
|
|
|
|
[siteFavicon release];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2012-06-21 11:53:48 -07:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)doCancelButton:(id)sender {
|
2012-06-22 22:57:17 -07:00
|
|
|
[commentField resignFirstResponder];
|
2012-06-21 11:53:48 -07:00
|
|
|
[appDelegate hideShareView];
|
|
|
|
}
|
2012-06-22 11:52:10 -07:00
|
|
|
|
|
|
|
- (IBAction)doToggleButton:(id)sender {
|
|
|
|
UIButton *button = (UIButton *)sender;
|
|
|
|
|
|
|
|
if (button.selected) {
|
|
|
|
button.selected = NO;
|
|
|
|
} else {
|
|
|
|
button.selected = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)doShareThisStory:(id)sender {
|
|
|
|
for (id key in appDelegate.activeStory) {
|
|
|
|
NSLog(@"Key in appDelegate.activeStory is %@" , key);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/social/share_story",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"story_feed_id"]];
|
|
|
|
NSString *storyIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"id"]];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
[request setPostValue:feedIdStr forKey:@"feed_id"];
|
2012-06-22 22:57:17 -07:00
|
|
|
[request setPostValue:storyIdStr forKey:@"story_id"];
|
|
|
|
|
|
|
|
NSString *comments = commentField.text;
|
|
|
|
if (comments) {
|
|
|
|
[request setPostValue:comments forKey:@"comments"];
|
|
|
|
}
|
2012-06-22 11:52:10 -07:00
|
|
|
[request setDelegate:self];
|
|
|
|
[request setDidFinishSelector:@selector(finishAddComment:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishAddComment:(ASIHTTPRequest *)request {
|
|
|
|
NSLog(@"%@", [request responseString]);
|
|
|
|
NSLog(@"Successfully added.");
|
2012-06-22 22:57:17 -07:00
|
|
|
[commentField resignFirstResponder];
|
2012-06-22 11:52:10 -07:00
|
|
|
[appDelegate hideShareView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request {
|
|
|
|
NSError *error = [request error];
|
|
|
|
NSLog(@"Error: %@", error);
|
|
|
|
}
|
|
|
|
|
2012-06-22 22:57:17 -07:00
|
|
|
-(void)keyboardWillHide:(NSNotification*)notification
|
|
|
|
{
|
|
|
|
NSDictionary *userInfo = notification.userInfo;
|
|
|
|
NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
|
|
|
UIViewAnimationCurve curve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
|
|
|
|
|
|
|
|
CGRect keyboardFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
|
|
|
|
|
|
CGRect shareViewFrame = self.view.frame;
|
|
|
|
CGRect storyDetailViewFrame = appDelegate.storyDetailViewController.view.frame;
|
|
|
|
|
|
|
|
NSLog(@"Keyboard y is %f", keyboardFrame.size.height);
|
|
|
|
shareViewFrame.origin.y = shareViewFrame.origin.y + keyboardFrame.size.height;
|
|
|
|
storyDetailViewFrame.size.height = storyDetailViewFrame.size.height + keyboardFrame.size.height;
|
|
|
|
|
|
|
|
[UIView animateWithDuration:duration
|
|
|
|
delay:0
|
|
|
|
options:UIViewAnimationOptionBeginFromCurrentState | curve
|
|
|
|
animations:^{
|
|
|
|
self.view.frame = shareViewFrame;
|
|
|
|
appDelegate.storyDetailViewController.view.frame = storyDetailViewFrame;
|
|
|
|
} completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)keyboardWillShow:(NSNotification*)notification
|
|
|
|
{
|
|
|
|
NSDictionary *userInfo = notification.userInfo;
|
|
|
|
NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
|
|
|
UIViewAnimationCurve curve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
|
|
|
|
|
|
|
|
CGRect keyboardFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
|
|
|
|
|
|
CGRect shareViewFrame = self.view.frame;
|
|
|
|
CGRect storyDetailViewFrame = appDelegate.storyDetailViewController.view.frame;
|
|
|
|
|
|
|
|
NSLog(@"Keyboard y is %f", keyboardFrame.size.height);
|
|
|
|
shareViewFrame.origin.y = shareViewFrame.origin.y - keyboardFrame.size.height;
|
|
|
|
storyDetailViewFrame.size.height = storyDetailViewFrame.size.height - keyboardFrame.size.height;
|
|
|
|
|
|
|
|
[UIView animateWithDuration:duration
|
|
|
|
delay:0
|
|
|
|
options:UIViewAnimationOptionBeginFromCurrentState | curve
|
|
|
|
animations:^{
|
|
|
|
self.view.frame = shareViewFrame;
|
|
|
|
appDelegate.storyDetailViewController.view.frame = storyDetailViewFrame;
|
|
|
|
} completion:nil];
|
|
|
|
}
|
|
|
|
|
2012-06-21 11:53:48 -07:00
|
|
|
@end
|