153 lines
5.2 KiB
Objective-C
153 lines
5.2 KiB
Objective-C
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2017 Vector Creations Ltd
|
|
Copyright 2015 OpenMarket Ltd
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
#import "RecentTableViewCell.h"
|
|
|
|
#import "AvatarGenerator.h"
|
|
|
|
#import "MXEvent.h"
|
|
#import "MXRoom+Riot.h"
|
|
|
|
#import "ThemeService.h"
|
|
#import "GeneratedInterface-Swift.h"
|
|
|
|
#import "MXRoomSummary+Riot.h"
|
|
|
|
@implementation RecentTableViewCell
|
|
|
|
#pragma mark - Class methods
|
|
|
|
- (void)awakeFromNib
|
|
{
|
|
[super awakeFromNib];
|
|
|
|
// Initialize unread count badge
|
|
[_missedNotifAndUnreadBadgeBgView.layer setCornerRadius:10];
|
|
_missedNotifAndUnreadBadgeBgViewWidthConstraint.constant = 0;
|
|
}
|
|
|
|
- (void)customizeTableViewCellRendering
|
|
{
|
|
[super customizeTableViewCellRendering];
|
|
|
|
self.contentView.backgroundColor = ThemeService.shared.theme.backgroundColor;
|
|
self.roomTitle.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
self.lastEventDescription.textColor = ThemeService.shared.theme.textSecondaryColor;
|
|
self.lastEventDate.textColor = ThemeService.shared.theme.textSecondaryColor;
|
|
self.missedNotifAndUnreadBadgeLabel.textColor = ThemeService.shared.theme.baseTextPrimaryColor;
|
|
self.presenceIndicatorView.borderColor = ThemeService.shared.theme.backgroundColor;
|
|
|
|
self.roomAvatar.defaultBackgroundColor = [UIColor clearColor];
|
|
}
|
|
|
|
- (void)layoutSubviews
|
|
{
|
|
[super layoutSubviews];
|
|
|
|
// Round image view
|
|
[_roomAvatar.layer setCornerRadius:_roomAvatar.frame.size.width / 2];
|
|
_roomAvatar.clipsToBounds = YES;
|
|
}
|
|
|
|
- (void)render:(MXKCellData *)cellData
|
|
{
|
|
// Hide by default missed notifications and unread widgets
|
|
self.missedNotifAndUnreadIndicator.hidden = YES;
|
|
self.missedNotifAndUnreadBadgeBgView.hidden = YES;
|
|
self.missedNotifAndUnreadBadgeBgViewWidthConstraint.constant = 0;
|
|
self.missedNotifAndUnreadBadgeLabel.text = @"";
|
|
|
|
roomCellData = (id<MXKRecentCellDataStoring>)cellData;
|
|
if (roomCellData)
|
|
{
|
|
// Report computed values as is
|
|
self.roomTitle.text = roomCellData.roomDisplayname;
|
|
self.lastEventDate.text = roomCellData.lastEventDate;
|
|
|
|
// Manage lastEventAttributedTextMessage optional property
|
|
if (!roomCellData.roomSummary.spaceChildInfo && [roomCellData respondsToSelector:@selector(lastEventAttributedTextMessage)])
|
|
{
|
|
// Attempt to correct the attributed string colors to match the current theme
|
|
self.lastEventDescription.attributedText = [roomCellData.lastEventAttributedTextMessage fixForegroundColor];
|
|
}
|
|
else
|
|
{
|
|
self.lastEventDescription.text = roomCellData.lastEventTextMessage;
|
|
}
|
|
|
|
self.unsentImageView.hidden = roomCellData.roomSummary.sentStatus == MXRoomSummarySentStatusOk;
|
|
self.lastEventDecriptionLabelTrailingConstraint.constant = self.unsentImageView.hidden ? 10 : 30;
|
|
|
|
// Notify unreads and bing
|
|
if (roomCellData.hasUnread)
|
|
{
|
|
self.missedNotifAndUnreadIndicator.hidden = NO;
|
|
if (0 < roomCellData.notificationCount)
|
|
{
|
|
self.missedNotifAndUnreadIndicator.backgroundColor = roomCellData.highlightCount ? ThemeService.shared.theme.noticeColor : ThemeService.shared.theme.noticeSecondaryColor;
|
|
|
|
self.missedNotifAndUnreadBadgeBgView.hidden = NO;
|
|
self.missedNotifAndUnreadBadgeBgView.backgroundColor = self.missedNotifAndUnreadIndicator.backgroundColor;
|
|
|
|
self.missedNotifAndUnreadBadgeLabel.text = roomCellData.notificationCountStringValue;
|
|
[self.missedNotifAndUnreadBadgeLabel sizeToFit];
|
|
|
|
self.missedNotifAndUnreadBadgeBgViewWidthConstraint.constant = self.missedNotifAndUnreadBadgeLabel.frame.size.width + 18;
|
|
}
|
|
else
|
|
{
|
|
self.missedNotifAndUnreadIndicator.backgroundColor = ThemeService.shared.theme.unreadRoomIndentColor;
|
|
}
|
|
|
|
// Use bold font for the room title
|
|
self.roomTitle.font = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
|
|
}
|
|
else
|
|
{
|
|
self.lastEventDate.textColor = ThemeService.shared.theme.textSecondaryColor;
|
|
|
|
// The room title is not bold anymore
|
|
self.roomTitle.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
|
|
}
|
|
|
|
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.avatarUrl
|
|
roomId:roomCellData.roomIdentifier
|
|
displayName:roomCellData.roomDisplayname
|
|
mediaManager:roomCellData.mxSession.mediaManager];
|
|
|
|
if (roomCellData.directUserId)
|
|
{
|
|
[self.presenceIndicatorView configureWithUserId:roomCellData.directUserId presence:roomCellData.presence];
|
|
}
|
|
else
|
|
{
|
|
[self.presenceIndicatorView stopListeningPresenceUpdates];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
self.lastEventDescription.text = @"";
|
|
}
|
|
}
|
|
|
|
- (void)prepareForReuse
|
|
{
|
|
[super prepareForReuse];
|
|
|
|
[self.presenceIndicatorView stopListeningPresenceUpdates];
|
|
}
|
|
|
|
+ (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth
|
|
{
|
|
// The height is fixed
|
|
return 74;
|
|
}
|
|
|
|
@end
|