Browse Source

OneDrive: Fix hierarchy navigation issue

During the `goBack` method, we're only setting the parentID.
This led to navigation failure when the hierarchy had more than
3 folders. With this patch, we now load the `parentItem`  that
loads its `parentReference`.
Soomin Lee 6 years ago
parent
commit
b55667447d

+ 1 - 0
Sources/VLCOneDriveController.h

@@ -33,6 +33,7 @@
 - (NSString *)configureSubtitleWithFileName:(NSString *)fileName folderItems:(NSArray *)folderItems;
 - (NSString *)configureSubtitleWithFileName:(NSString *)fileName folderItems:(NSArray *)folderItems;
 
 
 - (void)loadODItems;
 - (void)loadODItems;
+- (void)loadODParentItem;
 - (void)loadODItemsWithCompletionHandler:(void (^)(void))completionHandler;
 - (void)loadODItemsWithCompletionHandler:(void (^)(void))completionHandler;
 
 
 @end
 @end

+ 40 - 16
Sources/VLCOneDriveController.m

@@ -217,25 +217,49 @@
                 completionHandler();
                 completionHandler();
             }
             }
         } else {
         } else {
-            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[error localizedFailureReason]
-                                                                                     message:[error localizedDescription]
-                                                                              preferredStyle:UIAlertControllerStyleAlert];
+            [weakSelf handleLoadODItemErrorWithError:error itemID:itemID];
+        }
+    }];
+}
 
 
-            UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_OK", nil)
-                                                               style:UIAlertActionStyleCancel
-                                                             handler:^(UIAlertAction *alertAction) {
-                                                                 if (weakSelf.presentingViewController && [itemID isEqualToString:@"root"]) {
-                                                                     [weakSelf.presentingViewController.navigationController popViewControllerAnimated:YES];
-                                                                 }
-                                                             }];
+- (void)handleLoadODItemErrorWithError:(NSError *)error itemID:(NSString *)itemID
+{
+    __weak typeof(self) weakSelf = self;
 
 
-            [alertController addAction:okAction];
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[error localizedFailureReason]
+                                                                             message:[error localizedDescription]
+                                                                      preferredStyle:UIAlertControllerStyleAlert];
 
 
-            if (weakSelf.presentingViewController) {
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [weakSelf.presentingViewController presentViewController:alertController animated:YES completion:nil];
-                });
-            }
+    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_OK", nil)
+                                                       style:UIAlertActionStyleCancel
+                                                     handler:^(UIAlertAction *alertAction) {
+                                                         if (weakSelf.presentingViewController && [itemID isEqualToString:@"root"]) {
+                                                             [weakSelf.presentingViewController.navigationController popViewControllerAnimated:YES];
+                                                         }
+                                                     }];
+
+    [alertController addAction:okAction];
+
+    if (weakSelf.presentingViewController) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [weakSelf.presentingViewController presentViewController:alertController animated:YES completion:nil];
+        });
+    }
+}
+
+- (void)loadODParentItem
+{
+    NSString *parentID = _parentItem.id ? _parentItem.id : @"root";
+
+    ODItemRequest *request = [[[_oneDriveClient drive] items:parentID] request];
+
+    __weak typeof(self) weakSelf = self;
+
+    [request getWithCompletion:^(ODItem *response, NSError *error) {
+        if (!error) {
+            weakSelf.parentItem = response;
+        } else {
+            [weakSelf handleLoadODItemErrorWithError:error itemID:parentID];
         }
         }
     }];
     }];
 }
 }

+ 1 - 0
Sources/VLCOneDriveTableViewController.m

@@ -81,6 +81,7 @@
         }
         }
         [self.activityIndicator startAnimating];
         [self.activityIndicator startAnimating];
         [_oneDriveController loadODItems];
         [_oneDriveController loadODItems];
+        [_oneDriveController loadODParentItem];
     } else {
     } else {
         // We're at root, we need to pop the view
         // We're at root, we need to pop the view
         [self.navigationController popViewControllerAnimated:YES];
         [self.navigationController popViewControllerAnimated:YES];