Commit 1d19d3a1 authored by Soomin Lee's avatar Soomin Lee

VLCAlertViewController: VLCAlertButton: Add UIAlertActionStyle

parent 106ff6bb
......@@ -16,11 +16,18 @@ typealias AlertAction = (UIAlertAction) -> Void
@objcMembers class VLCAlertButton: NSObject {
let title: String
var action: AlertAction?
init(title: String, action: AlertAction? = nil) {
let style: UIAlertActionStyle
let action: AlertAction?
init(title: String, style: UIAlertActionStyle = .default, action: AlertAction? = nil) {
self.title = title
self.style = style
self.action = action
}
// For Objc
convenience init(title: String, action: AlertAction? = nil) {
self.init(title: title, action: action)
}
}
@objcMembers class VLCAlertViewController: UIAlertController {
......@@ -33,7 +40,7 @@ typealias AlertAction = (UIAlertAction) -> Void
let alert = UIAlertController(title: title, message: errorMessage, preferredStyle: .alert)
if let buttonsAction = buttonsAction {
for buttonAction in buttonsAction {
let action = UIAlertAction(title: buttonAction.title, style: UIAlertActionStyle.default, handler: buttonAction.action)
let action = UIAlertAction(title: buttonAction.title, style: buttonAction.style, handler: buttonAction.action)
alert.addAction(action)
}
} else {
......@@ -55,7 +62,7 @@ typealias AlertAction = (UIAlertAction) -> Void
textField.text = textFieldText
})
for buttonAction in buttonsAction {
let action = UIAlertAction(title: buttonAction.title, style: UIAlertActionStyle.default, handler: buttonAction.action)
let action = UIAlertAction(title: buttonAction.title, style: buttonAction.style, handler: buttonAction.action)
alert.addAction(action)
}
alert.show(viewController, sender: Any?.self)
......
......@@ -85,7 +85,7 @@
errorMessage:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_MESSAGE", nil)
viewController:self
buttonsAction:@[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_OK", nil)
action: ^(UIAlertAction* action){}]]];
action: nil]]];
}
- (void)updateUI
......
......@@ -233,14 +233,15 @@
if (_selectedFile.size.longLongValue < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
/* selected item is a proper file, ask the user if s/he wants to download it */
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){
self->_selectedFile = nil;
}],
style: UIAlertActionStyleCancel
action: ^(UIAlertAction* action){
self->_selectedFile = nil;
}],
[[VLCAlertButton alloc] initWithTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
action:^(UIAlertAction* action){
[self->_boxController downloadFileToDocumentFolder:self->_selectedFile];
self->_selectedFile = nil;
}]];
action:^(UIAlertAction* action){
[self->_boxController downloadFileToDocumentFolder:self->_selectedFile];
self->_selectedFile = nil;
}]];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
viewController:self
......
......@@ -36,12 +36,14 @@
- (void)handleBugreportRequest
{
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
action:nil],
style: UIAlertActionStyleCancel
action:nil],
[[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];
}]
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)
......
......@@ -166,14 +166,15 @@
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 */
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: ^(UIAlertAction* action){
self->_selectedFile = nil;
}],
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
action: ^(UIAlertAction* action){
[self->_dropboxController downloadFileToDocumentFolder:self->_selectedFile];
self->_selectedFile = nil;
}]
style: UIAlertActionStyleCancel
action: ^(UIAlertAction* action){
self->_selectedFile = nil;
}],
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
action: ^(UIAlertAction* action){
[self->_dropboxController downloadFileToDocumentFolder:self->_selectedFile];
self->_selectedFile = nil;
}]
];
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil)
errorMessage:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
......
......@@ -129,6 +129,7 @@
if (_selectedFile.size.longLongValue < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
/* selected item is a proper file, ask the user if s/he wants to download it */
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
style: UIAlertActionStyleCancel
action: ^(UIAlertAction* action){
self->_selectedFile = nil;
}],
......
......@@ -199,6 +199,7 @@
if (_selectedFile.size.longLongValue < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
/* selected item is a proper file, ask the user if s/he wants to download it */
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
style: UIAlertActionStyleCancel
action: ^(UIAlertAction* action){
self->_selectedFile = nil;
}],
......@@ -216,9 +217,10 @@
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){
self->_selectedFile = nil;
}]]];
style: UIAlertActionStyleDefault
action: ^(UIAlertAction* action){
self->_selectedFile = nil;
}]]];
}
}
#endif
......
......@@ -1189,11 +1189,12 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
[self setPlaybackPosition:lastPosition];
} else if (continuePlayback == 0) {
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
action: nil],
style: UIAlertActionStyleCancel
action: nil],
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CONTINUE", nil)
action: ^(UIAlertAction* action){
[self setPlaybackPosition:lastPosition];
}]
action: ^(UIAlertAction* action){
[self setPlaybackPosition:lastPosition];
}]
];
UIViewController *presentingVC = [UIApplication sharedApplication].delegate.window.rootViewController;
presentingVC = presentingVC.presentedViewController ?: presentingVC;
......
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