diff options
author | Vitaly Takmazov | 2019-03-21 16:20:26 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-21 16:20:26 +0300 |
commit | d86cbbf76ad40e9859df129656825086baa5fea9 (patch) | |
tree | 8bbbdf043b040da3be9add376e1a90bb18bd19c0 /Juick/Views/MessageCell.m | |
parent | 2640c7fcb81e5900ea25e5b79a395052dd6814c0 (diff) |
Drop TagListView
Diffstat (limited to 'Juick/Views/MessageCell.m')
-rw-r--r-- | Juick/Views/MessageCell.m | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m index 55e6054..6929436 100644 --- a/Juick/Views/MessageCell.m +++ b/Juick/Views/MessageCell.m @@ -11,6 +11,12 @@ #import "APIClient.h" #import "Entity.h" +@interface MessageCell() +@property(nonatomic, readonly) NSMutableParagraphStyle *quoteStyle; +@property(nonatomic, readonly) UIFont *boldFont; +@property(nonatomic, readonly) UIFont *italicFont; +@end + @implementation MessageCell - (void)awakeFromNib { @@ -21,11 +27,22 @@ self.title.textColor = [ColorScheme linkColor]; self.timestamp.textColor = [UIColor grayColor]; self.summary.textColor = [UIColor grayColor]; - self.tags.textFont = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]; UIGestureRecognizer *avatarTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarClicked:)]; [avatarTapRecognizer setEnabled:YES]; [self.avatar addGestureRecognizer:avatarTapRecognizer]; [self.avatar setUserInteractionEnabled:YES]; + _quoteStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + _quoteStyle.firstLineHeadIndent = 12.0f; + _quoteStyle.headIndent = 12.0f; + _quoteStyle.paragraphSpacing = 6.0f; + UIFontDescriptor* fontDescriptor = [UIFontDescriptor + preferredFontDescriptorWithTextStyle:UIFontTextStyleBody]; + UIFontDescriptor* boldFontDescriptor = [fontDescriptor + fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; + _boldFont = [UIFont fontWithDescriptor:boldFontDescriptor size: 0.0]; + UIFontDescriptor* italicFontDescriptor = [fontDescriptor + fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic]; + _italicFont = [UIFont fontWithDescriptor:italicFontDescriptor size: 0.0]; } - (void) configureWithMessage:(Message *)msg { @@ -88,28 +105,17 @@ } if ([entity.type isEqualToString:@"q"]) { [txt addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:currentRange]; - NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; - paragraphStyle.firstLineHeadIndent = 12.0f; - paragraphStyle.headIndent = 12.0f; - paragraphStyle.paragraphSpacing = 6.0f; - [txt addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:currentRange]; + [txt addAttribute:NSParagraphStyleAttributeName value:_quoteStyle range:currentRange]; } if ([entity.type isEqualToString:@"u"]) { [txt addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:currentRange]; } - UIFontDescriptor* fontDescriptor = [UIFontDescriptor - preferredFontDescriptorWithTextStyle:UIFontTextStyleBody]; + if ([entity.type isEqualToString:@"b"]) { - UIFontDescriptor* boldFontDescriptor = [fontDescriptor - fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; - UIFont* boldFont = [UIFont fontWithDescriptor:boldFontDescriptor size: 0.0]; - [txt addAttribute:NSFontAttributeName value:boldFont range:currentRange]; + [txt addAttribute:NSFontAttributeName value:_boldFont range:currentRange]; } if ([entity.type isEqualToString:@"i"]) { - UIFontDescriptor* italicFontDescriptor = [fontDescriptor - fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic]; - UIFont* italicFont = [UIFont fontWithDescriptor:italicFontDescriptor size: 0.0]; - [txt addAttribute:NSFontAttributeName value:italicFont range:currentRange]; + [txt addAttribute:NSFontAttributeName value:_italicFont range:currentRange]; } } [txt enumerateAttribute:@"displayText" inRange:NSMakeRange(0, [txt length]) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { @@ -117,15 +123,18 @@ [txt replaceCharactersInRange:range withString:value]; } }]; + if ([msg.tags count] > 0) { + NSString *tagsList = [NSString stringWithFormat:@"%@\n", [msg.tags componentsJoinedByString:@", "]]; + [txt insertAttributedString:[[NSAttributedString alloc] + initWithString:tagsList + attributes:@{ + NSFontAttributeName:_italicFont, + NSForegroundColorAttributeName:[UIColor darkGrayColor] + }] atIndex:0]; + } [txt endEditing]; self.text.attributedText = txt; } - [self.tags removeAllTags]; - if ([msg.tags count] > 0) { - [msg.tags enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - [self.tags addTag:obj]; - }]; - } } -(void) avatarClicked:(UIGestureRecognizer *)gestureRecognizer { |