From 540437033286aa962b940cefac84686abf6d9ffa Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 2 Dec 2010 03:33:09 -0800 Subject: [PATCH] Use UIApplication::networkActivityIndicator to indicate network activity. --- MobileCydia.mm | 46 ++++++++++++++++++++++++++++++--------- UICaboodle/BrowserView.h | 2 ++ UICaboodle/BrowserView.mm | 7 ++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index 7b4b70fe..5c12b8b1 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1184,6 +1184,8 @@ bool isSectionVisible(NSString *section) { @class PackageController; @protocol CydiaDelegate +- (void) retainNetworkActivityIndicator; +- (void) releaseNetworkActivityIndicator; - (void) setPackageController:(PackageController *)view; - (void) clearPackage:(Package *)package; - (void) installPackage:(Package *)package; @@ -1202,6 +1204,8 @@ bool isSectionVisible(NSString *section) { - (PackageController *) packageController; - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item; @end + +static id CydiaApp; /* }}} */ /* Status Delegation {{{ */ @@ -3580,6 +3584,8 @@ static NSString *Warning_; return; } + [CydiaApp retainNetworkActivityIndicator]; + bool failed = false; for (pkgAcquire::ItemIterator item = fetcher_->ItemsBegin(); item != fetcher_->ItemsEnd(); item++) { if ((*item)->Status == pkgAcquire::Item::StatDone && (*item)->Complete) @@ -3601,6 +3607,8 @@ static NSString *Warning_; ]; } + [CydiaApp releaseNetworkActivityIndicator]; + if (failed) { _trace(); return; @@ -6684,9 +6692,10 @@ freeing the view controllers on tab change */ } - (void) beginUpdate { - [self dropBar:YES]; [refreshbar_ start]; + [self dropBar:YES]; + [updatedelegate_ retainNetworkActivityIndicator]; updating_ = true; [NSThread @@ -6708,21 +6717,24 @@ freeing the view controllers on tab change */ ]; } -- (void) completeUpdate { - if (!updating_) - return; +- (void) stopUpdateWithSelector:(SEL)selector { updating_ = false; + [updatedelegate_ releaseNetworkActivityIndicator]; [self raiseBar:YES]; [refreshbar_ stop]; - [updatedelegate_ performSelector:@selector(reloadData) withObject:nil afterDelay:0]; + + [updatedelegate_ performSelector:selector withObject:nil afterDelay:0]; +} + +- (void) completeUpdate { + if (!updating_) + return; + [self stopUpdateWithSelector:@selector(reloadData)]; } - (void) cancelUpdate { - updating_ = false; - [self raiseBar:YES]; - [refreshbar_ stop]; - [updatedelegate_ performSelector:@selector(updateData) withObject:nil afterDelay:0]; + [self stopUpdateWithSelector:@selector(updateData)]; } - (void) cancelPressed { @@ -7991,9 +8003,11 @@ typedef enum { Database *database_; + NSURL *starturl_; int tag_; + unsigned locked_; - NSURL *starturl_; + unsigned activity_; SectionsController *sections_; ChangesController *changes_; @@ -8471,6 +8485,16 @@ static _finline void _setHomePage(Cydia *self) { [tabbar_ presentModalViewController:nav animated:YES]; } +- (void) retainNetworkActivityIndicator { + if (activity_++ == 0) + [self setNetworkActivityIndicatorVisible:YES]; +} + +- (void) releaseNetworkActivityIndicator { + if (--activity_ == 0) + [self setNetworkActivityIndicatorVisible:NO]; +} + - (void) setPackageController:(PackageController *)view { WebThreadLock(); [view setPackage:nil]; @@ -8766,6 +8790,8 @@ static _finline void _setHomePage(Cydia *self) { - (void) applicationDidFinishLaunching:(id)unused { _trace(); + CydiaApp = self; + [NSURLCache setSharedURLCache:[[[SDURLCache alloc] initWithMemoryCapacity:524288 diskCapacity:10485760 diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index f5d50294..f224326a 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -50,6 +50,8 @@ @end @protocol BrowserControllerDelegate +- (void) retainNetworkActivityIndicator; +- (void) releaseNetworkActivityIndicator; - (CYViewController *) pageForURL:(NSURL *)url hasTag:(int *)tag; @end diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index 5fd65c21..f1053f85 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -451,6 +451,8 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se if (title_ != nil) [title_ release]; + if ([loading_ count] != 0) + [delegate_ releaseNetworkActivityIndicator]; [loading_ release]; [reloaditem_ release]; @@ -904,11 +906,16 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se - (void) _didStartLoading { [self applyRightButton]; + + if ([loading_ count] != 1) + return; + [delegate_ retainNetworkActivityIndicator]; } - (void) _didFinishLoading { if ([loading_ count] != 0) return; + [delegate_ releaseNetworkActivityIndicator]; [self applyRightButton]; -- 2.45.2