NewsBlur/media/iphone/Classes/UserProfileViewController.m

122 lines
3.2 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-01 18:26:39 -07:00
#import "Utilities.h"
#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;
}
2012-07-01 18:26:39 -07:00
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
ProfileBadge *badge = [[ProfileBadge alloc] init];
badge.frame = CGRectMake(0, 0, 320, 140);
self.profileBadge = badge;
self.view.frame = CGRectMake(0, 0, 320, 500);
[self.view addSubview:self.profileBadge];
[badge release];
2012-07-01 18:26:39 -07:00
}
- (void)viewDidUnload
{
[self setFollowingCount:nil];
[self setFollowersCount:nil];
[self setProfileBadge:nil];
2012-07-01 18:26:39 -07:00
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (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];
[profileBadge 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 {
[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,
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;
}
[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