MediaManager refactoring: handle upload with mediaLoader (remove UploadManager).

This commit is contained in:
giomfo
2015-01-12 18:07:39 +01:00
parent 6baf80b501
commit f02f82b066
14 changed files with 247 additions and 292 deletions
+37 -14
View File
@@ -28,27 +28,21 @@ static MediaManager *sharedMediaManager = nil;
@implementation MediaManager
// Table of mediaLoaders in progress
// Table of downloads in progress
static NSMutableDictionary* downloadTableByURL = nil;
+ (id)sharedInstance {
@synchronized(self) {
if(sharedMediaManager == nil) {
sharedMediaManager = [[self alloc] init];
// Create download table here
downloadTableByURL = [[NSMutableDictionary alloc] init];
}
}
return sharedMediaManager;
}
// Table of uploads in progress
static NSMutableDictionary* uploadTableById = nil;
#pragma mark - Media Download
+ (MediaLoader*)downloadMedia:(NSString*)mediaURL mimeType:(NSString *)mimeType {
if ([mediaURL hasPrefix:kMediaManagerPrefixForDummyURL] == NO) {
+ (MediaLoader*)downloadMediaFromURL:(NSString*)mediaURL withType:(NSString *)mimeType {
if (mediaURL && [mediaURL hasPrefix:kMediaManagerPrefixForDummyURL] == NO) {
// Create a media loader to download data
MediaLoader *mediaLoader = [[MediaLoader alloc] init];
// Report this loader
if (!downloadTableByURL) {
downloadTableByURL = [[NSMutableDictionary alloc] init];
}
[downloadTableByURL setValue:mediaLoader forKey:mediaURL];
// Launch download
@@ -74,6 +68,35 @@ static NSMutableDictionary* downloadTableByURL = nil;
return nil;
}
#pragma mark - Media Uploader
+ (MediaLoader*)prepareUploaderWithId:(NSString *)uploadId initialRange:(CGFloat)initialRange andRange:(CGFloat)range {
if (uploadId) {
// Create a media loader to upload data
MediaLoader *mediaLoader = [[MediaLoader alloc] initWithUploadId:uploadId initialRange:initialRange andRange:range];
// Report this loader
if (!uploadTableById) {
uploadTableById = [[NSMutableDictionary alloc] init];
}
[uploadTableById setValue:mediaLoader forKey:uploadId];
return mediaLoader;
}
return nil;
}
+ (MediaLoader*)existingUploaderWithId:(NSString*)uploadId {
if (uploadTableById && uploadId) {
return [uploadTableById valueForKey:uploadId];
}
return nil;
}
+ (void)removeUploaderWithId:(NSString*)uploadId {
if (uploadTableById && uploadId) {
return [uploadTableById removeObjectForKey:uploadId];
}
}
#pragma mark - Cache Handling
+ (UIImage*)loadCachePictureForURL:(NSString*)pictureURL {