Commits

José Manuel Sánchez Peñarroja committed 67e8985

Fixed issue with uiviewcontroller poptorootviewcontroller. Fixed some issues with progresses. Changed block operation to add a taskid. Fixed issues with viewloaderswitch

  • Participants
  • Parent commits 20cc7c5

Comments (0)

Files changed (10)

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

Binary file modified.

bmf/ios/categories/UIViewController+BMF.m

 
 - (void) BMF_popToRootViewController {
 	if (self.BMF_popoverController) {
-		[self.BMF_popoverController dismissPopoverAnimated:YES];
+		[self.BMF_popoverController dismissPopoverAnimated:NO];
 		UIViewController *presentingVC = self.BMF_popoverController.presentingViewController;
 		self.BMF_popoverController = nil;
 		[self bmf_popViewController:presentingVC];
 		[vc.presentingViewController dismissViewControllerAnimated:YES completion:^{
 			[self bmf_popViewController:vc];
 		}];
+		return;
 	}
 	
 	if (vc.navigationController) {
 		[vc.navigationController popToRootViewControllerAnimated:YES];
+		vc = vc.navigationController.viewControllers.firstObject;
 	}
 	
 	if (vc.parentViewController) {

bmf/ios/view controllers/BMFPopoverController.h

 
 #import <UIKit/UIKit.h>
 
+#import "BMFTypes.h"
+
 @interface BMFPopoverController : UIPopoverController
 
 @property (nonatomic, weak) UIViewController *presentingViewController;

bmf/ios/view controllers/BMFPopoverController.m

 
 #import "UIViewController+BMF.h"
 
+@interface BMFPopoverController()
+
+@end
+
 @implementation BMFPopoverController
 
+- (instancetype) initWithContentViewController:(UIViewController *)viewController {
+	self = [super initWithContentViewController:viewController];
+	if (self) {
+		self.delegate = self;
+	}
+	return self;
+}
+
 - (void) presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated {
 	[NSException raise:@"Invalid method" format:@"Use presentPopoverFromBarButtonItem:permittedArrowDirections:inViewController:animated instead"];
 }
 	[super presentPopoverFromRect:rect inView:view permittedArrowDirections:arrowDirections animated:animated];
 }
 
-
 @end

bmf/shared/data/BMFProgress.h

 
 @property (nonatomic, readonly) BMFMutableWeakArray *children;
 
-/// Block to perform some action when progress changes
+/// Block to perform some action when progress changes. Passes itself as the sender
 @property (nonatomic, copy) BMFActionBlock changedBlock;
 
 /// This key is used to identify the task. The estimated time will be averaged based on it

bmf/shared/data/BMFProgress.m

     self = [super init];
     if (self) {
 		
-		serialQueue = dispatch_queue_create("BMFProgress queue", DISPATCH_QUEUE_CONCURRENT);
+		serialQueue = dispatch_queue_create("BMFProgress queue", DISPATCH_QUEUE_SERIAL);
 		
 		self.totalUnitCount = 1;
 		self.estimatedTime = 1; // 1 second by default
 }
 
 - (BMFMutableWeakArray *) children {
+	__block BMFMutableWeakArray *result = nil;
 	dispatch_sync(serialQueue, ^{
 		if (!_children) _children = [BMFMutableWeakArray new];
+		result = _children;
 	});
 	
-	return _children;
+	return result;
 }
 
 - (void) updateValuesFromChildren {
 	__block int64_t total = 0;
 	__block int64_t completed = 0;
 	__block int64_t estimated = 0;
+//	__block NSString *progressMsg = nil;
+//	__block BOOL isRunning = NO;
+
+	[self willChangeValueForKey:@"progressMessage"];
+	[self willChangeValueForKey:@"running"];
 	
 	dispatch_sync(serialQueue, ^{
 		_progressMessage = nil;
 		_estimatedTime = estimated;
 
 	});
+	
+	[self didChangeValueForKey:@"running"];
+	[self didChangeValueForKey:@"progressMessage"];
 		
 //	DDLogInfo(@"update Progress: %@ %@",self,self.changedBlock);
 	if (self.progressChangedBlock) self.progressChangedBlock(self);
 		return;	
 	}
 	
+	BMFMutableWeakArray *children = self.children;
 	dispatch_sync(serialQueue, ^{
-		[self.children addObject:child];
-		
-//		[_childrenEstimatedTimeSignal sendNext:RACObserve(child, estimatedTime)];
-//		[_childrenFractionCompletedSignal sendNext:RACObserve(child, fractionCompleted)];
-//		[_childrenRunningSignal sendNext:RACObserve(child, running)];
-//		[_childrenMessageSignal sendNext:RACObserve(child, progressMessage)];
+		[children addObject:child];
 	});
 	
 	child.progressChangedBlock = ^(BMFProgress *child) {

bmf/shared/data/operations/BMFBlockOperation.h

 @interface BMFBlockOperation : BMFAsyncOperation
 
 @property (nonatomic, copy) BMFOperationBlock block;
+@property (nonatomic, copy) NSString *taskId;
 
-- (instancetype) initWithBlock: (BMFOperationBlock) block;
+- (instancetype) initWithBlock: (BMFOperationBlock) block taskId:(NSString *) taskId;
 
 @end

bmf/shared/data/operations/BMFBlockOperation.m

 
 @implementation BMFBlockOperation
 
-- (instancetype) initWithBlock: (BMFOperationBlock) block {
+- (instancetype) initWithBlock: (BMFOperationBlock) block taskId:(NSString *)taskId {
+	BMFAssertReturnNil(block);
+	BMFAssertReturnNil(taskId.length>0);
+	
     self = [super init];
     if (self) {
-        self.block = block;
+        _block = [block copy];
+		_taskId = [taskId copy];
 		self.progress = [[BMFProgress alloc] init];
     }
     return self;
     return nil;
 }
 
+- (void) setBlock:(BMFOperationBlock)block {
+	BMFAssertReturn(block);
+	_block = [block copy];
+}
+
+- (void) setTaskId:(NSString *)taskId {
+	BMFAssertReturn(taskId.length>0);
+	
+	_taskId = [taskId copy];
+}
 
 - (void)performStart {
+	[self.progress start:self.taskId];
 	self.block(self,^(id result, NSError *error) {
 		self.output = result;
-		self.progress.failedError = error;
+		[self.progress stop:error];
 		if (!self.cancelled) [self finished];
 	});
 }

bmf/shared/data/operations/BMFOperationsTask.m

 				if (completionBlock) completionBlock(previous.output,previous.progress.failedError);
 			}
 		}
-	}];
+	} taskId:@"BMFLastTaskOperation"];
 
 	[blockOp addDependency:lastOp];
 

