2012-06-13 18:07:24 -07:00
|
|
|
//
|
|
|
|
// FirstTimeUserViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 6/13/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "FirstTimeUserViewController.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-06-15 15:02:30 -07:00
|
|
|
#import "ASIHTTPRequest.h"
|
2012-06-13 18:07:24 -07:00
|
|
|
|
2012-06-15 10:49:51 -07:00
|
|
|
#define WELCOME_BUTTON_TITLE @"LET'S GET STARTED"
|
2012-06-15 15:02:30 -07:00
|
|
|
#define ADD_SITES_SKIP_BUTTON_TITLE @"SKIP THIS STEP"
|
|
|
|
#define ADD_SITES_BUTTON_TITLE @"NEXT"
|
2012-06-15 10:49:51 -07:00
|
|
|
#define ADD_FRIENDS_BUTTON_TITLE @"SKIP THIS STEP"
|
|
|
|
#define ADD_NEWSBLUR_BUTTON_TITLE @"FINISH"
|
|
|
|
|
2012-06-13 18:07:24 -07:00
|
|
|
@implementation FirstTimeUserViewController
|
|
|
|
|
2012-06-15 10:49:51 -07:00
|
|
|
@synthesize appDelegate;
|
2012-06-14 10:19:36 -07:00
|
|
|
@synthesize googleReaderButton;
|
2012-06-15 10:49:51 -07:00
|
|
|
@synthesize welcomeView;
|
|
|
|
@synthesize addSitesView;
|
|
|
|
@synthesize addFriendsView;
|
|
|
|
@synthesize addNewsBlurView;
|
2012-06-15 13:32:39 -07:00
|
|
|
@synthesize toolbar;
|
|
|
|
@synthesize toolbarTitle;
|
2012-06-15 15:02:30 -07:00
|
|
|
@synthesize nextButton;
|
2012-06-20 07:39:49 -07:00
|
|
|
@synthesize logo;
|
2012-06-15 15:02:30 -07:00
|
|
|
@synthesize categories;
|
2012-06-14 10:19:36 -07:00
|
|
|
|
2012-06-13 18:07:24 -07:00
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
|
|
|
{
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
if (self) {
|
|
|
|
// Custom initialization
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
2012-06-15 15:02:30 -07:00
|
|
|
categories = [[NSMutableArray alloc] init];
|
2012-06-15 10:49:51 -07:00
|
|
|
currentStep = 0;
|
2012-06-15 15:02:30 -07:00
|
|
|
importedGoogle = 0;
|
2012-06-13 18:07:24 -07:00
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view from its nib.
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload
|
|
|
|
{
|
2012-06-14 10:19:36 -07:00
|
|
|
[self setGoogleReaderButton:nil];
|
2012-06-15 10:49:51 -07:00
|
|
|
[self setWelcomeView:nil];
|
|
|
|
[self setAddSitesView:nil];
|
|
|
|
[self setAddFriendsView:nil];
|
|
|
|
[self setAddNewsBlurView:nil];
|
2012-06-15 13:32:39 -07:00
|
|
|
[self setToolbar:nil];
|
|
|
|
[self setToolbarTitle:nil];
|
2012-06-15 15:02:30 -07:00
|
|
|
[self setNextButton:nil];
|
2012-06-20 07:39:49 -07:00
|
|
|
[self setLogo:nil];
|
2012-06-13 18:07:24 -07:00
|
|
|
[super viewDidUnload];
|
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
|
|
|
}
|
|
|
|
|
2012-06-20 07:39:49 -07:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
[self rotateLogo];
|
|
|
|
}
|
|
|
|
|
2012-06-13 18:07:24 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2012-06-14 10:19:36 -07:00
|
|
|
|
2012-06-15 15:02:30 -07:00
|
|
|
- (IBAction)tapNextButton {
|
2012-06-15 10:49:51 -07:00
|
|
|
currentStep++;
|
|
|
|
if (currentStep == 1) {
|
2012-06-15 13:32:39 -07:00
|
|
|
[toolbarTitle setTitle:@"Step 2 of 4" forState:normal];
|
2012-06-15 15:02:30 -07:00
|
|
|
nextButton.title = ADD_SITES_SKIP_BUTTON_TITLE;
|
2012-06-15 10:49:51 -07:00
|
|
|
self.addSitesView.frame = CGRectMake(768, 44, 768, 960);
|
|
|
|
[self.view addSubview:addSitesView];
|
|
|
|
[UIView animateWithDuration:0.35
|
|
|
|
animations:^{
|
|
|
|
self.welcomeView.frame = CGRectMake(-768, 44, 768, 960);
|
|
|
|
self.addSitesView.frame = CGRectMake(0, 44, 768, 960);
|
|
|
|
}];
|
|
|
|
|
|
|
|
} else if (currentStep == 2) {
|
2012-06-15 15:02:30 -07:00
|
|
|
[self addCategories];
|
2012-06-15 13:32:39 -07:00
|
|
|
[toolbarTitle setTitle:@"Step 3 of 4" forState:normal];
|
|
|
|
|
2012-06-15 10:49:51 -07:00
|
|
|
nextButton.title = ADD_FRIENDS_BUTTON_TITLE;
|
|
|
|
self.addFriendsView.frame = CGRectMake(768, 44, 768, 960);
|
|
|
|
[self.view addSubview:addFriendsView];
|
|
|
|
[UIView animateWithDuration:0.35
|
|
|
|
animations:^{
|
|
|
|
self.addSitesView.frame = CGRectMake(-768, 44, 768, 960);
|
|
|
|
self.addFriendsView.frame = CGRectMake(0, 44, 768, 960);
|
|
|
|
}];
|
|
|
|
} else if (currentStep == 3) {
|
2012-06-15 13:32:39 -07:00
|
|
|
[toolbarTitle setTitle:@"Step 4 of 4" forState:normal];
|
2012-06-15 10:49:51 -07:00
|
|
|
nextButton.title = ADD_NEWSBLUR_BUTTON_TITLE;
|
|
|
|
self.addNewsBlurView.frame = CGRectMake(768, 44, 768, 960);
|
|
|
|
[self.view addSubview:addNewsBlurView];
|
|
|
|
[UIView animateWithDuration:0.35
|
|
|
|
animations:^{
|
|
|
|
self.addFriendsView.frame = CGRectMake(-768, 44, 768, 960);
|
|
|
|
self.addNewsBlurView.frame = CGRectMake(0, 44, 768, 960);
|
|
|
|
}];
|
|
|
|
} else if (currentStep == 4) {
|
|
|
|
NSLog(@"Calling appDeletage reload feeds");
|
|
|
|
[self dismissModalViewControllerAnimated:YES];
|
|
|
|
[appDelegate reloadFeedsView:YES];
|
|
|
|
}
|
2012-06-15 13:32:39 -07:00
|
|
|
}
|
2012-06-15 15:02:30 -07:00
|
|
|
|
2012-06-15 13:32:39 -07:00
|
|
|
- (IBAction)tapCategoryButton:(id)sender {
|
|
|
|
UIButton *categoryButton = (UIButton *)sender;
|
2012-06-15 15:02:30 -07:00
|
|
|
NSString *category = categoryButton.currentTitle;
|
|
|
|
|
2012-06-15 13:32:39 -07:00
|
|
|
if (categoryButton.selected) {
|
|
|
|
categoryButton.selected = NO;
|
2012-06-15 15:02:30 -07:00
|
|
|
[categories removeObject:category];
|
2012-06-15 13:32:39 -07:00
|
|
|
} else {
|
2012-06-15 15:02:30 -07:00
|
|
|
[categories addObject: category];
|
2012-06-15 13:32:39 -07:00
|
|
|
categoryButton.selected = YES;
|
|
|
|
}
|
2012-06-15 15:02:30 -07:00
|
|
|
|
|
|
|
if (categories.count || importedGoogle) {
|
|
|
|
nextButton.title = ADD_SITES_BUTTON_TITLE;
|
|
|
|
} else {
|
|
|
|
nextButton.title = ADD_SITES_SKIP_BUTTON_TITLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 16:35:54 -07:00
|
|
|
- (IBAction)tapNewsBlurButton:(id)sender {
|
|
|
|
UIButton *button = (UIButton *)sender;
|
|
|
|
button.selected = YES;
|
|
|
|
button.userInteractionEnabled = NO;
|
|
|
|
[self addSite:@"http://blog.newsblur.com/"];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Import Google Reader
|
|
|
|
|
|
|
|
- (IBAction)tapGoogleReaderButton {
|
2012-06-15 17:24:37 -07:00
|
|
|
[appDelegate showGoogleReaderAuthentication];
|
2012-06-15 16:35:54 -07:00
|
|
|
}
|
|
|
|
|
2012-06-15 17:24:37 -07:00
|
|
|
- (void)selectGoogleReaderButton {
|
2012-06-15 16:35:54 -07:00
|
|
|
self.googleReaderButton.selected = YES;
|
|
|
|
self.googleReaderButton.userInteractionEnabled = NO;
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:02:30 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Add Categories
|
2012-06-15 13:32:39 -07:00
|
|
|
|
2012-06-15 15:02:30 -07:00
|
|
|
- (void)addCategories {
|
2012-06-15 13:32:39 -07:00
|
|
|
|
2012-06-15 15:02:30 -07:00
|
|
|
// TO DO: curate the list of sites
|
|
|
|
|
|
|
|
for (id key in categories) {
|
|
|
|
// add folder
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/add_folder",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
[request setPostValue:key forKey:@"folder"];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request setDidFinishSelector:@selector(finishAddFolder:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishAddFolder:(ASIHTTPRequest *)request {
|
2012-06-15 17:49:24 -07:00
|
|
|
NSLog(@"Successfully added.");
|
2012-06-15 10:49:51 -07:00
|
|
|
}
|
2012-06-15 15:02:30 -07:00
|
|
|
|
2012-06-20 07:39:49 -07:00
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request {
|
2012-06-15 15:02:30 -07:00
|
|
|
NSError *error = [request error];
|
|
|
|
NSLog(@"Error: %@", error);
|
|
|
|
}
|
|
|
|
|
2012-06-15 16:35:54 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Add Site
|
|
|
|
|
|
|
|
- (void)addSite:(NSString *)siteUrl {
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/add_url",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
|
|
|
|
[request setPostValue:siteUrl forKey:@"url"];
|
|
|
|
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request setDidFinishSelector:@selector(finishAddFolder:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
2012-06-15 15:02:30 -07:00
|
|
|
|
2012-06-20 07:39:49 -07:00
|
|
|
- (void)rotateLogo {
|
|
|
|
// Setup the animation
|
|
|
|
[UIView beginAnimations:nil context:NULL];
|
|
|
|
[UIView setAnimationDuration:(NSTimeInterval)60.0];
|
|
|
|
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
|
|
|
|
[UIView setAnimationBeginsFromCurrentState:YES];
|
|
|
|
|
|
|
|
NSLog(@"%f", M_PI);
|
|
|
|
|
|
|
|
// The transform matrix
|
|
|
|
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14);
|
|
|
|
self.logo.transform = transform;
|
|
|
|
|
|
|
|
// Commit the changes
|
|
|
|
[UIView commitAnimations];
|
|
|
|
}
|
|
|
|
|
2012-06-13 18:07:24 -07:00
|
|
|
@end
|