<commit_before>//
//  CLPickerTool.swift
//  ImageDeal
//
//  Created by darren on 2017/8/3.
//  Copyright © 2017年 陈亮陈亮. All rights reserved.
//

import UIKit
import Photos
import PhotosUI

public enum CLImagePickerToolType {
    case singlePicture   // 图片单选
    case singlePictureCrop   // 单选并裁剪
}
public enum CLImagePickerToolStatusBarType {
    case black   // 黑色
    case white   // 白色
}

public typealias CLPickerToolClouse = (Array<PHAsset>,UIImage?)->()

public class CLImagePickerTool: NSObject,UIImagePickerControllerDelegate,UINavigationControllerDelegate {
        
    @objc var cameraPicker: UIImagePickerController!
    
    private weak var superVC: UIViewController?
    
    public var clPickerToolClouse: CLPickerToolClouse?
    
    // 是否隐藏视频文件，默认不隐藏
    @objc public var isHiddenVideo: Bool = false
    // 是否隐藏图片文件，显示视频文件，默认不隐藏
    @objc public var isHiddenImage: Bool = false
    // 设置单选图片，单选图片并裁剪属性，默认多选
    public var singleImageChooseType: CLImagePickerToolType?
    // 设置相机在外部，默认不在外部
    @objc public var cameraOut: Bool = false
    // 单选模式下图片并且可裁剪。默认裁剪比例是1：1，也可以设置如下参数
    public var singlePictureCropScale: CGFloat?
    // 视频和照片只能选择一种，不能同时选择,默认可以同时选择
    @objc public var onlyChooseImageOrVideo: Bool = false
    // 单选模式下，图片可以编辑，默认不可编辑
    @objc public var singleModelImageCanEditor: Bool = false
    // 配置导航栏的颜色，默认是毛玻璃效果
    public var navColor: UIColor? = nil
    // 配置导航栏文字的颜色
    public var navTitleColor: UIColor? = nil
    // 配置状态栏的颜色
    public var statusBarType: CLImagePickerToolStatusBarType = .black
    // 相册中是否展示拍照图片
    public var showCamaroInPicture = true
    // 文字和图片的颜色 85 182 55
    public var tineColor = UIColor.init(red: 85/255.0, green: 182/255.0, blue: 55/255.0, alpha: 1) {
        didSet {
            CLPickersTools.instence.tineColor = tineColor
        }
    }
    
    // 第二种弹出方式
    @available(*, deprecated, message: "Use 'cl_setupImagePickerAnotherWayWith' instead.")
    public func setupImagePickerAnotherWayWith(maxImagesCount: Int,superVC: UIViewController,didChooseImageSuccess:@escaping (Array<PHAsset>,UIImage?)->()) {
        CLPickersTools.instence.authorize(authorizeClouse: { (state) in

            if state == .authorized {
                let anotherVC = CLImagePickerAnotherViewController.init(nibName: "CLImagePickerAnotherViewController", bundle: BundleUtil.getCurrentBundle())
                anotherVC.modalPresentationStyle = .custom
                anotherVC.transitioningDelegate = CLPresent.instance
                
                anotherVC.MaxImagesCount = maxImagesCount
                anotherVC.isHiddenVideo = self.isHiddenVideo
                anotherVC.isHiddenImage = self.isHiddenImage
                anotherVC.onlyChooseImageOrVideo = self.onlyChooseImageOrVideo
                
                anotherVC.singleChooseImageCompleteClouse = { (assetArr:Array<PHAsset>,image) in
                    didChooseImageSuccess(assetArr,image)
                }
                superVC.present(anotherVC, animated: true, completion: nil)
            }
        })
    }
    
