RoomInputToolbarView: Add separate actions for camera and media library.

This commit is contained in:
SBiOSoftWhare 2019-08-02 17:16:06 +02:00
parent edc03eeb48
commit b31087ec12
2 changed files with 32 additions and 71 deletions

View file

@ -45,6 +45,20 @@ typedef enum : NSUInteger
*/
- (void)roomInputToolbarViewDidTapFileUpload:(MXKRoomInputToolbarView*)toolbarView;
/**
Tells the delegate that the user wants to take photo or video with camera.
@param toolbarView the room input toolbar view
*/
- (void)roomInputToolbarViewDidTapCamera:(MXKRoomInputToolbarView*)toolbarView;
/**
Tells the delegate that the user wants to show media library.
@param toolbarView the room input toolbar view
*/
- (void)roomInputToolbarViewDidTapMediaLibrary:(MXKRoomInputToolbarView*)toolbarView;
@end
/**

View file

@ -24,12 +24,6 @@
#import "UINavigationController+Riot.h"
#import <MediaPlayer/MediaPlayer.h>
#import <Photos/Photos.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "WidgetManager.h"
#import "IntegrationManagerViewController.h"
@ -39,8 +33,6 @@
UIAlertController *actionSheet;
}
@property(nonatomic, weak) MediaPickerViewController *mediaPicker;
@end
@implementation RoomInputToolbarView
@ -322,6 +314,21 @@
actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
__weak typeof(self) weakSelf = self;
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"Take photo or video", @"Vector", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->actionSheet = nil;
[self.delegate roomInputToolbarViewDidTapCamera:self];
}
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_action_send_photo_or_video", @"Vector", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
@ -331,7 +338,7 @@
typeof(self) self = weakSelf;
self->actionSheet = nil;
[self showMediaPicker];
[self.delegate roomInputToolbarViewDidTapMediaLibrary:self];
}
}]];
@ -375,8 +382,8 @@
}]];
[actionSheet popoverPresentationController].sourceView = self.voiceCallButton;
[actionSheet popoverPresentationController].sourceRect = self.voiceCallButton.bounds;
[actionSheet popoverPresentationController].sourceView = self.attachMediaButton;
[actionSheet popoverPresentationController].sourceRect = self.attachMediaButton.bounds;
[self.window.rootViewController presentViewController:actionSheet animated:YES completion:nil];
}
else
@ -448,34 +455,8 @@
[super onTouchUpInside:button];
}
- (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)
{
MediaPickerViewController * mediaPicker = [MediaPickerViewController mediaPickerViewController];
mediaPicker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
mediaPicker.delegate = self;
UINavigationController *navigationController = [UINavigationController new];
[navigationController pushViewController:mediaPicker animated:NO];
self.mediaPicker = mediaPicker;
[self.delegate roomInputToolbarView:self presentViewController:navigationController];
}
else
{
// We use UIImagePickerController by default for iOS < 8
self.leftInputToolbarButton = self.attachMediaButton;
[super onTouchUpInside:self.leftInputToolbarButton];
}
}
- (void)destroy
{
[self dismissMediaPicker];
if (actionSheet)
{
[actionSheet dismissViewControllerAnimated:NO completion:nil];
@ -485,40 +466,6 @@
[super destroy];
}
#pragma mark - MediaPickerViewController Delegate
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectImage:(NSData*)imageData withMimeType:(NSString *)mimetype isPhotoLibraryAsset:(BOOL)isPhotoLibraryAsset
{
[self dismissMediaPicker];
[self sendSelectedImage:imageData withMimeType:mimetype andCompressionMode:MXKRoomInputToolbarCompressionModePrompt isPhotoLibraryAsset:isPhotoLibraryAsset];
}
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectVideo:(NSURL*)videoURL
{
[self dismissMediaPicker];
BOOL isPhotoLibraryAsset = ![videoURL.path hasPrefix:NSTemporaryDirectory()];
[self sendSelectedVideo:videoURL isPhotoLibraryAsset:isPhotoLibraryAsset];
}
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectAssets:(NSArray<PHAsset*>*)assets
{
[self dismissMediaPicker];
[self sendSelectedAssets:assets withCompressionMode:MXKRoomInputToolbarCompressionModePrompt];
}
#pragma mark - Media picker handling
- (void)dismissMediaPicker
{
if (self.mediaPicker)
{
[self.mediaPicker withdrawViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - Clipboard - Handle image/data paste from general pasteboard
- (void)paste:(id)sender