From 37f8fb16c6ce16ca601c386b62f65a48e31642fc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 13 May 2023 04:51:09 +0300 Subject: Message layout updates and clickable images --- Juick/Views/MessageCell.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'Juick/Views/MessageCell.m') diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m index ceb2ac5..9b1b593 100644 --- a/Juick/Views/MessageCell.m +++ b/Juick/Views/MessageCell.m @@ -16,6 +16,7 @@ @property(nonatomic, readonly) UIFont *boldFont; @property(nonatomic, readonly) UIFont *italicFont; - (void) updateAvatarWithUrl:(NSString *)avatarUrl; +@property(nonatomic, strong) NSString *attachment; @end @implementation MessageCell @@ -72,14 +73,15 @@ const NSString *unreadMarker = @"●"; }]; } if ([msg.attach length] > 0) { - CGFloat imageHeight = [msg.attachment.small.height floatValue] / [[UIScreen mainScreen] scale]; - CGFloat imageWidth = [msg.attachment.small.width floatValue] / [[UIScreen mainScreen] scale]; + self.attachment = msg.attachment.url; + CGFloat imageHeight = [msg.attachment.medium.height floatValue] / [[UIScreen mainScreen] scale]; + CGFloat imageWidth = [msg.attachment.medium.width floatValue] / [[UIScreen mainScreen] scale]; self.attach.image = [UIImage placeholderImageWithColor:[UIColor colorNamed:@"Muted"] size:CGSizeMake(imageWidth, imageHeight)]; self.attachmentHeight.constant = imageHeight; self.attachmentWidth.constant = imageWidth; __weak UIImageView *weakAttach = self.attach; - [[AppDelegate shared].api fetchImageWithURL:[NSURL URLWithString:msg.attachment.small.url] callback:^(NSData *data) { + [[AppDelegate shared].api fetchImageWithURL:[NSURL URLWithString:msg.attachment.medium.url] callback:^(NSData *data) { [UIView transitionWithView:weakAttach duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve @@ -88,6 +90,10 @@ const NSString *unreadMarker = @"●"; } completion:nil]; }]; + UITapGestureRecognizer *attachmentTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(linkClicked:)]; + [attachmentTapGestureRecognizer setEnabled:YES]; + [self.attach addGestureRecognizer:attachmentTapGestureRecognizer]; + [self.attach setUserInteractionEnabled:YES]; } else { self.attachmentHeight.constant = 0; self.attach.image = nil; @@ -174,5 +180,8 @@ const NSString *unreadMarker = @"●"; -(void) avatarClicked:(UIGestureRecognizer *)gestureRecognizer { [self.delegate avatarClicked:self.title.text]; } +-(void) linkClicked:(UIGestureRecognizer *)gestureRecognizer { + [self.delegate linkClicked:self.attachment]; +} @end -- cgit v1.2.3