2015-11-18 13:42:25 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2017-02-14 17:21:46 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2019-03-07 09:42:55 +00:00
|
|
|
Copyright 2019 New Vector Ltd
|
2017-02-14 17:21:46 +00:00
|
|
|
|
2015-11-18 13:42: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.
|
|
|
|
*/
|
|
|
|
|
2015-11-24 12:34:08 +00:00
|
|
|
#import "RoomActivitiesView.h"
|
2015-11-18 13:42:25 +00:00
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
#import "ThemeService.h"
|
2019-01-10 16:50:26 +00:00
|
|
|
#import "Riot-Swift.h"
|
2015-11-26 17:04:03 +00:00
|
|
|
|
2016-02-25 12:54:53 +00:00
|
|
|
#import <objc/runtime.h>
|
|
|
|
|
2017-02-13 15:45:19 +00:00
|
|
|
@interface RoomActivitiesView ()
|
|
|
|
{
|
|
|
|
// The default height as defined in the xib
|
|
|
|
CGFloat xibMainHeightConstraint;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-11-24 12:34:08 +00:00
|
|
|
@implementation RoomActivitiesView
|
2015-11-18 13:42:25 +00:00
|
|
|
|
|
|
|
+ (UINib *)nib
|
|
|
|
{
|
2015-11-24 12:34:08 +00:00
|
|
|
return [UINib nibWithNibName:NSStringFromClass([RoomActivitiesView class])
|
|
|
|
bundle:[NSBundle bundleForClass:[RoomActivitiesView class]]];
|
2015-11-18 13:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)height
|
|
|
|
{
|
2017-02-13 15:45:19 +00:00
|
|
|
[self checkHeight:NO];
|
|
|
|
|
2015-11-18 13:42:25 +00:00
|
|
|
return self.mainHeightConstraint.constant;
|
|
|
|
}
|
|
|
|
|
2017-02-13 15:45:19 +00:00
|
|
|
- (void)setHeight:(CGFloat)height notify:(BOOL)notify
|
|
|
|
{
|
|
|
|
if (self.mainHeightConstraint.constant != height)
|
|
|
|
{
|
|
|
|
CGFloat oldHeight = self.mainHeightConstraint.constant;
|
|
|
|
self.mainHeightConstraint.constant = height;
|
|
|
|
|
|
|
|
if (notify && self.delegate)
|
|
|
|
{
|
|
|
|
[self.delegate didChangeHeight:self oldHeight:oldHeight newHeight:self.mainHeightConstraint.constant];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)checkHeight:(BOOL)notify
|
|
|
|
{
|
|
|
|
if (!self.messageTextView.isHidden)
|
|
|
|
{
|
|
|
|
// Compute the required height to display the text in messageTextView
|
2017-02-14 10:01:38 +00:00
|
|
|
CGFloat height = [self.messageTextView sizeThatFits:self.messageTextView.frame.size].height + 20; // 20 is the top and bottom margins in xib
|
2017-02-13 15:45:19 +00:00
|
|
|
|
|
|
|
height = MAX(xibMainHeightConstraint, height);
|
|
|
|
if (height != self.mainHeightConstraint.constant)
|
|
|
|
{
|
|
|
|
[self setHeight:height notify:notify];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// In other use case, come back to the default xib value
|
|
|
|
if (self.mainHeightConstraint.constant != xibMainHeightConstraint)
|
|
|
|
{
|
|
|
|
[self setHeight:xibMainHeightConstraint notify:notify];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSubviews
|
|
|
|
{
|
|
|
|
[super layoutSubviews];
|
|
|
|
|
|
|
|
// Check the required height in case on view update
|
|
|
|
// We need to delay the check in case of screen rotation to get the right screen width
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self checkHeight:YES];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:42:25 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[super awakeFromNib];
|
|
|
|
|
2016-03-07 12:56:52 +00:00
|
|
|
// Adjust text view
|
|
|
|
// Remove the container inset: this operation impacts only the vertical margin.
|
|
|
|
// Reset textContainer.lineFragmentPadding to remove horizontal margin.
|
|
|
|
self.messageTextView.textContainerInset = UIEdgeInsetsZero;
|
|
|
|
self.messageTextView.textContainer.lineFragmentPadding = 0;
|
2017-02-13 15:45:19 +00:00
|
|
|
|
|
|
|
xibMainHeightConstraint = self.mainHeightConstraint.constant;
|
2016-02-25 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 08:57:42 +00:00
|
|
|
#pragma mark - Override MXKView
|
|
|
|
|
|
|
|
-(void)customizeViewRendering
|
|
|
|
{
|
|
|
|
[super customizeViewRendering];
|
2020-07-10 14:43:20 +00:00
|
|
|
|
|
|
|
self.separatorView.backgroundColor = ThemeService.shared.theme.lineBreakColor;
|
2019-01-18 12:40:09 +00:00
|
|
|
if (self.messageLabel.textColor != ThemeService.shared.theme.warningColor)
|
2017-08-11 14:56:09 +00:00
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
self.messageLabel.textColor = ThemeService.shared.theme.textSecondaryColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
}
|
2017-08-08 08:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2017-03-07 15:46:56 +00:00
|
|
|
- (void)displayUnsentMessagesNotification:(NSString*)notification withResendLink:(void (^)(void))onResendLinkPressed andCancelLink:(void (^)(void))onCancelLinkPressed andIconTapGesture:(void (^)(void))onIconTapGesture
|
2016-02-25 12:54:53 +00:00
|
|
|
{
|
|
|
|
[self reset];
|
2017-02-14 10:01:38 +00:00
|
|
|
|
2017-03-07 15:46:56 +00:00
|
|
|
if (onResendLinkPressed && onCancelLinkPressed)
|
2016-02-25 12:54:53 +00:00
|
|
|
{
|
2016-03-07 12:56:52 +00:00
|
|
|
NSString *resendLink = NSLocalizedStringFromTable(@"room_prompt_resend", @"Vector", nil);
|
2017-03-07 15:46:56 +00:00
|
|
|
NSString *cancelLink = NSLocalizedStringFromTable(@"room_prompt_cancel", @"Vector", nil);
|
|
|
|
|
|
|
|
NSString *notif = [NSString stringWithFormat:notification, resendLink, cancelLink];
|
|
|
|
NSMutableAttributedString *tappableNotif = [[NSMutableAttributedString alloc] initWithString:notif];
|
2016-02-25 12:54:53 +00:00
|
|
|
|
2016-03-07 12:56:52 +00:00
|
|
|
objc_setAssociatedObject(self.messageTextView, "onResendLinkPressed", [onResendLinkPressed copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
2017-03-07 15:46:56 +00:00
|
|
|
objc_setAssociatedObject(self.messageTextView, "onCancelLinkPressed", [onCancelLinkPressed copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
|
|
|
|
NSRange range = [notif rangeOfString:resendLink];
|
2016-03-07 12:56:52 +00:00
|
|
|
[tappableNotif addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
|
|
|
|
[tappableNotif addAttribute:NSLinkAttributeName value:@"onResendLink" range:range];
|
2017-03-07 15:46:56 +00:00
|
|
|
|
|
|
|
range = [notif rangeOfString:cancelLink];
|
|
|
|
[tappableNotif addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
|
|
|
|
[tappableNotif addAttribute:NSLinkAttributeName value:@"onCancelLink" range:range];
|
2016-03-07 12:56:52 +00:00
|
|
|
|
|
|
|
NSRange wholeString = NSMakeRange(0, tappableNotif.length);
|
2019-01-18 12:40:09 +00:00
|
|
|
[tappableNotif addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.warningColor range:wholeString];
|
2016-03-07 12:56:52 +00:00
|
|
|
[tappableNotif addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:wholeString];
|
|
|
|
|
|
|
|
self.messageTextView.attributedText = tappableNotif;
|
2019-01-18 12:40:09 +00:00
|
|
|
self.messageTextView.tintColor = ThemeService.shared.theme.warningColor;
|
2016-03-07 12:56:52 +00:00
|
|
|
self.messageTextView.hidden = NO;
|
2016-09-19 08:23:19 +00:00
|
|
|
self.messageTextView.backgroundColor = [UIColor clearColor];
|
2016-02-25 12:54:53 +00:00
|
|
|
}
|
2016-03-07 12:56:52 +00:00
|
|
|
else
|
2016-02-25 12:54:53 +00:00
|
|
|
{
|
2016-03-07 12:56:52 +00:00
|
|
|
self.messageLabel.text = notification;
|
2019-01-18 12:40:09 +00:00
|
|
|
self.messageLabel.textColor = ThemeService.shared.theme.warningColor;
|
2016-03-07 12:56:52 +00:00
|
|
|
self.messageLabel.hidden = NO;
|
2016-02-25 12:54:53 +00:00
|
|
|
}
|
2016-03-07 12:56:52 +00:00
|
|
|
|
|
|
|
self.iconImageView.image = [UIImage imageNamed:@"error"];
|
2020-07-10 23:18:08 +00:00
|
|
|
self.iconImageView.tintColor = ThemeService.shared.theme.tintColor;
|
2016-03-07 12:56:52 +00:00
|
|
|
self.iconImageView.hidden = NO;
|
|
|
|
|
|
|
|
if (onIconTapGesture)
|
|
|
|
{
|
|
|
|
objc_setAssociatedObject(self.iconImageView, "onIconTapGesture", [onIconTapGesture copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
|
|
|
|
// Listen to icon tap
|
|
|
|
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onIconTap:)];
|
|
|
|
[tapGesture setNumberOfTouchesRequired:1];
|
|
|
|
[tapGesture setNumberOfTapsRequired:1];
|
|
|
|
[tapGesture setDelegate:self];
|
|
|
|
[self.iconImageView addGestureRecognizer:tapGesture];
|
|
|
|
self.iconImageView.userInteractionEnabled = YES;
|
|
|
|
}
|
2017-02-13 15:45:19 +00:00
|
|
|
|
|
|
|
[self checkHeight:YES];
|
2016-02-25 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)displayNetworkErrorNotification:(NSString*)labelText
|
|
|
|
{
|
|
|
|
[self reset];
|
2015-11-18 14:59:04 +00:00
|
|
|
|
2016-02-25 12:54:53 +00:00
|
|
|
if (labelText.length)
|
|
|
|
{
|
|
|
|
self.iconImageView.image = [UIImage imageNamed:@"error"];
|
2020-07-10 23:18:08 +00:00
|
|
|
self.iconImageView.tintColor = ThemeService.shared.theme.noticeColor;
|
2016-02-25 12:54:53 +00:00
|
|
|
self.messageLabel.text = labelText;
|
2019-01-18 12:40:09 +00:00
|
|
|
self.messageLabel.textColor = ThemeService.shared.theme.warningColor;
|
2016-02-25 12:54:53 +00:00
|
|
|
|
|
|
|
self.iconImageView.hidden = NO;
|
|
|
|
self.messageLabel.hidden = NO;
|
|
|
|
}
|
2017-02-13 15:45:19 +00:00
|
|
|
|
|
|
|
[self checkHeight:YES];
|
2015-11-18 13:42:25 +00:00
|
|
|
}
|
2015-11-18 14:59:04 +00:00
|
|
|
|
2016-02-25 12:54:53 +00:00
|
|
|
- (void)displayTypingNotification:(NSString*)labelText
|
2015-11-18 14:59:04 +00:00
|
|
|
{
|
2016-02-25 12:54:53 +00:00
|
|
|
[self reset];
|
|
|
|
|
|
|
|
if (labelText.length)
|
2015-11-18 14:59:04 +00:00
|
|
|
{
|
2016-02-25 12:54:53 +00:00
|
|
|
self.iconImageView.image = [UIImage imageNamed:@"typing"];
|
2020-07-10 23:21:38 +00:00
|
|
|
self.iconImageView.tintColor = ThemeService.shared.theme.tintColor;
|
2016-02-25 12:54:53 +00:00
|
|
|
self.messageLabel.text = labelText;
|
|
|
|
|
|
|
|
self.iconImageView.hidden = NO;
|
|
|
|
self.messageLabel.hidden = NO;
|
2015-11-18 14:59:04 +00:00
|
|
|
}
|
2017-02-13 15:45:19 +00:00
|
|
|
|
|
|
|
[self checkHeight:YES];
|
2016-02-25 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 10:17:07 +00:00
|
|
|
- (void)displayOngoingConferenceCall:(void (^)(BOOL))onOngoingConferenceCallPressed onClosePressed:(void (^)(void))onOngoingConferenceCallClosePressed
|
2016-08-08 16:40:22 +00:00
|
|
|
{
|
|
|
|
[self reset];
|
|
|
|
|
2016-09-06 11:30:06 +00:00
|
|
|
objc_setAssociatedObject(self.messageTextView, "onOngoingConferenceCallPressed", [onOngoingConferenceCallPressed copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
2016-08-08 16:40:22 +00:00
|
|
|
|
2016-09-06 11:30:06 +00:00
|
|
|
// Build the string to display in the banner
|
2017-08-17 10:17:07 +00:00
|
|
|
NSString *onGoingConferenceCall;
|
|
|
|
|
|
|
|
if (!onOngoingConferenceCallClosePressed)
|
|
|
|
{
|
|
|
|
onGoingConferenceCall = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_ongoing_conference_call", @"Vector", nil),
|
|
|
|
NSLocalizedStringFromTable(@"voice", @"Vector", nil),
|
|
|
|
NSLocalizedStringFromTable(@"video", @"Vector", nil)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Display the banner with a "Close it" string
|
|
|
|
objc_setAssociatedObject(self.messageTextView, "onOngoingConferenceCallClosePressed", [onOngoingConferenceCallClosePressed copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
|
|
|
|
onGoingConferenceCall = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_ongoing_conference_call_with_close", @"Vector", nil),
|
|
|
|
NSLocalizedStringFromTable(@"voice", @"Vector", nil),
|
|
|
|
NSLocalizedStringFromTable(@"video", @"Vector", nil),
|
|
|
|
NSLocalizedStringFromTable(@"room_ongoing_conference_call_close", @"Vector", nil)];
|
|
|
|
}
|
2016-08-08 16:40:22 +00:00
|
|
|
|
2016-09-06 11:30:06 +00:00
|
|
|
NSMutableAttributedString *onGoingConferenceCallAttibutedString = [[NSMutableAttributedString alloc] initWithString:onGoingConferenceCall];
|
|
|
|
|
|
|
|
// Add a link on the "voice" string
|
|
|
|
NSRange voiceRange = [onGoingConferenceCall rangeOfString:NSLocalizedStringFromTable(@"voice", @"Vector", nil)];
|
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:voiceRange];
|
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSLinkAttributeName value:@"onOngoingConferenceCallWithVoicePressed" range:voiceRange];
|
|
|
|
|
|
|
|
// Add a link on the "video" string
|
|
|
|
NSRange videoRange = [onGoingConferenceCall rangeOfString:NSLocalizedStringFromTable(@"video", @"Vector", nil)];
|
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:videoRange];
|
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSLinkAttributeName value:@"onOngoingConferenceCallWithVideoPressed" range:videoRange];
|
|
|
|
|
2017-08-17 10:17:07 +00:00
|
|
|
// Add a link on the "Close" string
|
|
|
|
if (onOngoingConferenceCallClosePressed)
|
|
|
|
{
|
|
|
|
NSRange closeRange = [onGoingConferenceCall rangeOfString:NSLocalizedStringFromTable(@"room_ongoing_conference_call_close", @"Vector", nil)];
|
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:closeRange];
|
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSLinkAttributeName value:@"onOngoingConferenceCallClosePressed" range:closeRange];
|
|
|
|
}
|
|
|
|
|
2016-09-06 11:30:06 +00:00
|
|
|
// Display the string in white on pink red
|
|
|
|
NSRange wholeString = NSMakeRange(0, onGoingConferenceCallAttibutedString.length);
|
2019-01-11 10:45:27 +00:00
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.backgroundColor range:wholeString];
|
2019-03-07 09:42:55 +00:00
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSBackgroundColorAttributeName value:ThemeService.shared.theme.tintColor range:wholeString];
|
2016-09-06 11:30:06 +00:00
|
|
|
[onGoingConferenceCallAttibutedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:wholeString];
|
|
|
|
|
|
|
|
self.messageTextView.attributedText = onGoingConferenceCallAttibutedString;
|
2019-01-11 10:45:27 +00:00
|
|
|
self.messageTextView.tintColor = ThemeService.shared.theme.backgroundColor;
|
2016-09-06 11:30:06 +00:00
|
|
|
self.messageTextView.hidden = NO;
|
|
|
|
|
2019-03-07 09:42:55 +00:00
|
|
|
self.backgroundColor = ThemeService.shared.theme.tintColor;
|
|
|
|
self.messageTextView.backgroundColor = ThemeService.shared.theme.tintColor;
|
2016-09-06 11:42:10 +00:00
|
|
|
|
2020-07-10 14:43:20 +00:00
|
|
|
// Hide the separator to display correctly the red pink conf call banner
|
|
|
|
self.separatorView.hidden = YES;
|
|
|
|
|
2017-02-13 15:45:19 +00:00
|
|
|
[self checkHeight:YES];
|
2016-08-08 16:40:22 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 16:34:00 +00:00
|
|
|
- (void)displayScrollToBottomIcon:(NSUInteger)newMessagesCount onIconTapGesture:(void (^)(void))onIconTapGesture
|
|
|
|
{
|
|
|
|
if (newMessagesCount)
|
|
|
|
{
|
|
|
|
[self reset];
|
|
|
|
|
2020-07-10 23:10:02 +00:00
|
|
|
self.iconImageView.image = [UIImage imageNamed:@"scrolldown"];
|
|
|
|
self.iconImageView.tintColor = ThemeService.shared.theme.noticeColor;
|
2016-08-29 16:34:00 +00:00
|
|
|
|
|
|
|
NSString *notification;
|
|
|
|
if (newMessagesCount > 1)
|
|
|
|
{
|
|
|
|
notification = NSLocalizedStringFromTable(@"room_new_messages_notification", @"Vector", nil);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notification = NSLocalizedStringFromTable(@"room_new_message_notification", @"Vector", nil);
|
|
|
|
}
|
|
|
|
self.messageLabel.text = [NSString stringWithFormat:notification, newMessagesCount];
|
2019-01-18 12:40:09 +00:00
|
|
|
self.messageLabel.textColor = ThemeService.shared.theme.warningColor;
|
2016-08-29 16:34:00 +00:00
|
|
|
self.messageLabel.hidden = NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We keep the current message if any
|
|
|
|
[self resetIcon];
|
|
|
|
|
|
|
|
self.iconImageView.image = [UIImage imageNamed:@"scrolldown"];
|
2020-07-10 23:10:02 +00:00
|
|
|
self.iconImageView.tintColor = ThemeService.shared.theme.textPrimaryColor;
|
2016-08-29 16:34:00 +00:00
|
|
|
}
|
|
|
|
self.iconImageView.hidden = NO;
|
2019-09-20 15:21:00 +00:00
|
|
|
|
|
|
|
// Make VoiceOver consider it as a button
|
|
|
|
self.iconImageView.accessibilityLabel = NSLocalizedStringFromTable(@"room_accessiblity_scroll_to_bottom", @"Vector", nil);
|
|
|
|
self.iconImageView.isAccessibilityElement = YES;
|
|
|
|
self.iconImageView.accessibilityTraits = UIAccessibilityTraitButton;
|
2016-08-29 16:34:00 +00:00
|
|
|
|
|
|
|
if (onIconTapGesture)
|
|
|
|
{
|
|
|
|
objc_setAssociatedObject(self.iconImageView, "onIconTapGesture", [onIconTapGesture copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
|
|
|
|
// Listen to icon tap
|
|
|
|
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onIconTap:)];
|
|
|
|
[tapGesture setNumberOfTouchesRequired:1];
|
|
|
|
[tapGesture setNumberOfTapsRequired:1];
|
|
|
|
[tapGesture setDelegate:self];
|
|
|
|
[self.iconImageView addGestureRecognizer:tapGesture];
|
|
|
|
self.iconImageView.userInteractionEnabled = YES;
|
|
|
|
}
|
2017-02-13 15:45:19 +00:00
|
|
|
|
|
|
|
[self checkHeight:YES];
|
2016-08-29 16:34:00 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 09:48:38 +00:00
|
|
|
- (void)displayRoomReplacementWithRoomLinkTappedHandler:(void (^)(void))onRoomReplacementLinkTapped
|
|
|
|
{
|
|
|
|
[self reset];
|
|
|
|
|
|
|
|
if (onRoomReplacementLinkTapped)
|
|
|
|
{
|
2018-07-27 16:33:46 +00:00
|
|
|
CGFloat fontSize = 15.0f;
|
|
|
|
|
2018-07-27 09:48:38 +00:00
|
|
|
objc_setAssociatedObject(self.messageTextView, "onRoomReplacementLinkTapped", [onRoomReplacementLinkTapped copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
|
|
|
|
NSDictionary *roomReplacementReasonAttributes = @{
|
2018-07-27 16:33:46 +00:00
|
|
|
NSFontAttributeName : [UIFont systemFontOfSize:fontSize weight:UIFontWeightBold]
|
2018-07-27 09:48:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
NSDictionary *roomLinkAttributes = @{
|
2018-07-27 16:33:46 +00:00
|
|
|
NSFontAttributeName : [UIFont systemFontOfSize:fontSize],
|
2018-07-27 09:48:38 +00:00
|
|
|
NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),
|
|
|
|
NSLinkAttributeName : @"onRoomReplacementLinkTapped",
|
|
|
|
};
|
|
|
|
|
|
|
|
NSMutableAttributedString *roomReplacementAttributedString = [NSMutableAttributedString new];
|
|
|
|
|
|
|
|
NSString *roomReplacementReasonString = [NSString stringWithFormat:@"%@\n", NSLocalizedStringFromTable(@"room_replacement_information", @"Vector", nil)];
|
|
|
|
|
2018-07-27 16:33:46 +00:00
|
|
|
NSAttributedString *roomReplacementReasonAttributedString = [[NSAttributedString alloc] initWithString:roomReplacementReasonString attributes:roomReplacementReasonAttributes];
|
2018-07-27 09:48:38 +00:00
|
|
|
|
|
|
|
NSString *roomLinkString = NSLocalizedStringFromTable(@"room_replacement_link", @"Vector", nil);
|
2018-07-27 16:33:46 +00:00
|
|
|
NSAttributedString *roomLinkAttributedString = [[NSAttributedString alloc] initWithString:roomLinkString attributes:roomLinkAttributes];
|
2018-07-27 09:48:38 +00:00
|
|
|
|
|
|
|
[roomReplacementAttributedString appendAttributedString:roomReplacementReasonAttributedString];
|
|
|
|
[roomReplacementAttributedString appendAttributedString:roomLinkAttributedString];
|
|
|
|
|
|
|
|
NSRange wholeStringRange = NSMakeRange(0, roomReplacementAttributedString.length);
|
2019-01-11 10:45:27 +00:00
|
|
|
[roomReplacementAttributedString addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.textPrimaryColor range:wholeStringRange];
|
2018-07-27 09:48:38 +00:00
|
|
|
|
|
|
|
self.messageTextView.attributedText = roomReplacementAttributedString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.messageTextView.text = NSLocalizedStringFromTable(@"room_replacement_information", @"Vector", nil);
|
|
|
|
}
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.messageTextView.tintColor = ThemeService.shared.theme.textPrimaryColor;
|
2018-07-27 09:48:38 +00:00
|
|
|
self.messageTextView.hidden = NO;
|
|
|
|
self.messageTextView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
|
|
|
self.iconImageView.image = [UIImage imageNamed:@"error"];
|
2020-07-10 23:18:08 +00:00
|
|
|
self.iconImageView.tintColor = ThemeService.shared.theme.noticeColor;
|
2018-07-27 09:48:38 +00:00
|
|
|
self.iconImageView.hidden = NO;
|
|
|
|
|
|
|
|
[self checkHeight:YES];
|
|
|
|
}
|
|
|
|
|
2018-08-21 16:25:56 +00:00
|
|
|
- (void)showResourceLimitExceededError:(NSDictionary *)errorDict onAdminContactTapped:(void (^)(NSURL *adminContact))onAdminContactTapped
|
|
|
|
{
|
|
|
|
// Parse error data
|
|
|
|
NSString *limitType, *adminContactString;
|
|
|
|
|
|
|
|
MXJSONModelSetString(limitType, errorDict[kMXErrorResourceLimitExceededLimitTypeKey]);
|
|
|
|
MXJSONModelSetString(adminContactString, errorDict[kMXErrorResourceLimitExceededAdminContactKey]);
|
|
|
|
|
2018-10-02 13:30:00 +00:00
|
|
|
[self showResourceLimit:limitType adminContactString:adminContactString hardLimit:YES onAdminContactTapped:(void (^)(NSURL *adminContact))onAdminContactTapped];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showResourceUsageLimitNotice:(MXServerNoticeContent *)usageLimit onAdminContactTapped:(void (^)(NSURL *))onAdminContactTapped
|
|
|
|
{
|
|
|
|
[self showResourceLimit:usageLimit.limitType adminContactString:usageLimit.adminContact hardLimit:NO onAdminContactTapped:onAdminContactTapped];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showResourceLimit:(NSString *)limitType adminContactString:(NSString *)adminContactString hardLimit:(BOOL)hardLimit onAdminContactTapped:(void (^)(NSURL *adminContact))onAdminContactTapped
|
|
|
|
{
|
|
|
|
[self reset];
|
|
|
|
|
|
|
|
CGFloat fontSize = 15;
|
|
|
|
|
|
|
|
NSURL *adminContact;
|
2018-08-21 16:25:56 +00:00
|
|
|
if (adminContactString)
|
|
|
|
{
|
|
|
|
adminContact = [NSURL URLWithString:adminContactString];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the message content
|
|
|
|
NSMutableString *message = [NSMutableString new];
|
2018-10-02 13:30:00 +00:00
|
|
|
NSAttributedString *message2;
|
|
|
|
if (hardLimit)
|
2018-08-21 16:25:56 +00:00
|
|
|
{
|
2018-10-02 13:30:00 +00:00
|
|
|
// Reuse MatrixKit as is for the beginning of hardLimit
|
|
|
|
if ([limitType isEqualToString:kMXErrorResourceLimitExceededLimitTypeMonthlyActiveUserValue])
|
|
|
|
{
|
|
|
|
[message appendString:[NSBundle mxk_localizedStringForKey:@"login_error_resource_limit_exceeded_message_monthly_active_user"]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[message appendString:[NSBundle mxk_localizedStringForKey:@"login_error_resource_limit_exceeded_message_default"]];
|
|
|
|
}
|
2018-08-21 16:25:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-02 13:30:00 +00:00
|
|
|
if ([limitType isEqualToString:kMXErrorResourceLimitExceededLimitTypeMonthlyActiveUserValue])
|
|
|
|
{
|
|
|
|
[message appendString:NSLocalizedStringFromTable(@"room_resource_usage_limit_reached_message_1_monthly_active_user", @"Vector", nil)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[message appendString:NSLocalizedStringFromTable(@"room_resource_usage_limit_reached_message_1_default", @"Vector", nil)];
|
|
|
|
}
|
|
|
|
|
|
|
|
message2 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_usage_limit_reached_message_2", @"Vector", nil)
|
|
|
|
attributes:@{
|
|
|
|
NSFontAttributeName: [UIFont boldSystemFontOfSize:fontSize],
|
2019-01-11 10:45:27 +00:00
|
|
|
NSForegroundColorAttributeName: ThemeService.shared.theme.backgroundColor
|
2018-10-02 13:30:00 +00:00
|
|
|
}];
|
2018-08-21 16:25:56 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 15:05:22 +00:00
|
|
|
NSDictionary *attributes = @{
|
|
|
|
NSFontAttributeName: [UIFont systemFontOfSize:fontSize],
|
2019-01-11 10:45:27 +00:00
|
|
|
NSForegroundColorAttributeName: ThemeService.shared.theme.backgroundColor
|
2018-08-24 15:05:22 +00:00
|
|
|
};
|
|
|
|
|
2018-08-21 16:25:56 +00:00
|
|
|
NSDictionary *messageContact2LinkAttributes;
|
|
|
|
if (adminContact && onAdminContactTapped)
|
|
|
|
{
|
|
|
|
void (^onAdminContactTappedLink)(void) = ^() {
|
|
|
|
onAdminContactTapped(adminContact);
|
|
|
|
};
|
|
|
|
|
|
|
|
objc_setAssociatedObject(self.messageTextView, "onAdminContactTappedLink", [onAdminContactTappedLink copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
messageContact2LinkAttributes = @{
|
|
|
|
NSFontAttributeName : [UIFont systemFontOfSize:fontSize],
|
|
|
|
NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),
|
|
|
|
NSLinkAttributeName : @"onAdminContactTappedLink",
|
|
|
|
};
|
|
|
|
}
|
2018-08-24 15:05:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
messageContact2LinkAttributes = attributes;
|
|
|
|
}
|
2018-08-21 16:25:56 +00:00
|
|
|
|
|
|
|
NSAttributedString *messageContact1 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_limit_exceeded_message_contact_1", @"Vector", nil) attributes:attributes];
|
|
|
|
NSAttributedString *messageContact2Link = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_limit_exceeded_message_contact_2_link", @"Vector", nil) attributes:messageContact2LinkAttributes];
|
2018-10-02 13:30:00 +00:00
|
|
|
NSAttributedString *messageContact3;
|
|
|
|
if (hardLimit)
|
|
|
|
{
|
|
|
|
messageContact3 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_limit_exceeded_message_contact_3", @"Vector", nil) attributes:attributes];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
messageContact3 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_usage_limit_reached_message_contact_3", @"Vector", nil) attributes:attributes];
|
|
|
|
}
|
2018-08-21 16:25:56 +00:00
|
|
|
|
|
|
|
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:message attributes:attributes];
|
2018-10-02 13:30:00 +00:00
|
|
|
if (message2)
|
|
|
|
{
|
|
|
|
[attributedText appendAttributedString:message2];
|
|
|
|
}
|
2018-08-21 16:25:56 +00:00
|
|
|
[attributedText appendAttributedString:messageContact1];
|
|
|
|
[attributedText appendAttributedString:messageContact2Link];
|
|
|
|
[attributedText appendAttributedString:messageContact3];
|
|
|
|
|
|
|
|
self.messageTextView.attributedText = attributedText;
|
2019-01-11 10:45:27 +00:00
|
|
|
self.messageTextView.tintColor = ThemeService.shared.theme.backgroundColor;
|
2018-08-21 16:25:56 +00:00
|
|
|
self.messageTextView.hidden = NO;
|
|
|
|
|
2018-10-02 13:30:00 +00:00
|
|
|
if (hardLimit)
|
|
|
|
{
|
2019-01-18 12:40:09 +00:00
|
|
|
self.backgroundColor = ThemeService.shared.theme.warningColor;
|
|
|
|
self.messageTextView.backgroundColor = ThemeService.shared.theme.warningColor;
|
2018-10-02 13:30:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-11 10:57:02 +00:00
|
|
|
self.backgroundColor = ThemeService.shared.riotColorCuriousBlue;
|
|
|
|
self.messageTextView.backgroundColor = ThemeService.shared.riotColorCuriousBlue;
|
2018-10-02 13:30:00 +00:00
|
|
|
}
|
2018-08-21 16:25:56 +00:00
|
|
|
|
2020-07-10 14:43:20 +00:00
|
|
|
// Hide the separator to display correctly the banner
|
|
|
|
self.separatorView.hidden = YES;
|
|
|
|
|
2018-08-21 16:25:56 +00:00
|
|
|
[self checkHeight:YES];
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:54:53 +00:00
|
|
|
- (void)reset
|
|
|
|
{
|
2020-07-10 14:43:20 +00:00
|
|
|
self.separatorView.hidden = NO;
|
|
|
|
|
|
|
|
self.backgroundColor = UIColor.clearColor;
|
2016-09-06 11:42:10 +00:00
|
|
|
|
2016-08-29 16:34:00 +00:00
|
|
|
[self resetIcon];
|
|
|
|
[self resetMessage];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resetIcon
|
|
|
|
{
|
|
|
|
self.iconImageView.hidden = YES;
|
2016-02-25 12:54:53 +00:00
|
|
|
|
2016-03-07 12:56:52 +00:00
|
|
|
// Remove all gesture recognizers
|
|
|
|
while (self.iconImageView.gestureRecognizers.count)
|
2015-11-18 14:59:04 +00:00
|
|
|
{
|
2016-03-07 12:56:52 +00:00
|
|
|
[self.iconImageView removeGestureRecognizer:self.iconImageView.gestureRecognizers[0]];
|
2015-11-18 14:59:04 +00:00
|
|
|
}
|
2016-03-07 12:56:52 +00:00
|
|
|
self.iconImageView.userInteractionEnabled = NO;
|
2016-02-25 12:54:53 +00:00
|
|
|
|
2016-03-07 12:56:52 +00:00
|
|
|
objc_removeAssociatedObjects(self.iconImageView);
|
2017-02-13 15:45:19 +00:00
|
|
|
|
|
|
|
[self checkHeight:YES];
|
2016-08-29 16:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resetMessage
|
|
|
|
{
|
|
|
|
self.messageLabel.hidden = YES;
|
|
|
|
|
|
|
|
[self.messageTextView resignFirstResponder];
|
|
|
|
self.messageTextView.hidden = YES;
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.messageLabel.textColor = ThemeService.shared.theme.textSecondaryColor;
|
2016-08-29 16:34:00 +00:00
|
|
|
|
2016-03-07 12:56:52 +00:00
|
|
|
objc_removeAssociatedObjects(self.messageTextView);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - UITextViewDelegate
|
|
|
|
|
|
|
|
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
|
|
|
|
{
|
|
|
|
if ([[URL absoluteString] isEqualToString:@"onResendLink"])
|
|
|
|
{
|
|
|
|
void (^onResendLinkPressed)(void) = objc_getAssociatedObject(self.messageTextView, "onResendLinkPressed");
|
|
|
|
if (onResendLinkPressed)
|
|
|
|
{
|
|
|
|
onResendLinkPressed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
2017-03-07 15:46:56 +00:00
|
|
|
else if ([[URL absoluteString] isEqualToString:@"onCancelLink"])
|
|
|
|
{
|
|
|
|
void (^onCancelLinkPressed)(void) = objc_getAssociatedObject(self.messageTextView, "onCancelLinkPressed");
|
|
|
|
if (onCancelLinkPressed)
|
|
|
|
{
|
|
|
|
onCancelLinkPressed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
2016-09-06 11:30:06 +00:00
|
|
|
else if ([[URL absoluteString] isEqualToString:@"onOngoingConferenceCallWithVoicePressed"])
|
|
|
|
{
|
|
|
|
void (^onOngoingConferenceCallPressed)(BOOL) = objc_getAssociatedObject(self.messageTextView, "onOngoingConferenceCallPressed");
|
|
|
|
if (onOngoingConferenceCallPressed)
|
|
|
|
{
|
|
|
|
onOngoingConferenceCallPressed(NO);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else if ([[URL absoluteString] isEqualToString:@"onOngoingConferenceCallWithVideoPressed"])
|
|
|
|
{
|
|
|
|
void (^onOngoingConferenceCallPressed)(BOOL) = objc_getAssociatedObject(self.messageTextView, "onOngoingConferenceCallPressed");
|
|
|
|
if (onOngoingConferenceCallPressed)
|
|
|
|
{
|
|
|
|
onOngoingConferenceCallPressed(YES);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
2017-08-17 10:17:07 +00:00
|
|
|
else if ([[URL absoluteString] isEqualToString:@"onOngoingConferenceCallClosePressed"])
|
|
|
|
{
|
|
|
|
void (^onOngoingConferenceCallClosePressed)(BOOL) = objc_getAssociatedObject(self.messageTextView, "onOngoingConferenceCallClosePressed");
|
|
|
|
if (onOngoingConferenceCallClosePressed)
|
|
|
|
{
|
|
|
|
onOngoingConferenceCallClosePressed(YES);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
2018-07-27 09:48:38 +00:00
|
|
|
}
|
|
|
|
else if ([[URL absoluteString] isEqualToString:@"onRoomReplacementLinkTapped"])
|
|
|
|
{
|
|
|
|
void (^onRoomReplacementLinkTapped)(void) = objc_getAssociatedObject(self.messageTextView, "onRoomReplacementLinkTapped");
|
|
|
|
if (onRoomReplacementLinkTapped)
|
|
|
|
{
|
|
|
|
onRoomReplacementLinkTapped();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
2018-08-21 16:25:56 +00:00
|
|
|
else if ([[URL absoluteString] isEqualToString:@"onAdminContactTappedLink"])
|
|
|
|
{
|
|
|
|
void (^onAdminContactTappedLink)(void) = objc_getAssociatedObject(self.messageTextView, "onAdminContactTappedLink");
|
|
|
|
if (onAdminContactTappedLink)
|
|
|
|
{
|
|
|
|
onAdminContactTappedLink();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
2018-07-27 09:48:38 +00:00
|
|
|
|
|
|
|
return YES;
|
2016-03-07 12:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - UIGestureRecognizerDelegate
|
|
|
|
|
|
|
|
- (void)onIconTap:(UITapGestureRecognizer*)sender
|
|
|
|
{
|
|
|
|
void (^onIconTapGesture)(void) = objc_getAssociatedObject(self.iconImageView, "onIconTapGesture");
|
|
|
|
if (onIconTapGesture)
|
|
|
|
{
|
|
|
|
onIconTapGesture ();
|
|
|
|
}
|
2015-11-18 14:59:04 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 13:42:25 +00:00
|
|
|
@end
|