2012-07-10 12:34:58 -07:00
|
|
|
//
|
|
|
|
// DashboardViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 7/10/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "DashboardViewController.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-07-11 18:08:07 -07:00
|
|
|
#import "ActivityModule.h"
|
2012-07-11 20:19:42 -07:00
|
|
|
#import "InteractionsModule.h"
|
2012-07-12 00:10:42 -07:00
|
|
|
#import "UserProfileViewController.h"
|
2012-07-10 16:48:05 -07:00
|
|
|
#import "JSON.h"
|
2012-07-10 12:34:58 -07:00
|
|
|
|
|
|
|
@implementation DashboardViewController
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
2012-07-12 10:59:17 -07:00
|
|
|
@synthesize interactionsLabel;
|
|
|
|
@synthesize interactionsModule;
|
|
|
|
@synthesize activitesLabel;
|
|
|
|
@synthesize activitiesModule;
|
2012-07-10 12:34:58 -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.
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload {
|
|
|
|
[self setAppDelegate:nil];
|
2012-07-12 10:59:17 -07:00
|
|
|
[self setInteractionsLabel:nil];
|
|
|
|
[self setInteractionsModule:nil];
|
|
|
|
[self setActivitesLabel:nil];
|
|
|
|
[self setActivitiesModule:nil];
|
2012-07-10 12:34:58 -07:00
|
|
|
[super viewDidUnload];
|
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
2012-07-11 20:30:55 -07:00
|
|
|
|
|
|
|
CGRect frame = CGRectMake(0, 0, 400, 44);
|
2012-07-15 15:06:06 -07:00
|
|
|
UILabel *label = [[UILabel alloc] initWithFrame:frame];
|
2012-07-11 20:30:55 -07:00
|
|
|
label.backgroundColor = [UIColor clearColor];
|
|
|
|
label.font = [UIFont boldSystemFontOfSize:16.0];
|
|
|
|
label.textAlignment = UITextAlignmentCenter;
|
|
|
|
label.textColor = [UIColor whiteColor];
|
|
|
|
label.text = DASHBOARD_TITLE;
|
|
|
|
self.navigationItem.titleView = label;
|
2012-07-12 10:59:17 -07:00
|
|
|
|
|
|
|
[self repositionDashboard];
|
2012-07-10 12:34:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2012-07-12 10:59:17 -07:00
|
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
|
|
|
[self repositionDashboard];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)repositionDashboard {
|
2012-07-12 11:35:32 -07:00
|
|
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
|
|
|
if (UIInterfaceOrientationIsPortrait(orientation)) {
|
2012-07-12 10:59:17 -07:00
|
|
|
self.interactionsLabel.frame = CGRectMake(151,
|
|
|
|
42,
|
|
|
|
self.interactionsLabel.frame.size.width,
|
|
|
|
self.interactionsLabel.frame.size.height);
|
|
|
|
self.interactionsModule.frame = CGRectMake(self.interactionsModule.frame.origin.x,
|
|
|
|
self.interactionsModule.frame.origin.y,
|
|
|
|
440,
|
|
|
|
self.interactionsModule.frame.size.height);
|
|
|
|
self.activitesLabel.frame = CGRectMake(151,
|
2012-07-12 22:05:23 -07:00
|
|
|
494,
|
2012-07-12 10:59:17 -07:00
|
|
|
self.activitesLabel.frame.size.width,
|
|
|
|
self.activitesLabel.frame.size.height);
|
|
|
|
self.activitiesModule.frame = CGRectMake(20,
|
|
|
|
555,
|
|
|
|
440,
|
|
|
|
self.interactionsModule.frame.size.height);
|
|
|
|
} else {
|
|
|
|
self.interactionsLabel.frame = CGRectMake(80,
|
|
|
|
self.interactionsLabel.frame.origin.y,
|
|
|
|
self.interactionsLabel.frame.size.width,
|
|
|
|
self.interactionsLabel.frame.size.height);
|
|
|
|
self.interactionsModule.frame = CGRectMake(self.interactionsModule.frame.origin.x,
|
|
|
|
self.interactionsModule.frame.origin.y,
|
2012-07-12 22:05:23 -07:00
|
|
|
320,
|
2012-07-12 10:59:17 -07:00
|
|
|
self.interactionsModule.frame.size.height);
|
|
|
|
|
2012-07-12 22:05:23 -07:00
|
|
|
self.activitesLabel.frame = CGRectMake(450,
|
2012-07-12 10:59:17 -07:00
|
|
|
self.interactionsLabel.frame.origin.y,
|
|
|
|
self.activitesLabel.frame.size.width,
|
|
|
|
self.activitesLabel.frame.size.height);
|
2012-07-12 22:05:23 -07:00
|
|
|
self.activitiesModule.frame = CGRectMake(380,
|
2012-07-12 10:59:17 -07:00
|
|
|
100,
|
2012-07-12 22:05:23 -07:00
|
|
|
320,
|
2012-07-12 10:59:17 -07:00
|
|
|
self.interactionsModule.frame.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-10 12:34:58 -07:00
|
|
|
- (IBAction)doLogout:(id)sender {
|
|
|
|
[appDelegate confirmLogout];
|
|
|
|
}
|
2012-07-10 16:48:05 -07:00
|
|
|
|
|
|
|
# pragma mark
|
2012-07-15 15:06:06 -07:00
|
|
|
# pragma mark Interactions
|
2012-07-10 16:48:05 -07:00
|
|
|
|
|
|
|
- (void)refreshInteractions {
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/social/interactions?user_id=%@",
|
|
|
|
NEWSBLUR_URL,
|
|
|
|
[appDelegate.dictUserProfile objectForKey:@"user_id"]];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
|
|
|
|
|
|
|
|
[request setDidFinishSelector:@selector(finishLoadInteractions:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
2012-07-11 20:19:42 -07:00
|
|
|
- (void)finishLoadInteractions:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[responseString JSONValue]];
|
|
|
|
|
|
|
|
appDelegate.dictUserInteractions = [results objectForKey:@"interactions"];
|
|
|
|
|
|
|
|
InteractionsModule *interactions = [[InteractionsModule alloc] init];
|
|
|
|
interactions.frame = CGRectMake(20, 100, 438, 300);
|
|
|
|
[interactions refreshWithInteractions:appDelegate.dictUserInteractions];
|
2012-07-12 10:59:17 -07:00
|
|
|
self.interactionsModule = interactions;
|
|
|
|
[self.view addSubview:self.interactionsModule];
|
|
|
|
[self repositionDashboard];
|
2012-07-11 20:19:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request {
|
|
|
|
NSLog(@"Error in finishLoadInteractions is %@", [request error]);
|
|
|
|
}
|
|
|
|
|
|
|
|
# pragma mark
|
2012-07-15 15:06:06 -07:00
|
|
|
# pragma mark Activities
|
2012-07-11 20:19:42 -07:00
|
|
|
|
2012-07-11 18:08:07 -07:00
|
|
|
- (void)refreshActivity {
|
2012-07-11 20:19:42 -07:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/social/activities?user_id=%@",
|
2012-07-11 18:08:07 -07:00
|
|
|
NEWSBLUR_URL,
|
|
|
|
[appDelegate.dictUserProfile objectForKey:@"user_id"]];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
|
|
|
|
[request setDidFinishSelector:@selector(finishLoadActivities:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishLoadActivities:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[responseString JSONValue]];
|
|
|
|
|
2012-07-11 20:19:42 -07:00
|
|
|
appDelegate.dictUserActivities = results;
|
2012-07-11 18:08:07 -07:00
|
|
|
|
|
|
|
ActivityModule *activity = [[ActivityModule alloc] init];
|
|
|
|
activity.frame = CGRectMake(20, 510, 438, 300);
|
2012-07-11 20:19:42 -07:00
|
|
|
[activity refreshWithActivities:appDelegate.dictUserActivities];
|
2012-07-12 10:59:17 -07:00
|
|
|
self.activitiesModule = activity;
|
|
|
|
[self.view addSubview:self.activitiesModule];
|
|
|
|
[self repositionDashboard];
|
2012-07-11 18:08:07 -07:00
|
|
|
}
|
|
|
|
|
2012-07-10 12:34:58 -07:00
|
|
|
@end
|