summaryrefslogtreecommitdiff
path: root/Juick/Views/BubbleMessageCell.m
blob: 42b60191326f1c5ee46ca70edca2b771e5ff9083 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
//  BubbleMessageCell.m
//  Juick
//
//  Created by Vitaly Takmazov on 04/03/2018.
//  Copyright © 2018 com.juick. All rights reserved.
//

#import "BubbleMessageCell.h"
#import "ColorScheme.h"

@implementation BubbleMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void) configureWithMessage:(Message *)message isMe:(BOOL)isMe {
    self.message.backgroundColor = isMe ? [ColorScheme secondaryBackground] : [ColorScheme mainBackground];
    self.message.textColor = isMe ? [UIColor whiteColor] : [ColorScheme textColor];
    self.message.linkAttributes = @{ (id)kCTForegroundColorAttributeName: isMe ? [UIColor whiteColor] : [ColorScheme linkColor],
                                     (id)kCTUnderlineStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle] };
    self.name.text = message.user.uname;
    self.message.text = message.text;
    self.unreadMarker.text = @"";
    __weak UIImageView *weakAvatar = self.avatarView;
    [self.avatarView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/a/%d.png", [message.user.uid intValue]]]] placeholderImage:nil success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) {
        [UIView transitionWithView:weakAvatar
                          duration:0.3
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^{
                            weakAvatar.image = image;
                        }
                        completion:nil];
    } failure:nil];
    self.message.enabledTextCheckingTypes = NSTextCheckingTypeLink;
    self.message.clipsToBounds = YES;
    self.message.textInsets = UIEdgeInsetsMake(4.0f, 8.0f, 4.0f, 8.0f);
}

-(void) attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
    [[UIApplication sharedApplication] openURL:url options:
     @{} completionHandler:nil];
}

@end