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.h | 2 + Juick/Views/MessageCell.m | 15 ++++-- Juick/Views/MessageCell.xib | 112 ++++++++++++++++++++++---------------------- 3 files changed, 70 insertions(+), 59 deletions(-) (limited to 'Juick/Views') diff --git a/Juick/Views/MessageCell.h b/Juick/Views/MessageCell.h index d50751b..f568bdc 100644 --- a/Juick/Views/MessageCell.h +++ b/Juick/Views/MessageCell.h @@ -11,6 +11,8 @@ @protocol MessageCellDelegate -(void) avatarClicked:(NSString *)uname; +-(void) linkClicked:(NSString *)url; + @end @interface MessageCell : UITableViewCell 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 diff --git a/Juick/Views/MessageCell.xib b/Juick/Views/MessageCell.xib index 53a2408..5d35561 100644 --- a/Juick/Views/MessageCell.xib +++ b/Juick/Views/MessageCell.xib @@ -18,68 +18,71 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. - - - - - + + - - + + - + + + + + + + - + + + + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. + + + + + + + + + + + - - - - + + + + + + + + + + + + + @@ -99,8 +102,5 @@ - - - -- cgit v1.2.3