From 901a2e1cdd953558f7589dd0a398fea2fcf0e7e4 Mon Sep 17 00:00:00 2001 From: Moritz Haarmann Date: Mon, 12 May 2014 02:05:45 +0200 Subject: [PATCH] + Async loading of attachments once shown. --- Classes/BITFeedbackListViewController.m | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Classes/BITFeedbackListViewController.m b/Classes/BITFeedbackListViewController.m index 535373af0f..f9d2094694 100644 --- a/Classes/BITFeedbackListViewController.m +++ b/Classes/BITFeedbackListViewController.m @@ -74,6 +74,7 @@ @property (nonatomic, strong) NSDateFormatter *lastUpdateDateFormatter; @property (nonatomic) BOOL userDataComposeFlow; @property (nonatomic, strong) NSArray *cachedPreviewItems; +@property (nonatomic, strong) NSOperationQueue *thumbnailQueue; @end @@ -95,6 +96,8 @@ [self.lastUpdateDateFormatter setDateStyle:NSDateFormatterShortStyle]; [self.lastUpdateDateFormatter setTimeStyle:NSDateFormatterShortStyle]; self.lastUpdateDateFormatter.locale = [NSLocale currentLocale]; + + _thumbnailQueue = [NSOperationQueue new]; } return self; } @@ -636,6 +639,22 @@ cell.labelText.userInteractionEnabled = YES; cell.delegate = self; [cell setAttachments:message.attachments]; + + for (BITFeedbackMessageAttachment *attachment in message.attachments){ + if (attachment.needsLoadingFromURL && !attachment.isLoading){ + attachment.isLoading = YES; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:attachment.sourceURL]]; + [NSURLConnection sendAsynchronousRequest:request queue:self.thumbnailQueue completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *err) { + if (responseData.length){ + [attachment replaceData:responseData]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.tableView reloadData]; + }); + [[BITHockeyManager sharedHockeyManager].feedbackManager saveMessages]; + } + }]; + } + } if ( [self.manager isPreiOS7Environment] || @@ -819,14 +838,14 @@ if (attachment.needsLoadingFromURL && !attachment.isLoading){ attachment.isLoading = YES; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:attachment.sourceURL]]; - [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue new] completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *err) { + [NSURLConnection sendAsynchronousRequest:request queue:self.thumbnailQueue completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *err) { if (responseData.length){ [attachment replaceData:responseData]; [controller reloadData]; [[BITHockeyManager sharedHockeyManager].feedbackManager saveMessages]; } }]; - return nil; + return attachment; } else { return self.cachedPreviewItems[index]; }