2017-05-05 13:30:35 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RoomCollectionViewCell.h"
|
|
|
|
|
|
|
|
#import "AvatarGenerator.h"
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
#import "ThemeService.h"
|
2018-11-30 15:36:34 +00:00
|
|
|
#import "Riot-Swift.h"
|
2017-05-05 13:30:35 +00:00
|
|
|
|
2017-09-14 14:00:50 +00:00
|
|
|
#import "MXRoomSummary+Riot.h"
|
2017-05-05 13:30:35 +00:00
|
|
|
|
2017-06-30 15:06:23 +00:00
|
|
|
#import "MXTools.h"
|
|
|
|
|
2018-06-08 09:31:39 +00:00
|
|
|
#pragma mark - Defines & Constants
|
|
|
|
|
|
|
|
static const CGFloat kDirectRoomBorderColorAlpha = 0.75;
|
|
|
|
static const CGFloat kDirectRoomBorderWidth = 3.0;
|
|
|
|
|
2017-05-05 13:30:35 +00:00
|
|
|
@implementation RoomCollectionViewCell
|
|
|
|
|
|
|
|
#pragma mark - Class methods
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[super awakeFromNib];
|
|
|
|
|
2017-05-11 12:58:55 +00:00
|
|
|
// Round room image view
|
|
|
|
[_roomAvatar.layer setCornerRadius:_roomAvatar.frame.size.width / 2];
|
|
|
|
_roomAvatar.clipsToBounds = YES;
|
|
|
|
|
2017-05-05 13:30:35 +00:00
|
|
|
// Initialize unread count badge
|
|
|
|
[_missedNotifAndUnreadBadgeBgView.layer setCornerRadius:10];
|
|
|
|
_missedNotifAndUnreadBadgeBgViewWidthConstraint.constant = 0;
|
|
|
|
|
|
|
|
// Disable the user interaction on the room avatar.
|
|
|
|
self.roomAvatar.userInteractionEnabled = NO;
|
2017-07-09 16:32:40 +00:00
|
|
|
|
|
|
|
// define arrow mask
|
|
|
|
CAShapeLayer *arrowMaskLayer = [[CAShapeLayer alloc] init];
|
|
|
|
arrowMaskLayer.frame = self.editionArrowView.bounds;
|
|
|
|
CGSize viewSize = self.editionArrowView.frame.size;
|
|
|
|
UIBezierPath *path = [[UIBezierPath alloc] init];
|
|
|
|
[path moveToPoint:CGPointMake(0, viewSize.height)]; // arrow left bottom point
|
|
|
|
[path addLineToPoint:CGPointMake(viewSize.width / 2, 0)]; // arrow head
|
|
|
|
[path addLineToPoint:CGPointMake(viewSize.width, viewSize.height)]; // arrow right bottom point
|
|
|
|
[path closePath]; // arrow top side
|
|
|
|
arrowMaskLayer.path = path.CGPath;
|
|
|
|
self.editionArrowView.layer.mask = arrowMaskLayer;
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 14:05:43 +00:00
|
|
|
- (void)customizeCollectionViewCellRendering
|
|
|
|
{
|
|
|
|
[super customizeCollectionViewCellRendering];
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.roomTitle.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
self.roomTitle1.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
self.roomTitle2.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
self.missedNotifAndUnreadBadgeLabel.textColor = ThemeService.shared.theme.backgroundColor;
|
2017-08-08 14:05:43 +00:00
|
|
|
|
|
|
|
// Prepare direct room border
|
2019-01-11 10:45:27 +00:00
|
|
|
CGColorRef directRoomBorderColor = CGColorCreateCopyWithAlpha(ThemeService.shared.theme.tintColor.CGColor, kDirectRoomBorderColorAlpha);
|
2018-06-08 09:31:39 +00:00
|
|
|
|
2017-08-08 14:05:43 +00:00
|
|
|
[self.directRoomBorderView.layer setCornerRadius:self.directRoomBorderView.frame.size.width / 2];
|
|
|
|
self.directRoomBorderView.clipsToBounds = YES;
|
2018-06-08 09:31:39 +00:00
|
|
|
self.directRoomBorderView.layer.borderColor = directRoomBorderColor;
|
|
|
|
self.directRoomBorderView.layer.borderWidth = kDirectRoomBorderWidth;
|
|
|
|
|
|
|
|
CFRelease(directRoomBorderColor);
|
2017-08-08 14:05:43 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.editionArrowView.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
|
2017-08-14 17:11:13 +00:00
|
|
|
|
|
|
|
self.roomAvatar.defaultBackgroundColor = [UIColor clearColor];
|
2017-08-08 14:05:43 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 13:30:35 +00:00
|
|
|
- (void)layoutSubviews
|
|
|
|
{
|
|
|
|
[super layoutSubviews];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)render:(MXKCellData *)cellData
|
|
|
|
{
|
|
|
|
// Hide by default missed notifications and unread widgets
|
|
|
|
self.missedNotifAndUnreadBadgeBgView.hidden = YES;
|
|
|
|
self.missedNotifAndUnreadBadgeBgViewWidthConstraint.constant = 0;
|
|
|
|
|
|
|
|
roomCellData = (id<MXKRecentCellDataStoring>)cellData;
|
|
|
|
if (roomCellData)
|
|
|
|
{
|
|
|
|
// Report computed values as is
|
2017-06-30 15:06:23 +00:00
|
|
|
self.roomTitle.hidden = NO;
|
2017-05-05 13:30:35 +00:00
|
|
|
self.roomTitle.text = roomCellData.roomDisplayname;
|
2017-06-30 15:06:23 +00:00
|
|
|
self.roomTitle1.hidden = YES;
|
|
|
|
self.roomTitle2.hidden = YES;
|
|
|
|
|
|
|
|
// Check whether the room display name is an alias to keep visible the HS.
|
|
|
|
if ([MXTools isMatrixRoomAlias:roomCellData.roomDisplayname])
|
|
|
|
{
|
|
|
|
NSRange range = [roomCellData.roomDisplayname rangeOfString:@":" options:NSBackwardsSearch];
|
|
|
|
if (range.location != NSNotFound)
|
|
|
|
{
|
|
|
|
self.roomTitle.hidden = YES;
|
|
|
|
self.roomTitle1.hidden = NO;
|
|
|
|
self.roomTitle1.text = [roomCellData.roomDisplayname substringToIndex:range.location + 1];
|
|
|
|
self.roomTitle2.hidden = NO;
|
|
|
|
self.roomTitle2.text = [roomCellData.roomDisplayname substringFromIndex:range.location + 1];
|
|
|
|
}
|
|
|
|
}
|
2017-05-05 13:30:35 +00:00
|
|
|
|
|
|
|
// Notify unreads and bing
|
|
|
|
if (roomCellData.hasUnread)
|
|
|
|
{
|
|
|
|
if (0 < roomCellData.notificationCount)
|
|
|
|
{
|
|
|
|
self.missedNotifAndUnreadBadgeBgView.hidden = NO;
|
2019-02-12 18:06:22 +00:00
|
|
|
self.missedNotifAndUnreadBadgeBgView.backgroundColor = roomCellData.highlightCount ? ThemeService.shared.theme.noticeColor : ThemeService.shared.theme.noticeSecondaryColor;
|
2017-05-05 13:30:35 +00:00
|
|
|
|
2017-05-11 12:58:55 +00:00
|
|
|
self.missedNotifAndUnreadBadgeLabel.text = roomCellData.notificationCountStringValue;
|
2017-05-05 13:30:35 +00:00
|
|
|
[self.missedNotifAndUnreadBadgeLabel sizeToFit];
|
|
|
|
|
|
|
|
self.missedNotifAndUnreadBadgeBgViewWidthConstraint.constant = self.missedNotifAndUnreadBadgeLabel.frame.size.width + 18;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use bold font for the room title
|
|
|
|
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)])
|
|
|
|
{
|
2017-06-30 15:37:43 +00:00
|
|
|
self.roomTitle.font = self.roomTitle1.font = self.roomTitle2.font = [UIFont systemFontOfSize:13 weight:UIFontWeightBold];
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-30 15:37:43 +00:00
|
|
|
self.roomTitle.font = self.roomTitle1.font = self.roomTitle2.font = [UIFont boldSystemFontOfSize:13];
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-17 16:00:56 +00:00
|
|
|
else if (roomCellData.roomSummary.room.summary.membership == MXMembershipInvite)
|
2017-06-14 11:58:26 +00:00
|
|
|
{
|
|
|
|
self.missedNotifAndUnreadBadgeBgView.hidden = NO;
|
2019-02-12 18:06:22 +00:00
|
|
|
self.missedNotifAndUnreadBadgeBgView.backgroundColor = ThemeService.shared.theme.noticeColor;
|
2017-06-14 11:58:26 +00:00
|
|
|
|
|
|
|
self.missedNotifAndUnreadBadgeLabel.text = @"!";
|
|
|
|
[self.missedNotifAndUnreadBadgeLabel sizeToFit];
|
|
|
|
|
|
|
|
self.missedNotifAndUnreadBadgeBgViewWidthConstraint.constant = self.missedNotifAndUnreadBadgeLabel.frame.size.width + 18;
|
|
|
|
|
|
|
|
// Use bold font for the room title
|
|
|
|
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)])
|
|
|
|
{
|
2017-06-30 15:37:43 +00:00
|
|
|
self.roomTitle.font = self.roomTitle1.font = self.roomTitle2.font = [UIFont systemFontOfSize:13 weight:UIFontWeightBold];
|
2017-06-14 11:58:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-30 15:37:43 +00:00
|
|
|
self.roomTitle.font = self.roomTitle1.font = self.roomTitle2.font = [UIFont boldSystemFontOfSize:13];
|
2017-06-14 11:58:26 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-05 13:30:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// The room title is not bold anymore
|
|
|
|
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)])
|
|
|
|
{
|
2017-06-30 15:37:43 +00:00
|
|
|
self.roomTitle.font = self.roomTitle1.font = self.roomTitle2.font = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium];
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-30 15:37:43 +00:00
|
|
|
self.roomTitle.font = self.roomTitle1.font = self.roomTitle2.font = [UIFont systemFontOfSize:13];
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.directRoomBorderView.hidden = !roomCellData.roomSummary.room.isDirect;
|
|
|
|
|
|
|
|
self.encryptedRoomIcon.hidden = !roomCellData.roomSummary.isEncrypted;
|
|
|
|
|
2017-09-14 14:00:50 +00:00
|
|
|
[roomCellData.roomSummary setRoomAvatarImageIn:self.roomAvatar];
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:17:24 +00:00
|
|
|
- (MXKCellData*)renderedCellData
|
|
|
|
{
|
|
|
|
return roomCellData;
|
|
|
|
}
|
|
|
|
|
2017-05-05 13:30:35 +00:00
|
|
|
+ (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth
|
|
|
|
{
|
|
|
|
// The height is fixed
|
2017-06-30 15:37:43 +00:00
|
|
|
return 115;
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (CGSize)defaultCellSize
|
|
|
|
{
|
2017-06-30 15:37:43 +00:00
|
|
|
return CGSizeMake(80, 115);
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)prepareForReuse
|
|
|
|
{
|
|
|
|
[super prepareForReuse];
|
|
|
|
|
|
|
|
// Remove all gesture recognizers
|
|
|
|
while (self.gestureRecognizers.count)
|
|
|
|
{
|
|
|
|
[self removeGestureRecognizer:self.gestureRecognizers[0]];
|
|
|
|
}
|
|
|
|
self.tag = -1;
|
2017-07-09 16:32:40 +00:00
|
|
|
self.collectionViewTag = -1;
|
|
|
|
|
|
|
|
self.editionArrowView.hidden = YES;
|
2017-06-22 13:03:30 +00:00
|
|
|
|
|
|
|
roomCellData = nil;
|
2017-05-05 13:30:35 +00:00
|
|
|
}
|
|
|
|
|
2017-07-09 16:32:40 +00:00
|
|
|
- (NSString*)roomId
|
|
|
|
{
|
|
|
|
if (roomCellData)
|
|
|
|
{
|
|
|
|
return roomCellData.roomSummary.roomId;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2017-05-05 13:30:35 +00:00
|
|
|
@end
|
|
|
|
|