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-01 18:26:39 -07:00
|
|
|
#import "Utilities.h"
|
2012-07-03 17:54:36 -07:00
|
|
|
#import "MBProgressHUD.h"
|
2012-07-01 18:26:39 -07:00
|
|
|
|
|
|
|
@implementation UserProfileViewController
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
|
|
|
@synthesize followingCount;
|
|
|
|
@synthesize followersCount;
|
2012-07-09 21:13:06 -07:00
|
|
|
@synthesize profileBadge;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view from its nib.
|
2012-07-09 21:13:06 -07:00
|
|
|
self.profileBadge.frame = CGRectMake(0, 0, 320, 140);
|
2012-07-01 18:26:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload
|
|
|
|
{
|
|
|
|
[self setFollowingCount:nil];
|
|
|
|
[self setFollowersCount:nil];
|
|
|
|
[super viewDidUnload];
|
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
|
|
|
}
|
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
[self getUserProfile];
|
|
|
|
}
|
|
|
|
|
2012-07-01 18:26:39 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[appDelegate release];
|
|
|
|
[followingCount release];
|
|
|
|
[followersCount release];
|
|
|
|
[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 {
|
2012-07-03 17:54:36 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
HUD.labelText = @"Finding...";
|
|
|
|
|
2012-07-09 21:13:06 -07:00
|
|
|
[self.profileBadge initProfile];
|
2012-07-01 18:26:39 -07:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/social/settings/%@",
|
|
|
|
NEWSBLUR_URL,
|
2012-07-03 17:54:36 -07:00
|
|
|
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]];
|
|
|
|
// int statusCode = [request responseStatusCode];
|
|
|
|
int code = [[results valueForKey:@"code"] intValue];
|
|
|
|
if (code == -1) {
|
|
|
|
NSLog(@"ERROR");
|
|
|
|
[results release];
|
|
|
|
return;
|
|
|
|
}
|
2012-07-01 21:58:55 -07:00
|
|
|
|
|
|
|
NSLog(@"results %@", results);
|
2012-07-03 17:54:36 -07:00
|
|
|
NSLog(@"appDelegate.activeUserProfileId %@", appDelegate.activeUserProfileId);
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
2012-07-09 21:26:53 -07:00
|
|
|
[self.profileBadge refreshWithProfile:results];
|
2012-07-01 21:58:55 -07:00
|
|
|
|
2012-07-01 18:26:39 -07:00
|
|
|
[results release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request
|
|
|
|
{
|
|
|
|
NSError *error = [request error];
|
|
|
|
NSLog(@"Error: %@", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|