Skip to content

Commit

Permalink
Merge pull request omz#27 from sirnacnud/review-errors
Browse files Browse the repository at this point in the history
Improve ReviewDownloader error handling
  • Loading branch information
nicolasgomollon committed Jun 10, 2017
2 parents 0983173 + c49f9f9 commit ebf0716
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions Classes/ReviewDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
NSString *const kITCReviewAPIPlatformiOS = @"ios";
NSString *const kITCReviewAPIPlatformMac = @"osx";

@interface ReviewDownloader ()

@property (nonatomic, assign) BOOL showingAlert;
@property (nonatomic, weak) MBProgressHUD *hud;

@end

@implementation ReviewDownloader

- (instancetype)initWithProduct:(Product *)product {
Expand Down Expand Up @@ -60,11 +67,11 @@ - (void)start {

- (void)loginSucceeded {
[self downloadProgress:0.1f withStatus:NSLocalizedString(@"Loading reviews...", nil)];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
hud.mode = MBProgressHUDModeDeterminateHorizontalBar;
hud.labelText = NSLocalizedString(@"Downloading", nil);

self.hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
self.hud.mode = MBProgressHUDModeDeterminateHorizontalBar;
self.hud.labelText = NSLocalizedString(@"Downloading", nil);

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul), ^{
NSString *platform = [_product.platform isEqualToString:kProductPlatformMac] ? kITCReviewAPIPlatformMac : kITCReviewAPIPlatformiOS;
NSString *summaryPagePath = [NSString stringWithFormat:kITCReviewAPISummaryPageAction, _product.productID, platform];
Expand Down Expand Up @@ -234,11 +241,16 @@ - (void)showAlert:(NSString *)title withMessages:(NSDictionary *)messages {
}
}
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:[errorMessage componentsJoinedByString:@"\n"]
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:nil]];
[alertController show];
if (!self.showingAlert) {
self.showingAlert = YES;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:[errorMessage componentsJoinedByString:@"\n"]
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
self.showingAlert = NO;
}]];
[alertController show];
}
});
}

Expand All @@ -258,9 +270,7 @@ - (void)downloadProgress:(CGFloat)progress withStatus:(NSString *)status {
_product.account.downloadStatus = status;
}
_product.account.downloadProgress = progress;

MBProgressHUD *hud = [MBProgressHUD HUDForView:[UIApplication sharedApplication].keyWindow];
hud.progress = progress;
self.hud.progress = progress;
});
}

Expand All @@ -273,7 +283,7 @@ - (void)completeDownloadWithStatus:(NSString *)status {
if ([self.delegate respondsToSelector:@selector(reviewDownloaderDidFinish:)]) {
[self.delegate reviewDownloaderDidFinish:self];
}
[MBProgressHUD hideHUDForView:[UIApplication sharedApplication].keyWindow animated:YES];
[self.hud hide:YES];
_product.account.downloadStatus = status;
_product.account.downloadProgress = 1.0f;
_product.account.isDownloadingReports = NO;
Expand Down

0 comments on commit ebf0716

Please sign in to comment.