2012-07-11 20:19:42 -07:00
|
|
|
//
|
|
|
|
// InteractionsModule.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 7/11/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "InteractionsModule.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2012-07-12 00:10:42 -07:00
|
|
|
#import "DashboardViewController.h"
|
|
|
|
#import "UserProfileViewController.h"
|
2012-07-11 20:19:42 -07:00
|
|
|
|
|
|
|
@implementation InteractionsModule
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
|
|
|
@synthesize interactionsTable;
|
|
|
|
@synthesize interactionsArray;
|
|
|
|
|
|
|
|
- (id)initWithFrame:(CGRect)frame
|
|
|
|
{
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
if (self) {
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[appDelegate release];
|
|
|
|
[interactionsTable release];
|
|
|
|
[interactionsArray release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSubviews {
|
|
|
|
[super layoutSubviews];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)refreshWithInteractions:(NSMutableArray *)interactions {
|
|
|
|
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
|
self.interactionsArray = interactions;
|
|
|
|
|
|
|
|
self.interactionsTable = [[[UITableView alloc] init] autorelease];
|
|
|
|
self.interactionsTable.dataSource = self;
|
|
|
|
self.interactionsTable.delegate = self;
|
|
|
|
self.interactionsTable.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
|
|
|
|
self.interactionsTable.layer.cornerRadius = 10;
|
2012-07-12 10:59:17 -07:00
|
|
|
self.interactionsTable.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
2012-07-11 20:19:42 -07:00
|
|
|
|
|
|
|
[self addSubview:self.interactionsTable];
|
|
|
|
[self.interactionsTable reloadData];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Table View - Interactions List
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
|
{
|
2012-07-12 00:10:42 -07:00
|
|
|
int userInteractionsCount = [appDelegate.dictUserInteractions count];
|
|
|
|
if (userInteractionsCount) {
|
|
|
|
return userInteractionsCount;
|
2012-07-11 20:19:42 -07:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
static NSString *CellIdentifier = @"Cell";
|
|
|
|
|
|
|
|
UITableViewCell *cell = [tableView
|
|
|
|
dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
|
|
if (cell == nil) {
|
|
|
|
cell = [[[UITableViewCell alloc]
|
|
|
|
initWithStyle:UITableViewCellStyleDefault
|
|
|
|
reuseIdentifier:CellIdentifier] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
int userInteractions = [appDelegate.dictUserInteractions count];
|
|
|
|
if (userInteractions) {
|
2012-07-11 20:30:55 -07:00
|
|
|
cell.textLabel.font = [UIFont systemFontOfSize:13];
|
2012-07-11 20:19:42 -07:00
|
|
|
NSDictionary *interaction = [appDelegate.dictUserInteractions objectAtIndex:indexPath.row];
|
|
|
|
NSString *category = [interaction objectForKey:@"category"];
|
|
|
|
NSString *content = [interaction objectForKey:@"content"];
|
2012-07-11 20:30:55 -07:00
|
|
|
NSString *title = [interaction objectForKey:@"title"];
|
2012-07-11 20:19:42 -07:00
|
|
|
NSString *username = [[interaction objectForKey:@"with_user"] objectForKey:@"username"];
|
2012-07-11 20:30:55 -07:00
|
|
|
|
2012-07-11 20:19:42 -07:00
|
|
|
if ([category isEqualToString:@"follow"]) {
|
|
|
|
cell.textLabel.text = [NSString stringWithFormat:@"%@ is now following you", username];
|
2012-07-11 20:30:55 -07:00
|
|
|
|
2012-07-11 20:19:42 -07:00
|
|
|
} else if ([category isEqualToString:@"comment_reply"]) {
|
|
|
|
cell.textLabel.text = [NSString stringWithFormat:@"%@ replied to your comment: %@", username, content];
|
2012-07-11 20:30:55 -07:00
|
|
|
|
|
|
|
} else if ([category isEqualToString:@"reply_reply"]) {
|
|
|
|
cell.textLabel.text = [NSString stringWithFormat:@"%@ replied to your reply: %@", username, content];
|
|
|
|
|
|
|
|
} else if ([category isEqualToString:@"story_reshare"]) {
|
|
|
|
cell.textLabel.text = [NSString stringWithFormat:@"%@ re-shared: %@ | %@", username, title, content];
|
2012-07-11 20:19:42 -07:00
|
|
|
}
|
2012-07-11 20:30:55 -07:00
|
|
|
|
2012-07-11 20:19:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2012-07-12 00:10:42 -07:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
int userInteractions = [appDelegate.dictUserInteractions count];
|
|
|
|
if (indexPath.row < userInteractions) {
|
|
|
|
NSDictionary *interaction = [appDelegate.dictUserInteractions objectAtIndex:indexPath.row];
|
|
|
|
NSString *category = [interaction objectForKey:@"category"];
|
|
|
|
if ([category isEqualToString:@"follow"]) {
|
|
|
|
NSString *userId = [[interaction objectForKey:@"with_user"] objectForKey:@"user_id"];
|
|
|
|
appDelegate.activeUserProfileId = userId;
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
|
|
|
|
|
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
|
|
|
|
|
|
|
|
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:appDelegate.userProfileViewController];
|
2012-07-13 21:31:48 -07:00
|
|
|
[popoverController setPopoverContentSize:CGSizeMake(320, 416)];
|
2012-07-12 00:10:42 -07:00
|
|
|
[popoverController presentPopoverFromRect:cell.bounds
|
|
|
|
inView:cell
|
|
|
|
permittedArrowDirections:UIPopoverArrowDirectionAny
|
|
|
|
animated:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-11 20:19:42 -07:00
|
|
|
@end
|