2012-07-11 18:08:07 -07:00
|
|
|
//
|
|
|
|
// ActivityModule.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 7/11/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "ActivityModule.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-07-11 20:19:42 -07:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2012-07-11 18:08:07 -07:00
|
|
|
|
|
|
|
@implementation ActivityModule
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
|
|
|
@synthesize activitiesTable;
|
|
|
|
@synthesize activitiesArray;
|
2012-07-11 20:19:42 -07:00
|
|
|
@synthesize activitiesUsername;
|
2012-07-11 18:08:07 -07:00
|
|
|
|
|
|
|
- (id)initWithFrame:(CGRect)frame
|
|
|
|
{
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
if (self) {
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[appDelegate release];
|
|
|
|
[activitiesTable release];
|
|
|
|
[activitiesArray release];
|
2012-07-11 20:19:42 -07:00
|
|
|
[activitiesUsername release];
|
2012-07-11 18:08:07 -07:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSubviews {
|
|
|
|
[super layoutSubviews];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-11 20:19:42 -07:00
|
|
|
- (void)refreshWithActivities:(NSDictionary *)activitiesDict {
|
2012-07-11 18:08:07 -07:00
|
|
|
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
|
2012-07-11 20:19:42 -07:00
|
|
|
self.activitiesArray = [activitiesDict objectForKey:@"activities"];
|
|
|
|
self.activitiesUsername = [activitiesDict objectForKey:@"username"];
|
2012-07-11 18:08:07 -07:00
|
|
|
|
2012-07-12 00:10:42 -07:00
|
|
|
if (!self.activitiesUsername) {
|
|
|
|
self.activitiesUsername = [[activitiesDict objectForKey:@"user_profile"] objectForKey:@"username"];
|
|
|
|
}
|
|
|
|
|
2012-07-11 18:08:07 -07:00
|
|
|
self.activitiesTable = [[[UITableView alloc] init] autorelease];
|
|
|
|
self.activitiesTable.dataSource = self;
|
|
|
|
self.activitiesTable.delegate = self;
|
|
|
|
self.activitiesTable.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
|
2012-07-11 20:19:42 -07:00
|
|
|
self.activitiesTable.layer.cornerRadius = 10;
|
2012-07-12 10:59:17 -07:00
|
|
|
self.activitiesTable.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
2012-07-11 18:08:07 -07:00
|
|
|
|
|
|
|
[self addSubview:self.activitiesTable];
|
|
|
|
[self.activitiesTable reloadData];
|
|
|
|
}
|
|
|
|
|
2012-07-12 00:10:42 -07:00
|
|
|
|
2012-07-11 18:08:07 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Table View - Interactions List
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
|
{
|
|
|
|
int activitesCount = [self.activitiesArray count];
|
|
|
|
if (activitesCount) {
|
|
|
|
return activitesCount;
|
|
|
|
} 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 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"]) {
|
2012-07-11 20:19:42 -07:00
|
|
|
|
|
|
|
NSString *withUserUsername = [[activity objectForKey:@"with_user"] objectForKey:@"username"];
|
|
|
|
cell.textLabel.text = [NSString stringWithFormat:@"%@ followed %@", self.activitiesUsername, withUserUsername];
|
2012-07-11 18:08:07 -07:00
|
|
|
|
|
|
|
} else if ([category isEqualToString:@"comment_reply"]) {
|
2012-07-11 20:19:42 -07:00
|
|
|
NSString *withUserUsername = [[activity objectForKey:@"with_user"] objectForKey:@"username"];
|
|
|
|
cell.textLabel.text = [NSString stringWithFormat:@"%@ replied to %@", self.activitiesUsername, withUserUsername];
|
2012-07-11 18:08:07 -07:00
|
|
|
|
|
|
|
} else if ([category isEqualToString:@"sharedstory"]) {
|
2012-07-11 20:19:42 -07:00
|
|
|
cell.textLabel.text = [NSString stringWithFormat:@"%@ shared %@ : %@", self.activitiesUsername, title, content];
|
2012-07-11 18:08:07 -07:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end
|