NewsBlur/clients/ios/Classes/FirstTimeUserAddNewsBlurViewController.m

158 lines
5.1 KiB
Mathematica
Raw Normal View History

2012-07-22 14:23:50 -07:00
//
// FTUXAddNewsBlurViewController.m
// NewsBlur
//
// Created by Roy Yang on 7/22/12.
// Copyright (c) 2012 NewsBlur. All rights reserved.
//
#import "FirstTimeUserAddNewsBlurViewController.h"
2012-08-12 20:19:07 -07:00
#import "NewsBlurViewController.h"
2012-07-22 14:23:50 -07:00
@implementation FirstTimeUserAddNewsBlurViewController
@synthesize appDelegate;
@synthesize nextButton;
@synthesize instructionsLabel;
2012-07-22 14:23:50 -07:00
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
2012-07-22 14:23:50 -07:00
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
2012-08-15 19:31:34 -07:00
UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithTitle:@"Start reading" style:UIBarButtonSystemItemDone target:self action:@selector(tapNextButton)];
2012-07-22 14:23:50 -07:00
self.nextButton = next;
self.navigationItem.rightBarButtonItem = next;
self.navigationItem.title = @"All Done";
2012-07-22 14:23:50 -07:00
}
- (void)viewDidUnload
{
[self setNextButton:nil];
[self setInstructionsLabel:nil];
2012-07-22 14:23:50 -07:00
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated {
2014-09-18 11:25:51 -07:00
[super viewWillAppear:animated];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
2012-07-22 14:23:50 -07:00
}
- (void)viewDidAppear:(BOOL)animated {
2014-09-18 11:25:51 -07:00
[super viewDidAppear:animated];
[self addSite:@"http://blog.newsblur.com/rss"];
[self addPopular];
2012-07-22 14:23:50 -07:00
}
2012-08-11 18:03:28 -07:00
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
} else if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
return YES;
}
return NO;
2012-07-22 14:23:50 -07:00
}
- (IBAction)tapNextButton {
[appDelegate.ftuxNavigationController dismissViewControllerAnimated:YES completion:nil];
2012-08-15 13:04:05 -07:00
[appDelegate.feedsViewController fetchFeedList:NO];
2012-07-22 14:23:50 -07:00
}
- (IBAction)tapNewsBlurButton:(id)sender {
UIButton *button = (UIButton *)sender;
button.selected = YES;
button.userInteractionEnabled = NO;
2012-08-12 20:09:45 -07:00
UIImage *checkmark = [UIImage imageNamed:@"258-checkmark"];
UIImageView *checkmarkView = [[UIImageView alloc] initWithImage:checkmark];
checkmarkView.frame = CGRectMake(button.frame.origin.x + button.frame.size.width - 24,
button.frame.origin.y + 8,
16,
16);
[self.view addSubview:checkmarkView];
[self addSite:@"http://blog.newsblur.com/rss"];
2012-07-22 14:23:50 -07:00
}
2012-08-12 20:09:45 -07:00
- (IBAction)tapPopularButton:(id)sender {
UIButton *button = (UIButton *)sender;
button.selected = YES;
button.userInteractionEnabled = NO;
UIImage *checkmark = [UIImage imageNamed:@"258-checkmark"];
UIImageView *checkmarkView = [[UIImageView alloc] initWithImage:checkmark];
checkmarkView.frame = CGRectMake(button.frame.origin.x + button.frame.size.width - 24,
button.frame.origin.y + 8,
16,
16);
[self.view addSubview:checkmarkView];
[self addPopular];
}
2012-07-22 14:23:50 -07:00
#pragma mark -
#pragma mark Add Site
2012-08-12 20:09:45 -07:00
- (void)addPopular {
NSString *urlString = [NSString stringWithFormat:@"%@/social/follow/",
2016-01-21 22:11:37 -08:00
self.appDelegate.url];
2012-08-12 20:09:45 -07:00
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"social:popular" forKey:@"user_id"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(finishAddSite:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request startAsynchronous];
}
2012-07-22 14:23:50 -07:00
- (void)addSite:(NSString *)siteUrl {
NSString *urlString = [NSString stringWithFormat:@"%@/reader/add_url/",
2016-01-21 22:11:37 -08:00
self.appDelegate.url];
2012-07-22 14:23:50 -07:00
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:siteUrl forKey:@"url"];
[request setPostValue:@"true" forKey:@"auto_active"];
[request setPostValue:@"true" forKey:@"skip_fetch"];
2012-07-22 14:23:50 -07:00
[request setDelegate:self];
[request setDidFinishSelector:@selector(finishAddSite:)];
2012-07-22 14:23:50 -07:00
[request setDidFailSelector:@selector(requestFailed:)];
[request startAsynchronous];
}
- (void)requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
NSLog(@"Error: %@", error);
[appDelegate informError:error];
}
- (void)finishAddSite:(ASIHTTPRequest *)request {
2012-08-12 20:19:07 -07:00
NSString *responseString = [request responseString];
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *results = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSLog(@"results are %@", results);
2012-07-22 14:23:50 -07:00
}
@end