Commits

José Manuel Sánchez Peñarroja  committed 9a9bf7b

Fixes for progresses

  • Participants
  • Parent commits 5652c12

Comments (0)

Files changed (5)

File Example/Example.xcworkspace/xcuserdata/josanchez.xcuserdatad/UserInterfaceState.xcuserstate

Binary file modified.

File bmf/ios/subspecs/m13/BMFM13NavigationBarProgressView.m

 
 - (void) updateRunning: (BOOL) running {
 	if (running) {
-		DDLogDebug(@"Fraction completed when starting: %f",self.progress.fractionCompleted);
-		
+		DDLogDebug(@"Hide progress");
 		[self.viewController.navigationController setProgress:0 animated:NO];
 		[self.viewController.navigationController showProgress];
 	}
 		if (self.progress.fractionCompleted==1) {
 			if (self.progress.failedError) {
 				if (self.viewController.navigationController.isShowingProgressBar) {
+					DDLogDebug(@"Cancel progress");
 					[self.viewController.navigationController cancelProgress];
 				}
 			}
 			else {
 				if (self.viewController.navigationController.isShowingProgressBar) {
+					DDLogDebug(@"Finish progress");
 					[self.viewController.navigationController finishProgress];
 				}
 			}
 }
 
 - (void) updateProgress:(CGFloat) progress {
-	DDLogInfo(@"Progress: %f",progress);
 	if (self.progress.running) [self.viewController.navigationController setProgress:progress animated:YES];
 }
 

File bmf/shared/data/BMFProgress.m

 
 	});
 		
+//	DDLogInfo(@"update Progress: %@ %@",self,self.changedBlock);
+	if (self.progressChangedBlock) self.progressChangedBlock(self);
 	if (self.changedBlock) self.changedBlock(self);
 }
 
 	});
 	
 	if (self.progressChangedBlock) self.progressChangedBlock(self);
+	
 	if (self.changedBlock) self.changedBlock(self);
 }
 
 }
 
 - (void) reset {
-	[self.children removeAllObjects];
+	dispatch_sync(serialQueue, ^{
+		for (BMFProgress *child in _children) {
+			child.progressChangedBlock = nil;
+		}
+
+		[_children removeAllObjects];
+	});
+
 	[self clear];
 }
 
 	});
 	
 	if (self.progressChangedBlock) self.progressChangedBlock(self);
+
 	if (self.changedBlock) self.changedBlock(self);
 }
 
 }
 
 - (void) setCompletedUnitCount:(int64_t)completedUnitCount {
-	[self willChangeValueForKey:@"completedUnitCount"];
-	[self willChangeValueForKey:@"fractionCompleted"];
 	dispatch_sync(serialQueue, ^{
 		_completedUnitCount = completedUnitCount;
 	});
-	[self didChangeValueForKey:@"fractionCompleted"];
-	[self didChangeValueForKey:@"completedUnitCount"];
 	
 	if (self.progressChangedBlock) self.progressChangedBlock(self);
 	if (self.changedBlock) self.changedBlock(self);

File bmf/shared/data/loaders/BMFAFURLSessionLoader.m

 		
 		self.finalUrl = self.url;
 		
+		[_progress start:self.url.absoluteString];
+		
 		_progress.progressMessage = BMFLocalized(@"Loading data", nil);
 		
 		if (self.cache) {
 				[self.cache setObject:responseObject forKey:self.url];
 			}
 			else {
+//				[_progress start:[NSString stringWithFormat:@"%@_cache",self.url.absoluteString]];
 				DDLogInfo(@"Loader returning cached data");
 				[_progress stop:nil];
 				completionBlock(responseObject,nil);
 			}
 		}
 		
-		[_progress start:self.url.absoluteString];
 		
 		DDLogDebug(@"Load url: %@ params: %@",self.url.absoluteString,self.parameters);
 		
 		
 		dataTask = [sessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
 			
-			[_progress stop:error];
-			
 			if (error) {
 				if (![self callBlocksForUrl:self.url result:nil error:error]) {
 					completionBlock(nil,error);
 				
 				[self.cache setObject:responseObject forKey:self.url cost:malloc_size((__bridge const void *)(responseObject))];
 			}
+			
+			[_progress stop:error];
 		}];
 		
 		[sessionManager setTaskDidSendBodyDataBlock:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {

File bmf/shared/views/BMFProgressUI.m

 
 @end
 
-@implementation BMFProgressUI
+@implementation BMFProgressUI {
+	BOOL wasRunning;
+}
 
 - (instancetype)init
 {
     self = [super init];
     if (self) {
-		_progress = [BMFProgress new];
-		
-		_progress.changedBlock = ^(BMFProgress *progress) {
-			dispatch_async(dispatch_get_main_queue(), ^{
-				[self updateRunning:progress.running];
-				[self updateProgress:[self displayedProgressWithFractionCompleted:progress.fractionCompleted]];				
-			});
-		};
+		self.progress = [BMFProgress new];
 		
 //		@weakify(self);
 //		[[RACObserve(self, progress.running) deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(NSNumber *runningNumber) {
     return self;
 }
 
+- (void) setProgress:(BMFProgress *)progress {
+	_progress.changedBlock = nil;
+	
+	_progress = progress;
+	_progress.changedBlock = ^(BMFProgress *progress) {
+		BOOL isRunning = progress.running;
+		
+		dispatch_async(dispatch_get_main_queue(), ^{
+//			DDLogDebug(@"Progress: %@",_progress);
+//			[self updateRunning:isRunning];
+//			DDLogInfo(@"was %d is %d",wasRunning,isRunning);
+			if (wasRunning!=isRunning && (progress.fractionCompleted<0.01 || progress.fractionCompleted>0.99)) {
+				[self updateRunning:isRunning];
+				wasRunning = isRunning;
+			}
+			
+			[self updateProgress:[self displayedProgressWithFractionCompleted:progress.fractionCompleted]];
+		});
+	};
+}
+
 - (CGFloat) displayedProgressWithFractionCompleted:(CGFloat) fractionCompleted {
 	CGFloat result;