Browse Source

VLCOpenNetworkStreamViewController: add check if self.urlField.text can be converted to a url

if not we show the user an alert that the url is not supported
Carola Nitz 7 years ago
parent
commit
664d8f7624
2 changed files with 28 additions and 15 deletions
  1. 2 0
      Resources/en.lproj/Localizable.strings
  2. 26 15
      Sources/VLCOpenNetworkStreamViewController.m

+ 2 - 0
Resources/en.lproj/Localizable.strings

@@ -322,6 +322,8 @@
 "BONJOUR_FILE_SERVERS" = "BONJOUR File Server";
 "DSM_WORKGROUP" = "Workgroup";
 
+"URL_NOT_SUPPORTED" = "The URL can't be opened";
+
 // Insert %@ where play-pause-glyph should be placed
 "DELETE_ITEM_HINT" = "Press %@ to Delete"; /* Insert %@ where play-pause-glyph should be placed */
 

+ 26 - 15
Sources/VLCOpenNetworkStreamViewController.m

@@ -178,22 +178,33 @@
 
 - (IBAction)openButtonAction:(id)sender
 {
-    if ([self.urlField.text length] > 0) {
-        if (!self.privateToggleSwitch.on) {
-            NSString *urlString = self.urlField.text;
-            if ([_recentURLs indexOfObject:urlString] != NSNotFound)
-                [_recentURLs removeObject:urlString];
-
-            if (_recentURLs.count >= 100)
-                [_recentURLs removeLastObject];
-            [_recentURLs addObject:urlString];
-            [[NSUbiquitousKeyValueStore defaultStore] setArray:_recentURLs forKey:kVLCRecentURLs];
-
-            [self.historyTableView reloadData];
-        }
-        [self.urlField resignFirstResponder];
-        [self _openURLStringAndDismiss:self.urlField.text];
+    if ([self.urlField.text length] <= 0 || [NSURL URLWithString:self.urlField.text] == nil) {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"URL_NOT_SUPPORTED", nil)
+                                                                                 message:nil
+                                                                          preferredStyle:UIAlertControllerStyleAlert];
+
+        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_OK", nil)
+                                                           style:UIAlertActionStyleCancel
+                                                         handler:nil];
+
+        [alertController addAction:okAction];
+        [self presentViewController:alertController animated:YES completion:nil];
+        return;
     }
+    if (!self.privateToggleSwitch.on) {
+        NSString *urlString = self.urlField.text;
+        if ([_recentURLs indexOfObject:urlString] != NSNotFound)
+            [_recentURLs removeObject:urlString];
+
+        if (_recentURLs.count >= 100)
+            [_recentURLs removeLastObject];
+        [_recentURLs addObject:urlString];
+        [[NSUbiquitousKeyValueStore defaultStore] setArray:_recentURLs forKey:kVLCRecentURLs];
+
+        [self.historyTableView reloadData];
+    }
+    [self.urlField resignFirstResponder];
+    [self _openURLStringAndDismiss:self.urlField.text];
 }
 
 - (void)renameStreamFromCell:(UITableViewCell *)cell {