2015-12-30 15:23:25 +00:00
|
|
|
/*
|
2016-10-03 13:26:58 +00:00
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-03-08 15:14:41 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-12-30 15:23:25 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-10-03 13:26:58 +00:00
|
|
|
#import "FilesSearchTableViewCell.h"
|
2015-12-30 15:23:25 +00:00
|
|
|
|
2017-03-08 15:14:41 +00:00
|
|
|
#import "RiotDesignValues.h"
|
2016-10-03 13:26:58 +00:00
|
|
|
|
|
|
|
@implementation FilesSearchTableViewCell
|
2016-10-12 10:03:39 +00:00
|
|
|
@synthesize delegate, mxkCellData;
|
2016-10-03 13:26:58 +00:00
|
|
|
|
2017-08-08 14:05:43 +00:00
|
|
|
- (void)customizeTableViewCellRendering
|
2016-10-03 13:26:58 +00:00
|
|
|
{
|
2017-08-08 14:05:43 +00:00
|
|
|
[super customizeTableViewCellRendering];
|
2016-10-03 13:26:58 +00:00
|
|
|
|
2017-03-08 15:14:41 +00:00
|
|
|
self.title.textColor = kRiotTextColorBlack;
|
2016-10-03 13:26:58 +00:00
|
|
|
|
2017-03-08 15:14:41 +00:00
|
|
|
self.message.textColor = kRiotTextColorGray;
|
2016-10-03 13:26:58 +00:00
|
|
|
|
2017-03-08 15:14:41 +00:00
|
|
|
self.date.tintColor = kRiotTextColorGray;
|
2016-10-03 13:26:58 +00:00
|
|
|
}
|
2015-12-30 15:23:25 +00:00
|
|
|
|
|
|
|
+ (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth
|
|
|
|
{
|
|
|
|
// The height is fixed
|
|
|
|
return 74;
|
|
|
|
}
|
|
|
|
|
2016-10-12 10:03:39 +00:00
|
|
|
- (void)render:(MXKCellData*)cellData
|
|
|
|
{
|
|
|
|
self.attachmentImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
|
|
|
if ([cellData conformsToProtocol:@protocol(MXKSearchCellDataStoring)])
|
|
|
|
{
|
|
|
|
[super render:cellData];
|
|
|
|
}
|
|
|
|
else if ([cellData isKindOfClass:[MXKRoomBubbleCellData class]])
|
|
|
|
{
|
|
|
|
MXKRoomBubbleCellData *bubbleData = (MXKRoomBubbleCellData*)cellData;
|
|
|
|
mxkCellData = cellData;
|
|
|
|
|
|
|
|
if (bubbleData.attachment)
|
|
|
|
{
|
|
|
|
self.title.text = bubbleData.attachment.originalFileName;
|
2016-12-17 18:04:16 +00:00
|
|
|
|
|
|
|
// In case of attachment, the bubble data is composed by only one component.
|
|
|
|
if (bubbleData.bubbleComponents.count)
|
|
|
|
{
|
|
|
|
MXKRoomBubbleComponent *component = bubbleData.bubbleComponents.firstObject;
|
|
|
|
self.date.text = [bubbleData.eventFormatter dateStringFromEvent:component.event withTime:NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.date.text = nil;
|
|
|
|
}
|
|
|
|
|
2016-10-12 10:03:39 +00:00
|
|
|
self.message.text = bubbleData.senderDisplayName;
|
|
|
|
|
|
|
|
self.attachmentImageView.image = nil;
|
|
|
|
self.attachmentImageView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
|
|
|
if (bubbleData.isAttachmentWithThumbnail)
|
|
|
|
{
|
|
|
|
// Set attached media folders
|
|
|
|
self.attachmentImageView.mediaFolder = bubbleData.roomId;
|
|
|
|
|
|
|
|
NSString *mimetype = nil;
|
|
|
|
if (bubbleData.attachment.thumbnailInfo)
|
|
|
|
{
|
|
|
|
mimetype = bubbleData.attachment.thumbnailInfo[@"mimetype"];
|
|
|
|
}
|
|
|
|
else if (bubbleData.attachment.contentInfo)
|
|
|
|
{
|
|
|
|
mimetype = bubbleData.attachment.contentInfo[@"mimetype"];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *url = bubbleData.attachment.thumbnailURL;
|
2016-12-16 17:24:24 +00:00
|
|
|
UIImage *preview = bubbleData.attachment.previewImage;
|
2016-10-12 10:03:39 +00:00
|
|
|
|
|
|
|
if (url.length || preview)
|
|
|
|
{
|
|
|
|
self.attachmentImageView.enableInMemoryCache = YES;
|
|
|
|
[self.attachmentImageView setImageURL:url withType:mimetype andImageOrientation:bubbleData.attachment.thumbnailOrientation previewImage:preview];
|
|
|
|
|
|
|
|
self.attachmentImageView.backgroundColor = [UIColor whiteColor];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.iconImage.image = [self attachmentIcon:bubbleData.attachment.type];
|
2016-10-12 11:54:34 +00:00
|
|
|
|
|
|
|
// Disable any interactions defined in the cell
|
|
|
|
// because we want [tableView didSelectRowAtIndexPath:] to be called
|
|
|
|
self.contentView.userInteractionEnabled = NO;
|
2016-10-12 10:03:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.title.text = nil;
|
|
|
|
self.date.text = nil;
|
|
|
|
self.message.text = @"";
|
|
|
|
|
|
|
|
self.attachmentImageView.image = nil;
|
|
|
|
self.iconImage.image = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
- (UIImage*)attachmentIcon: (MXKAttachmentType)type
|
|
|
|
{
|
|
|
|
UIImage *image = nil;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MXKAttachmentTypeImage:
|
|
|
|
image = [UIImage imageNamed:@"file_photo_icon"];
|
|
|
|
break;
|
|
|
|
case MXKAttachmentTypeAudio:
|
2017-07-06 09:06:12 +00:00
|
|
|
image = [UIImage imageNamed:@"file_music_icon"];
|
2016-10-12 10:03:39 +00:00
|
|
|
break;
|
|
|
|
case MXKAttachmentTypeVideo:
|
|
|
|
image = [UIImage imageNamed:@"file_video_icon"];
|
|
|
|
break;
|
|
|
|
case MXKAttachmentTypeFile:
|
|
|
|
image = [UIImage imageNamed:@"file_doc_icon"];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-30 15:23:25 +00:00
|
|
|
@end
|