Commit 4900ef1f authored by Quentin Richard's avatar Quentin Richard Committed by Carola Nitz

Refactoring on VLCAlertViewController

parent 08197551
......@@ -22,10 +22,9 @@
#else
- (void)vlc_showAlertWithTitle:(NSString *)title message:(NSString *)message buttonTitle:(NSString *)buttonTitle
{
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: buttonTitle
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: buttonTitle
action: ^(UIAlertAction* action){}]
];
[VLCAlertViewController alertViewManagerWithTitle:title
errorMessage:message
viewController:self
......
......@@ -172,11 +172,12 @@
self.loginInformation = login;
NSError *error = nil;
if (![self.savedLoginsDataSource saveLogin:login error:&error]) {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil) buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:error.localizedDescription errorMessage: error.localizedFailureReason viewController:self buttonsAction:buttonsAction];
[VLCAlertViewController alertViewManagerWithTitle:error.localizedDescription
errorMessage: error.localizedFailureReason
viewController:self
buttonsAction:@[[[VLCAlertButton alloc]
initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
}
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
......@@ -198,19 +199,14 @@
- (BOOL)protocolSelected
{
if (self.protocolDataSource.protocol == VLCServerProtocolUndefined) {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"PROTOCOL_NOT_SELECTED", nil)
errorMessage: NSLocalizedString(@"PROTOCOL_NOT_SELECTED", nil)
viewController:self
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
return NO;
}
return YES;
}
......
......@@ -270,14 +270,11 @@
- (void)showAlert:(NSString *)title message:(NSString *)message
{
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *okAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: okAction];
[VLCAlertViewController alertViewManagerWithTitle:title
errorMessage:message
viewController:self.delegate
buttonsAction:buttonsAction];
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
}
- (void)calculateRemainingTime:(CGFloat)receivedDataSize expectedDownloadSize:(CGFloat)expectedDownloadSize
......
......@@ -232,29 +232,25 @@
if (_selectedFile.size.longLongValue < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
/* selected item is a proper file, ask the user if s/he wants to download it */
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
buttonAction: ^(UIAlertAction* action){}];
ButtonAction *downloadAction = [[ButtonAction alloc] initWithButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
buttonAction:^(UIAlertAction* action){
[_boxController downloadFileToDocumentFolder:_selectedFile];
_selectedFile = nil;
}];
[buttonsAction addObject: cancelAction];
[buttonsAction addObject: downloadAction];
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){
_selectedFile = nil;
}],
[[VLCAlertButton alloc] initWithTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
action:^(UIAlertAction* action){
[_boxController downloadFileToDocumentFolder:_selectedFile];
_selectedFile = nil;
}]];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:buttonsAction];
} else {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:buttonsAction];;
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];;
}
}
......
......@@ -35,16 +35,14 @@
- (void)handleBugreportRequest
{
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
buttonAction: ^(UIAlertAction* action){}];
ButtonAction *reportAction = [[ButtonAction alloc] initWithButtonTitle:NSLocalizedString(@"BUG_REPORT_BUTTON", nil)
buttonAction: ^(UIAlertAction* action){
NSURL *url = [NSURL URLWithString:@"https://trac.videolan.org/vlc/newticket"];
[[UIApplication sharedApplication] openURL:url];
}];
[buttonsAction addObject: cancelAction];
[buttonsAction addObject: reportAction];
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}],
[[VLCAlertButton alloc] initWithTitle:NSLocalizedString(@"BUG_REPORT_BUTTON", nil)
action: ^(UIAlertAction* action){
NSURL *url = [NSURL URLWithString:@"https://trac.videolan.org/vlc/newticket"];
[[UIApplication sharedApplication] openURL:url];
}]
];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"BUG_REPORT_TITLE", nil)
errorMessage:NSLocalizedString(@"BUG_REPORT_MESSAGE", nil)
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
......
......@@ -139,17 +139,19 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) {
if ([self.urlField.text length] > 0) {
NSURL *URLtoSave = [NSURL URLWithString:self.urlField.text];
if (![URLtoSave.lastPathComponent isSupportedFormat] && ![URLtoSave.lastPathComponent.pathExtension isEqualToString:@""]) {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil) buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil) errorMessage: [NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), URLtoSave.lastPathComponent] viewController:self buttonsAction:buttonsAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
errorMessage: [NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), URLtoSave.lastPathComponent]
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]]];
return;
}
if (![URLtoSave.scheme isEqualToString:@"http"] & ![URLtoSave.scheme isEqualToString:@"https"] && ![URLtoSave.scheme isEqualToString:@"ftp"]) {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil) buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil) errorMessage: [NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme] viewController:self buttonsAction:buttonsAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil)
errorMessage: [NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme]
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]]];
return;
}
......@@ -313,10 +315,11 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) {
- (void)downloadFailedWithErrorDescription:(NSString *)description
{
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil) buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil) errorMessage: description viewController:self buttonsAction:buttonsAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil)
errorMessage: description
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]]];
}
- (void)progressUpdatedTo:(CGFloat)percentage receivedDataSize:(CGFloat)receivedDataSize expectedDownloadSize:(CGFloat)expectedDownloadSize
......@@ -389,10 +392,11 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) {
{
_FTPDownloadRequest = nil;
[self downloadEnded];
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil) buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:[NSString stringWithFormat:NSLocalizedString(@"ERROR_NUMBER", nil), request.error.errorCode] errorMessage: request.error.message viewController:self buttonsAction:buttonsAction];
[VLCAlertViewController alertViewManagerWithTitle:[NSString stringWithFormat:NSLocalizedString(@"ERROR_NUMBER", nil), request.error.errorCode]
errorMessage: request.error.message
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]]];
}
#pragma mark - table view data source
......
......@@ -326,14 +326,12 @@
- (void)_handleError:(NSError *)error
{
#if TARGET_OS_IOS
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:[NSString stringWithFormat:NSLocalizedString(@"ERROR_NUMBER", nil), error.code]
errorMessage:error.localizedDescription
viewController:self.delegate
buttonsAction:buttonsAction];
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]
]];
#else
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedString(@"ERROR_NUMBER", nil), error.code]
message:error.localizedDescription
......
......@@ -169,30 +169,27 @@
if (((DBFILESFileMetadata *)_selectedFile).size.longLongValue < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
/* selected item is a proper file, ask the user if s/he wants to download it */
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
buttonAction: ^(UIAlertAction* action){}];
ButtonAction *downloadAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
buttonAction: ^(UIAlertAction* action){
[_dropboxController downloadFileToDocumentFolder:_selectedFile];
_selectedFile = nil;
}];
[buttonsAction addObject: cancelAction];
[buttonsAction addObject: downloadAction];
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){
_selectedFile = nil;
}],
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
action: ^(UIAlertAction* action){
[_dropboxController downloadFileToDocumentFolder:_selectedFile];
_selectedFile = nil;
}]
];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:buttonsAction];
} else {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
}
}
......
......@@ -129,14 +129,11 @@
- (void)showAlert:(NSString *)title message:(NSString *)message
{
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:title
errorMessage:message
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
}
#pragma mark - file management
......
......@@ -128,30 +128,26 @@
if (_selectedFile.size.longLongValue < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
/* selected item is a proper file, ask the user if s/he wants to download it */
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
buttonAction: ^(UIAlertAction* action){}];
ButtonAction *downloadAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
buttonAction: ^(UIAlertAction* action){
[_googleDriveController downloadFileToDocumentFolder:_selectedFile];
_selectedFile = nil;
}];
[buttonsAction addObject: cancelAction];
[buttonsAction addObject: downloadAction];
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){
_selectedFile = nil;
}],
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
action: ^(UIAlertAction* action){
[_googleDriveController downloadFileToDocumentFolder:_selectedFile];
_selectedFile = nil;
}]
];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:buttonsAction];
} else {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
}
}
#pragma mark - login dialog
......
......@@ -723,17 +723,14 @@
- (void)notifyUserAboutEndOfFreeStorage:(NSString *)filename
{
#if TARGET_OS_IOS
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *okAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: okAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:
NSLocalizedString(@"DISK_FULL_FORMAT", nil),
filename,
[[UIDevice currentDevice] model]]
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
#else
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
message:[NSString stringWithFormat:
......
......@@ -112,14 +112,11 @@
_expectedDownloadSize = [response expectedContentLength];
APLog(@"expected download size: %lli", _expectedDownloadSize);
if (_expectedDownloadSize > [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) { //handle too big a download
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *okAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: okAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _fileName, [[UIDevice currentDevice] model]]
viewController:self.delegate
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
[_sessionTask cancel];
[self _downloadEnded];
return;
......
......@@ -198,29 +198,27 @@
if (_selectedFile.size.longLongValue < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
/* selected item is a proper file, ask the user if s/he wants to download it */
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
buttonAction: ^(UIAlertAction* action){}];
ButtonAction *downloadAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
buttonAction: ^(UIAlertAction* action){
[_oneDriveController downloadObject:_selectedFile];
_selectedFile = nil;
}];
[buttonsAction addObject: cancelAction];
[buttonsAction addObject: downloadAction];
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){
_selectedFile = nil;
}],
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
action: ^(UIAlertAction* action){
[_oneDriveController downloadObject:_selectedFile];
_selectedFile = nil;
}]];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:buttonsAction];
} else {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){
_selectedFile = nil;
}]]];
}
}
#endif
......
......@@ -85,14 +85,11 @@
} else if (count == 1) {
[self presentDocumentInteractionControllerWithFileURL:[_fileURLs firstObject]];
} else {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SHARING_ERROR_NO_FILES", nil)
errorMessage:nil
viewController:self.activityViewController
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
[self activityDidFinish:NO];
}
}
......@@ -129,15 +126,12 @@
controllerWasPresentedSuccessfully = [self->_documentInteractionController presentOpenInMenuFromBarButtonItem:self.presentingBarButtonItem animated:YES];
if (!controllerWasPresentedSuccessfully) {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SHARING_ERROR_NO_APPLICATIONS", nil)
errorMessage:nil
viewController:self.activityViewController
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]
]];
[self activityDidFinish:NO];
}
};
......
......@@ -203,14 +203,11 @@
- (IBAction)openButtonAction:(id)sender
{
if ([self.urlField.text length] <= 0 || [NSURL URLWithString:self.urlField.text] == nil) {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"URL_NOT_SUPPORTED", nil)
errorMessage: NSLocalizedString(@"PROTOCOL_NOT_SELECTED", nil)
viewController:self
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
return;
}
if (!self.privateToggleSwitch.on) {
......@@ -424,10 +421,11 @@ forRowAtIndexPath:(NSIndexPath *)indexPath
}
[receivedSub writeToFile:fileSubtitlePath atomically:YES];
} else {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *okAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil) buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: okAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil) errorMessage: [NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), fileName, [[UIDevice currentDevice] model]] viewController:self buttonsAction:buttonsAction];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage: [NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), fileName, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
}
return fileSubtitlePath;
......
......@@ -1173,18 +1173,16 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
if (continuePlayback == 1) {
[self setPlaybackPosition:lastPosition];
} else if (continuePlayback == 0) {
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
buttonAction: ^(UIAlertAction* action){}];
ButtonAction *continueAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_CONTINUE", nil)
buttonAction: ^(UIAlertAction* action){
[self setPlaybackPosition:lastPosition];
}];
[buttonsAction addObject: cancelAction];
[buttonsAction addObject: continueAction];
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}],
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CONTINUE", nil)
action: ^(UIAlertAction* action){
[self setPlaybackPosition:lastPosition];
}]
];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"CONTINUE_PLAYBACK", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"CONTINUE_PLAYBACK_LONG", nil), item.title]
viewController:self
viewController:self.delegate
buttonsAction:buttonsAction];
}
}
......
......@@ -188,10 +188,6 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
{
NSString *failedString = NSLocalizedString(@"PLAYBACK_FAILED", nil);
#if TARGET_OS_IOS
NSMutableArray<ButtonAction *> *buttonsAction = [[NSMutableArray alloc] init];
ButtonAction *cancelAction = [[ButtonAction alloc] initWithButtonTitle: NSLocalizedString(@"BUTTON_OK", nil)
buttonAction: ^(UIAlertAction* action){}];
[buttonsAction addObject: cancelAction];
switch (self.displayMode) {
case VLCPlayerDisplayControllerDisplayModeFullscreen:
if ([self.movieViewController respondsToSelector:@selector(showStatusMessage:forPlaybackController:)]) {
......@@ -203,7 +199,8 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
[VLCAlertViewController alertViewManagerWithTitle:failedString
errorMessage:nil
viewController:self
buttonsAction:buttonsAction];
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
break;
}
#else
......
/*****************************************************************************
* VLCAlertControllerExtension.swift
* VLCAlertViewController.swift
* VLC for iOS
*****************************************************************************
* Copyright (c) 2018 VideoLAN. All rights reserved.
......@@ -15,44 +15,42 @@ import UIKit
typealias AlertAction = (UIAlertAction) -> Void
@objcMembers class ButtonAction: NSObject {
let buttonTitle: String
var buttonAction: AlertAction
init(buttonTitle: String, buttonAction: @escaping AlertAction) {
self.buttonTitle = buttonTitle
self.buttonAction = buttonAction
@objcMembers class VLCAlertButton: NSObject {
let title: String
var action: AlertAction
init(title: String, action: @escaping AlertAction) {
self.title = title
self.action = action
}
}
@objc class VLCAlertViewController: UIAlertController {
@objcMembers class VLCAlertViewController: UIAlertController {
@objc class func alertViewManager(title: String, errorMessage: String? = nil, viewController: UIViewController,
buttonsAction: [ButtonAction]) {
class func alertViewManager(title: String, errorMessage: String? = nil, viewController: UIViewController,
buttonsAction: [VLCAlertButton]) {
let alert = UIAlertController(title: title, message: errorMessage, preferredStyle: .alert)
alert.show(viewController, sender: Any?.self)
for buttonAction in buttonsAction {
let action = UIAlertAction(title: buttonAction.buttonTitle, style: UIAlertActionStyle.default, handler: buttonAction.buttonAction)
let action = UIAlertAction(title: buttonAction.title, style: UIAlertActionStyle.default, handler: buttonAction.action)
alert.addAction(action)
}
alert.show(viewController, sender: Any?.self)
viewController.present(alert, animated: true, completion: nil)
}
@objc class func alertManagerWithTextField(title: String, errorMessage: String? = nil, viewController: UIViewController,
buttonsAction: [ButtonAction], textFieldText: String? = nil,
textFieldPlaceholder: String? = nil) {
class func alertManagerWithTextField(title: String, errorMessage: String? = nil, viewController: UIViewController,
buttonsAction: [VLCAlertButton],
textFieldText: String? = nil,
textFieldPlaceholder: String? = nil) {
let alert = UIAlertController(title: title, message: errorMessage, preferredStyle: .alert)
alert.show(viewController, sender: Any?.self)
alert.addTextField(configurationHandler: { textField in
textField.placeholder = textFieldPlaceholder
textField.text = textFieldText
textField.isSecureTextEntry = false
textField.textAlignment = .left
})
for buttonAction in buttonsAction {
let action = UIAlertAction(title: buttonAction.buttonTitle, style: UIAlertActionStyle.default, handler: buttonAction.buttonAction)
let action = UIAlertAction(title: buttonAction.title, style: UIAlertActionStyle.default, handler: buttonAction.action)
alert.addAction(action)
}
alert.show(viewController, sender: Any?.self)
viewController.present(alert, animated: true, completion: nil)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment