2015-08-18 08:04:30 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2017-03-08 15:14:41 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-08-18 08:04:30 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RoomInputToolbarView.h"
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
#import "ThemeService.h"
|
2018-11-30 16:10:28 +00:00
|
|
|
#import "Riot-Swift.h"
|
2015-12-16 21:36:14 +00:00
|
|
|
|
2017-05-19 12:46:30 +00:00
|
|
|
#import "GBDeviceInfo_iOS.h"
|
|
|
|
|
2017-03-09 10:50:12 +00:00
|
|
|
#import "UINavigationController+Riot.h"
|
2016-09-22 13:32:13 +00:00
|
|
|
|
2015-09-02 07:43:52 +00:00
|
|
|
#import <MediaPlayer/MediaPlayer.h>
|
|
|
|
|
2015-09-08 15:22:39 +00:00
|
|
|
#import <Photos/Photos.h>
|
2015-08-18 08:04:30 +00:00
|
|
|
|
2017-02-28 09:24:27 +00:00
|
|
|
#import <MobileCoreServices/MobileCoreServices.h>
|
|
|
|
|
2018-05-24 09:56:33 +00:00
|
|
|
#import "WidgetManager.h"
|
|
|
|
#import "IntegrationManagerViewController.h"
|
|
|
|
|
2015-08-18 08:04:30 +00:00
|
|
|
@interface RoomInputToolbarView()
|
|
|
|
{
|
2018-05-24 09:56:33 +00:00
|
|
|
// The intermediate action sheet
|
|
|
|
UIAlertController *actionSheet;
|
2015-08-18 08:04:30 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 15:56:59 +00:00
|
|
|
@property(nonatomic, weak) MediaPickerViewController *mediaPicker;
|
|
|
|
|
2015-08-18 08:04:30 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RoomInputToolbarView
|
2018-05-24 09:56:33 +00:00
|
|
|
@dynamic delegate;
|
2015-08-18 08:04:30 +00:00
|
|
|
|
|
|
|
+ (UINib *)nib
|
|
|
|
{
|
|
|
|
return [UINib nibWithNibName:NSStringFromClass([RoomInputToolbarView class])
|
|
|
|
bundle:[NSBundle bundleForClass:[RoomInputToolbarView class]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (instancetype)roomInputToolbarView
|
|
|
|
{
|
|
|
|
if ([[self class] nib])
|
|
|
|
{
|
|
|
|
return [[[self class] nib] instantiateWithOwner:nil options:nil].firstObject;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return [[self alloc] init];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[super awakeFromNib];
|
|
|
|
|
2016-03-11 13:45:06 +00:00
|
|
|
_supportCallOption = YES;
|
2019-04-30 15:07:43 +00:00
|
|
|
_sendMode = RoomInputToolbarViewSendModeSend;
|
2016-03-11 13:45:06 +00:00
|
|
|
|
2015-08-25 13:42:19 +00:00
|
|
|
self.rightInputToolbarButton.hidden = YES;
|
2015-12-16 21:36:14 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
[self.rightInputToolbarButton setTitleColor:ThemeService.shared.theme.tintColor forState:UIControlStateNormal];
|
|
|
|
[self.rightInputToolbarButton setTitleColor:ThemeService.shared.theme.tintColor forState:UIControlStateHighlighted];
|
2016-07-15 13:10:59 +00:00
|
|
|
|
2017-08-08 08:57:42 +00:00
|
|
|
self.isEncryptionEnabled = _isEncryptionEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Override MXKView
|
|
|
|
|
|
|
|
-(void)customizeViewRendering
|
|
|
|
{
|
|
|
|
[super customizeViewRendering];
|
|
|
|
|
|
|
|
// Remove default toolbar background color
|
|
|
|
self.backgroundColor = [UIColor clearColor];
|
|
|
|
|
2019-02-18 11:53:13 +00:00
|
|
|
self.separatorView.backgroundColor = ThemeService.shared.theme.lineBreakColor;
|
2015-12-16 21:36:14 +00:00
|
|
|
|
|
|
|
// Custom the growingTextView display
|
|
|
|
growingTextView.layer.cornerRadius = 0;
|
|
|
|
growingTextView.layer.borderWidth = 0;
|
|
|
|
growingTextView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
|
|
|
growingTextView.font = [UIFont systemFontOfSize:15];
|
2019-01-11 10:45:27 +00:00
|
|
|
growingTextView.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
growingTextView.tintColor = ThemeService.shared.theme.tintColor;
|
2017-11-22 02:55:11 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
growingTextView.internalTextView.keyboardAppearance = ThemeService.shared.theme.keyboardAppearance;
|
2015-08-18 08:04:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 08:57:42 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2016-03-11 13:45:06 +00:00
|
|
|
- (void)setSupportCallOption:(BOOL)supportCallOption
|
|
|
|
{
|
|
|
|
if (_supportCallOption != supportCallOption)
|
|
|
|
{
|
|
|
|
_supportCallOption = supportCallOption;
|
|
|
|
|
|
|
|
if (supportCallOption)
|
|
|
|
{
|
|
|
|
self.voiceCallButtonWidthConstraint.constant = 46;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.voiceCallButtonWidthConstraint.constant = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setNeedsUpdateConstraints];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 09:58:11 +00:00
|
|
|
- (void)setIsEncryptionEnabled:(BOOL)isEncryptionEnabled
|
2016-11-07 10:36:32 +00:00
|
|
|
{
|
2017-05-19 12:46:30 +00:00
|
|
|
_isEncryptionEnabled = isEncryptionEnabled;
|
|
|
|
|
|
|
|
// Consider the default placeholder
|
|
|
|
NSString *placeholder= NSLocalizedStringFromTable(@"room_message_short_placeholder", @"Vector", nil);
|
|
|
|
|
|
|
|
if (_isEncryptionEnabled)
|
2016-11-07 10:36:32 +00:00
|
|
|
{
|
2016-11-10 15:23:43 +00:00
|
|
|
self.encryptedRoomIcon.image = [UIImage imageNamed:@"e2e_verified"];
|
2017-05-19 12:46:30 +00:00
|
|
|
|
|
|
|
// Check the device screen size before using large placeholder
|
|
|
|
if ([GBDeviceInfo deviceInfo].family == GBDeviceFamilyiPad || [GBDeviceInfo deviceInfo].displayInfo.display >= GBDeviceDisplay4p7Inch)
|
|
|
|
{
|
|
|
|
placeholder = NSLocalizedStringFromTable(@"encrypted_room_message_placeholder", @"Vector", nil);
|
|
|
|
}
|
2016-11-07 10:36:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-10 15:23:43 +00:00
|
|
|
self.encryptedRoomIcon.image = [UIImage imageNamed:@"e2e_unencrypted"];
|
2017-05-19 12:46:30 +00:00
|
|
|
|
|
|
|
// Check the device screen size before using large placeholder
|
|
|
|
if ([GBDeviceInfo deviceInfo].family == GBDeviceFamilyiPad || [GBDeviceInfo deviceInfo].displayInfo.display >= GBDeviceDisplay4p7Inch)
|
|
|
|
{
|
|
|
|
placeholder = NSLocalizedStringFromTable(@"room_message_placeholder", @"Vector", nil);
|
|
|
|
}
|
2016-11-07 10:36:32 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 12:46:30 +00:00
|
|
|
|
|
|
|
self.placeholder = placeholder;
|
2016-11-07 10:36:32 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 15:07:43 +00:00
|
|
|
- (void)setSendMode:(RoomInputToolbarViewSendMode)sendMode
|
2018-07-23 14:54:23 +00:00
|
|
|
{
|
2019-04-30 15:07:43 +00:00
|
|
|
_sendMode = sendMode;
|
|
|
|
|
2018-07-23 14:54:23 +00:00
|
|
|
[self updatePlaceholder];
|
2019-04-30 15:27:57 +00:00
|
|
|
[self updateToolbarButtonLabel];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateToolbarButtonLabel
|
|
|
|
{
|
|
|
|
NSString *title;
|
|
|
|
|
|
|
|
switch (_sendMode)
|
|
|
|
{
|
|
|
|
case RoomInputToolbarViewSendModeReply:
|
|
|
|
title = NSLocalizedStringFromTable(@"room_action_reply", @"Vector", nil);
|
|
|
|
break;
|
2019-06-13 14:37:28 +00:00
|
|
|
case RoomInputToolbarViewSendModeEdit:
|
|
|
|
title = NSLocalizedStringFromTable(@"save", @"Vector", nil);
|
|
|
|
break;
|
2019-04-30 15:27:57 +00:00
|
|
|
default:
|
|
|
|
title = [NSBundle mxk_localizedStringForKey:@"send"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.rightInputToolbarButton setTitle:title forState:UIControlStateNormal];
|
|
|
|
[self.rightInputToolbarButton setTitle:title forState:UIControlStateHighlighted];
|
2018-07-23 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updatePlaceholder
|
|
|
|
{
|
|
|
|
// Consider the default placeholder
|
|
|
|
|
|
|
|
NSString *placeholder;
|
|
|
|
|
|
|
|
// Check the device screen size before using large placeholder
|
|
|
|
BOOL shouldDisplayLargePlaceholder = [GBDeviceInfo deviceInfo].family == GBDeviceFamilyiPad || [GBDeviceInfo deviceInfo].displayInfo.display >= GBDeviceDisplay4p7Inch;
|
|
|
|
|
2018-07-24 11:32:40 +00:00
|
|
|
if (!shouldDisplayLargePlaceholder)
|
2018-07-23 14:54:23 +00:00
|
|
|
{
|
2019-04-30 15:07:43 +00:00
|
|
|
switch (_sendMode)
|
|
|
|
{
|
|
|
|
case RoomInputToolbarViewSendModeReply:
|
|
|
|
placeholder = NSLocalizedStringFromTable(@"room_message_reply_to_short_placeholder", @"Vector", nil);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
placeholder = NSLocalizedStringFromTable(@"room_message_short_placeholder", @"Vector", nil);
|
|
|
|
break;
|
|
|
|
}
|
2018-07-23 14:54:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_isEncryptionEnabled)
|
|
|
|
{
|
2019-04-30 15:07:43 +00:00
|
|
|
switch (_sendMode)
|
|
|
|
{
|
|
|
|
case RoomInputToolbarViewSendModeReply:
|
|
|
|
placeholder = NSLocalizedStringFromTable(@"encrypted_room_message_reply_to_placeholder", @"Vector", nil);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
placeholder = NSLocalizedStringFromTable(@"encrypted_room_message_placeholder", @"Vector", nil);
|
|
|
|
break;
|
|
|
|
}
|
2018-07-23 14:54:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-30 15:07:43 +00:00
|
|
|
switch (_sendMode)
|
|
|
|
{
|
|
|
|
case RoomInputToolbarViewSendModeReply:
|
|
|
|
placeholder = NSLocalizedStringFromTable(@"room_message_reply_to_placeholder", @"Vector", nil);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
placeholder = NSLocalizedStringFromTable(@"room_message_placeholder", @"Vector", nil);
|
|
|
|
break;
|
|
|
|
}
|
2018-07-23 14:54:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.placeholder = placeholder;
|
|
|
|
}
|
|
|
|
|
2016-08-09 12:17:18 +00:00
|
|
|
- (void)setActiveCall:(BOOL)activeCall
|
|
|
|
{
|
|
|
|
if (_activeCall != activeCall)
|
|
|
|
{
|
|
|
|
_activeCall = activeCall;
|
|
|
|
|
2016-09-14 14:18:16 +00:00
|
|
|
self.voiceCallButton.hidden = (_activeCall || !self.rightInputToolbarButton.hidden);
|
|
|
|
self.hangupCallButton.hidden = (!_activeCall || !self.rightInputToolbarButton.hidden);
|
2016-08-09 12:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 08:04:30 +00:00
|
|
|
#pragma mark - HPGrowingTextView delegate
|
|
|
|
|
2015-12-16 21:36:14 +00:00
|
|
|
//- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)hpGrowingTextView
|
|
|
|
//{
|
|
|
|
// // The return sends the message rather than giving a carriage return.
|
|
|
|
// [self onTouchUpInside:self.rightInputToolbarButton];
|
|
|
|
//
|
|
|
|
// return NO;
|
|
|
|
//}
|
2015-08-18 08:04:30 +00:00
|
|
|
|
2015-12-16 21:36:14 +00:00
|
|
|
- (void)growingTextViewDidChange:(HPGrowingTextView *)hpGrowingTextView
|
2015-08-18 08:04:30 +00:00
|
|
|
{
|
2015-08-18 08:51:28 +00:00
|
|
|
// Clean the carriage return added on return press
|
|
|
|
if ([self.textMessage isEqualToString:@"\n"])
|
2015-08-18 08:04:30 +00:00
|
|
|
{
|
2015-08-18 08:51:28 +00:00
|
|
|
self.textMessage = nil;
|
2015-08-18 08:04:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 21:36:14 +00:00
|
|
|
[super growingTextViewDidChange:hpGrowingTextView];
|
2015-08-25 13:42:19 +00:00
|
|
|
|
2016-11-11 17:31:44 +00:00
|
|
|
if (self.rightInputToolbarButton.isEnabled && self.rightInputToolbarButton.isHidden)
|
2015-08-25 13:42:19 +00:00
|
|
|
{
|
|
|
|
self.rightInputToolbarButton.hidden = NO;
|
|
|
|
self.attachMediaButton.hidden = YES;
|
2015-12-04 15:06:11 +00:00
|
|
|
self.voiceCallButton.hidden = YES;
|
2016-09-14 14:18:16 +00:00
|
|
|
self.hangupCallButton.hidden = YES;
|
2015-08-25 16:36:27 +00:00
|
|
|
|
2015-08-25 13:42:19 +00:00
|
|
|
self.messageComposerContainerTrailingConstraint.constant = self.frame.size.width - self.rightInputToolbarButton.frame.origin.x + 4;
|
|
|
|
}
|
2016-11-11 17:31:44 +00:00
|
|
|
else if (!self.rightInputToolbarButton.isEnabled && !self.rightInputToolbarButton.isHidden)
|
2015-08-25 13:42:19 +00:00
|
|
|
{
|
2016-11-11 17:31:44 +00:00
|
|
|
self.rightInputToolbarButton.hidden = YES;
|
|
|
|
self.attachMediaButton.hidden = NO;
|
2016-11-16 14:35:46 +00:00
|
|
|
self.voiceCallButton.hidden = _activeCall;
|
|
|
|
self.hangupCallButton.hidden = !_activeCall;
|
2016-11-11 17:31:44 +00:00
|
|
|
|
|
|
|
self.messageComposerContainerTrailingConstraint.constant = self.frame.size.width - self.attachMediaButton.frame.origin.x + 4;
|
2015-08-25 13:42:19 +00:00
|
|
|
}
|
2015-08-18 08:04:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 21:36:14 +00:00
|
|
|
- (void)growingTextView:(HPGrowingTextView *)hpGrowingTextView willChangeHeight:(float)height
|
2015-08-18 14:24:48 +00:00
|
|
|
{
|
2015-08-25 16:36:27 +00:00
|
|
|
// Update height of the main toolbar (message composer)
|
2015-12-16 21:36:14 +00:00
|
|
|
CGFloat updatedHeight = height + (self.messageComposerContainerTopConstraint.constant + self.messageComposerContainerBottomConstraint.constant);
|
|
|
|
|
|
|
|
if (updatedHeight < self.mainToolbarMinHeightConstraint.constant)
|
|
|
|
{
|
|
|
|
updatedHeight = self.mainToolbarMinHeightConstraint.constant;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.mainToolbarHeightConstraint.constant = updatedHeight;
|
2015-08-25 16:36:27 +00:00
|
|
|
|
|
|
|
// Update toolbar superview
|
|
|
|
if ([self.delegate respondsToSelector:@selector(roomInputToolbarView:heightDidChanged:completion:)])
|
|
|
|
{
|
2015-12-16 21:36:14 +00:00
|
|
|
[self.delegate roomInputToolbarView:self heightDidChanged:updatedHeight completion:nil];
|
2015-08-25 16:36:27 +00:00
|
|
|
}
|
2015-08-18 14:24:48 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 08:04:30 +00:00
|
|
|
#pragma mark - Override MXKRoomInputToolbarView
|
|
|
|
|
|
|
|
- (IBAction)onTouchUpInside:(UIButton*)button
|
|
|
|
{
|
2015-08-18 08:51:28 +00:00
|
|
|
if (button == self.attachMediaButton)
|
2015-08-18 08:04:30 +00:00
|
|
|
{
|
|
|
|
// Check whether media attachment is supported
|
|
|
|
if ([self.delegate respondsToSelector:@selector(roomInputToolbarView:presentViewController:)])
|
|
|
|
{
|
2018-05-24 09:56:33 +00:00
|
|
|
// Ask the user the kind of the call: voice or video?
|
|
|
|
actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_action_send_photo_or_video", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->actionSheet = nil;
|
|
|
|
|
|
|
|
[self showMediaPicker];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_action_send_sticker", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->actionSheet = nil;
|
|
|
|
|
|
|
|
[self.delegate roomInputToolbarViewPresentStickerPicker:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
2019-07-11 17:03:32 +00:00
|
|
|
|
|
|
|
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_action_send_file", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->actionSheet = nil;
|
|
|
|
|
|
|
|
[self.delegate roomInputToolbarViewDidTapFileUpload:self];
|
|
|
|
}
|
|
|
|
}]];
|
2018-05-24 09:56:33 +00:00
|
|
|
|
|
|
|
[actionSheet addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
|
|
|
style:UIAlertActionStyleCancel
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
self->actionSheet = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[actionSheet popoverPresentationController].sourceView = self.voiceCallButton;
|
|
|
|
[actionSheet popoverPresentationController].sourceRect = self.voiceCallButton.bounds;
|
|
|
|
[self.window.rootViewController presentViewController:actionSheet animated:YES completion:nil];
|
2015-08-18 08:04:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog(@"[RoomInputToolbarView] Attach media is not supported");
|
|
|
|
}
|
|
|
|
}
|
2015-12-04 15:06:11 +00:00
|
|
|
else if (button == self.voiceCallButton)
|
2015-08-18 14:24:48 +00:00
|
|
|
{
|
|
|
|
if ([self.delegate respondsToSelector:@selector(roomInputToolbarView:placeCallWithVideo:)])
|
|
|
|
{
|
2016-04-08 14:34:52 +00:00
|
|
|
// Ask the user the kind of the call: voice or video?
|
2018-05-24 09:56:33 +00:00
|
|
|
actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
2016-04-08 14:34:52 +00:00
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
2018-05-24 09:56:33 +00:00
|
|
|
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"voice", @"Vector", nil)
|
2017-07-14 14:41:25 +00:00
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
2018-05-24 09:56:33 +00:00
|
|
|
self->actionSheet = nil;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
|
|
|
[self.delegate roomInputToolbarView:self placeCallWithVideo:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
2016-04-08 14:34:52 +00:00
|
|
|
|
2018-05-24 09:56:33 +00:00
|
|
|
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"video", @"Vector", nil)
|
2017-07-14 14:41:25 +00:00
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
2018-05-24 09:56:33 +00:00
|
|
|
self->actionSheet = nil;
|
2017-07-14 14:41:25 +00:00
|
|
|
|
|
|
|
[self.delegate roomInputToolbarView:self placeCallWithVideo:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
2018-05-24 09:56:33 +00:00
|
|
|
[actionSheet addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
2018-01-19 02:43:28 +00:00
|
|
|
style:UIAlertActionStyleCancel
|
2017-07-14 14:41:25 +00:00
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
typeof(self) self = weakSelf;
|
2018-05-24 09:56:33 +00:00
|
|
|
self->actionSheet = nil;
|
2017-07-14 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
2018-05-24 09:56:33 +00:00
|
|
|
[actionSheet popoverPresentationController].sourceView = self.voiceCallButton;
|
|
|
|
[actionSheet popoverPresentationController].sourceRect = self.voiceCallButton.bounds;
|
|
|
|
[self.window.rootViewController presentViewController:actionSheet animated:YES completion:nil];
|
2015-08-18 14:24:48 +00:00
|
|
|
}
|
2015-08-18 08:04:30 +00:00
|
|
|
}
|
2016-08-09 12:17:18 +00:00
|
|
|
else if (button == self.hangupCallButton)
|
|
|
|
{
|
|
|
|
if ([self.delegate respondsToSelector:@selector(roomInputToolbarViewHangupCall:)])
|
|
|
|
{
|
|
|
|
[self.delegate roomInputToolbarViewHangupCall:self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 08:51:28 +00:00
|
|
|
[super onTouchUpInside:button];
|
2015-08-18 08:04:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 09:56:33 +00:00
|
|
|
- (void)showMediaPicker
|
|
|
|
{
|
|
|
|
// MediaPickerViewController is based on the Photos framework. So it is available only for iOS 8 and later.
|
|
|
|
Class PHAsset_class = NSClassFromString(@"PHAsset");
|
|
|
|
if (PHAsset_class)
|
|
|
|
{
|
2019-04-24 15:56:59 +00:00
|
|
|
MediaPickerViewController * mediaPicker = [MediaPickerViewController mediaPickerViewController];
|
2018-05-24 09:56:33 +00:00
|
|
|
mediaPicker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
|
|
|
|
mediaPicker.delegate = self;
|
|
|
|
UINavigationController *navigationController = [UINavigationController new];
|
|
|
|
[navigationController pushViewController:mediaPicker animated:NO];
|
2019-04-24 15:56:59 +00:00
|
|
|
|
|
|
|
self.mediaPicker = mediaPicker;
|
2018-05-24 09:56:33 +00:00
|
|
|
|
|
|
|
[self.delegate roomInputToolbarView:self presentViewController:navigationController];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We use UIImagePickerController by default for iOS < 8
|
|
|
|
self.leftInputToolbarButton = self.attachMediaButton;
|
|
|
|
[super onTouchUpInside:self.leftInputToolbarButton];
|
|
|
|
}
|
|
|
|
}
|
2015-08-18 08:04:30 +00:00
|
|
|
|
|
|
|
- (void)destroy
|
|
|
|
{
|
2015-09-16 17:11:49 +00:00
|
|
|
[self dismissMediaPicker];
|
2016-04-08 14:34:52 +00:00
|
|
|
|
2018-05-24 09:56:33 +00:00
|
|
|
if (actionSheet)
|
2016-04-08 14:34:52 +00:00
|
|
|
{
|
2018-05-24 09:56:33 +00:00
|
|
|
[actionSheet dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
actionSheet = nil;
|
2016-04-08 14:34:52 +00:00
|
|
|
}
|
2015-09-16 17:11:49 +00:00
|
|
|
|
2015-08-18 08:04:30 +00:00
|
|
|
[super destroy];
|
|
|
|
}
|
|
|
|
|
2015-09-02 07:43:52 +00:00
|
|
|
#pragma mark - MediaPickerViewController Delegate
|
2015-08-18 08:04:30 +00:00
|
|
|
|
2017-11-17 13:33:24 +00:00
|
|
|
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectImage:(NSData*)imageData withMimeType:(NSString *)mimetype isPhotoLibraryAsset:(BOOL)isPhotoLibraryAsset
|
2015-09-02 07:43:52 +00:00
|
|
|
{
|
2015-09-16 17:11:49 +00:00
|
|
|
[self dismissMediaPicker];
|
|
|
|
|
2017-11-17 13:33:24 +00:00
|
|
|
[self sendSelectedImage:imageData withMimeType:mimetype andCompressionMode:MXKRoomInputToolbarCompressionModePrompt isPhotoLibraryAsset:isPhotoLibraryAsset];
|
2015-09-02 07:43:52 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 17:59:40 +00:00
|
|
|
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectVideo:(NSURL*)videoURL
|
2015-09-02 07:43:52 +00:00
|
|
|
{
|
2015-09-16 17:11:49 +00:00
|
|
|
[self dismissMediaPicker];
|
|
|
|
|
2016-03-01 09:38:56 +00:00
|
|
|
BOOL isPhotoLibraryAsset = ![videoURL.path hasPrefix:NSTemporaryDirectory()];
|
|
|
|
[self sendSelectedVideo:videoURL isPhotoLibraryAsset:isPhotoLibraryAsset];
|
2015-09-02 07:43:52 +00:00
|
|
|
}
|
2015-08-18 08:04:30 +00:00
|
|
|
|
2016-08-04 15:59:26 +00:00
|
|
|
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectAssets:(NSArray<PHAsset*>*)assets
|
|
|
|
{
|
|
|
|
[self dismissMediaPicker];
|
|
|
|
|
|
|
|
[self sendSelectedAssets:assets withCompressionMode:MXKRoomInputToolbarCompressionModePrompt];
|
|
|
|
}
|
|
|
|
|
2015-09-16 17:11:49 +00:00
|
|
|
#pragma mark - Media picker handling
|
|
|
|
|
|
|
|
- (void)dismissMediaPicker
|
|
|
|
{
|
2019-04-24 15:56:59 +00:00
|
|
|
if (self.mediaPicker)
|
2015-09-16 17:11:49 +00:00
|
|
|
{
|
2019-04-24 15:56:59 +00:00
|
|
|
[self.mediaPicker withdrawViewControllerAnimated:YES completion:nil];
|
2015-09-16 17:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-04 22:54:58 +00:00
|
|
|
#pragma mark - Clipboard - Handle image/data paste from general pasteboard
|
|
|
|
|
|
|
|
- (void)paste:(id)sender
|
|
|
|
{
|
|
|
|
// TODO Custom here the validation screen for each available item
|
|
|
|
|
|
|
|
[super paste:sender];
|
|
|
|
}
|
|
|
|
|
2015-08-18 08:04:30 +00:00
|
|
|
@end
|