Files
bundesmessenger-ios/Riot/Modules/Common/Recents/Views/RecentTableViewCell.m
T
JanNiklas Grabowski d07184c687 Merge commit 'ee6e5de4358a2c0a2705194cd954f9207ff772cf' into feature/5854_foss_merge
* commit 'ee6e5de4358a2c0a2705194cd954f9207ff772cf':
  finish version++
  version++
  Fix a bug where QR codes aren't detected if the camera is too close. (#7762)
  element-hq/element-meta/issues/2201 - Disable mark as unread - relates to element-hq/element-meta/issues/891 - relates to element-hq/element-ios/issues/7253
  Fix dictation when using the Rich Text Editor. (#7752)
  Prepare for new sprint
  finish version++
  version++
  changelog.d: Upgrade MatrixSDK version ([v0.27.6](https://github.com/matrix-org/matrix-ios-sdk/releases/tag/v0.27.6)).
  corrected translations
  Added translation using Weblate (Persian (Old))
  Translated using Weblate (Albanian)
  Translated using Weblate (Chinese (Simplified))
  Translated using Weblate (Chinese (Simplified))
  Translated using Weblate (Albanian)
  changelog
  fix
  Prepare for new sprint
  GH actions: remove triaging process and old GH projects

# Conflicts:
#	Config/AppVersion.xcconfig
#	Riot/Modules/ContextMenu/ActionProviders/RoomActionProvider.swift
2024-03-11 12:13:51 +01:00

231 lines
8.9 KiB
Objective-C

/*
Copyright 2015 OpenMarket Ltd
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 "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;
// bwi: 5203 add federation icon
self.federationImage = FederationIconHelper.shared.federationBadgeImage;
self.federationImageView = [[UIImageView alloc] initWithImage:self.federationImage];
self.federationImageView.translatesAutoresizingMaskIntoConstraints = NO;
self.federationImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:self.federationImageView];
// scale and new with federation icon
float scaleFactor = ((self.roomAvatar.frame.size.height * 0.34) / self.federationImage.size.height);
float imageWidth = scaleFactor * self.federationImage.size.width;
// offset federation icon
float offsetTrailing = 3 * scaleFactor;
float offsetBotom = 1;
[self.federationImageView.bottomAnchor constraintEqualToAnchor:self.roomAvatar.bottomAnchor constant:offsetBotom].active = YES;
[self.federationImageView.trailingAnchor constraintEqualToAnchor:self.roomAvatar.trailingAnchor constant:offsetTrailing].active = YES;
[self.federationImageView.heightAnchor constraintEqualToConstant:(self.roomAvatar.frame.size.height * 0.34)].active = YES;
[self.federationImageView.widthAnchor constraintEqualToConstant:imageWidth].active = YES;
}
- (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;
// bwi: 5203 add federation icon
self.federationImage = FederationIconHelper.shared.federationBadgeImage;
self.federationImageView.image = self.federationImage;
}
- (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)
{
// bwi: 5203 add federation icon
if (BWIBuildSettings.shared.isFederationEnabled)
{
MXRoom *room = [roomCellData.mxSession roomWithRoomId:roomCellData.roomSummary.roomId];
if (room.isPersonalNotesRoom)
{
self.federationImageView.hidden = YES;
}
else
{
if (room.isDirect)
{
if (room.isDMFederated)
{
self.federationImageView.hidden = NO;
}
else
{
self.federationImageView.hidden = YES;
}
}
else
{
[room getFederationStatusWithCompletion:^(BOOL isFederated) {
self.federationImageView.hidden = !isFederated;
}];
}
}
}
else
{
self.federationImageView.hidden = YES;
}
// 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)
{
if( [BWIBuildSettings.shared showMentionsInRoom] ) {
self.missedNotifAndUnreadIndicator.backgroundColor = [Mentions countMentionsWithRoomID:roomCellData.roomIdentifier] > 0 ? ThemeService.shared.theme.noticeColor : ThemeService.shared.theme.noticeSecondaryColor;
} else {
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];
}
// bwi: if the room is a personal notes room a local image is used as room avatar
PersonalNotesDefaultService *service = [[PersonalNotesDefaultService alloc] initWithMxSession:roomCellData.mxSession];
if (BWIBuildSettings.shared.bwiUseCustomPersonalNotesAvatar && [roomCellData.roomIdentifier isEqualToString:[service personalNotesRoomId]]) {
self.roomAvatar.image = [UIImage imageNamed:[service avatarImageUrl]];
} else {
[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