NewsBlur/media/ios/Classes/AuthorizeServicesViewController.m

115 lines
3.8 KiB
Mathematica
Raw Normal View History

2012-08-10 21:10:32 -07:00
//
// AuthorizeServicesViewController.m
// NewsBlur
//
// Created by Roy Yang on 8/10/12.
// Copyright (c) 2012 NewsBlur. All rights reserved.
//
#import "AuthorizeServicesViewController.h"
#import "NewsBlurAppDelegate.h"
#import "FirstTimeUserAddSitesViewController.h"
#import "FirstTimeUserAddFriendsViewController.h"
@implementation AuthorizeServicesViewController
@synthesize appDelegate;
@synthesize webView;
@synthesize url;
@synthesize type;
- (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.
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
self.webView.delegate = self;
}
- (void)viewDidUnload {
[self setWebView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated {
2012-08-12 16:50:34 -07:00
if ([type isEqualToString:@"google"]) {
self.navigationItem.title = @"Google Reader";
} else if ([type isEqualToString:@"facebook"]) {
self.navigationItem.title = @"Facebook";
} else if ([type isEqualToString:@"twitter"]) {
self.navigationItem.title = @"Twitter";
}
2012-08-10 21:10:32 -07:00
NSString *urlAddress = [NSString stringWithFormat:@"http://%@%@", NEWSBLUR_URL, url];
NSURL *fullUrl = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:fullUrl];
[self.webView loadRequest:requestObj];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
NSLog(@"URL STRING IS %@", URLString);
if ([URLString isEqualToString:[NSString stringWithFormat:@"http://%@/", NEWSBLUR_URL]]) {
2012-08-12 20:09:45 -07:00
NSString *error = [self.webView stringByEvaluatingJavaScriptFromString:@"NEWSBLUR.error"];
2012-08-10 21:10:32 -07:00
[self.navigationController popViewControllerAnimated:YES];
if ([type isEqualToString:@"google"]) {
[appDelegate.firstTimeUserAddSitesViewController importFromGoogleReader];
2012-08-10 21:10:32 -07:00
} else if ([type isEqualToString:@"facebook"]) {
2012-08-12 20:09:45 -07:00
if (error.length) {
[self showError:error];
} else {
[appDelegate.firstTimeUserAddFriendsViewController selectFacebookButton];
}
2012-08-10 21:10:32 -07:00
} else if ([type isEqualToString:@"twitter"]) {
2012-08-12 20:09:45 -07:00
if (error.length) {
[self showError:error];
} else {
[appDelegate.firstTimeUserAddFriendsViewController selectTwitterButton];
}
2012-08-10 21:10:32 -07:00
}
return NO;
}
2012-08-11 18:03:28 -07:00
// for failed google reader authorization
2012-08-12 20:09:45 -07:00
if ([URLString hasPrefix:[NSString stringWithFormat:@"http://%@/import/callback", NEWSBLUR_URL]]) {
2012-08-11 18:03:28 -07:00
[self.navigationController popViewControllerAnimated:YES];
[appDelegate.firstTimeUserAddSitesViewController importFromGoogleReaderFailed];
return NO;
}
2012-08-10 21:10:32 -07:00
return YES;
}
2012-08-12 20:09:45 -07:00
- (void)showError:(NSString *)error {
[MBProgressHUD hideHUDForView:appDelegate.firstTimeUserAddFriendsViewController.view animated:YES];
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:appDelegate.firstTimeUserAddFriendsViewController.view animated:YES];
[HUD setCustomView:[[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"warning.gif"]]];
[HUD setMode:MBProgressHUDModeCustomView];
HUD.labelText = error;
[HUD hide:YES afterDelay:4];
}
2012-08-10 21:10:32 -07:00
@end