    public func cl_setupImagePickerAnotherWayWith(maxImagesCount: Int,superVC: UIViewController? = nil, didChooseImageSuccess:@escaping (Array<PHAsset>,UIImage?)->()) {
        CLPickersTools.instence.authorize(authorizeClouse: { (state) in
            
            self.superVC = superVC
            if self.superVC == nil {
                self.superVC = self.getCurrentViewcontroller()
            }
            if state == .authorized {
                let anotherVC = CLImagePickerAnotherViewController.init(nibName: "CLImagePickerAnotherViewController", bundle: BundleUtil.getCurrentBundle())
                anotherVC.modalPresentationStyle = .custom
                anotherVC.transitioningDelegate = CLPresent.instance
                
                anotherVC.MaxImagesCount = maxImagesCount
                anotherVC.isHiddenVideo = self.isHiddenVideo
                anotherVC.isHiddenImage = self.isHiddenImage
                anotherVC.onlyChooseImageOrVideo = self.onlyChooseImageOrVideo
                
                anotherVC.singleChooseImageCompleteClouse = { (assetArr:Array<PHAsset>,image) in
                    didChooseImageSuccess(assetArr,image)
                }
                self.superVC?.present(anotherVC, animated: true, completion: nil)
            }
        })
    }

    // 判断相机是放在外面还是内部
    @available(*, deprecated, message: "Use 'cl_setupImagePickerWith' instead.")
    @objc public func setupImagePickerWith(MaxImagesCount: Int,superVC:UIViewController,didChooseImageSuccess:@escaping (Array<PHAsset>,UIImage?)->()) {
        
        self.superVC = superVC
        self.clPickerToolClouse = didChooseImageSuccess

        if self.cameraOut == true {  // 拍照功能在外面
            var alert: UIAlertController!
            alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertController.Style.actionSheet)
            let cleanAction = UIAlertAction(title: cancelStr, style: UIAlertAction.Style.cancel,handler:nil)
            let photoAction = UIAlertAction(title: tackPhotoStr, style: UIAlertAction.Style.default){ (action:UIAlertAction)in
                // 访问相机
                self.camera(superVC:superVC)
            }
            let choseAction = UIAlertAction(title: chooseStr, style: UIAlertAction.Style.default){ (action:UIAlertAction)in
                
                self.gotoPhoto(MaxImagesCount: MaxImagesCount)
            }
            
            alert.addAction(cleanAction)
            alert.addAction(photoAction)
            alert.addAction(choseAction)
            superVC.present(alert, animated: true, completion: nil)

        } else {
            self.gotoPhoto(MaxImagesCount: MaxImagesCount)
        }
    }
    
    @objc public func cl_setupImagePickerWith(MaxImagesCount: Int,superVC:UIViewController? = nil,didChooseImageSuccess:@escaping (Array<PHAsset>,UIImage?)->()) {
        
        self.superVC = superVC
        if self.superVC == nil {
            self.superVC = self.getCurrentViewcontroller()
        }
        if self.superVC == nil {
            print("未获取到当前控制器")
            return
        }
        self.clPickerToolClouse = didChooseImageSuccess
        
        if self.cameraOut == true {  // 拍照功能在外面
            var alert: UIAlertController!
            alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertController.Style.actionSheet)
            let cleanAction = UIAlertAction(title: cancelStr, style: UIAlertAction.Style.cancel,handler:nil)
            let photoAction = UIAlertAction(title: tackPhotoStr, style: UIAlertAction.Style.default){ (action:UIAlertAction)in
                // 访问相机
                self.cl_camera(superVC: self.superVC)
            }
            let choseAction = UIAlertAction(title: chooseStr, style: UIAlertAction.Style.default){ (action:UIAlertAction)in
                
                self.gotoPhoto(MaxImagesCount: MaxImagesCount)
            }
            
            alert.addAction(cleanAction)<commit_msg>fix actionSheet在iPad中崩溃的问题<commit_after>//
//  CLPickerTool.swift
//  ImageDeal
//
//  Created by darren on 2017/8/3.
//  Copyright © 2017年 陈亮陈亮. All rights reserved.
//

import UIKit
import Photos
import PhotosUI

public enum CLImagePickerToolType {
    case singlePicture   // 图片单选
    case singlePictureCrop   // 单选并裁剪
}
public enum CLImagePickerToolStatusBarType {
    case black   // 黑色
    case white   // 白色
}

public typealias CLPickerToolClouse = (Array<PHAsset>,UIImage?)->()

public class CLImagePickerTool: NSObject,UIImagePickerControllerDelegate,UINavigationControllerDelegate {
        
    @objc var cameraPicker: UIImagePickerController!
    
    private weak var superVC: UIViewController?
    
    public var clPickerToolClouse: CLPickerToolClouse?
    
    // 是否隐藏视频文件，默认不隐藏
    @objc public var isHiddenVideo: Bool = false
    // 是否隐藏图片文件，显示视频文件，默认不隐藏
    @objc public var isHiddenImage: Bool = false
    // 设置单选图片，单选图片并裁剪属性，默认多选
    public var singleImageChooseType: CLImagePickerToolType?
    // 设置相机在外部，默认不在外部
    @objc public var cameraOut: Bool = false
    // 单选模式下图片并且可裁剪。默认裁剪比例是1：1，也可以设置如下参数
    public var singlePictureCropScale: CGFloat?
    // 视频和照片只能选择一种，不能同时选择,默认可以同时选择
    @objc public var onlyChooseImageOrVideo: Bool = false
    // 单选模式下，图片可以编辑，默认不可编辑
    @objc public var singleModelImageCanEditor: Bool = false
    // 配置导航栏的颜色，默认是毛玻璃效果
    public var navColor: UIColor? = nil
    // 配置导航栏文字的颜色
    public var navTitleColor: UIColor? = nil
    // 配置状态栏的颜色
    public var statusBarType: CLImagePickerToolStatusBarType = .black
    // 相册中是否展示拍照图片
    public var showCamaroInPicture = true
    // 文字和图片的颜色 85 182 55
    public var tineColor = UIColor.init(red: 85/255.0, green: 182/255.0, blue: 55/255.0, alpha: 1) {
        didSet {
            CLPickersTools.instence.tineColor = tineColor
        }
    }
    
    private let isPad: Bool = UIDevice.current.model == "iPad"
    
    // 第二种弹出方式
    @available(*, deprecated, message: "Use 'cl_setupImagePickerAnotherWayWith' instead.")
    public func setupImagePickerAnotherWayWith(maxImagesCount: Int,superVC: UIViewController,didChooseImageSuccess:@escaping (Array<PHAsset>,UIImage?)->()) {
        CLPickersTools.instence.authorize(authorizeClouse: { (state) in

            if state == .authorized {
                let anotherVC = CLImagePickerAnotherViewController.init(nibName: "CLImagePickerAnotherViewController", bundle: BundleUtil.getCurrentBundle())
                anotherVC.modalPresentationStyle = .custom
                anotherVC.transitioningDelegate = CLPresent.instance
                
                anotherVC.MaxImagesCount = maxImagesCount
                anotherVC.isHiddenVideo = self.isHiddenVideo
                anotherVC.isHiddenImage = self.isHiddenImage
                anotherVC.onlyChooseImageOrVideo = self.onlyChooseImageOrVideo
                
                anotherVC.singleChooseImageCompleteClouse = { (assetArr:Array<PHAsset>,image) in
                    didChooseImageSuccess(assetArr,image)
                }
                superVC.present(anotherVC, animated: true, completion: nil)
            }
        })
    }
    
    public func cl_setupImagePickerAnotherWayWith(maxImagesCount: Int,superVC: UIViewController? = nil, didChooseImageSuccess:@escaping (Array<PHAsset>,UIImage?)->()) {
        CLPickersTools.instence.authorize(authorizeClouse: { (state) in
            
            self.superVC = superVC
            if self.superVC == nil {
                self.superVC = self.getCurrentViewcontroller()
            }
            if state == .authorized {
                let anotherVC = CLImagePickerAnotherViewController.init(nibName: "CLImagePickerAnotherViewController", bundle: BundleUtil.getCurrentBundle())
                anotherVC.modalPresentationStyle = .custom
                anotherVC.transitioningDelegate = CLPresent.instance
                
                anotherVC.MaxImagesCount = maxImagesCount
                anotherVC.isHiddenVideo = self.isHiddenVideo
                anotherVC.isHiddenImage = self.isHiddenImage
                anotherVC.onlyChooseImageOrVideo = self.onlyChooseImageOrVideo
                
                anotherVC.singleChooseImageCompleteClouse = { (assetArr:Array<PHAsset>,image) in
                    didChooseImageSuccess(assetArr,image)
                }
                self.superVC?.present(anotherVC, animated: true, completion: nil)
            }
        })
    }

    // 判断相机是放在外面还是内部
    @available(*, deprecated, message: "Use 'cl_setupImagePickerWith' instead.")
    @objc public func setupImagePickerWith(MaxImagesCount: Int,superVC:UIViewController,didChooseImageSuccess:@escaping (Array<PHAsset>,UIImage?)->()) {
        
        self.superVC = superVC
        self.clPickerToolClouse = didChooseImageSuccess

        if self.cameraOut == true {  // 拍照功能在外面
            var alert: UIAlertController!
            alert = UIAlertController(title: nil, message: nil, preferredStyle: isPad ? .alert : .actionSheet)
            let cleanAction = UIAlertAction(title: cancelStr, style: UIAlertAction.Style.cancel,handler:nil)
            let photoAction = UIAlertAction(title: tackPhotoStr, style: UIAlertAction.Style.default){ (action:UIAlertAction)in
                // 访问相机
                self.camera(superVC:superVC)
            }
            let choseAction = UIAlertAction(title: chooseStr, style: UIAlertAction.Style.default){ (action:UIAlertAction)in
                
                self.gotoPhoto(MaxImagesCount: MaxImagesCount)
            }
            
            alert.addAction(cleanAction)
            alert.addAction(photoAction)
            alert.addAction(choseAction)
            superVC.present(alert, animated: true, completion: nil)

        } else {
            self.gotoPhoto(MaxImagesCount: MaxImagesCount)
        }
    }
    
    @objc public func cl_setupImagePickerWith(MaxImagesCount: Int,superVC:UIViewController? = nil,didChooseImageSuccess:@escaping (Array<PHAsset>,UIImage?)->()) {
        
        self.superVC = superVC
        if self.superVC == nil {
            self.superVC = self.getCurrentViewcontroller()
        }
        if self.superVC == nil {
            print("未获取到当前控制器")
            return
        }
        self.clPickerToolClouse = didChooseImageSuccess
        
        if self.cameraOut == true {  // 拍照功能在外面
            var alert: UIAlertController!
            alert = UIAlertController(title: nil, message: nil, preferredStyle: isPad ? .alert : .actionSheet)
            let cleanAction = UIAlertAction(title: cancelStr, style: UIAlertAction.Style.cancel,handler:nil)
            let photoAction = UIAlertAction(title: tackPhotoStr, style: UIAlertAction.Style.default){ (action:UIAlertAction)in
                // 访问相机
                self.cl_camera(superVC: self.superVC)
            }
            let choseAction = UIAlertAction(title: chooseStr, style: UIAlertAction.Style.default){ (action:UIAlertAction)in
                
                self.gotoPhoto(MaxImagesCount: MaxImagesCount)
            }
            
            alert.addAction(cleanAction)
{'fraction_non_alphanumeric': 0.08331568170585328, 'fraction_numerical': 0.005507307773776742, 'mean_word_length': 2.4521082135023153, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1789509', 'n_tokens_mistral': 4413, 'n_tokens_neox': 4366, 'n_words': 744}