Skip to content

Commit

Permalink
more relevant status text while downloading reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkean committed Nov 24, 2009
1 parent 7792f1e commit b1e8ed7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Classes/AppCell.m
Expand Up @@ -91,7 +91,11 @@ - (void)drawRect:(CGRect)rect

[((cell.highlighted) ? [UIColor whiteColor] : [UIColor darkGrayColor]) set];
int numberOfReviews = [app.reviewsByUser count];
NSString *numberOfReviewsDescription = [NSString stringWithFormat:NSLocalizedString(@"%i Reviews (%i new)",nil), numberOfReviews, app.newReviewsCount];
NSString *numberOfReviewsDescription = [NSString stringWithFormat:NSLocalizedString(@"%i Reviews",nil), numberOfReviews];
if (app.newReviewsCount) {
numberOfReviewsDescription = [numberOfReviewsDescription stringByAppendingFormat:
NSLocalizedString(@" (%i new)",nil), app.newReviewsCount];
}
[numberOfReviewsDescription drawInRect:CGRectMake(50, 25, 140, 15) withFont:[UIFont systemFontOfSize:12.0]];
}

Expand Down
1 change: 0 additions & 1 deletion Classes/ReportManager.m
Expand Up @@ -527,7 +527,6 @@ - (void)downloadReviews
[UIApplication sharedApplication].idleTimerDisabled = YES;

isDownloadingReviews = YES;
[self updateReviewDownloadProgress:NSLocalizedString(@"Downloading reviews...",nil)];

NSMutableDictionary *appIDs = [NSMutableDictionary dictionary];
for (NSString *appID in [self.appsByID allKeys]) {
Expand Down
3 changes: 2 additions & 1 deletion Classes/ReviewUpdater.h
Expand Up @@ -4,8 +4,9 @@

@interface ReviewUpdater : NSObject {
NSDictionary *appsByID;
NSUInteger numberOfStores; // for presentation

id callback; // FIXME. Ugly hack, used to update the GUI status
id callback; // FIXME Ugly hack, used to update the GUI status

// used by worker threads
NSCondition *condition;
Expand Down
15 changes: 11 additions & 4 deletions Classes/ReviewUpdater.m
Expand Up @@ -54,13 +54,19 @@ - (void) dealloc {

- (NSDictionary*) getNextStoreToFetch {
NSDictionary *storeInfo;
NSString *status = nil;
@synchronized (storeInfos) {
storeInfo = [storeInfos lastObject];
if (storeInfo) {
const NSUInteger percentComplete = 100 * (1 - (storeInfos.count / (float)numberOfStores));
status = [NSString stringWithFormat:@"%2d complete", percentComplete];
[storeInfos removeLastObject];
}
}
return storeInfo; // gcc is retarded and warns if returning inside synchronized block
if (status) {
[callback performSelectorOnMainThread:@selector(updateReviewDownloadProgress:) withObject:status waitUntilDone:NO]; // FIXME
}
return storeInfo;
}

- (void) workerDone {
Expand Down Expand Up @@ -101,10 +107,7 @@ - (void) workerThreadFetch { // called by worker threads

while ((storeInfo = [self getNextStoreToFetch]) != nil) {
NSAutoreleasePool *innerPool = [NSAutoreleasePool new];
NSString *countryName = [storeInfo objectForKey:@"countryName"];
NSString *countryCode = [storeInfo objectForKey:@"countryCode"];
NSString *status = [NSString stringWithFormat:@"%@", countryName];
[callback performSelectorOnMainThread:@selector(updateReviewDownloadProgress:) withObject:status waitUntilDone:NO]; // FIXME

for (NSString *appID in [appsByID keyEnumerator]) {
//NSLog(@"Downloading reviews for app %@ in %@", [appIDs objectForKey:appID], countryName);
Expand Down Expand Up @@ -536,16 +539,20 @@ - (void) updateReviews {
@"143462", @"storeFrontID",
nil]];

numberOfStores = storeInfos.count;

condition = [[NSCondition alloc] init];
numThreadsActive = NUMBER_OF_FETCHING_THREADS;

for (int i=0; i < NUMBER_OF_FETCHING_THREADS; i++) {
[self performSelectorInBackground:@selector(workerThreadFetch) withObject:nil];
}

NSDate *start = [NSDate date];
[condition lock];
[condition wait]; // wait for workers to finish
[condition unlock];
NSLog(@"update took %f sec", -1*[start timeIntervalSinceNow]);

[condition release];
condition = nil;
Expand Down

0 comments on commit b1e8ed7

Please sign in to comment.