Image preview aspect ratio fixed

Signed-off-by: Aleksandra Lazarevic <aleksandra@nextcloud.com>
This commit is contained in:
Aleksandra 2021-10-27 09:06:44 +02:00
Родитель 423dce6260
Коммит 1ee5a2dab6
5 изменённых файлов: 22 добавлений и 30 удалений

Просмотреть файл

@ -29,6 +29,7 @@
static CGFloat kFileMessageCellMinimumHeight = 50.0; static CGFloat kFileMessageCellMinimumHeight = 50.0;
static CGFloat kFileMessageCellAvatarHeight = 30.0; static CGFloat kFileMessageCellAvatarHeight = 30.0;
static CGFloat kFileMessageCellFilePreviewHeight = 120.0; static CGFloat kFileMessageCellFilePreviewHeight = 120.0;
static CGFloat maxPreviewImageWidth = 230.0;
static NSString *FileMessageCellIdentifier = @"FileMessageCellIdentifier"; static NSString *FileMessageCellIdentifier = @"FileMessageCellIdentifier";
static NSString *GroupedFileMessageCellIdentifier = @"GroupedFileMessageCellIdentifier"; static NSString *GroupedFileMessageCellIdentifier = @"GroupedFileMessageCellIdentifier";
@ -57,7 +58,6 @@ static NSString *GroupedFileMessageCellIdentifier = @"GroupedFileMessageCellId
@property (nonatomic, strong) UIView *fileStatusView; @property (nonatomic, strong) UIView *fileStatusView;
@property (nonatomic, strong) NCMessageFileParameter *fileParameter; @property (nonatomic, strong) NCMessageFileParameter *fileParameter;
@property (atomic) int imageh;
@property (nonatomic, strong) NSArray<NSLayoutConstraint *> *vPreviewSize; @property (nonatomic, strong) NSArray<NSLayoutConstraint *> *vPreviewSize;
@property (nonatomic, strong) NSArray<NSLayoutConstraint *> *hPreviewSize; @property (nonatomic, strong) NSArray<NSLayoutConstraint *> *hPreviewSize;

Просмотреть файл

