Преглед на файлове

OneDrive: Handle content.downloadURl nil case by displaying an error message

Carola Nitz преди 6 години
родител
ревизия
ba47b33d9b
променени са 3 файла, в които са добавени 29 реда и са изтрити 14 реда
  1. 2 0
      Resources/en.lproj/Localizable.strings
  2. 1 1
      Sources/VLCCloudStorageTableViewCell.m
  3. 26 13
      Sources/VLCOneDriveTableViewController.m

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

@@ -148,6 +148,8 @@
 "GDRIVE_ERROR_DOWNLOADING_FILE" = "An error occured while downloading";
 "GDRIVE_ERROR_DOWNLOADING_FILE_TITLE" = "ERROR";
 
+"ONEDRIVE_MEDIA_WITHOUT_URL" = "The selected Media doesn't have a playable url";
+
 "DISK_FULL" = "Storage limit reached";
 "DISK_FULL_FORMAT" = "%@ cannot be stored on your %@, because you don't have enough free space left.";
 

+ 1 - 1
Sources/VLCCloudStorageTableViewCell.m

@@ -70,7 +70,7 @@
 
 - (void)loadThumbnail
 {
-    // The dropboxapi has no way to cancel a request and the ODThumbnail has no back reference to it's item
+    // The onedrive Api has no way to cancel a request and the ODThumbnail has no back reference to it's item
     // so this might lead to wrong thumbnails if the cell is reused since we have no way of cancelling requests or check if the completion is still for the set item
     ODDriveRequestBuilder *drive = [[ODClient loadCurrentClient] drive];
     ODThumbnailRequest *request = [[[[drive items:_oneDriveFile.id] thumbnails:@"0"] medium] request];

+ 26 - 13
Sources/VLCOneDriveTableViewController.m

@@ -126,20 +126,33 @@
         [_oneDriveController loadODItems];
         self.title = selectedItem.name;
     } else {
-        VLCMediaList *mediaList;
-        NSURL *url = [NSURL URLWithString:selectedItem.dictionaryFromItem[@"@content.downloadUrl"]];
-        NSString *subtitlePath = nil;
-        NSInteger positionIndex = 0;
-
-        if (![[NSUserDefaults standardUserDefaults] boolForKey:kVLCAutomaticallyPlayNextItem]) {
-            mediaList = [[VLCMediaList alloc] initWithArray:@[[VLCMedia mediaWithURL:url]]];
-            subtitlePath = [_oneDriveController configureSubtitleWithFileName:selectedItem.name
-                                                                  folderItems:items];
+        NSString *streamingURLString = selectedItem.dictionaryFromItem[@"@content.downloadUrl"];
+        if (streamingURLString) {
+            VLCMediaList *mediaList;
+            NSURL *url = [NSURL URLWithString:streamingURLString];
+            NSString *subtitlePath = nil;
+            NSInteger positionIndex = 0;
+
+            if (![[NSUserDefaults standardUserDefaults] boolForKey:kVLCAutomaticallyPlayNextItem]) {
+                mediaList = [[VLCMediaList alloc] initWithArray:@[[VLCMedia mediaWithURL:url]]];
+                subtitlePath = [_oneDriveController configureSubtitleWithFileName:selectedItem.name
+                                                                      folderItems:items];
+            } else {
+                mediaList = [self createMediaListWithODItem:selectedItem positionIndex:&positionIndex];
+            }
+            [self streamMediaList:mediaList startingAtIndex:positionIndex subtitlesFilePath:subtitlePath];
         } else {
-            mediaList = [self createMediaListWithODItem:selectedItem positionIndex:&positionIndex];
-        }
+            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"ERROR", nil)
+                                                                                     message:NSLocalizedString(@"ONEDRIVE_MEDIA_WITHOUT_URL", nil)
+                                                                              preferredStyle:UIAlertControllerStyleAlert];
+
+            UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_OK", nil)
+                                                               style:UIAlertActionStyleCancel
+                                                             handler:nil];
 
-        [self streamMediaList:mediaList startingAtIndex:positionIndex subtitlesFilePath:subtitlePath];
+            [alertController addAction:okAction];
+            [self presentViewController:alertController animated:YES completion:nil];
+        }
     }
     [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
 }
@@ -231,7 +244,7 @@
         UIAlertAction *downloadAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
                                                            style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction *alertAction){
-                                                             [_oneDriveController startDownloadingODItem:selectedItem];
+                                                             [self->_oneDriveController startDownloadingODItem:selectedItem];
                                                          }];
         UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
                                                                style:UIAlertActionStyleCancel