mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-05 07:27:42 +02:00
MediaManager refactoring: handle upload with mediaLoader (remove UploadManager).
This commit is contained in:
@@ -16,14 +16,22 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
// provide the download/upload progress
|
||||
// Provide the download progress
|
||||
// object: URL
|
||||
// userInfo: kMediaLoaderProgressRateKey : progress value nested in a NSNumber (range 0->1)
|
||||
// : kMediaLoaderProgressStringKey : progress string XXX KB / XXX MB" (optional)
|
||||
// : kMediaLoaderProgressRemaingTimeKey : remaining time string "XX s left" (optional)
|
||||
// : kMediaLoaderProgressDownloadRateKey : string like XX MB/s (optional)
|
||||
extern NSString *const kMediaDownloadProgressNotification;
|
||||
|
||||
// Provide the upload progress
|
||||
// object: uploadId
|
||||
// userInfo: kMediaLoaderProgressRateKey : progress value nested in a NSNumber (range 0->1)
|
||||
// : kMediaLoaderProgressStringKey : progress string XXX KB / XXX MB" (optional)
|
||||
// : kMediaLoaderProgressRemaingTimeKey : remaining time string "XX s left" (optional)
|
||||
// : kMediaLoaderProgressDownloadRateKey : string like XX MB/s (optional)
|
||||
extern NSString *const kMediaUploadProgressNotification;
|
||||
|
||||
// userInfo keys
|
||||
extern NSString *const kMediaLoaderProgressRateKey;
|
||||
extern NSString *const kMediaLoaderProgressStringKey;
|
||||
@@ -31,18 +39,18 @@ extern NSString *const kMediaLoaderProgressRemaingTimeKey;
|
||||
extern NSString *const kMediaLoaderProgressDownloadRateKey;
|
||||
|
||||
// The callback blocks
|
||||
typedef void (^blockMediaLoader_onMediaReady)(NSString *cacheFilePath);
|
||||
typedef void (^blockMediaLoader_onSuccess)(NSString *url); // url is a cache file path for successful download, or a remote url for upload.
|
||||
typedef void (^blockMediaLoader_onError)(NSError *error);
|
||||
|
||||
@interface MediaLoader : NSObject <NSURLConnectionDataDelegate> {
|
||||
NSString *mediaURL;
|
||||
NSString *mimeType;
|
||||
|
||||
blockMediaLoader_onMediaReady onMediaReady;
|
||||
blockMediaLoader_onSuccess onSuccess;
|
||||
blockMediaLoader_onError onError;
|
||||
|
||||
// Download
|
||||
NSString *mediaURL;
|
||||
long long expectedSize;
|
||||
|
||||
NSMutableData *downloadData;
|
||||
NSURLConnection *downloadConnection;
|
||||
|
||||
@@ -51,15 +59,33 @@ typedef void (^blockMediaLoader_onError)(NSError *error);
|
||||
CFAbsoluteTime downloadStartTime;
|
||||
CFAbsoluteTime lastProgressEventTimeStamp;
|
||||
NSTimer* progressCheckTimer;
|
||||
|
||||
// Upload
|
||||
NSString *uploadId;
|
||||
CGFloat initialRange;
|
||||
CGFloat range;
|
||||
}
|
||||
|
||||
@property (strong, readonly) NSMutableDictionary* downloadStatsDict;
|
||||
|
||||
- (void)downloadMedia:(NSString*)aMediaURL
|
||||
mimeType:(NSString *)aMimeType
|
||||
success:(blockMediaLoader_onMediaReady)success
|
||||
failure:(blockMediaLoader_onError)failure;
|
||||
@property (strong, readonly) NSMutableDictionary* statisticsDict;
|
||||
|
||||
- (void)cancel;
|
||||
|
||||
// Download
|
||||
- (void)downloadMedia:(NSString *)aMediaURL
|
||||
mimeType:(NSString *)aMimeType
|
||||
success:(blockMediaLoader_onSuccess)success
|
||||
failure:(blockMediaLoader_onError)failure;
|
||||
|
||||
// Upload
|
||||
// initialRange / range: an upload could be a subpart of uploads. initialRange defines the global upload progress already did done before this current upload.
|
||||
// range is the range value of this upload in the global scope.
|
||||
// e.g. : Upload a media can be split in two parts :
|
||||
// 1 - upload the thumbnail -> initialRange = 0, range = 0.1 : assume that the thumbnail upload is 10% of the upload process
|
||||
// 2 - upload the media -> initialRange = 0.1, range = 0.9 : the media upload is 90% of the global upload
|
||||
- (id)initWithUploadId:(NSString *)anUploadId initialRange:(CGFloat)anInitialRange andRange:(CGFloat)aRange;
|
||||
- (void)uploadData:(NSData *)data
|
||||
mimeType:(NSString *)aMimeType
|
||||
success:(blockMediaLoader_onSuccess)success
|
||||
failure:(blockMediaLoader_onError)failure;
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user