Explorar o código

cloud services: correctly implement OneDrive session state

Felix Paul Kühne %!s(int64=10) %!d(string=hai) anos
pai
achega
968fa93d95

+ 7 - 2
Sources/VLCCloudServicesTableViewController.m

@@ -54,16 +54,23 @@
 }
 - (void)viewWillAppear:(BOOL)animated
 {
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(authenticationSessionsChanged:) name:VLCOneDriveControllerSessionUpdated object:nil];
     [self.tableView reloadData];
     [super viewWillAppear:animated];
 }
 
 - (void)goBack
 {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
     VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
     [[appDelegate revealController] toggleSidebar:![appDelegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
 }
 
+- (void)authenticationSessionsChanged:(NSNotification *)notification
+{
+    [self.tableView reloadData];
+}
+
 #pragma mark - Table view data source
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
@@ -136,8 +143,6 @@
     return cell;
 }
 
-
-
 #pragma mark - Table view delegate
 
 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

+ 2 - 0
Sources/VLCOneDriveController.h

@@ -13,6 +13,8 @@
 #import "VLCOneDriveTableViewController.h"
 #import "VLCOneDriveObject.h"
 
+#define VLCOneDriveControllerSessionUpdated @"VLCOneDriveControllerSessionUpdated"
+
 @protocol VLCOneDriveControllerDelegate <NSObject>
 
 @required

+ 8 - 5
Sources/VLCOneDriveController.m

@@ -95,20 +95,22 @@
 {
     APLog(@"OneDrive: authCompleted, status %i, state %@", status, userState);
 
-    if (status == 1 && session != NULL && [userState isEqualToString:@"init"])
+    if (session != NULL && [userState isEqualToString:@"init"] && status == 1)
         _activeSession = YES;
-    else
-        _activeSession = NO;
 
-    if (status == 1 && session != NULL && [userState isEqualToString:@"login"])
+    if (session != NULL && [userState isEqualToString:@"login"] && status == 1)
         _userAuthenticated = YES;
-    else
+
+    if (status == 0) {
+        _activeSession = NO;
         _userAuthenticated = NO;
+    }
 
     if (self.delegate) {
         if ([self.delegate respondsToSelector:@selector(sessionWasUpdated)])
             [self.delegate performSelector:@selector(sessionWasUpdated)];
     }
+    [[NSNotificationCenter defaultCenter] postNotificationName:VLCOneDriveControllerSessionUpdated object:self];
 }
 
 - (void)authFailed:(NSError *)error userState:(id)userState
@@ -120,6 +122,7 @@
         if ([self.delegate respondsToSelector:@selector(sessionWasUpdated)])
             [self.delegate performSelector:@selector(sessionWasUpdated)];
     }
+    [[NSNotificationCenter defaultCenter] postNotificationName:VLCOneDriveControllerSessionUpdated object:self];
 }
 
 - (void)liveOperationSucceeded:(LiveDownloadOperation *)operation