NewsBlur/media/iphone/Classes/ShareViewController.m

105 lines
2.8 KiB
Mathematica
Raw Normal View History

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 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 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-21 11:53:48 -07:00
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)dealloc {
[appDelegate release];
2012-06-22 11:52:10 -07:00
[commentField release];
2012-06-21 11:53:48 -07:00
[super dealloc];
}
- (IBAction)doCancelButton:(id)sender {
[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"];
[request setPostValue:storyIdStr forKey:@"story_id"];
[request setPostValue:@"Hello World" forKey:@"comments"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(finishAddComment:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request startAsynchronous];
}
- (void)finishAddComment:(ASIHTTPRequest *)request {
NSLog(@"%@", [request responseString]);
NSLog(@"Successfully added.");
[appDelegate hideShareView];
}
- (void)requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
NSLog(@"Error: %@", error);
}
2012-06-21 11:53:48 -07:00
@end