diff options
author | Grant Paul <chpwn@chpwn.com> | 2010-11-06 13:41:16 -0700 |
---|---|---|
committer | Grant Paul <chpwn@chpwn.com> | 2010-11-06 13:41:16 -0700 |
commit | 45e21ffab72e0370345c58ce7c52c218ee41043c (patch) | |
tree | d34272a8b53905d4bfa1b2ad32bdf3a51acf0f8a /MobileCydia.mm | |
parent | 427754d6526113a4754910c8ab00fa626742556a (diff) |
Improved handling of the refresh sequence.
Specifically, it now no longer shows "Loading Data" and act strange when the internet connection is very slow, and it doesn't even run that check in the case of some partial-connection scenarios where it is still attempting to determine connection status while reloading (due to an install, etc).
Also, removed the "Reloading Data" when cancelling the refresh bar (and fixed another bug cancelling the bar, as well).
Finally, made a small formatting change to the changes badge to remove redundant code.
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r-- | MobileCydia.mm | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index 8482fe2..bc4d946 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -7024,7 +7024,7 @@ freeing the view controllers on tab change */ - (void) refreshButtonClicked { [delegate_ beginUpdate]; - [[self navigationItem] setLeftBarButtonItem:nil]; + [[self navigationItem] setLeftBarButtonItem:nil animated:YES]; } - (void) upgradeButtonClicked { @@ -7677,6 +7677,7 @@ freeing the view controllers on tab change */ } - (void) completeUpdate { + if (!updating_) return; updating_ = false; [self raiseBar:YES]; @@ -7685,8 +7686,10 @@ freeing the view controllers on tab change */ } - (void) cancelUpdate { - [refreshbar_ cancel]; - [self completeUpdate]; + updating_ = false; + [self raiseBar:YES]; + [refreshbar_ stop]; + [updatedelegate_ performSelector:@selector(updateData) withObject:nil afterDelay:0]; } - (void) cancelPressed { @@ -7986,6 +7989,30 @@ static _finline void _setHomePage(Cydia *self) { - (void) _refreshIfPossible { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + bool recently = false; + NSDate *update([Metadata_ objectForKey:@"LastUpdate"]); + if (update != nil) { + NSTimeInterval interval([update timeIntervalSinceNow]); + if (interval <= 0 && interval > -(15*60)) + recently = true; + } + + // Don't automatic refresh if: + // - We already refreshed recently. + // - We already auto-refreshed this launch. + // - Auto-refresh is disabled. + if (recently || loaded_ || ManualRefresh) { + [self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO]; + + // If we are cancelling due to ManualRefresh or a recent refresh + // we need to make sure it knows it's already loaded. + loaded_ = true; + return; + } else { + // We are going to load, so remember that. + loaded_ = true; + } + SCNetworkReachabilityFlags flags; { SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(NULL, "cydia.saurik.com")); SCNetworkReachabilityGetFlags(reachability, &flags); @@ -8004,21 +8031,9 @@ static _finline void _setHomePage(Cydia *self) { ) ); - if (loaded_ || ManualRefresh || !reachable) loaded: - [self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO]; - else { - loaded_ = true; - - NSDate *update([Metadata_ objectForKey:@"LastUpdate"]); - - if (update != nil) { - NSTimeInterval interval([update timeIntervalSinceNow]); - if (interval <= 0 && interval > -(15*60)) - goto loaded; - } - + // If we can reach the server, auto-refresh! + if (reachable) [container_ performSelectorOnMainThread:@selector(setUpdate:) withObject:update waitUntilDone:NO]; - } [pool release]; } @@ -8052,18 +8067,19 @@ static _finline void _setHomePage(Cydia *self) { } } + UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem]; if (changes != 0) { NSString *badge([[NSNumber numberWithInt:changes] stringValue]); - [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem] setBadgeValue:badge]; - [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem] setAnimatedBadge:YES]; + [changesItem setBadgeValue:badge]; + [changesItem setAnimatedBadge:YES]; if ([self respondsToSelector:@selector(setApplicationBadge:)]) [self setApplicationBadge:badge]; else [self setApplicationBadgeString:badge]; } else { - [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem] setBadgeValue:nil]; - [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem] setAnimatedBadge:NO]; + [changesItem setBadgeValue:nil]; + [changesItem setAnimatedBadge:NO]; if ([self respondsToSelector:@selector(removeApplicationBadge)]) [self removeApplicationBadge]; |