mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 02:22:44 +02:00
Send sticker: UI integration: RoomInputToolbar: Let user choose between "Send photo or video" and "Send sticker"
https://github.com/vector-im/riot-ios/issues/1860
This commit is contained in:
@@ -18,12 +18,28 @@
|
||||
|
||||
#import "MediaPickerViewController.h"
|
||||
|
||||
@protocol RoomInputToolbarViewDelegate <MXKRoomInputToolbarViewDelegate>
|
||||
|
||||
/**
|
||||
Tells the delegate that the user wants to display the sticker picker.
|
||||
|
||||
@param toolbarView the room input toolbar view.
|
||||
*/
|
||||
- (void)roomInputToolbarViewPresentStickerPicker:(MXKRoomInputToolbarView*)toolbarView;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
`RoomInputToolbarView` instance is a view used to handle all kinds of available inputs
|
||||
for a room (message composer, attachments selection...).
|
||||
*/
|
||||
@interface RoomInputToolbarView : MXKRoomInputToolbarViewWithHPGrowingText <MediaPickerViewControllerDelegate>
|
||||
|
||||
/**
|
||||
The delegate notified when inputs are ready.
|
||||
*/
|
||||
@property (nonatomic) id<RoomInputToolbarViewDelegate> delegate;
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UIView *mainToolbarView;
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UIView *separatorView;
|
||||
|
||||
@@ -29,17 +29,21 @@
|
||||
|
||||
#import <MobileCoreServices/MobileCoreServices.h>
|
||||
|
||||
#import "WidgetManager.h"
|
||||
#import "IntegrationManagerViewController.h"
|
||||
|
||||
@interface RoomInputToolbarView()
|
||||
{
|
||||
MediaPickerViewController *mediaPicker;
|
||||
|
||||
// The call type selection (voice or video)
|
||||
UIAlertController *callActionSheet;
|
||||
// The intermediate action sheet
|
||||
UIAlertController *actionSheet;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RoomInputToolbarView
|
||||
@dynamic delegate;
|
||||
|
||||
+ (UINib *)nib
|
||||
{
|
||||
@@ -228,24 +232,53 @@
|
||||
// Check whether media attachment is supported
|
||||
if ([self.delegate respondsToSelector:@selector(roomInputToolbarView:presentViewController:)])
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
mediaPicker = [MediaPickerViewController mediaPickerViewController];
|
||||
mediaPicker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
|
||||
mediaPicker.delegate = self;
|
||||
UINavigationController *navigationController = [UINavigationController new];
|
||||
[navigationController pushViewController:mediaPicker animated:NO];
|
||||
|
||||
[self.delegate roomInputToolbarView:self presentViewController:navigationController];
|
||||
}
|
||||
else
|
||||
{
|
||||
// We use UIImagePickerController by default for iOS < 8
|
||||
self.leftInputToolbarButton = self.attachMediaButton;
|
||||
[super onTouchUpInside:self.leftInputToolbarButton];
|
||||
}
|
||||
// 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];
|
||||
}
|
||||
|
||||
}]];
|
||||
|
||||
[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];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -257,52 +290,52 @@
|
||||
if ([self.delegate respondsToSelector:@selector(roomInputToolbarView:placeCallWithVideo:)])
|
||||
{
|
||||
// Ask the user the kind of the call: voice or video?
|
||||
callActionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
||||
actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[callActionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"voice", @"Vector", nil)
|
||||
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"voice", @"Vector", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction * action) {
|
||||
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
self->callActionSheet = nil;
|
||||
self->actionSheet = nil;
|
||||
|
||||
[self.delegate roomInputToolbarView:self placeCallWithVideo:NO];
|
||||
}
|
||||
|
||||
}]];
|
||||
|
||||
[callActionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"video", @"Vector", nil)
|
||||
[actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"video", @"Vector", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction * action) {
|
||||
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
self->callActionSheet = nil;
|
||||
self->actionSheet = nil;
|
||||
|
||||
[self.delegate roomInputToolbarView:self placeCallWithVideo:YES];
|
||||
}
|
||||
|
||||
}]];
|
||||
|
||||
[callActionSheet addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
||||
[actionSheet addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
||||
style:UIAlertActionStyleCancel
|
||||
handler:^(UIAlertAction * action) {
|
||||
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
self->callActionSheet = nil;
|
||||
self->actionSheet = nil;
|
||||
}
|
||||
|
||||
}]];
|
||||
|
||||
[callActionSheet popoverPresentationController].sourceView = self.voiceCallButton;
|
||||
[callActionSheet popoverPresentationController].sourceRect = self.voiceCallButton.bounds;
|
||||
[self.window.rootViewController presentViewController:callActionSheet animated:YES completion:nil];
|
||||
[actionSheet popoverPresentationController].sourceView = self.voiceCallButton;
|
||||
[actionSheet popoverPresentationController].sourceRect = self.voiceCallButton.bounds;
|
||||
[self.window.rootViewController presentViewController:actionSheet animated:YES completion:nil];
|
||||
}
|
||||
}
|
||||
else if (button == self.hangupCallButton)
|
||||
@@ -316,15 +349,36 @@
|
||||
[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)
|
||||
{
|
||||
mediaPicker = [MediaPickerViewController mediaPickerViewController];
|
||||
mediaPicker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
|
||||
mediaPicker.delegate = self;
|
||||
UINavigationController *navigationController = [UINavigationController new];
|
||||
[navigationController pushViewController:mediaPicker animated:NO];
|
||||
|
||||
[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 (callActionSheet)
|
||||
if (actionSheet)
|
||||
{
|
||||
[callActionSheet dismissViewControllerAnimated:NO completion:nil];
|
||||
callActionSheet = nil;
|
||||
[actionSheet dismissViewControllerAnimated:NO completion:nil];
|
||||
actionSheet = nil;
|
||||
}
|
||||
|
||||
[super destroy];
|
||||
|
||||
Reference in New Issue
Block a user