2012-07-16 23:48:07 -07:00
|
|
|
//
|
|
|
|
// InteractionCell.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 7/16/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "InteractionCell.h"
|
|
|
|
#import "NSAttributedString+Attributes.h"
|
2012-07-18 12:17:55 -07:00
|
|
|
#import "UIImageView+AFNetworking.h"
|
|
|
|
#import "Utilities.h"
|
2012-07-18 17:23:57 -07:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2012-07-16 23:48:07 -07:00
|
|
|
|
|
|
|
@implementation InteractionCell
|
|
|
|
|
|
|
|
@synthesize interactionLabel;
|
|
|
|
|
|
|
|
- (id)initWithFrame:(CGRect)frame
|
|
|
|
{
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
if (self) {
|
|
|
|
// Initialization code
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Only override drawRect: if you perform custom drawing.
|
|
|
|
// An empty implementation adversely affects performance during animation.
|
|
|
|
- (void)drawRect:(CGRect)rect
|
|
|
|
{
|
|
|
|
// Drawing code
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-07-18 12:17:55 -07:00
|
|
|
- (int)refreshInteraction:(NSDictionary *)interaction withWidth:(int)width {
|
|
|
|
UIImageView *avatarView = [[UIImageView alloc] init];
|
2012-07-18 15:26:55 -07:00
|
|
|
UIImage *placeholder = [UIImage imageNamed:@"user"];
|
|
|
|
[avatarView setImageWithURL:[NSURL URLWithString:[[interaction objectForKey:@"with_user"] objectForKey:@"photo_url"]]
|
|
|
|
placeholderImage:placeholder];
|
2012-07-18 12:17:55 -07:00
|
|
|
|
2012-07-18 17:23:57 -07:00
|
|
|
// avatarView.layer.cornerRadius = 6;
|
|
|
|
// avatarView.layer.masksToBounds = YES;
|
|
|
|
|
2012-07-18 12:17:55 -07:00
|
|
|
avatarView.frame = CGRectMake(20, 15, 48, 48);
|
|
|
|
[self addSubview:avatarView];
|
|
|
|
|
2012-07-16 23:48:07 -07:00
|
|
|
self.interactionLabel = [[OHAttributedLabel alloc] init];
|
2012-07-18 17:23:57 -07:00
|
|
|
self.interactionLabel.frame = CGRectMake(83, 14, 365, 200);
|
|
|
|
self.interactionLabel.backgroundColor = [UIColor whiteColor];
|
2012-07-16 23:48:07 -07:00
|
|
|
self.interactionLabel.automaticallyAddLinksForType = NO;
|
|
|
|
|
|
|
|
NSString *category = [interaction objectForKey:@"category"];
|
|
|
|
NSString *content = [interaction objectForKey:@"content"];
|
|
|
|
NSString *title = [self stripFormatting:[NSString stringWithFormat:@"%@", [interaction objectForKey:@"title"]]];
|
|
|
|
NSString *username = [[interaction objectForKey:@"with_user"] objectForKey:@"username"];
|
2012-07-18 12:17:55 -07:00
|
|
|
NSString *time = [[NSString stringWithFormat:@"%@ ago", [interaction objectForKey:@"time_since"]] uppercaseString];
|
2012-07-18 15:26:55 -07:00
|
|
|
NSString *comment = [NSString stringWithFormat:@"\"%@\"", content];
|
|
|
|
NSString *txt;
|
2012-07-16 23:48:07 -07:00
|
|
|
|
|
|
|
if ([category isEqualToString:@"follow"]) {
|
2012-07-18 15:26:55 -07:00
|
|
|
txt = [NSString stringWithFormat:@"%@ is now following you.", username];
|
2012-07-16 23:48:07 -07:00
|
|
|
} else if ([category isEqualToString:@"comment_reply"]) {
|
2012-07-18 15:26:55 -07:00
|
|
|
txt = [NSString stringWithFormat:@"%@ replied to your comment:\n%@", username, comment];
|
2012-07-16 23:48:07 -07:00
|
|
|
} else if ([category isEqualToString:@"reply_reply"]) {
|
2012-07-18 15:26:55 -07:00
|
|
|
txt = [NSString stringWithFormat:@"%@ replied to your reply:\n%@", username, comment];
|
2012-07-16 23:48:07 -07:00
|
|
|
} else if ([category isEqualToString:@"story_reshare"]) {
|
2012-07-18 15:26:55 -07:00
|
|
|
if ([content isEqualToString:@""] || content == nil) {
|
2012-07-16 23:48:07 -07:00
|
|
|
txt = [NSString stringWithFormat:@"%@ re-shared %@.", username, title];
|
2012-07-18 15:26:55 -07:00
|
|
|
} else {
|
|
|
|
txt = [NSString stringWithFormat:@"%@ re-shared %@:\n%@", username, title, comment];
|
2012-07-16 23:48:07 -07:00
|
|
|
}
|
2012-07-18 15:26:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NSString *txtWithTime = [NSString stringWithFormat:@"%@\n%@", txt, time];
|
|
|
|
NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:txtWithTime];
|
2012-07-16 23:48:07 -07:00
|
|
|
|
2012-07-18 15:26:55 -07:00
|
|
|
[attrStr setFont:[UIFont fontWithName:@"Helvetica" size:14]];
|
|
|
|
[attrStr setTextColor:UIColorFromRGB(0x333333)];
|
|
|
|
|
|
|
|
if (![username isEqualToString:@"You"]){
|
|
|
|
[attrStr setTextColor:UIColorFromRGB(NEWSBLUR_ORANGE) range:[txtWithTime rangeOfString:username]];
|
|
|
|
[attrStr setTextBold:YES range:[txt rangeOfString:username]];
|
2012-07-16 23:48:07 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 15:26:55 -07:00
|
|
|
[attrStr setTextColor:UIColorFromRGB(NEWSBLUR_ORANGE) range:[txtWithTime rangeOfString:title]];
|
|
|
|
[attrStr setTextColor:UIColorFromRGB(0x666666) range:[txtWithTime rangeOfString:comment]];
|
|
|
|
|
|
|
|
[attrStr setTextColor:UIColorFromRGB(0x999999) range:[txtWithTime rangeOfString:time]];
|
|
|
|
[attrStr setFont:[UIFont fontWithName:@"Helvetica" size:10] range:[txtWithTime rangeOfString:time]];
|
2012-07-18 17:23:57 -07:00
|
|
|
// [attrStr setTextAlignment:kCTLeftTextAlignment lineBreakMode:kCTLineBreakByTruncatingTail range:[txtWithTime rangeOfString:time] lineHeight:20.0];
|
|
|
|
[attrStr setTextAlignment:kCTLeftTextAlignment lineBreakMode:kCTLineBreakByWordWrapping lineHeight:4];
|
2012-07-18 15:26:55 -07:00
|
|
|
self.interactionLabel.attributedText = attrStr;
|
|
|
|
|
2012-07-18 17:23:57 -07:00
|
|
|
|
2012-07-16 23:48:07 -07:00
|
|
|
[self.interactionLabel sizeToFit];
|
|
|
|
|
2012-07-18 15:26:55 -07:00
|
|
|
|
2012-07-16 23:48:07 -07:00
|
|
|
[self addSubview:self.interactionLabel];
|
|
|
|
int height = self.interactionLabel.frame.size.height;
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)stripFormatting:(NSString *)str {
|
|
|
|
while ([str rangeOfString:@" "].location != NSNotFound) {
|
|
|
|
str = [str stringByReplacingOccurrencesOfString:@" " withString:@" "];
|
|
|
|
}
|
|
|
|
while ([str rangeOfString:@"\n"].location != NSNotFound) {
|
|
|
|
str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|