bmf/shared/views/BMFViewLoaderSwitch.m

         _loaderView = loaderView;
 		_view = view;
 		
-		RACSignal *runningSignal = RACObserve(self, loaderView.progress.running);
-		RAC(self.loaderView,hidden) = [runningSignal not];
-		RAC(self.view,hidden) = runningSignal;
-		[runningSignal subscribeNext:^(id x) {
-			DDLogDebug(@"Loader running changed");
-		}];
+		self.loaderView.progress.changedBlock = ^(BMFProgress *progress) {
+			dispatch_async(dispatch_get_main_queue(), ^{
+				BOOL running = progress.running;
+				self.loaderView.hidden = !running;
+				self.view.hidden = running;				
+			});
+		};
+		
+//		RACSignal *runningSignal = RACObserve(self, loaderView.progress.running);
+//		RAC(self.loaderView,hidden) = [[runningSignal not] map:^id(id value) {
+//			DDLogDebug(@"loader view hidden signal %@",value);
+//			return value;
+//		}];
+//		RAC(self.view,hidden) = [runningSignal map:^id(id value) {
+//			DDLogDebug(@"view hidden signal %@",value);
+//			return value;
+//		}];
+
+//		[runningSignal subscribeNext:^(id x) {
+//			DDLogDebug(@"Loader running changed");
+//		}];
     }
     return self;
 }