@ -66,7 +66,7 @@
_avatarView.layer.cornerRadius = kFileMessageCellAvatarHeight/2.0; _avatarView.layer.cornerRadius = kFileMessageCellAvatarHeight/2.0;
_avatarView.layer.masksToBounds = YES; _avatarView.layer.masksToBounds = YES;
_previewImageView = [[FilePreviewImageView alloc] initWithFrame:CGRectMake(0, 0, kFileMessageCellFilePreviewHeight, self.imageh)]; _previewImageView = [[FilePreviewImageView alloc] initWithFrame:CGRectMake(0, 0, kFileMessageCellFilePreviewHeight, kFileMessageCellFilePreviewHeight)];
_previewImageView.translatesAutoresizingMaskIntoConstraints = NO; _previewImageView.translatesAutoresizingMaskIntoConstraints = NO;
_previewImageView.userInteractionEnabled = NO; _previewImageView.userInteractionEnabled = NO;
_previewImageView.layer.cornerRadius = 4.0; _previewImageView.layer.cornerRadius = 4.0;
@ -128,9 +128,8 @@
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[avatarView(avatarSize)]-(>=0)-|" options:0 metrics:metrics views:views]]; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[avatarView(avatarSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[titleLabel(28)]-left-[fileStatusView(previewSize)]-right-[statusView(statusSize)]-left-|" options:0 metrics:metrics views:views]]; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[titleLabel(28)]-left-[fileStatusView(previewSize)]-(>=0)-[statusView(statusSize)]-left-|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[titleLabel(28)]-left-[fileStatusView(previewSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
} else if ([self.reuseIdentifier isEqualToString:GroupedFileMessageCellIdentifier]) { } else if ([self.reuseIdentifier isEqualToString:GroupedFileMessageCellIdentifier]) {
self.hGroupedPreviewSize = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-avatarGap-[previewImageView(previewSize)]-(>=0)-|" options:0 metrics:metrics views:views]; self.hGroupedPreviewSize = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-avatarGap-[previewImageView(previewSize)]-(>=0)-|" options:0 metrics:metrics views:views];
@ -143,9 +142,7 @@
self.vGroupedPreviewSize = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-left-[previewImageView(previewSize)]-right-[bodyTextView(>=0@999)]-left-|" options:0 metrics:metrics views:views]; self.vGroupedPreviewSize = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-left-[previewImageView(previewSize)]-right-[bodyTextView(>=0@999)]-left-|" options:0 metrics:metrics views:views];
[self.contentView addConstraints:self.vGroupedPreviewSize]; [self.contentView addConstraints:self.vGroupedPreviewSize];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-left-[fileStatusView(previewSize)]-right-[statusView(statusSize)]-left-|" options:0 metrics:metrics views:views]]; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-left-[fileStatusView(previewSize)]-(>=0)-[statusView(statusSize)]-left-|" options:0 metrics:metrics views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-left-[fileStatusView(previewSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
} }
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeIsDownloading:) name:NCChatFileControllerDidChangeIsDownloadingNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeIsDownloading:) name:NCChatFileControllerDidChangeIsDownloadingNotification object:nil];
@ -195,25 +192,22 @@
[self.previewImageView setImageWithURLRequest:[[NCAPIController sharedInstance] createPreviewRequestForFile:message.file.parameterId withMaxHeight:200 usingAccount:activeAccount] [self.previewImageView setImageWithURLRequest:[[NCAPIController sharedInstance] createPreviewRequestForFile:message.file.parameterId withMaxHeight:200 usingAccount:activeAccount]
placeholderImage:filePreviewImage success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) { placeholderImage:filePreviewImage success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) {
//[weakPreviewImageView setImage:image];
//TODO: How to adjust for dark mode? //TODO: How to adjust for dark mode?
weakPreviewImageView.layer.borderColor = [[UIColor colorWithWhite:0.9 alpha:1.0] CGColor]; weakPreviewImageView.layer.borderColor = [[UIColor colorWithWhite:0.9 alpha:1.0] CGColor];
if (@available(iOS 13.0, *)) { if (@available(iOS 13.0, *)) {
weakPreviewImageView.layer.borderColor = [[UIColor secondarySystemFillColor] CGColor]; weakPreviewImageView.layer.borderColor = [[UIColor secondarySystemFillColor] CGColor];
} }
// weakPreviewImageView.layer.borderWidth = 1.0f; weakPreviewImageView.layer.borderWidth = 1.0f;
if (self.delegate) { if (self.delegate) {
[self.delegate cellHasDownloadedPreviewImage:image fromMessage:message]; [self.delegate cellHasDownloadedPreviewImage:image fromMessage:message];
} }
CGFloat width = [UIScreen mainScreen].bounds.size.width;
dispatch_async(dispatch_get_main_queue(), ^(void){ dispatch_async(dispatch_get_main_queue(), ^(void){
self.vPreviewSize[3].constant = image.size.height + 40; self.vPreviewSize[3].constant = image.size.height ;
self.hPreviewSize[3].constant = (image.size.width > 230) ? 230 : image.size.width + 30; self.hPreviewSize[3].constant = (image.size.width > maxPreviewImageWidth) ? maxPreviewImageWidth : image.size.width ;
self.hPreviewSize[3].constant = (image.size.width > 230) ? 230 : image.size.width + 30; self.hGroupedPreviewSize[1].constant = (image.size.width > maxPreviewImageWidth) ? maxPreviewImageWidth : image.size.width;
self.vGroupedPreviewSize[1].constant = image.size.height + 78 ; self.vGroupedPreviewSize[1].constant = image.size.height ;
[weakPreviewImageView setImage:image]; [weakPreviewImageView setImage:image];
}); });

Просмотреть файл

@ -1535,13 +1535,12 @@ NSInteger const kReceivedChatMessagesLimit = 100;
#pragma mark - File previews #pragma mark - File previews
- (NSURLRequest *)createPreviewRequestForFile:(NSString *)fileId width:(NSInteger)width height:(NSInteger)height usingAccount:(TalkAccount *)account - (NSURLRequest *)createPreviewRequestForFile:(NSString *)fileId width:(NSInteger)width height:(NSInteger)height usingAccount:(TalkAccount *)account
{ {
NSString *urlString = [NSString stringWithFormat:@"%@/index.php/core/preview?fileId=%@&x=%ld&y=%ld&a=1&forceIcon=1", account.server, fileId, (long)width, (long)height]; NSString *urlString = [NSString stringWithFormat:@"%@/index.php/core/preview?fileId=%@&x=%ld&y=%ld&forceIcon=1", account.server, fileId, (long)width, (long)height];
NSMutableURLRequest *previewRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60]; NSMutableURLRequest *previewRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];
[previewRequest setValue:[self authHeaderForAccount:account] forHTTPHeaderField:@"Authorization"]; [previewRequest setValue:[self authHeaderForAccount:account] forHTTPHeaderField:@"Authorization"];
return previewRequest; return previewRequest;
} }
// /core/preview?fileId={fileId}&x=-1&y={height}&a=1
- (NSURLRequest *)createPreviewRequestForFile:(NSString *)fileId withMaxHeight:(NSInteger) height usingAccount:(TalkAccount *)account - (NSURLRequest *)createPreviewRequestForFile:(NSString *)fileId withMaxHeight:(NSInteger) height usingAccount:(TalkAccount *)account
{ {
NSString *urlString = [NSString stringWithFormat:@"%@/index.php/core/preview?fileId=%@&x=-1&y=%ld&a=1&forceIcon=1", account.server, fileId, (long)height]; NSString *urlString = [NSString stringWithFormat:@"%@/index.php/core/preview?fileId=%@&x=-1&y=%ld&a=1&forceIcon=1", account.server, fileId, (long)height];

Просмотреть файл

@ -2943,10 +2943,6 @@ NSString * const NCChatViewControllerForwardNotification = @"NCChatViewControlle
width -= tableView.safeAreaInsets.left + tableView.safeAreaInsets.right; width -= tableView.safeAreaInsets.left + tableView.safeAreaInsets.right;
} }
if(message.file) {
return message.file.image_height + 120;
}
return [self getCellHeightForMessage:message withWidth:width]; return [self getCellHeightForMessage:message withWidth:width];
} }
else { else {
@ -3008,7 +3004,12 @@ NSString * const NCChatViewControllerForwardNotification = @"NCChatViewControlle
} }
if (message.file) { if (message.file) {
return height += kFileMessageCellFilePreviewHeight + 15; if(message.file.previewImageHeight > 0) {
return height += message.file.previewImageHeight ;
}
else {
return height += kFileMessageCellFilePreviewHeight + 15;
}
} }
if (message.geoLocation) { if (message.geoLocation) {
@ -3207,11 +3208,9 @@ NSString * const NCChatViewControllerForwardNotification = @"NCChatViewControlle
- (void)cellHasDownloadedPreviewImage:(UIImage *)loadedImage fromMessage:(NCChatMessage *)message - (void)cellHasDownloadedPreviewImage:(UIImage *)loadedImage fromMessage:(NCChatMessage *)message
{ {
message.file.image_height = loadedImage.size.height; message.file.previewImageHeight = loadedImage.size.height;
[self.tableView beginUpdates]; NSIndexPath *indexPath = [self indexPathForMessage:message];
[self.view setNeedsLayout]; [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.view layoutIfNeeded];
[self.tableView endUpdates];
} }
#pragma mark - VoiceMessageTableViewCellDelegate #pragma mark - VoiceMessageTableViewCellDelegate

Просмотреть файл

@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) NSString *mimetype; @property (nonatomic, strong) NSString *mimetype;
@property (nonatomic, assign) BOOL previewAvailable; @property (nonatomic, assign) BOOL previewAvailable;
@property (nonatomic, strong) NCChatFileStatus *fileStatus; @property (nonatomic, strong) NCChatFileStatus *fileStatus;
@property (nonatomic, assign) int image_height; @property (nonatomic, assign) int previewImageHeight;
@end @end