element-ios/Riot/Modules/Room/Views/Title/RoomTitleView.m

193 lines
6.7 KiB
Mathematica
Raw Normal View History

/*
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 "RoomTitleView.h"
#import "ThemeService.h"
#import "Riot-Swift.h"
@implementation RoomTitleView
+ (UINib *)nib
{
return [UINib nibWithNibName:NSStringFromClass([RoomTitleView class])
bundle:[NSBundle bundleForClass:[RoomTitleView class]]];
}
- (void)dealloc
{
_roomPreviewData = nil;
}
- (void)awakeFromNib
{
[super awakeFromNib];
2020-04-08 13:06:59 +00:00
self.badgeImageView.image = nil;
2016-04-14 00:34:30 +00:00
if (_titleMask)
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reportTapGesture:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[self.titleMask addGestureRecognizer:tap];
self.titleMask.userInteractionEnabled = YES;
self.dotView.layer.masksToBounds = YES;
self.dotView.layer.cornerRadius = CGRectGetMidX(self.dotView.bounds);
2016-04-14 00:34:30 +00:00
}
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.pictureView.layer.cornerRadius = self.pictureView.bounds.size.width / 2.;
if (self.superview)
{
2020-09-01 12:19:21 +00:00
// Force the title view layout by adding 2 new constraints on the UINavigationBarContentView instance.
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.superview
attribute:NSLayoutAttributeTop
multiplier:1.0f
constant:0.0f];
NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.superview
2020-09-01 12:19:21 +00:00
attribute:NSLayoutAttributeCenterX
multiplier:1.0f
constant:0.0f];
2020-09-01 12:19:21 +00:00
[NSLayoutConstraint activateConstraints:@[topConstraint, centerXConstraint]];
}
}
-(void)customizeViewRendering
{
[super customizeViewRendering];
self.backgroundColor = UIColor.clearColor;
2020-07-02 17:06:14 +00:00
self.displayNameTextField.textColor = (self.mxRoom.summary.displayname.length ? ThemeService.shared.theme.textPrimaryColor : ThemeService.shared.theme.textSecondaryColor);
self.typingLabel.textColor = ThemeService.shared.theme.textSecondaryColor;
self.dotView.backgroundColor = ThemeService.shared.theme.warningColor;
self.missedDiscussionsBadgeLabel.textColor = ThemeService.shared.theme.tintColor;
}
- (void)setRoomPreviewData:(RoomPreviewData *)roomPreviewData
{
_roomPreviewData = roomPreviewData;
[self refreshDisplay];
}
- (void)refreshDisplay
{
[super refreshDisplay];
// Consider in priority the preview data (if any)
if (self.roomPreviewData)
{
self.displayNameTextField.text = self.roomPreviewData.roomName;
}
else if (self.mxRoom)
{
self.displayNameTextField.text = self.mxRoom.summary.displayname;
if (!self.displayNameTextField.text.length)
{
self.displayNameTextField.text = [NSBundle mxk_localizedStringForKey:@"room_displayname_empty_room"];
2019-01-11 10:45:27 +00:00
self.displayNameTextField.textColor = ThemeService.shared.theme.textSecondaryColor;
}
else
{
2020-07-02 17:06:14 +00:00
self.displayNameTextField.textColor = ThemeService.shared.theme.textPrimaryColor;
}
}
}
- (void)destroy
{
self.tapGestureDelegate = nil;
[super destroy];
}
2016-02-10 09:59:48 +00:00
- (void)reportTapGesture:(UITapGestureRecognizer*)tapGestureRecognizer
{
if (self.tapGestureDelegate)
{
[self.tapGestureDelegate roomTitleView:self recognizeTapGesture:tapGestureRecognizer];
}
}
- (void)updateLayoutForOrientation:(UIInterfaceOrientation)orientation
{
if (UIInterfaceOrientationIsLandscape(orientation))
{
self.missedDiscussionsBadgeLabel.font = [UIFont systemFontOfSize:10];
self.missedDiscussionsBadgeLabelLeadingConstraint.constant = -24;
self.pictureViewWidthConstraint.constant = 28;
self.pictureViewHeightConstraint.constant = 28;
self.displayNameTextField.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
self.typingLabel.font = [UIFont systemFontOfSize:10];
}
else
{
self.missedDiscussionsBadgeLabel.font = [UIFont systemFontOfSize:15];
self.missedDiscussionsBadgeLabelLeadingConstraint.constant = -32;
self.pictureViewWidthConstraint.constant = 32;
self.pictureViewHeightConstraint.constant = 32;
self.displayNameTextField.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
self.typingLabel.font = [UIFont systemFontOfSize:12];
}
}
- (void)setTypingNotificationString:(NSString *)typingNotificationString
{
if (typingNotificationString.length > 0)
{
self.typingLabel.text = typingNotificationString;
[self layoutIfNeeded];
[UIView animateWithDuration:.1 animations:^{
self.typingLabel.alpha = 1;
self.displayNameCenterYConstraint.constant = -8;
[self layoutIfNeeded];
}];
}
else
{
[UIView animateWithDuration:.1 animations:^{
self.typingLabel.alpha = 0;
self.displayNameCenterYConstraint.constant = 0;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
self.typingLabel.text = nil;
}];
}
}
- (NSString *)typingNotificationString
{
return self.typingLabel.text;
}
@end