Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix never ending login loop & choose Button #6

Merged
merged 2 commits into from

2 participants

Stephan Diederich Simon Whitaker
Stephan Diederich

No description provided.

diederich added some commits
Stephan Diederich diederich fix never-ending login loop
if the app has not been linked yet, viewWillAppear
always presented the login-Controller resulting in a loop
the user is stuck in.
Fix it by factoring out code to present controller and thus
use the retry-count. if retries are reached, let the delegate know we cancelled.

Also, disable the 'cancel' barButton while the login-controller is presented.
This fixes a crash when DropboxSDK presents the login-controller async
and use dismisses the selection controller.
029bf27
Stephan Diederich diederich disable choose button while there's no valid data yet
factor test from tableViewDatasource and reuse it
to enable the choose button.
f20344b
Simon Whitaker simonwhitaker merged commit 2c31b4a into from
Simon Whitaker

Thanks, and sorry for taking so long to merge it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 23, 2013
  1. Stephan Diederich

    fix never-ending login loop

    diederich authored
    if the app has not been linked yet, viewWillAppear
    always presented the login-Controller resulting in a loop
    the user is stuck in.
    Fix it by factoring out code to present controller and thus
    use the retry-count. if retries are reached, let the delegate know we cancelled.
    
    Also, disable the 'cancel' barButton while the login-controller is presented.
    This fixes a crash when DropboxSDK presents the login-controller async
    and use dismisses the selection controller.
  2. Stephan Diederich

    disable choose button while there's no valid data yet

    diederich authored
    factor test from tableViewDatasource and reuse it
    to enable the choose button.
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 8 deletions.
  1. +40 −8 GSDropboxActivity/GSDropboxDestinationSelectionViewController.m
48 GSDropboxActivity/GSDropboxDestinationSelectionViewController.m
View
@@ -75,6 +75,8 @@ - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
+ [self updateChooseButton];
+
if (self.rootPath == nil)
self.rootPath = @"/";
@@ -85,6 +87,23 @@ - (void)viewWillAppear:(BOOL)animated
}
self.navigationItem.prompt = NSLocalizedString(@"Choose a destination for uploads.", @"Prompt asking user to select a destination folder on Dropbox to which uploads will be saved.") ;
self.isLoading = YES;
+ self.navigationItem.rightBarButtonItem.enabled = YES;
+}
+
+- (void) updateChooseButton {
+ NSArray* toolbarButtons = self.toolbarItems;
+ if(toolbarButtons.count < 2) {
+ //Not found
+ return;
+ }
+ UIBarButtonItem *item = toolbarButtons[1];
+ BOOL hasValidData = [self hasValidData];
+ item.enabled = hasValidData;
+}
+
+- (BOOL) hasValidData {
+ BOOL valid = self.subdirectories != nil && self.isLoading == NO;
+ return valid;
}
- (void)viewDidAppear:(BOOL)animated
@@ -92,12 +111,25 @@ - (void)viewDidAppear:(BOOL)animated
[super viewDidAppear:animated];
if (![[DBSession sharedSession] isLinked]) {
- [[DBSession sharedSession] linkFromController:self];
+ [self showLoginDialogOrCancel];
} else {
[self.dropboxClient loadMetadata:self.rootPath];
}
}
+- (void) showLoginDialogOrCancel {
+ if(self.dropboxConnectionRetryCount < kDropboxConnectionMaxRetries) {
+ self.dropboxConnectionRetryCount++;
+ //disable cancel button, as if the user pressed it while we're presenting
+ //the loging viewcontroller (async), UIKit crashes with multiple viewcontroller
+ //animations
+ self.navigationItem.rightBarButtonItem.enabled = NO;
+ [[DBSession sharedSession] linkFromController:self];
+ } else {
+ [self.delegate dropboxDestinationSelectionViewControllerDidCancel:self];
+ }
+}
+
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
@@ -125,9 +157,8 @@ - (DBRestClient *)dropboxClient
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- if (self.isLoading || self.subdirectories == nil || [self.subdirectories count] == 0) {
- return 1;
- }
+ if (![self hasValidData] || self.subdirectories.count < 1) return 1;
+
return [self.subdirectories count];
}
@@ -186,18 +217,19 @@ - (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata
}
self.subdirectories = [array sortedArrayUsingSelector:@selector(compare:)];
self.isLoading = NO;
+ [self updateChooseButton];
}
- (void)restClient:(DBRestClient *)client loadMetadataFailedWithError:(NSError *)error
{
// Error 401 gets returned if a token is invalid, e.g. if the user has deleted
// the app from their list of authorized apps at dropbox.com
- if (error.code == 401 && self.dropboxConnectionRetryCount < kDropboxConnectionMaxRetries) {
- self.dropboxConnectionRetryCount++;
- [[DBSession sharedSession] linkFromController:self];
+ if (error.code == 401) {
+ [self showLoginDialogOrCancel];
} else {
self.isLoading = NO;
}
+ [self updateChooseButton];
}
- (void)setIsLoading:(BOOL)isLoading
@@ -231,7 +263,7 @@ - (void)handleApplicationBecameActive:(NSNotification *)notification
// to authenticate
[self.dropboxClient loadMetadata:self.rootPath];
self.isLoading = YES;
-
+ self.navigationItem.rightBarButtonItem.enabled = YES;
}
@end
Something went wrong with that request. Please try again.