Source

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

Full commit
//
//  BMFM13NavigationBarProgressView.m
//  Pods
//
//  Created by Jose Manuel Sánchez Peñarroja on 28/05/14.
//
//

#import "BMFM13NavigationBarProgressView.h"

#import <M13ProgressSuite/UINavigationController+M13ProgressViewBar.h>
#import <ReactiveCocoa/RACEXTScope.h>
#import "BMF.h"

@interface BMFM13NavigationBarProgressView()

@property (nonatomic, weak) UIViewController *viewController;

@end

@implementation BMFM13NavigationBarProgressView

- (instancetype)init
{
    self = [super init];
    if (self) {
		
		_progress = [BMFProgress new];
		
        @weakify(self);
		[[RACObserve(self, progress.running) deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(NSNumber *runningNumber) {
			@strongify(self);
			
			if (runningNumber.boolValue) {
				[self.viewController.navigationController showProgress];
			}
			else {
				if (self.progress.fractionCompleted==1) {
					if (self.progress.failedError) {
						if (self.viewController.navigationController.isShowingProgressBar) {
							[self.viewController.navigationController cancelProgress];	
						}
					}
					else {
						if (self.viewController.navigationController.isShowingProgressBar) {
							[self.viewController.navigationController finishProgress];
						}
					}
				}
//				else {
//					if (self.viewController.navigationController.isShowingProgressBar){
//						[self.viewController.navigationController cancelProgress];	
//					}
//				}
			}

		}];
		[[RACObserve(self, progress.fractionCompleted) deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(NSNumber *completed) {
			@strongify(self);
			DDLogInfo(@"Progress: %f",completed.floatValue);
			if (self.progress.running) [self.viewController.navigationController setProgress:completed.floatValue animated:YES];
		}];
    }
    return self;
}

- (void) addToViewController:(UIViewController *) vc {
	self.viewController = vc;
}

@end