Switching composer between text mode & action mode

This commit is contained in:
Gil Eluard
2021-03-25 22:15:18 +01:00
parent cc0a7a08e1
commit e6ef3b2d34
25 changed files with 467 additions and 210 deletions
+124 -95
View File
@@ -410,6 +410,8 @@ NSNotificationName const RoomCallTileTappedNotification = @"RoomCallTileTappedNo
}];
[self userInterfaceThemeDidChange];
[self setupActions];
}
- (void)userInterfaceThemeDidChange
@@ -1697,6 +1699,128 @@ NSNotificationName const RoomCallTileTappedNotification = @"RoomCallTileTappedNo
[self.roomInfoCoordinatorBridgePresenter pushFrom:self.navigationController animated:YES];
}
- (void)setupActions {
RoomInputToolbarView *roomInputView = ((RoomInputToolbarView *) self.inputToolbarView);
__weak typeof(self) weakSelf = self;
roomInputView.actionsBar.actionItems = @[
[[RoomActionItem alloc] initWithImage:[UIImage imageNamed:@"action_camera"] andAction:^{
if (weakSelf)
{
typeof(self) self = weakSelf;
roomInputView.actionMenuOpened = NO;
[self showCameraControllerAnimated:YES];
}
}],
[[RoomActionItem alloc] initWithImage:[UIImage imageNamed:@"action_media_library"] andAction:^{
if (weakSelf)
{
typeof(self) self = weakSelf;
roomInputView.actionMenuOpened = NO;
[self showMediaPickerAnimated:YES];
}
}],
[[RoomActionItem alloc] initWithImage:[UIImage imageNamed:@"action_sticker"] andAction:^{
if (weakSelf)
{
typeof(self) self = weakSelf;
roomInputView.actionMenuOpened = NO;
[self roomInputToolbarViewPresentStickerPicker];
}
}],
[[RoomActionItem alloc] initWithImage:[UIImage imageNamed:@"action_file"] andAction:^{
if (weakSelf)
{
typeof(self) self = weakSelf;
roomInputView.actionMenuOpened = NO;
[self roomInputToolbarViewDidTapFileUpload];
}
}],
];
}
- (void)roomInputToolbarViewPresentStickerPicker
{
// Search for the sticker picker widget in the user account
Widget *widget = [[WidgetManager sharedManager] userWidgets:self.roomDataSource.mxSession ofTypes:@[kWidgetTypeStickerPicker]].firstObject;
if (widget)
{
// Display the widget
[widget widgetUrl:^(NSString * _Nonnull widgetUrl) {
StickerPickerViewController *stickerPickerVC = [[StickerPickerViewController alloc] initWithUrl:widgetUrl forWidget:widget];
stickerPickerVC.roomDataSource = self.roomDataSource;
[self.navigationController pushViewController:stickerPickerVC animated:YES];
} failure:^(NSError * _Nonnull error) {
NSLog(@"[RoomVC] Cannot display widget %@", widget);
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
else
{
// The Sticker picker widget is not installed yet. Propose the user to install it
__weak typeof(self) weakSelf = self;
[currentAlert dismissViewControllerAnimated:NO completion:nil];
NSString *alertMessage = [NSString stringWithFormat:@"%@\n%@",
NSLocalizedStringFromTable(@"widget_sticker_picker_no_stickerpacks_alert", @"Vector", nil),
NSLocalizedStringFromTable(@"widget_sticker_picker_no_stickerpacks_alert_add_now", @"Vector", nil)
];
currentAlert = [UIAlertController alertControllerWithTitle:nil message:alertMessage preferredStyle:UIAlertControllerStyleAlert];
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"]
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
}
}]];
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
// Show the sticker picker settings screen
IntegrationManagerViewController *modularVC = [[IntegrationManagerViewController alloc]
initForMXSession:self.roomDataSource.mxSession
inRoom:self.roomDataSource.roomId
screen:[IntegrationManagerViewController screenForWidget:kWidgetTypeStickerPicker]
widgetId:nil];
[self presentViewController:modularVC animated:NO completion:nil];
}
}]];
[currentAlert mxk_setAccessibilityIdentifier:@"RoomVCStickerPickerAlert"];
[self presentViewController:currentAlert animated:YES completion:nil];
}
}
- (void)roomInputToolbarViewDidTapFileUpload
{
MXKDocumentPickerPresenter *documentPickerPresenter = [MXKDocumentPickerPresenter new];
documentPickerPresenter.delegate = self;
NSArray<MXKUTI*> *allowedUTIs = @[MXKUTI.data];
[documentPickerPresenter presentDocumentPickerWith:allowedUTIs from:self animated:YES completion:nil];
self.documentPickerPresenter = documentPickerPresenter;
}
#pragma mark - Dialpad
- (void)openDialpad
@@ -3321,80 +3445,6 @@ NSNotificationName const RoomCallTileTappedNotification = @"RoomCallTileTappedNo
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}
#pragma mark - RoomInputToolbarViewDelegate
- (void)roomInputToolbarViewPresentStickerPicker:(MXKRoomInputToolbarView*)toolbarView
{
// Search for the sticker picker widget in the user account
Widget *widget = [[WidgetManager sharedManager] userWidgets:self.roomDataSource.mxSession ofTypes:@[kWidgetTypeStickerPicker]].firstObject;
if (widget)
{
// Display the widget
[widget widgetUrl:^(NSString * _Nonnull widgetUrl) {
StickerPickerViewController *stickerPickerVC = [[StickerPickerViewController alloc] initWithUrl:widgetUrl forWidget:widget];
stickerPickerVC.roomDataSource = self.roomDataSource;
[self.navigationController pushViewController:stickerPickerVC animated:YES];
} failure:^(NSError * _Nonnull error) {
NSLog(@"[RoomVC] Cannot display widget %@", widget);
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
else
{
// The Sticker picker widget is not installed yet. Propose the user to install it
__weak typeof(self) weakSelf = self;
[currentAlert dismissViewControllerAnimated:NO completion:nil];
NSString *alertMessage = [NSString stringWithFormat:@"%@\n%@",
NSLocalizedStringFromTable(@"widget_sticker_picker_no_stickerpacks_alert", @"Vector", nil),
NSLocalizedStringFromTable(@"widget_sticker_picker_no_stickerpacks_alert_add_now", @"Vector", nil)
];
currentAlert = [UIAlertController alertControllerWithTitle:nil message:alertMessage preferredStyle:UIAlertControllerStyleAlert];
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"]
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
}
}]];
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
// Show the sticker picker settings screen
IntegrationManagerViewController *modularVC = [[IntegrationManagerViewController alloc]
initForMXSession:self.roomDataSource.mxSession
inRoom:self.roomDataSource.roomId
screen:[IntegrationManagerViewController screenForWidget:kWidgetTypeStickerPicker]
widgetId:nil];
[self presentViewController:modularVC animated:NO completion:nil];
}
}]];
[currentAlert mxk_setAccessibilityIdentifier:@"RoomVCStickerPickerAlert"];
[self presentViewController:currentAlert animated:YES completion:nil];
}
}
#pragma mark - VoIP
- (void)placeCallWithVideo:(BOOL)video
@@ -3641,27 +3691,6 @@ NSNotificationName const RoomCallTileTappedNotification = @"RoomCallTileTappedNo
}
}
- (void)roomInputToolbarViewDidTapFileUpload:(MXKRoomInputToolbarView *)toolbarView
{
MXKDocumentPickerPresenter *documentPickerPresenter = [MXKDocumentPickerPresenter new];
documentPickerPresenter.delegate = self;
NSArray<MXKUTI*> *allowedUTIs = @[MXKUTI.data];
[documentPickerPresenter presentDocumentPickerWith:allowedUTIs from:self animated:YES completion:nil];
self.documentPickerPresenter = documentPickerPresenter;
}
- (void)roomInputToolbarViewDidTapCamera:(MXKRoomInputToolbarView*)toolbarView
{
[self showCameraControllerAnimated:YES];
}
- (void)roomInputToolbarViewDidTapMediaLibrary:(MXKRoomInputToolbarView*)toolbarView
{
[self showMediaPickerAnimated:YES];
}
- (void)roomInputToolbarViewDidTapCancel:(MXKRoomInputToolbarView*)toolbarView
{
[self cancelEventSelection];