// // MessageCell.m // Juick // // Created by Vitaly Takmazov on 03/12/2017. // Copyright © 2017 com.juick. All rights reserved. // #import "MessageCell.h" #import "ColorScheme.h" #import "UIImage+Utils.h" #import "APIClient.h" @import DateTools; @import MWFeedParser; @import YYWebImage; @implementation MessageCell - (void)awakeFromNib { [super awakeFromNib]; self.text.textColor = [ColorScheme textColor]; self.text.enabledTextCheckingTypes = NSTextCheckingTypeLink; self.text.delegate = self; self.text.linkAttributes = @{ (id)kCTForegroundColorAttributeName: [ColorScheme linkColor], (id)kCTUnderlineStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle] }; self.title.textColor = [ColorScheme linkColor]; self.timestamp.textColor = [UIColor grayColor]; self.summary.textColor = [UIColor grayColor]; self.tags.textFont = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]; } - (void) configureWithMessage:(Message *)msg { [self.avatar yy_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/a/%d.png", [msg.user.uid intValue]]] options:YYWebImageOptionProgressiveBlur|YYWebImageOptionSetImageWithFadeAnimation]; if ([msg.attach length] > 0) { CGFloat imageHeight = [msg.attachment.small.height floatValue] / [[UIScreen mainScreen] scale]; self.attachmentHeight.constant = imageHeight; [self.attach yy_setImageWithURL:[NSURL URLWithString:msg.attach] options:YYWebImageOptionProgressiveBlur|YYWebImageOptionSetImageWithFadeAnimation]; } else { self.attachmentHeight.constant = 0; self.attach.image = nil; } self.title.text = msg.user.uname; self.timestamp.text = [[[APIClient sharedClient].dateFormatter dateFromString:msg.timestamp] timeAgoSinceNow]; NSUInteger count = [msg.repliesCount unsignedIntegerValue]; if (count > 0) { if ([msg.repliesBy length] > 0) { self.summary.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy]; } else { self.summary.text = [NSString stringWithFormat:@"%@ replies", msg.repliesCount]; } } else { self.summary.text = nil; } self.text.text = [msg.text stringByDecodingHTMLEntities]; [self.tags removeAllTags]; if ([msg.tags count] > 0) { [msg.tags enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [self.tags addTag:obj]; }]; } } -(void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url { [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; } @end