Sfoglia il codice sorgente

VLCAlertViewController: VLCAlertButton: Add UIAlertActionStyle

Soomin Lee 6 anni fa
parent
commit
1d19d3a134

+ 11 - 4
SharedSources/VLCAlertViewController.swift

@@ -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)

+ 1 - 1
Sources/LocalNetworkConnectivity/VLCNetworkServerBrowserViewController.m

@@ -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

+ 8 - 7
Sources/VLCBoxTableViewController.m

@@ -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

+ 7 - 5
Sources/VLCBugreporter.m

@@ -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)

+ 9 - 8
Sources/VLCDropboxTableViewController.m

@@ -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]]

+ 1 - 0
Sources/VLCGoogleDriveTableViewController.m

@@ -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;
                                                                                   }],

+ 5 - 3
Sources/VLCOneDriveTableViewController.m

@@ -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

+ 5 - 4
Sources/VLCPlaybackController.m

@@ -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;