NewsBlur/media/ios/Classes/UserProfileViewController.m

135 lines
3.8 KiB
Mathematica
Raw Normal View History

2012-07-01 18:26:39 -07:00
//
// UserProfileViewController.m
// NewsBlur
//
// Created by Roy Yang on 7/1/12.
// Copyright (c) 2012 NewsBlur. All rights reserved.
//
#import "UserProfileViewController.h"
#import "NewsBlurAppDelegate.h"
#import "ASIHTTPRequest.h"
#import "JSON.h"
2012-07-09 21:13:06 -07:00
#import "ProfileBadge.h"
2012-07-11 18:08:07 -07:00
#import "ActivityModule.h"
2012-07-01 18:26:39 -07:00
#import "Utilities.h"
#import "MBProgressHUD.h"
2012-07-01 18:26:39 -07:00
@implementation UserProfileViewController
@synthesize appDelegate;
2012-07-09 21:13:06 -07:00
@synthesize profileBadge;
2012-07-11 18:08:07 -07:00
@synthesize activityModule;
2012-07-01 18:26:39 -07:00
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
2012-07-01 18:26:39 -07:00
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[self setActivityModule:nil];
[self setProfileBadge:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated {
ProfileBadge *badge = [[ProfileBadge alloc] init];
badge.frame = CGRectMake(0, 0, 320, 140);
self.profileBadge = badge;
2012-07-11 18:08:07 -07:00
ActivityModule *activity = [[ActivityModule alloc] init];
activity.frame = CGRectMake(0, badge.frame.size.height, 320, 300);
self.activityModule = activity;
self.view.frame = CGRectMake(0, 0, 320, 500);
2012-07-11 18:08:07 -07:00
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.profileBadge];
[self.view addSubview:self.activityModule];
[badge release];
2012-07-11 18:08:07 -07:00
[activity release];
[self getUserProfile];
2012-07-01 18:26:39 -07:00
}
- (void)viewDidDisappear:(BOOL)animated {
[self.profileBadge removeFromSuperview];
[self.activityModule removeFromSuperview];
}
2012-07-01 18:26:39 -07:00
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)dealloc {
[appDelegate release];
[profileBadge release];
2012-07-11 18:08:07 -07:00
[activityModule release];
2012-07-01 18:26:39 -07:00
[super dealloc];
}
2012-07-01 21:58:55 -07:00
- (void)doCancelButton {
[appDelegate.findFriendsNavigationController dismissModalViewControllerAnimated:NO];
}
2012-07-01 18:26:39 -07:00
- (void)getUserProfile {
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
[MBProgressHUD hideHUDForView:self.view animated:YES];
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
2012-07-11 18:08:07 -07:00
HUD.labelText = @"Profiling...";
2012-07-09 21:13:06 -07:00
[self.profileBadge initProfile];
2012-07-11 18:08:07 -07:00
NSString *urlString = [NSString stringWithFormat:@"http://%@/social/profile?user_id=%@",
2012-07-01 18:26:39 -07:00
NEWSBLUR_URL,
appDelegate.activeUserProfileId];
2012-07-01 18:26:39 -07:00
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestFinished:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSString *responseString = [request responseString];
NSDictionary *results = [[NSDictionary alloc]
initWithDictionary:[responseString JSONValue]];
2012-07-01 18:26:39 -07:00
// int statusCode = [request responseStatusCode];
int code = [[results valueForKey:@"code"] intValue];
if (code == -1) {
NSLog(@"ERROR");
[results release];
return;
}
[MBProgressHUD hideHUDForView:self.view animated:YES];
2012-07-11 18:08:07 -07:00
[self.profileBadge refreshWithProfile:[results objectForKey:@"user_profile"]];
[self.activityModule refreshWithActivities:results];
2012-07-11 18:08:07 -07:00
2012-07-01 18:26:39 -07:00
[results release];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(@"Error: %@", error);
}
@end