Fix SYIOS-41 : file uploads (and downloads) should be able to happen in parallel with basic progress meters

This commit is contained in:
ylecollen
2015-01-07 10:45:35 +01:00
parent 4bdd855cd8
commit fccc963202
7 changed files with 94 additions and 4 deletions
+54
View File
@@ -35,14 +35,68 @@
@implementation OutgoingMessageTableCell
- (void)dealloc {
[self stopAnimating];
}
-(void)startAnimating {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMediaUploadProgressNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUploadProgress:) name:kMediaUploadProgressNotification object:nil];
self.activityIndicator.hidden = NO;
[self.activityIndicator startAnimating];
[self updateUploadProgressTo:self.message.uploadProgress];
}
-(void)stopAnimating {
// remove any pie chart
[pieChartView removeFromSuperview];
pieChartView = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMediaUploadProgressNotification object:nil];
[self.activityIndicator stopAnimating];
}
- (void)onUploadProgress:(NSNotification *)notif {
// sanity check
if ([notif.object isKindOfClass:[NSString class]]) {
NSString* url = notif.object;
if ([url isEqualToString:self.message.thumbnailURL] || [url isEqualToString:self.message.attachmentURL]) {
NSNumber* progressNumber = [notif.userInfo valueForKey:kMediaManagerProgressKey];
if (progressNumber) {
[self updateUploadProgressTo:progressNumber.floatValue];
}
}
}
}
- (void) updateUploadProgressTo:(CGFloat)progress {
// nothing to display
if (progress <= 0) {
[pieChartView removeFromSuperview];
pieChartView = nil;
self.activityIndicator.hidden = NO;
} else {
if (!pieChartView) {
pieChartView = [[PieChartView alloc] init];
pieChartView.frame = self.activityIndicator.frame;
pieChartView.progress = 0;
pieChartView.progressColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5];
pieChartView.unprogressColor = [UIColor clearColor];
[self.contentView addSubview:pieChartView];
}
self.message.uploadProgress = progress;
self.activityIndicator.hidden = YES;
pieChartView.progress = progress;
}
}
- (void)layoutSubviews {
[super layoutSubviews];