Skip to content

Commit

Permalink
Break up method signatures for increased readability
Browse files Browse the repository at this point in the history
  • Loading branch information
freak4pc committed Apr 25, 2017
1 parent b7cd13c commit 22565a0
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions RxMediaPicker/RxMediaPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public enum RxMediaPickerError: Error {
self.delegate = delegate
}

open func recordVideo(device: UIImagePickerControllerCameraDevice = .rear, quality: UIImagePickerControllerQualityType = .typeMedium, maximumDuration: TimeInterval = 600, editable: Bool = false) -> Observable<URL> {

open func recordVideo(device: UIImagePickerControllerCameraDevice = .rear,
quality: UIImagePickerControllerQualityType = .typeMedium,
maximumDuration: TimeInterval = 600, editable: Bool = false) -> Observable<URL> {
return Observable.create { observer in
self.currentAction = RxMediaPickerAction.video(observer: observer, maxDuration: maximumDuration)

Expand All @@ -57,8 +58,9 @@ public enum RxMediaPickerError: Error {
}
}

open func selectVideo(source: UIImagePickerControllerSourceType = .photoLibrary, maximumDuration: TimeInterval = 600, editable: Bool = false) -> Observable<URL> {

open func selectVideo(source: UIImagePickerControllerSourceType = .photoLibrary,
maximumDuration: TimeInterval = 600,
editable: Bool = false) -> Observable<URL> {
return Observable.create { [unowned self] observer in
self.currentAction = RxMediaPickerAction.video(observer: observer, maxDuration: maximumDuration)

Expand All @@ -75,8 +77,9 @@ public enum RxMediaPickerError: Error {
}
}

open func takePhoto(device: UIImagePickerControllerCameraDevice = .rear, flashMode: UIImagePickerControllerCameraFlashMode = .auto, editable: Bool = false) -> Observable<(UIImage, UIImage?)> {

open func takePhoto(device: UIImagePickerControllerCameraDevice = .rear,
flashMode: UIImagePickerControllerCameraFlashMode = .auto,
editable: Bool = false) -> Observable<(UIImage, UIImage?)> {
return Observable.create { [unowned self] observer in
self.currentAction = RxMediaPickerAction.photo(observer: observer)

Expand All @@ -99,8 +102,8 @@ public enum RxMediaPickerError: Error {
}
}

open func selectImage(source: UIImagePickerControllerSourceType = .photoLibrary, editable: Bool = false) -> Observable<(UIImage, UIImage?)> {

open func selectImage(source: UIImagePickerControllerSourceType = .photoLibrary,
editable: Bool = false) -> Observable<(UIImage, UIImage?)> {
return Observable.create { [unowned self] observer in
self.currentAction = RxMediaPickerAction.photo(observer: observer)

Expand All @@ -115,7 +118,8 @@ public enum RxMediaPickerError: Error {
}
}

func processPhoto(info: [String : AnyObject], observer: AnyObserver<(UIImage, UIImage?)>) {
func processPhoto(info: [String : AnyObject],
observer: AnyObserver<(UIImage, UIImage?)>) {
guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage,
let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage else {
observer.on(.error(RxMediaPickerError.generalError))
Expand All @@ -126,7 +130,10 @@ public enum RxMediaPickerError: Error {
observer.on(.completed)
}

func processVideo(info: [String : Any], observer: AnyObserver<URL>, maxDuration: TimeInterval, picker: UIImagePickerController) {
func processVideo(info: [String : Any],
observer: AnyObserver<URL>,
maxDuration: TimeInterval,
picker: UIImagePickerController) {
guard let videoURL = info[UIImagePickerControllerMediaURL] as? URL else {
observer.on(.error(RxMediaPickerError.generalError))
dismissPicker(picker)
Expand Down Expand Up @@ -164,7 +171,10 @@ public enum RxMediaPickerError: Error {
}
}

fileprivate func processVideo(url: URL, observer: AnyObserver<URL>, maxDuration: TimeInterval, picker: UIImagePickerController) {
fileprivate func processVideo(url: URL,
observer: AnyObserver<URL>,
maxDuration: TimeInterval,
picker: UIImagePickerController) {
let asset = AVURLAsset(url: url)
let duration = CMTimeGetSeconds(asset.duration)

Expand Down

0 comments on commit 22565a0

Please sign in to comment.