I'm working on an application that allows the user to upload more files on the server. Items are displayed in a table and each cell has a progressbar and display informations regarding the current item status.
The client asks me to display information about all items in a single progress bar and also the time remaining until the end of the upload. The items are loaded from the gallery and are placed in a queue and then are sent to the server one by one. I have to work on the existing structure of the backend for this product.
I implemented, based on existing WS, show progress bar for all items but to display the time I need some help.
I have already tried the method proposed by Mzeeshaind : https://github.com/mzeeshanid/MZDownloadManager
This is the code :
switch (item.status){
case ENotifyFileUploadEvents_PROGRESS:
{
ProgressNotice* pn = (ProgressNotice*)(item.notice.args);
// Progress View
self.percentToShow = (self._itemsCount - self._itemsCountCompleted)+ pn.percentage;
self.progressView.progress = self.percentToShow/self._itemsCount;
self.lblStatusProgress.text = [NSString stringWithFormat:@"Uploading ... %0.2f %%", self.percentToShow/self._itemsCount*100];
UploadedItem *obj = [self.itemsToUpload objectAtIndex:self._itemsCount - self._itemsCountCompleted];
self.progressLabel.text =[NSString stringWithFormat:@"File Progress (%ld of %ld), %@", (self._itemsCount - self._itemsCountCompleted), self._itemsCount, obj.uploadWithFilename];
// Time Remaning - this code calculte time only for an item not for all
NSTimeInterval downloadTime = -1 * [self.uploadStartDate timeIntervalSinceNow];//self.uploadStartDate - NSDate initialized when user open the screen
float speed = pn.current / downloadTime;
unsigned long long remainingContentLength = pn.total - pn.current;
int remainingTime = (int)remainingContentLength / speed;
int hours = remainingTime / 3600;
int minutes = (remainingTime - hours * 3600) / 60;
int seconds = remainingTime - hours * 3600 - minutes * 60;
NSMutableString *remainingTimeStr = [[NSMutableString alloc] init];
if(hours>0)
[remainingTimeStr appendFormat:@"%d Hours ",hours];
if(minutes>0)
[remainingTimeStr appendFormat:@"%d Min ",minutes];
if(seconds>0)
[remainingTimeStr appendFormat:@"%d sec",seconds];
self.progressLabel.text = [NSString stringWithFormat:@"Time Left: %@",remainingTimeStr];
}
I need help to calculate the time remaining until the end of the upload for all items on the server.
Thanks in advance for your help.
Aucun commentaire:
Enregistrer un commentaire