From 27e9c3d6f6a9e8099cfcb1b526d01362bd4c1805 Mon Sep 17 00:00:00 2001 From: jonkean Date: Thu, 10 Mar 2011 21:49:47 -0800 Subject: [PATCH] Tower is suppose to be easy to use and 'better' than command line git. I suppose 'better' includes the ability to do crazy git ignore changes that delete everything (and for the changes not to show up on ones local repo) --- Classes/ReviewManager.m | 166 +++------------------------------------- 1 file changed, 10 insertions(+), 156 deletions(-) diff --git a/Classes/ReviewManager.m b/Classes/ReviewManager.m index f5c8441a..8c3d04ef 100644 --- a/Classes/ReviewManager.m +++ b/Classes/ReviewManager.m @@ -21,7 +21,7 @@ // used to pass stuff between background worker threads and main thread // could refactor this so this object is doing the update work @interface ReviewUpdateBundle : NSObject { - @private +@private NSString *appID; NSArray *input; NSMutableArray *needsUpdating; @@ -52,7 +52,7 @@ - (void) dealloc { @interface StoreInfo : NSObject { - @private +@private NSString *countryCode; NSString *storeFrontID; NSString *countryName; @@ -123,12 +123,8 @@ + (ReviewManager*) sharedManager { } - (id) init { - if (self = [super init]) { - NSString *notification = UIApplicationWillTerminateNotification; - if (&UIApplicationDidEnterBackgroundNotification) { - notification = UIApplicationDidEnterBackgroundNotification; - } - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cancel) name:notification object:nil]; + if ((self = [super init]) != nil) { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cancel) name:UIApplicationDidEnterBackgroundNotification object:nil]; } return self; } @@ -191,11 +187,11 @@ - (void) checkIfReviewsUpToDate:(ReviewUpdateBundle*)bundle { if (oldReview == nil) { // new review [bundle.needsUpdating addObject:fetchedReview]; // needs translation and updating } else if (! [oldReview.text isEqual:fetchedReview.text]) { - // fetched review is different than what's stored + // fetched review is different than what's stored const NSTimeInterval ageOfStaleReviewsToIgnore = 24 * 60 * 60; // 1 day NSComparisonResult compare = [fetchedReview.reviewDate compare:oldReview.reviewDate]; if ((compare == NSOrderedSame || compare == NSOrderedDescending) - && ageOfStaleReviewsToIgnore < -1*[fetchedReview.reviewDate timeIntervalSinceNow]) { + && ageOfStaleReviewsToIgnore < -1*[fetchedReview.reviewDate timeIntervalSinceNow]) { // if a user writes a review then immediately submits a different review, // occasionally Apples web servers won't propagate the updated review to all it's webservers, // leaving different reviews on different web servers. @@ -369,149 +365,7 @@ - (void) updateReviews { #if APPSALES_DEBUG NSDate *start = [NSDate date]; #endif - -<<<<<<< HEAD -======= - // setup store fronts, this should probably go into a plist...: - NSDateFormatter *frDateFormatter = [[[NSDateFormatter alloc] init] autorelease]; - NSLocale *frLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"fr"] autorelease]; - [frDateFormatter setLocale:frLocale]; - [frDateFormatter setDateFormat:@"dd MMM yyyy"]; - - NSDateFormatter *deDateFormatter = [[[NSDateFormatter alloc] init] autorelease]; - NSLocale *deLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"de"] autorelease]; - [deDateFormatter setLocale:deLocale]; - [deDateFormatter setDateFormat:@"dd.MM.yyyy"]; - - NSDateFormatter *itDateFormatter = [[[NSDateFormatter alloc] init] autorelease]; - NSLocale *itLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"it"] autorelease]; - [itDateFormatter setLocale:itLocale]; - [itDateFormatter setDateFormat:@"dd-MMM-yyyy"]; - - NSDateFormatter *usDateFormatter = [[[NSDateFormatter alloc] init] autorelease]; - NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en-us"] autorelease]; - [usDateFormatter setLocale:usLocale]; - [usDateFormatter setDateFormat:@"MMM dd, yyyy"]; - - defaultDateFormatter = [[NSDateFormatter alloc] init]; - [defaultDateFormatter setDateFormat:@"dd-MMM-yyyy"]; - [defaultDateFormatter setLocale:usLocale]; - - storeInfos = [[NSMutableArray alloc] initWithObjects: - getStoreInfoDictionary(@"ae", @"143481", nil), - getStoreInfoDictionary(@"am", @"143524", nil), - getStoreInfoDictionary(@"ar", @"143505", nil), - getStoreInfoDictionary(@"at", @"143445", nil), - getStoreInfoDictionary(@"au", @"143460", nil), - getStoreInfoDictionary(@"bd", @"143446", nil), - getStoreInfoDictionary(@"be", @"143446", nil), - getStoreInfoDictionary(@"bg", @"143526", nil), - getStoreInfoDictionary(@"br", @"143503", nil), - getStoreInfoDictionary(@"bw", @"143525", nil), - getStoreInfoDictionary(@"ca", @"143455", nil), - getStoreInfoDictionary(@"ch", @"143459", nil), - getStoreInfoDictionary(@"ci", @"143527", nil), - getStoreInfoDictionary(@"cl", @"143483", nil), - getStoreInfoDictionary(@"cn", @"143465", nil), - getStoreInfoDictionary(@"co", @"143501", nil), - getStoreInfoDictionary(@"cr", @"143495", nil), - getStoreInfoDictionary(@"cz", @"143489", nil), - getStoreInfoDictionary(@"de", @"143443", deDateFormatter), - getStoreInfoDictionary(@"dk", @"143458", nil), - getStoreInfoDictionary(@"do", @"143508", nil), - getStoreInfoDictionary(@"ec", @"143509", nil), - getStoreInfoDictionary(@"ee", @"143518", nil), - getStoreInfoDictionary(@"eg", @"143516", nil), - getStoreInfoDictionary(@"es", @"143454", nil), - getStoreInfoDictionary(@"fi", @"143447", nil), - getStoreInfoDictionary(@"fr", @"143442", frDateFormatter), - getStoreInfoDictionary(@"gb", @"143444", nil), - getStoreInfoDictionary(@"gr", @"143448", nil), - getStoreInfoDictionary(@"gt", @"143504", nil), - getStoreInfoDictionary(@"hk", @"143463", nil), - getStoreInfoDictionary(@"hn", @"143510", nil), - getStoreInfoDictionary(@"hr", @"143494", nil), - getStoreInfoDictionary(@"hu", @"143482", nil), - getStoreInfoDictionary(@"id", @"143476", nil), - getStoreInfoDictionary(@"ie", @"143449", nil), - getStoreInfoDictionary(@"il", @"143491", nil), - getStoreInfoDictionary(@"in", @"143467", nil), - getStoreInfoDictionary(@"it", @"143450", itDateFormatter), - getStoreInfoDictionary(@"jm", @"143511", nil), - getStoreInfoDictionary(@"jo", @"143528", nil), - getStoreInfoDictionary(@"jp", @"143462", nil), - getStoreInfoDictionary(@"ke", @"143529", nil), - getStoreInfoDictionary(@"kr", @"143466", nil), - getStoreInfoDictionary(@"kw", @"143493", nil), - getStoreInfoDictionary(@"kz", @"143517", nil), - getStoreInfoDictionary(@"lb", @"143497", nil), - getStoreInfoDictionary(@"li", @"143522", nil), - getStoreInfoDictionary(@"lk", @"143486", nil), - getStoreInfoDictionary(@"lt", @"143520", nil), - getStoreInfoDictionary(@"lu", @"143451", nil), - getStoreInfoDictionary(@"lv", @"143519", nil), - getStoreInfoDictionary(@"md", @"143523", nil), - getStoreInfoDictionary(@"mg", @"143531", nil), - getStoreInfoDictionary(@"mk", @"143530", nil), - getStoreInfoDictionary(@"ml", @"143532", nil), - getStoreInfoDictionary(@"mo", @"143515", nil), - getStoreInfoDictionary(@"mt", @"143521", nil), - getStoreInfoDictionary(@"mu", @"143533", nil), - getStoreInfoDictionary(@"mv", @"143488", nil), - getStoreInfoDictionary(@"mx", @"143468", nil), - getStoreInfoDictionary(@"my", @"143473", nil), - getStoreInfoDictionary(@"ne", @"143534", nil), - getStoreInfoDictionary(@"ni", @"143512", nil), - getStoreInfoDictionary(@"nl", @"143452", nil), - getStoreInfoDictionary(@"no", @"143457", nil), - getStoreInfoDictionary(@"np", @"143484", nil), - getStoreInfoDictionary(@"nz", @"143461", nil), - getStoreInfoDictionary(@"pa", @"143485", nil), - getStoreInfoDictionary(@"pe", @"143507", nil), - getStoreInfoDictionary(@"ph", @"143474", nil), - getStoreInfoDictionary(@"pk", @"143477", nil), - getStoreInfoDictionary(@"pl", @"143478", nil), - getStoreInfoDictionary(@"pt", @"143453", nil), - getStoreInfoDictionary(@"py", @"143513", nil), - getStoreInfoDictionary(@"qa", @"143498", nil), - getStoreInfoDictionary(@"ro", @"143487", nil), - getStoreInfoDictionary(@"rs", @"143500", nil), - getStoreInfoDictionary(@"ru", @"143469", nil), - getStoreInfoDictionary(@"sa", @"143479", nil), - getStoreInfoDictionary(@"se", @"143456", nil), - getStoreInfoDictionary(@"sg", @"143464", nil), - getStoreInfoDictionary(@"si", @"143499", nil), - getStoreInfoDictionary(@"sk", @"143496", nil), - getStoreInfoDictionary(@"sn", @"143535", nil), - getStoreInfoDictionary(@"sv", @"143506", nil), - getStoreInfoDictionary(@"th", @"143475", nil), - getStoreInfoDictionary(@"tn", @"143536", nil), - getStoreInfoDictionary(@"tr", @"143480", nil), - getStoreInfoDictionary(@"tw", @"143470", nil), - getStoreInfoDictionary(@"ua", @"143492", nil), - getStoreInfoDictionary(@"ug", @"143537", nil), - getStoreInfoDictionary(@"us", @"143441", usDateFormatter), - getStoreInfoDictionary(@"uy", @"143514", nil), - getStoreInfoDictionary(@"ve", @"143502", nil), - getStoreInfoDictionary(@"vn", @"143471", nil), - getStoreInfoDictionary(@"za", @"143472", nil), - nil]; - - // sort regions by its number of existing reviews, so the less active regions are downloaded last - NSMutableDictionary *numExistingReviews = [NSMutableDictionary dictionary]; - for (App *app in [AppManager sharedManager].allApps) { - for (Review *review in [app.reviewsByUser objectEnumerator]) { - NSNumber *object = [numExistingReviews objectForKey:review.countryCode]; - const NSUInteger count = (object ? object.intValue + 1 : 1); - [numExistingReviews setObject:[NSNumber numberWithInt:count] forKey:review.countryCode]; - } - } - [storeInfos sortUsingFunction:&numStoreReviewsComparator context:numExistingReviews]; - - // increment field can only be accessed on main thread - NSNumber *increment = [NSNumber numberWithFloat:100.0f / storeInfos.count]; - [self performSelectorOnMainThread:@selector(resetProgressIncrement:) withObject:increment waitUntilDone:NO]; ->>>>>>> 60a240bec0eec7cfbeb54d3f6e804409f68d509d + downloadDate = [NSDate new]; condition = [NSCondition new]; @@ -537,14 +391,14 @@ - (void) updateReviews { defaultDateFormatter = nil; [downloadDate release]; downloadDate = nil; - + [self performSelectorOnMainThread:@selector(finishDownloadingReviews) withObject:nil waitUntilDone:NO]; APPSALESLOG(@"update took %f sec", -1*start.timeIntervalSinceNow); [pool release]; } - (void) updateReviewDownloadProgress:(NSString*)status { -// NSAssert([NSThread isMainThread], nil); + // NSAssert([NSThread isMainThread], nil); [status retain]; // must retain first [reviewDownloadStatus release]; reviewDownloadStatus = status; @@ -746,7 +600,7 @@ - (void) downloadReviews { NSMutableArray *numAllAppRegionReviews = [NSMutableArray arrayWithCapacity:allApps.count * storeInfos.count]; // raw review count for all app regions NSMutableDictionary *numRegionReviews = [NSMutableDictionary dictionaryWithCapacity:storeInfos.count]; // number reviews for all apps (countryCode -> NSNumber) NSMutableDictionary *appRegionReviews = [NSMutableDictionary dictionaryWithCapacity:allApps.count]; // number of reviews for app region (appID -> (countryCode -> NSNumber)) - + for (App *app in allApps) { NSMutableDictionary *numAppRegionReviews = [NSMutableDictionary dictionaryWithCapacity:storeInfos.count]; [appRegionReviews setValue:numAppRegionReviews forKey:app.appID];