Commit 28c8bb0b authored by Carola Nitz's avatar Carola Nitz

VLCAlertViewController :made the buttonsAction optional

when no action is supplied the user is only able to accept whatever the dialog states and it will be dismissed
parent 4900ef1f
......@@ -23,8 +23,7 @@
- (void)vlc_showAlertWithTitle:(NSString *)title message:(NSString *)message buttonTitle:(NSString *)buttonTitle
{
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: buttonTitle
action: ^(UIAlertAction* action){}]
];
action: nil]];
[VLCAlertViewController alertViewManagerWithTitle:title
errorMessage:message
viewController:self
......
......@@ -173,11 +173,9 @@
NSError *error = nil;
if (![self.savedLoginsDataSource saveLogin:login error:&error]) {
[VLCAlertViewController alertViewManagerWithTitle:error.localizedDescription
errorMessage: error.localizedFailureReason
errorMessage:error.localizedFailureReason
viewController:self
buttonsAction:@[[[VLCAlertButton alloc]
initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
}
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
......@@ -200,10 +198,9 @@
{
if (self.protocolDataSource.protocol == VLCServerProtocolUndefined) {
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"PROTOCOL_NOT_SELECTED", nil)
errorMessage: NSLocalizedString(@"PROTOCOL_NOT_SELECTED", nil)
errorMessage:NSLocalizedString(@"PROTOCOL_NOT_SELECTED", nil)
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
return NO;
}
......
......@@ -273,8 +273,7 @@
[VLCAlertViewController alertViewManagerWithTitle:title
errorMessage:message
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
}
- (void)calculateRemainingTime:(CGFloat)receivedDataSize expectedDownloadSize:(CGFloat)expectedDownloadSize
......
......@@ -249,8 +249,7 @@
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];;
buttonsAction:nil];
}
}
......
......@@ -35,8 +35,8 @@
- (void)handleBugreportRequest
{
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}],
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
action:nil],
[[VLCAlertButton alloc] initWithTitle:NSLocalizedString(@"BUG_REPORT_BUTTON", nil)
action: ^(UIAlertAction* action){
NSURL *url = [NSURL URLWithString:@"https://trac.videolan.org/vlc/newticket"];
......
......@@ -140,18 +140,16 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) {
NSURL *URLtoSave = [NSURL URLWithString:self.urlField.text];
if (![URLtoSave.lastPathComponent isSupportedFormat] && ![URLtoSave.lastPathComponent.pathExtension isEqualToString:@""]) {
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
errorMessage: [NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), URLtoSave.lastPathComponent]
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), URLtoSave.lastPathComponent]
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
return;
}
if (![URLtoSave.scheme isEqualToString:@"http"] & ![URLtoSave.scheme isEqualToString:@"https"] && ![URLtoSave.scheme isEqualToString:@"ftp"]) {
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil)
errorMessage: [NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme]
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme]
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
return;
}
......@@ -316,10 +314,9 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) {
- (void)downloadFailedWithErrorDescription:(NSString *)description
{
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil)
errorMessage: description
errorMessage:description
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
}
- (void)progressUpdatedTo:(CGFloat)percentage receivedDataSize:(CGFloat)receivedDataSize expectedDownloadSize:(CGFloat)expectedDownloadSize
......@@ -393,10 +390,9 @@ typedef NS_ENUM(NSUInteger, VLCDownloadScheme) {
_FTPDownloadRequest = nil;
[self downloadEnded];
[VLCAlertViewController alertViewManagerWithTitle:[NSString stringWithFormat:NSLocalizedString(@"ERROR_NUMBER", nil), request.error.errorCode]
errorMessage: request.error.message
errorMessage:request.error.message
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
}
#pragma mark - table view data source
......
......@@ -329,9 +329,7 @@
[VLCAlertViewController alertViewManagerWithTitle:[NSString stringWithFormat:NSLocalizedString(@"ERROR_NUMBER", nil), error.code]
errorMessage:error.localizedDescription
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}]
]];
buttonsAction:nil];
#else
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedString(@"ERROR_NUMBER", nil), error.code]
message:error.localizedDescription
......
......@@ -188,8 +188,7 @@
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
}
}
......
......@@ -132,8 +132,7 @@
[VLCAlertViewController alertViewManagerWithTitle:title
errorMessage:message
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
}
#pragma mark - file management
......
......@@ -146,8 +146,7 @@
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
}
}
#pragma mark - login dialog
......
......@@ -729,8 +729,7 @@
filename,
[[UIDevice currentDevice] model]]
viewController:[UIApplication sharedApplication].keyWindow.rootViewController
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
#else
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
message:[NSString stringWithFormat:
......
......@@ -115,8 +115,7 @@
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _fileName, [[UIDevice currentDevice] model]]
viewController:self.delegate
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
[_sessionTask cancel];
[self _downloadEnded];
return;
......
......@@ -88,8 +88,7 @@
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SHARING_ERROR_NO_FILES", nil)
errorMessage:nil
viewController:self.activityViewController
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
[self activityDidFinish:NO];
}
}
......@@ -129,9 +128,7 @@
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SHARING_ERROR_NO_APPLICATIONS", nil)
errorMessage:nil
viewController:self.activityViewController
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]
]];
buttonsAction:nil];
[self activityDidFinish:NO];
}
};
......
......@@ -204,10 +204,9 @@
{
if ([self.urlField.text length] <= 0 || [NSURL URLWithString:self.urlField.text] == nil) {
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"URL_NOT_SUPPORTED", nil)
errorMessage: NSLocalizedString(@"PROTOCOL_NOT_SELECTED", nil)
errorMessage:NSLocalizedString(@"PROTOCOL_NOT_SELECTED", nil)
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
return;
}
if (!self.privateToggleSwitch.on) {
......@@ -422,10 +421,9 @@ forRowAtIndexPath:(NSIndexPath *)indexPath
[receivedSub writeToFile:fileSubtitlePath atomically:YES];
} else {
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DISK_FULL", nil)
errorMessage: [NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), fileName, [[UIDevice currentDevice] model]]
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){}]]];
buttonsAction:nil];
}
return fileSubtitlePath;
......
......@@ -1174,7 +1174,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
[self setPlaybackPosition:lastPosition];
} else if (continuePlayback == 0) {
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){}],
action: nil],
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CONTINUE", nil)
action: ^(UIAlertAction* action){
[self setPlaybackPosition:lastPosition];
......
......@@ -199,8 +199,7 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
[VLCAlertViewController alertViewManagerWithTitle:failedString
errorMessage:nil
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
buttonsAction:nil];
break;
}
#else
......
......@@ -14,11 +14,10 @@ import UIKit
typealias AlertAction = (UIAlertAction) -> Void
@objcMembers class VLCAlertButton: NSObject {
let title: String
var action: AlertAction
init(title: String, action: @escaping AlertAction) {
var action: AlertAction?
init(title: String, action: AlertAction? = nil) {
self.title = title
self.action = action
}
......@@ -27,10 +26,15 @@ typealias AlertAction = (UIAlertAction) -> Void
@objcMembers class VLCAlertViewController: UIAlertController {
class func alertViewManager(title: String, errorMessage: String? = nil, viewController: UIViewController,
buttonsAction: [VLCAlertButton]) {
buttonsAction: [VLCAlertButton]?) {
let alert = UIAlertController(title: title, message: errorMessage, preferredStyle: .alert)
for buttonAction in buttonsAction {
let action = UIAlertAction(title: buttonAction.title, style: UIAlertActionStyle.default, handler: buttonAction.action)
if let buttonsAction = buttonsAction {
for buttonAction in buttonsAction {
let action = UIAlertAction(title: buttonAction.title, style: UIAlertActionStyle.default, handler: buttonAction.action)
alert.addAction(action)
}
} else {
let action = UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment:""), style: UIAlertActionStyle.default, handler: nil)
alert.addAction(action)
}
alert.show(viewController, sender: Any?.self)
......
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