Skip to content

Commit

Permalink
Make theRunAround use SSO
Browse files Browse the repository at this point in the history
Summary: n/a

Task ID: #

Blame Rev:

Reviewers: brent, jbrusstar, lshepard, arunv

CC:

Test Plan: verified login via SSO worked

Revert Plan:

Tags:

- begin *PUBLIC* platform impact section -
Bugzilla: #
- end platform impact -

DiffCamp Revision: 179100
  • Loading branch information
Yariv Sadan authored and Yariv Sadan committed Nov 5, 2010
1 parent 21d4775 commit 21d1423
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 71 deletions.
15 changes: 8 additions & 7 deletions sample/theRunAround/Classes/mainViewController.h
Expand Up @@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -23,28 +23,28 @@

@class Runs;

@interface mainViewController : UIViewController <FBSessionDelegate,
@interface mainViewController : UIViewController <FBSessionDelegate,
UserInfoLoadDelegate,
UITextFieldDelegate,
FBDialogDelegate> {

IBOutlet FBLoginButton* _fbButton;
IBOutlet UIButton* _addRunButton;
Facebook *_facebook;
Session *_session;
NSArray *_permissions;
UserInfo *_userInfo;
MyRunViewController *_myRunController;

IBOutlet UITextField *_location;
IBOutlet UITextField *_distance;
IBOutlet UIDatePicker *_date;

IBOutlet UIView *_logoutView;
IBOutlet UIScrollView *_loginView;
IBOutlet UIView *_headerView;
IBOutlet UIView *_addRunView;

UITableView *_friendTableView;
NSManagedObjectContext *_managedObjectContext;
}
Expand All @@ -56,6 +56,7 @@
@property(nonatomic, retain) UIView *addRunView;
@property(nonatomic, retain) MyRunViewController *myRunController;
@property(nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@property(nonatomic, retain) Facebook *facebook;

- (IBAction) fbButtonClick: (id) sender;
- (IBAction) addRunButtonClick: (id) sender;
Expand Down
85 changes: 45 additions & 40 deletions sample/theRunAround/Classes/mainViewController.m
Expand Up @@ -27,12 +27,13 @@

@implementation mainViewController

@synthesize managedObjectContext = _managedObjectContext,
@synthesize managedObjectContext = _managedObjectContext,
logoutView = _logoutView,
loginView = _loginView,
headerView = _headerView,
addRunView = _addRunView,
myRunController = _myRunController;
myRunController = _myRunController,
facebook = _facebook;

///////////////////////////////////////////////////////////////////////////////////////////////////
// Private helper function for login / logout
Expand All @@ -43,7 +44,7 @@ - (void) login {

- (void) logout {
[_session unsave];
[_facebook logout:self];
[_facebook logout:self];
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -53,24 +54,28 @@ - (void) logout {
* initialization
*/
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (!kAppId) {
NSLog(@"Missing app id!");
exit(1);
}
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
_permissions = [[NSArray arrayWithObjects:
_permissions = [[NSArray arrayWithObjects:
@"publish_stream",@"read_stream", @"offline_access",nil] retain];

}
return self;
}


- (void)viewDidLoad {
[super viewDidLoad];

_location.keyboardType = UIKeyboardTypeDefault;
_location.returnKeyType = UIReturnKeyDone;
_location.delegate = self;
_distance.returnKeyType = UIReturnKeyDone;
_distance.delegate = self;

_session = [[Session alloc] init];
_facebook = [[_session restore] retain];
if (_facebook == nil) {
Expand All @@ -89,7 +94,7 @@ - (void)viewDidLoad {
[[self view] addSubview:[self headerView]];
[_headerView addSubview:_fbButton];



}

Expand All @@ -99,7 +104,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}

- (void)dealloc {

[_facebook release];
[_permissions release];
[_userInfo release];
Expand All @@ -125,13 +130,13 @@ - (IBAction) fbButtonClick: (id) sender {
*/
- (IBAction) addRunButtonClick: (id) sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.view cache:YES];

[_loginView removeFromSuperview];
[_headerView removeFromSuperview];


[self.view addSubview:self.addRunView];
[UIView commitAnimations];
Expand All @@ -141,49 +146,49 @@ - (IBAction) addRunButtonClick: (id) sender {
* IBAction for Add My Run button click
*/
- (IBAction) insertRun: (id) sender{
NSEntityDescription *runEntity = [NSEntityDescription entityForName:@"Runs"

NSEntityDescription *runEntity = [NSEntityDescription entityForName:@"Runs"
inManagedObjectContext:_managedObjectContext];
Runs *newRun = [[[NSManagedObject alloc] initWithEntity:runEntity
Runs *newRun = [[[NSManagedObject alloc] initWithEntity:runEntity
insertIntoManagedObjectContext:_managedObjectContext] autorelease];
newRun.location = _location.text;

NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
newRun.facebookUid = [f numberFromString:_userInfo.uid];

newRun.date = _date.date;

if (_distance.text) {
newRun.distance = [f numberFromString:_distance.text];
newRun.distance = [f numberFromString:_distance.text];
}

[f release];

NSError *error = nil;
if (![_managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
[_addRunView removeFromSuperview];

[_addRunView removeFromSuperview];
[self.view addSubview:_headerView];
_myRunController.managedObjectContext = _managedObjectContext;
[self.myRunController viewWillAppear:YES];
[self.view addSubview:_loginView];


SBJSON *jsonWriter = [[SBJSON new] autorelease];


NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:

NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
@"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil];

NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSString *caption = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",

NSString *caption = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",
@"I run",_distance.text, @"miles at", _location.text ,@"on",
[dateFormatter stringFromDate:_date.date]];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
Expand All @@ -192,7 +197,7 @@ - (IBAction) insertRun: (id) sender{
@"It finally happened, I started exercising.", @"description",
@"http://itsti.me/", @"href", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];


NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"api_key",
Expand All @@ -201,38 +206,38 @@ - (IBAction) insertRun: (id) sender{
attachmentStr, @"attachment",
nil];
[dateFormatter release];

[_facebook dialog: @"stream.publish"
andParams: params
andDelegate: self];

}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Delegates

/**
* FBSessionDelegate
*/
*/
-(void) fbDidLogin {
[_logoutView removeFromSuperview];
[_addRunView removeFromSuperview];

_fbButton.isLoggedIn = YES;
[_fbButton updateImage];
_addRunButton.hidden = NO;
_userInfo = [[[[UserInfo alloc] initializeWithFacebook:_facebook andDelegate: self]
autorelease]

_userInfo = [[[[UserInfo alloc] initializeWithFacebook:_facebook andDelegate: self]
autorelease]
retain];
[_userInfo requestAllInfo];

[self.view addSubview:self.loginView];
}

/**
* FBSessionDelegate
*/
*/
-(void) fbDidLogout {
[_session unsave];
[_loginView removeFromSuperview];
Expand All @@ -248,7 +253,7 @@ -(void) fbDidLogout {
- (void)userInfoDidLoad {
[_session setSessionWithFacebook:_facebook andUid:_userInfo.uid];
[_session save];

_myRunController = [[MyRunViewController alloc] init];
_myRunController.managedObjectContext = _managedObjectContext;
_myRunController.userInfo = _userInfo;
Expand All @@ -258,11 +263,11 @@ - (void)userInfoDidLoad {
}

- (void)userInfoFailToLoad {
[self logout];
[self logout];
_fbButton.isLoggedIn = NO;
_addRunButton.hidden = YES;
[self.view addSubview:self.logoutView];

}
/**
* UITextFieldDelegate
Expand Down

0 comments on commit 21d1423

Please sign in to comment.