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"
|
2012-07-03 17:54:36 -07:00
|
|
|
#import "MBProgressHUD.h"
|
2012-07-13 14:21:55 -07:00
|
|
|
#import <QuartzCore/QuartzCore.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-13 14:21:55 -07:00
|
|
|
@synthesize profileTable;
|
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-09 22:10:55 -07:00
|
|
|
|
2012-07-01 18:26:39 -07:00
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view from its nib.
|
2012-07-12 00:10:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload
|
|
|
|
{
|
|
|
|
[self setActivityModule:nil];
|
|
|
|
[self setProfileBadge:nil];
|
2012-07-13 14:21:55 -07:00
|
|
|
[self setProfileTable:nil];
|
2012-07-12 00:10:42 -07:00
|
|
|
[super viewDidUnload];
|
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2012-07-13 14:21:55 -07:00
|
|
|
|
|
|
|
self.profileTable = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStyleGrouped] autorelease];
|
|
|
|
self.profileTable.dataSource = self;
|
|
|
|
self.profileTable.delegate = self;
|
|
|
|
self.profileTable.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
|
|
2012-07-09 22:10:55 -07:00
|
|
|
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;
|
2012-07-12 00:10:42 -07:00
|
|
|
|
2012-07-09 22:10:55 -07:00
|
|
|
self.view.frame = CGRectMake(0, 0, 320, 500);
|
2012-07-11 18:08:07 -07:00
|
|
|
self.view.backgroundColor = [UIColor whiteColor];
|
2012-07-13 14:21:55 -07:00
|
|
|
// [self.view addSubview:self.profileBadge];
|
|
|
|
// [self.view addSubview:self.activityModule];
|
|
|
|
[self.view addSubview:self.profileTable];
|
|
|
|
|
2012-07-09 22:10:55 -07:00
|
|
|
[badge release];
|
2012-07-11 18:08:07 -07:00
|
|
|
[activity release];
|
2012-07-12 00:10:42 -07:00
|
|
|
[self getUserProfile];
|
2012-07-01 18:26:39 -07:00
|
|
|
}
|
|
|
|
|
2012-07-12 00:10:42 -07:00
|
|
|
- (void)viewDidDisappear:(BOOL)animated {
|
|
|
|
[self.profileBadge removeFromSuperview];
|
|
|
|
[self.activityModule removeFromSuperview];
|
2012-07-03 17:54:36 -07:00
|
|
|
}
|
|
|
|
|
2012-07-01 18:26:39 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[appDelegate release];
|
2012-07-09 22:10:55 -07:00
|
|
|
[profileBadge release];
|
2012-07-11 18:08:07 -07:00
|
|
|
[activityModule release];
|
2012-07-13 14:21:55 -07:00
|
|
|
[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 {
|
2012-07-12 22:05:23 -07:00
|
|
|
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
|
2012-07-03 17:54:36 -07:00
|
|
|
[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,
|
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]];
|
2012-07-12 22:05:23 -07:00
|
|
|
|
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;
|
|
|
|
}
|
2012-07-09 22:10:55 -07:00
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
2012-07-12 00:10:42 -07:00
|
|
|
|
2012-07-11 18:08:07 -07:00
|
|
|
[self.profileBadge refreshWithProfile:[results objectForKey:@"user_profile"]];
|
2012-07-12 00:10:42 -07:00
|
|
|
[self.activityModule refreshWithActivities:results];
|
2012-07-13 14:21:55 -07:00
|
|
|
[self.profileTable reloadData];
|
2012-07-01 18:26:39 -07:00
|
|
|
[results release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request
|
|
|
|
{
|
|
|
|
NSError *error = [request error];
|
|
|
|
NSLog(@"Error: %@", error);
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:21:55 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Table View - Profile Modules List
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
|
|
|
|
if (section == 1) {
|
|
|
|
return @"Latest Activity";
|
|
|
|
} else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
if (section == 0) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
if (indexPath.section == 0) {
|
|
|
|
return 180;
|
|
|
|
} else {
|
|
|
|
return 44;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
static NSString *CellIdentifier;
|
|
|
|
|
|
|
|
if (indexPath.section == 0) {
|
|
|
|
CellIdentifier = @"ProfileBadgeCellIdentifier";
|
|
|
|
} else {
|
|
|
|
CellIdentifier = @"ActivityCellIdentifier";
|
|
|
|
}
|
|
|
|
|
|
|
|
UITableViewCell *cell = [tableView
|
|
|
|
dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
|
|
if (cell == nil) {
|
|
|
|
cell = [[[UITableViewCell alloc]
|
|
|
|
initWithStyle:UITableViewCellStyleDefault
|
|
|
|
reuseIdentifier:CellIdentifier] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSLog(@"indexPath.section is %i", indexPath.section);
|
|
|
|
if (indexPath.section == 0) {
|
|
|
|
[cell addSubview:self.profileBadge];
|
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
} else {
|
|
|
|
cell.textLabel.text = @"test";
|
|
|
|
}
|
|
|
|
// int activitesCount = [self.activitiesArray count];
|
|
|
|
// if (activitesCount) {
|
|
|
|
//
|
|
|
|
// NSDictionary *activity = [self.activitiesArray objectAtIndex:indexPath.row];
|
|
|
|
// NSString *category = [activity objectForKey:@"category"];
|
|
|
|
// NSString *content = [activity objectForKey:@"content"];
|
|
|
|
// NSString *title = [activity objectForKey:@"title"];
|
|
|
|
//
|
|
|
|
// if ([category isEqualToString:@"follow"]) {
|
|
|
|
//
|
|
|
|
// NSString *withUserUsername = [[activity objectForKey:@"with_user"] objectForKey:@"username"];
|
|
|
|
// cell.textLabel.text = [NSString stringWithFormat:@"%@ followed %@", self.activitiesUsername, withUserUsername];
|
|
|
|
//
|
|
|
|
// } else if ([category isEqualToString:@"comment_reply"]) {
|
|
|
|
// NSString *withUserUsername = [[activity objectForKey:@"with_user"] objectForKey:@"username"];
|
|
|
|
// cell.textLabel.text = [NSString stringWithFormat:@"%@ replied to %@", self.activitiesUsername, withUserUsername];
|
|
|
|
//
|
|
|
|
// } else if ([category isEqualToString:@"sharedstory"]) {
|
|
|
|
// cell.textLabel.text = [NSString stringWithFormat:@"%@ shared %@ : %@", self.activitiesUsername, title, content];
|
|
|
|
//
|
|
|
|
// // star and feedsub are always private.
|
|
|
|
// } else if ([category isEqualToString:@"star"]) {
|
|
|
|
// cell.textLabel.text = [NSString stringWithFormat:@"You saved %@", content];
|
|
|
|
//
|
|
|
|
// } else if ([category isEqualToString:@"feedsub"]) {
|
|
|
|
//
|
|
|
|
// cell.textLabel.text = [NSString stringWithFormat:@"You subscribed to %@", content];
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// cell.textLabel.font = [UIFont systemFontOfSize:13];
|
|
|
|
// }
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-01 18:26:39 -07:00
|
|
|
@end
|