swiftlint autocorrect

This commit is contained in:
haranicle 2017-07-01 15:02:21 +09:00
parent c6a501b4cb
commit dac1bba0cb
24 changed files with 326 additions and 284 deletions

47
.swiftlint.yml Normal file
View File

@ -0,0 +1,47 @@
disabled_rules: # rule identifiers to exclude from running
- todo
# - colon
# - comma
# - control_statement
- file_length
- force_cast
- force_try
- function_body_length
# - leading_whitespace
- line_length
- legacy_constructor
- nesting
# - opening_brace
# - operator_whitespace
# - return_arrow_whitespace
# - statement_position
# - todo
# - trailing_newline
# - trailing_semicolon
# - trailing_whitespace
- type_body_length
- type_name
- variable_name_max_length
- variable_name_min_length
- variable_name
- valid_docs
- function_parameter_count
- cyclomatic_complexity
excluded: # paths to ignore during linting.
- Carthage
- Pods
- .git
# parameterized rules can be customized from this configuration file
line_length: 300 # default 100
type_body_length:
- 200 # warning default 200
- 650 # error default 350
function_body_length:
- 80 # warning default 40
- 250 # error default 100
file_length:
- 400 # warning default 400
- 1300 # error default 1000
variable_name_min_length:
- 1 # warning default 3
- 0 # error default 2

View File

@ -51,4 +51,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

View File

@ -23,7 +23,7 @@ struct Cell {
}
class DemoListViewController: UITableViewController, NohanaImagePickerControllerDelegate {
let cells = [
Cell(title: "Default", selector: #selector(DemoListViewController.showDefaultPicker)),
Cell(title: "Large thumbnail", selector: #selector(DemoListViewController.showLargeThumbnailPicker)),
@ -31,31 +31,31 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
Cell(title: "Disable to pick assets", selector: #selector(DemoListViewController.showDisableToPickAssetsPicker)),
Cell(title: "Custom UI", selector: #selector(DemoListViewController.showCustomUIPicker)),
]
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let indexPathForSelectedRow = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: indexPathForSelectedRow, animated: true)
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cells.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
cell.textLabel?.text = cells[indexPath.row].title
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
checkIfAuthorizedToAccessPhotos { isAuthorized in
DispatchQueue.main.async(execute: {
DispatchQueue.main.async(execute: {
if isAuthorized {
self.perform(self.cells[indexPath.row].selector)
} else {
@ -66,13 +66,13 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
})
}
}
// MARK: - Photos
func checkIfAuthorizedToAccessPhotos(_ handler: @escaping (_ isAuthorized: Bool) -> Void) {
switch PHPhotoLibrary.authorizationStatus() {
case .notDetermined:
PHPhotoLibrary.requestAuthorization{ status in
PHPhotoLibrary.requestAuthorization { status in
switch status {
case .authorized:
handler(true)
@ -80,7 +80,7 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
handler(false)
}
}
case .restricted:
handler(false)
case .denied:
@ -89,7 +89,7 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
handler(true)
}
}
// MARK: - Show NohanaImagePicker
@objc
@ -120,12 +120,12 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
func showDisableToPickAssetsPicker() {
let picker = NohanaImagePickerController()
picker.delegate = self
picker.canPickAsset = { (asset:Asset) -> Bool in
picker.canPickAsset = { (asset: Asset) -> Bool in
return asset.identifier % 2 == 0
}
present(picker, animated: true, completion: nil)
}
@objc
func showCustomUIPicker() {
let picker = NohanaImagePickerController()
@ -137,59 +137,59 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
picker.config.image.pickedSmall = UIImage(named: "btn_selected_m")
present(picker, animated: true, completion: nil)
}
// MARK: - NohanaImagePickerControllerDelegate
func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController) {
print("🐷Canceled🙅")
picker.dismiss(animated: true, completion: nil)
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts :[PHAsset]) {
func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts: [PHAsset]) {
print("🐷Completed🙆\n\tpickedAssets = \(pickedAssts)")
picker.dismiss(animated: true, completion: nil)
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, willPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool {
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
return true
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, didPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) {
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, willDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool {
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
return true
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, didDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) {
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectPhotoKitAsset asset: PHAsset) {
print("🐷\(#function)\n\tasset = \(asset)\n\t")
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectPhotoKitAssetList assetList: PHAssetCollection) {
print("🐷\(#function)\n\t\tassetList = \(assetList)\n\t")
}
func nohanaImagePickerDidSelectMoment(_ picker: NohanaImagePickerController) -> Void {
print("🐷\(#function)")
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell {
print("🐷\(#function)\n\tindexPath = \(indexPath)\n\tphotoKitAsset = \(photoKitAsset)")
return cell
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell {
print("🐷\(#function)\n\tindexPath = \(indexPath)\n\tphotoKitAsset = \(photoKitAsset)")
return cell
}
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, didChangeAssetDetailPage indexPath: IndexPath, photoKitAsset: PHAsset) {
print("🐷\(#function)\n\tindexPath = \(indexPath)")
}

View File

@ -20,7 +20,7 @@ public protocol ActivityIndicatable {
}
public extension ActivityIndicatable where Self: UIViewController {
func updateVisibilityOfActivityIndicator(_ activityIndicator: UIView) {
if isProgressing() {
if !view.subviews.contains(activityIndicator) {

View File

@ -15,32 +15,32 @@
*/
class AlbumListEmptyIndicator: UILabel {
init(message: String, description: String, frame: CGRect, config: NohanaImagePickerController.Config) {
super.init(frame: frame)
let centerStyle = NSMutableParagraphStyle()
centerStyle.alignment = NSTextAlignment.center
let messageAttributes = [
NSForegroundColorAttributeName : config.color.empty ?? UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1),
NSFontAttributeName : UIFont.systemFont(ofSize: 26),
NSParagraphStyleAttributeName : centerStyle
]
let messageText = NSAttributedString(string: message, attributes: messageAttributes)
let descriptionAttributes = [
NSForegroundColorAttributeName : config.color.empty ?? UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1),
NSFontAttributeName : UIFont.systemFont(ofSize: 14),
NSParagraphStyleAttributeName : centerStyle
]
let descriptionText = NSAttributedString(string: description, attributes: descriptionAttributes)
let attributedText = NSMutableAttributedString()
attributedText.append(messageText)
attributedText.append(NSAttributedString(string: "\n\n", attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 6)]))
attributedText.append(descriptionText)
self.numberOfLines = 0
self.attributedText = attributedText
}

View File

@ -18,11 +18,11 @@ import UIKit
import Photos
class AlbumListViewController: UITableViewController, EmptyIndicatable, ActivityIndicatable {
enum AlbumListViewControllerSectionType: Int {
case moment = 0
case albums
static func count() -> Int {
var count: Int = 0
for i in 0..<Int.max {
@ -34,26 +34,26 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
return count
}
}
weak var nohanaImagePickerController: NohanaImagePickerController?
var photoKitAlbumList: PhotoKitAlbumList!
override func viewDidLoad() {
super.viewDidLoad()
if let nohanaImagePickerController = nohanaImagePickerController {
view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white
title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
setUpToolbarItems()
navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden ,animated: false)
navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden, animated: false)
}
setUpEmptyIndicator()
setUpActivityIndicator()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let nohanaImagePickerController = nohanaImagePickerController {
@ -63,14 +63,14 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
tableView.deselectRow(at: indexPathForSelectedRow, animated: true)
}
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
tableView.reloadData()
}
// MARK: - UITableViewDelegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
fatalError("Invalid section")
@ -85,7 +85,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAssetList: photoKitAlbumList[indexPath.row].assetList)
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
fatalError("Invalid section")
@ -97,13 +97,13 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
return 82
}
}
// MARK: - UITableViewDataSource
override func numberOfSections(in tableView: UITableView) -> Int {
return AlbumListViewControllerSectionType.count()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let emptyIndicator = emptyIndicator {
updateVisibilityOfEmptyIndicator(emptyIndicator)
@ -111,28 +111,28 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
if let activityIndicator = activityIndicator {
updateVisibilityOfActivityIndicator(activityIndicator)
}
guard let sectionType = AlbumListViewControllerSectionType(rawValue: section) else {
fatalError("Invalid section")
}
switch sectionType {
case .moment:
if let nohanaImagePickerController = nohanaImagePickerController {
return nohanaImagePickerController.shouldShowMoment ? 1 : 0
}
return 0
case .albums:
return photoKitAlbumList.count
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
fatalError("Invalid section")
}
switch sectionType {
case .moment:
guard let cell = tableView.dequeueReusableCell(withIdentifier: "MomentAlbumCell") as? MomentCell else {
@ -172,9 +172,9 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
return cell
}
}
// MARK: - Storyboard
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let sectionType = AlbumListViewControllerSectionType(rawValue: tableView.indexPathForSelectedRow!.section) else {
fatalError("Invalid section")
@ -202,19 +202,19 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
assetListViewController.nohanaImagePickerController = nohanaImagePickerController
}
}
// MARK: - IBAction
@IBAction func didPushCancel(_ sender: AnyObject) {
if let nohanaImagePickerController = nohanaImagePickerController {
nohanaImagePickerController.delegate?.nohanaImagePickerDidCancel(nohanaImagePickerController)
}
}
// MARK: - EmptyIndicatable
var emptyIndicator: UIView?
func setUpEmptyIndicator() {
let frame = CGRect(origin: CGPoint.zero, size: Size.screenRectWithoutAppBar(self).size)
guard let nohanaImagePickerController = nohanaImagePickerController else {
@ -226,46 +226,46 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
frame: frame,
config: nohanaImagePickerController.config)
}
func isEmpty() -> Bool {
if isProgressing() {
return false
}
return photoKitAlbumList.count == 0
}
// MARK: - ActivityIndicatable
var activityIndicator: UIActivityIndicatorView?
var isLoading = true
func setUpActivityIndicator() {
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
let screenRect = Size.screenRectWithoutAppBar(self)
activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2)
activityIndicator?.startAnimating()
}
func isProgressing() -> Bool {
return isLoading
}
}
extension UIViewController {
// MARK: - Toolbar
func setUpToolbarItems() {
let leftSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let rightSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let infoButton = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
infoButton.isEnabled = false
infoButton.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14), NSForegroundColorAttributeName: UIColor.black], for: UIControlState())
self.toolbarItems = [leftSpace, infoButton, rightSpace]
}
func setToolbarTitle(_ nohanaImagePickerController:NohanaImagePickerController) {
func setToolbarTitle(_ nohanaImagePickerController: NohanaImagePickerController) {
let count: Int? = toolbarItems?.count
guard count != nil && count! >= 2 else {
return
@ -284,21 +284,21 @@ extension UIViewController {
infoButton.title = title
}
}
// MARK: - Notification
func addPickPhotoKitAssetNotificationObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didPickPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didPick, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didDropPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didDrop, object: nil)
}
func didPickPhotoKitAsset(_ notification: Notification) {
guard let picker = notification.object as? NohanaImagePickerController else {
return
}
setToolbarTitle(picker)
}
func didDropPhotoKitAsset(_ notification: Notification) {
guard let picker = notification.object as? NohanaImagePickerController else {
return

View File

@ -17,16 +17,16 @@
import UIKit
class AnimatableNavigationController: UINavigationController, UINavigationControllerDelegate {
let swipeInteractionController = SwipeInteractionController()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.delegate = self
}
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch operation {
case .push where fromVC is AssetListViewController:
guard let fromVC = fromVC as? AssetListViewController,
@ -47,11 +47,11 @@ class AnimatableNavigationController: UINavigationController, UINavigationContro
return nil
}
}
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
swipeInteractionController.attachToViewController(viewController)
}
func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
if animationController is ExpandingAnimationController {
return nil
@ -61,5 +61,5 @@ class AnimatableNavigationController: UINavigationController, UINavigationContro
}
return swipeInteractionController
}
}

View File

@ -16,25 +16,25 @@
import UIKit
class AssetCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var pickButton: UIButton!
@IBOutlet weak var overlayView: UIView!
weak var nohanaImagePickerController: NohanaImagePickerController?
var asset: Asset?
override func willMove(toSuperview newSuperview: UIView?) {
super.willMove(toSuperview: newSuperview)
if let nohanaImagePickerController = nohanaImagePickerController {
let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedSmall ?? UIImage(named: "btn_select_m", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedSmall ?? UIImage(named: "btn_selected_m", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
pickButton.setImage(droppedImage, for: UIControlState())
pickButton.setImage(pickedImage, for: .selected)
}
}
@IBAction func didPushPickButton(_ sender: UIButton) {
guard let asset = asset else {
return
@ -50,11 +50,11 @@ class AssetCell: UICollectionViewCell {
}
self.overlayView.isHidden = !pickButton.isSelected
}
func update(asset: Asset, nohanaImagePickerController: NohanaImagePickerController) {
self.asset = asset
self.nohanaImagePickerController = nohanaImagePickerController
self.pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset)
self.pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset)
self.overlayView.isHidden = !pickButton.isSelected
self.pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) )
}

View File

@ -17,39 +17,39 @@
import UIKit
class AssetDetailCell: UICollectionViewCell, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var imageViewHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var imageViewWidthConstraint: NSLayoutConstraint!
let doubleTapGestureRecognizer :UITapGestureRecognizer = UITapGestureRecognizer()
let doubleTapGestureRecognizer: UITapGestureRecognizer = UITapGestureRecognizer()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
doubleTapGestureRecognizer.addTarget(self, action: #selector(AssetDetailCell.didDoubleTap(_:)))
doubleTapGestureRecognizer.numberOfTapsRequired = 2
}
override func willMove(toSuperview newSuperview: UIView?) {
super.willMove(toSuperview: newSuperview)
scrollView.removeGestureRecognizer(doubleTapGestureRecognizer)
scrollView.addGestureRecognizer(doubleTapGestureRecognizer)
}
deinit {
scrollView.removeGestureRecognizer(doubleTapGestureRecognizer)
doubleTapGestureRecognizer.removeTarget(self, action: #selector(AssetDetailCell.didDoubleTap(_:)))
}
// MARK: - UIScrollViewDelegate
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return imageView
}
// MARK: - Zoom
func didDoubleTap(_ sender: UITapGestureRecognizer) {
if scrollView.zoomScale < scrollView.maximumZoomScale {
let center = sender.location(in: imageView)
@ -59,16 +59,16 @@ class AssetDetailCell: UICollectionViewCell, UIScrollViewDelegate {
scrollView.setZoomScale(defaultScale, animated: true)
}
}
func zoomRect(_ center: CGPoint) -> CGRect {
var zoomRect: CGRect = CGRect()
zoomRect.size.height = scrollView.frame.size.height / scrollView.maximumZoomScale
zoomRect.size.width = scrollView.frame.size.width / scrollView.maximumZoomScale
zoomRect.origin.x = center.x - zoomRect.size.width / 2.0
zoomRect.origin.y = center.y - zoomRect.size.height / 2.0
return zoomRect
}
}

View File

@ -17,7 +17,7 @@
import UIKit
class AssetDetailListViewController: AssetListViewController {
var currentIndexPath: IndexPath = IndexPath() {
willSet {
if currentIndexPath != newValue {
@ -25,24 +25,24 @@ class AssetDetailListViewController: AssetListViewController {
}
}
}
@IBOutlet weak var pickButton: UIButton!
override var cellSize: CGSize {
return Size.screenRectWithoutAppBar(self).size
}
override func viewDidLoad() {
super.viewDidLoad()
if let nohanaImagePickerController = nohanaImagePickerController {
let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedLarge ?? UIImage(named: "btn_select_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedLarge ?? UIImage(named: "btn_selected_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
pickButton.setImage(droppedImage, for: UIControlState())
pickButton.setImage(pickedImage, for: .selected)
}
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
let indexPath = currentIndexPath
@ -54,12 +54,12 @@ class AssetDetailListViewController: AssetListViewController {
self.view.isHidden = false
}
}
override func updateTitle() {
self.title = ""
}
func didChangeAssetDetailPage(_ indexPath:IndexPath) {
func didChangeAssetDetailPage(_ indexPath: IndexPath) {
guard let nohanaImagePickerController = nohanaImagePickerController else {
return
}
@ -68,7 +68,7 @@ class AssetDetailListViewController: AssetListViewController {
pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) )
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetDetailListViewController: self, didChangeAssetDetailPage: indexPath, photoKitAsset: asset.originalAsset)
}
override func scrollCollectionView(to indexPath: IndexPath) {
let count: Int? = photoKitAssetList?.count
guard count != nil && count! > 0 else {
@ -79,7 +79,7 @@ class AssetDetailListViewController: AssetListViewController {
self.collectionView?.scrollToItem(at: toIndexPath, at: UICollectionViewScrollPosition.centeredHorizontally, animated: false)
}
}
override func scrollCollectionViewToInitialPosition() {
guard isFirstAppearance else {
return
@ -88,9 +88,9 @@ class AssetDetailListViewController: AssetListViewController {
scrollCollectionView(to: indexPath)
isFirstAppearance = false
}
// MARK: - IBAction
@IBAction func didPushPickButton(_ sender: UIButton) {
let asset = photoKitAssetList[currentIndexPath.row]
if pickButton.isSelected {
@ -103,9 +103,9 @@ class AssetDetailListViewController: AssetListViewController {
}
}
}
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell,
let nohanaImagePickerController = nohanaImagePickerController else {
@ -113,7 +113,7 @@ class AssetDetailListViewController: AssetListViewController {
}
cell.scrollView.zoomScale = 1
cell.tag = indexPath.item
let imageSize = CGSize(
width: cellSize.width * UIScreen.main.scale,
height: cellSize.height * UIScreen.main.scale
@ -132,9 +132,9 @@ class AssetDetailListViewController: AssetListViewController {
}
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetDetailListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
}
// MARK: - UIScrollViewDelegate
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard let collectionView = collectionView else {
return
@ -148,11 +148,11 @@ class AssetDetailListViewController: AssetListViewController {
currentIndexPath = IndexPath(row: row, section: currentIndexPath.section)
}
}
// MARK: - UICollectionViewDelegateFlowLayout
override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
return cellSize
}
}

View File

@ -18,10 +18,10 @@ import UIKit
import Photos
class AssetListViewController: UICollectionViewController {
weak var nohanaImagePickerController: NohanaImagePickerController?
var photoKitAssetList: PhotoKitAssetList!
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = nohanaImagePickerController?.config.color.background ?? .white
@ -29,7 +29,7 @@ class AssetListViewController: UICollectionViewController {
setUpToolbarItems()
addPickPhotoKitAssetNotificationObservers()
}
var cellSize: CGSize {
guard let nohanaImagePickerController = nohanaImagePickerController else {
return CGSize.zero
@ -38,15 +38,15 @@ class AssetListViewController: UICollectionViewController {
if UIInterfaceOrientationIsPortrait(UIApplication.shared.statusBarOrientation) {
numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait
}
let cellMargin:CGFloat = 2
let cellMargin: CGFloat = 2
let cellWidth = (view.frame.width - cellMargin * (CGFloat(numberOfColumns) - 1)) / CGFloat(numberOfColumns)
return CGSize(width: cellWidth, height: cellWidth)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let nohanaImagePickerController = nohanaImagePickerController {
@ -55,7 +55,7 @@ class AssetListViewController: UICollectionViewController {
collectionView?.reloadData()
scrollCollectionViewToInitialPosition()
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
view.isHidden = true
@ -69,13 +69,13 @@ class AssetListViewController: UICollectionViewController {
self.view.isHidden = false
}
}
var isFirstAppearance = true
func updateTitle() {
title = photoKitAssetList.title
}
func scrollCollectionView(to indexPath: IndexPath) {
let count: Int? = photoKitAssetList?.count
guard count != nil && count! > 0 else {
@ -85,7 +85,7 @@ class AssetListViewController: UICollectionViewController {
self.collectionView?.scrollToItem(at: indexPath, at: .bottom, animated: false)
}
}
func scrollCollectionViewToInitialPosition() {
guard isFirstAppearance else {
return
@ -94,21 +94,21 @@ class AssetListViewController: UICollectionViewController {
self.scrollCollectionView(to: indexPath)
isFirstAppearance = false
}
// MARK: - UICollectionViewDataSource
// MARK: - UICollectionViewDataSource
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return photoKitAssetList.count
}
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let nohanaImagePickerController = nohanaImagePickerController {
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: photoKitAssetList[indexPath.item].originalAsset)
}
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell,
let nohanaImagePickerController = nohanaImagePickerController else {
@ -116,7 +116,7 @@ class AssetListViewController: UICollectionViewController {
}
cell.tag = indexPath.item
cell.update(asset: photoKitAssetList[indexPath.row], nohanaImagePickerController: nohanaImagePickerController)
let imageSize = CGSize(
width: cellSize.width * UIScreen.main.scale,
height: cellSize.height * UIScreen.main.scale
@ -133,31 +133,29 @@ class AssetListViewController: UICollectionViewController {
}
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
}
// MARK: - UICollectionViewDelegateFlowLayout
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
return cellSize
}
// MARK: - Storyboard
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first else {
return
}
let assetListDetailViewController = segue.destination as! AssetDetailListViewController
assetListDetailViewController.photoKitAssetList = photoKitAssetList
assetListDetailViewController.nohanaImagePickerController = nohanaImagePickerController
assetListDetailViewController.currentIndexPath = selectedIndexPath
}
// MARK: - IBAction
@IBAction func didPushDone(_ sender: AnyObject) {
let pickedPhotoKitAssets = nohanaImagePickerController!.pickedAssetList.map{ ($0 as! PhotoKitAsset).originalAsset }
let pickedPhotoKitAssets = nohanaImagePickerController!.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset }
nohanaImagePickerController!.delegate?.nohanaImagePicker(nohanaImagePickerController!, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets )
}
}

View File

@ -21,7 +21,7 @@ extension Size {
let origin = CGPoint(x: toCell.frame.origin.x, y: toCell.frame.origin.y - toVC.collectionView!.contentOffset.y)
return CGRect(origin: origin, size: toCell.frame.size)
}
static func contractingAnimationFromCellRect(_ fromVC: AssetDetailListViewController, fromCell: AssetDetailCell, contractingImageSize: CGSize) -> CGRect {
var rect = AVMakeRect(aspectRatio: contractingImageSize, insideRect: fromCell.imageView.frame)
rect.origin.y += Size.appBarHeight(fromVC)
@ -32,17 +32,17 @@ extension Size {
}
class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
var fromCell: AssetDetailCell
init(_ fromCell: AssetDetailCell) {
self.fromCell = fromCell
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.3
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as? AssetDetailListViewController,
@ -50,7 +50,7 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
else {
return
}
var toCellTmp = toVC.collectionView?.cellForItem(at: fromVC.currentIndexPath as IndexPath) as? AssetCell
if toCellTmp == nil {
// if toCell is not shown in collection view, scroll collection view to toCell index path.
@ -58,11 +58,11 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
toVC.collectionView?.layoutIfNeeded()
toCellTmp = toVC.collectionView?.cellForItem(at: fromVC.currentIndexPath as IndexPath) as? AssetCell
}
guard let toCell = toCellTmp else {
return
}
let contractingImageView = UIImageView(image: fromCell.imageView.image)
contractingImageView.contentMode = toCell.imageView.contentMode
contractingImageView.clipsToBounds = true
@ -73,7 +73,7 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
toVC.view.alpha = 0
fromCell.alpha = 0
toCell.alpha = 0
UIView.animate(
withDuration: transitionDuration(using: transitionContext),
delay: 0,
@ -87,8 +87,8 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
contractingImageView.removeFromSuperview()
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}
}

View File

@ -21,7 +21,7 @@ public protocol EmptyIndicatable {
public extension EmptyIndicatable where Self: UIViewController {
func updateVisibilityOfEmptyIndicator(_ emptyIndicator: UIView) {
if isEmpty(){
if isEmpty() {
if !view.subviews.contains(emptyIndicator) {
view.addSubview(emptyIndicator)
}

View File

@ -22,31 +22,31 @@ extension Size {
let origin = CGPoint(x: fromCell.frame.origin.x, y: fromCell.frame.origin.y - fromVC.collectionView!.contentOffset.y)
return CGRect(origin: origin, size: fromCell.frame.size)
}
static func expandingAnimationToCellRect(_ fromVC: UIViewController, toSize:CGSize) -> CGRect {
static func expandingAnimationToCellRect(_ fromVC: UIViewController, toSize: CGSize) -> CGRect {
return AVMakeRect(aspectRatio: toSize, insideRect: Size.screenRectWithoutAppBar(fromVC))
}
}
class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
var fromCell: AssetCell
init(_ fromCell: AssetCell) {
self.fromCell = fromCell
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.3
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as? AssetListViewController,
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as? AssetDetailListViewController
else {
return
}
let expandingImageView = UIImageView(image: fromCell.imageView.image)
expandingImageView.contentMode = fromCell.imageView.contentMode
expandingImageView.clipsToBounds = true
@ -58,7 +58,7 @@ class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransition
toVC.collectionView?.isHidden = true
toVC.view.backgroundColor = UIColor.black
fromCell.alpha = 0
UIView.animate(
withDuration: transitionDuration(using: transitionContext),
delay: 0,
@ -75,6 +75,5 @@ class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransition
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}
}
}

View File

@ -16,7 +16,7 @@
public protocol ItemList: Collection {
associatedtype Item
var title:String { get }
var title: String { get }
func update(_ handler:(() -> Void)?)
subscript (index: Int) -> Item { get }
}
@ -28,8 +28,8 @@ extension ItemList {
}
public protocol Asset {
var identifier:Int { get }
func image(targetSize:CGSize, handler: @escaping (ImageData?) -> Void)
var identifier: Int { get }
func image(targetSize: CGSize, handler: @escaping (ImageData?) -> Void)
}
public struct ImageData {

View File

@ -18,7 +18,7 @@ import UIKit
class MomentCell: AlbumCell {
var config: NohanaImagePickerController.Config!
override func draw(_ rect: CGRect) {
super.draw(rect)
let lineWidth: CGFloat = 1 / UIScreen.main.scale

View File

@ -18,20 +18,20 @@ import UIKit
import Photos
class MomentViewController: AssetListViewController, ActivityIndicatable {
var momentAlbumList: PhotoKitAlbumList!
override func viewDidLoad() {
super.viewDidLoad()
setUpActivityIndicator()
}
override func updateTitle() {
if let nohanaImagePickerController = nohanaImagePickerController {
title = NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
}
}
override func scrollCollectionView(to indexPath: IndexPath) {
let count: Int? = momentAlbumList?.count
guard count != nil && count! > 0 else {
@ -41,7 +41,7 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
self.collectionView?.scrollToItem(at: indexPath, at: .bottom, animated: false)
}
}
override func scrollCollectionViewToInitialPosition() {
guard isFirstAppearance else {
return
@ -54,29 +54,29 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
scrollCollectionView(to: indexPath)
isFirstAppearance = false
}
// MARK: - UICollectionViewDataSource
override func numberOfSections(in collectionView: UICollectionView) -> Int {
if let activityIndicator = activityIndicator {
updateVisibilityOfActivityIndicator(activityIndicator)
}
return momentAlbumList.count
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return momentAlbumList[section].count
}
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell,
let nohanaImagePickerController = nohanaImagePickerController else {
fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")")
}
let asset = momentAlbumList[indexPath.section][indexPath.row]
cell.tag = indexPath.item
cell.update(asset: asset, nohanaImagePickerController: nohanaImagePickerController)
@ -96,7 +96,7 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
}
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
@ -110,7 +110,7 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
formatter.dateStyle = .long
formatter.timeStyle = DateFormatter.Style.none
header.dateLabel.text = formatter.string(from: date as Date)
} else {
} else {
header.dateLabel.text = ""
}
return header
@ -118,33 +118,33 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
fatalError("failed to create MomentHeader")
}
}
// MARK: - ActivityIndicatable
var activityIndicator: UIActivityIndicatorView?
var isLoading = true
func setUpActivityIndicator() {
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
let screenRect = Size.screenRectWithoutAppBar(self)
activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2)
activityIndicator?.startAnimating()
}
func isProgressing() -> Bool {
return isLoading
}
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let nohanaImagePickerController = nohanaImagePickerController {
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: momentAlbumList[indexPath.section][indexPath.row].originalAsset)
}
}
// MARK: - Storyboard
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first else {
return
@ -154,11 +154,11 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
assetListDetailViewController.nohanaImagePickerController = nohanaImagePickerController
assetListDetailViewController.currentIndexPath = selectedIndexPath
}
// MARK: - IBAction
@IBAction override func didPushDone(_ sender: AnyObject) {
super.didPushDone(sender)
}
}

View File

@ -23,7 +23,7 @@ public enum MediaType: Int {
@objc public protocol NohanaImagePickerControllerDelegate {
func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController)
func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts :[PHAsset])
func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts: [PHAsset])
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, willPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, didPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int)
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, willDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool
@ -34,11 +34,11 @@ public enum MediaType: Int {
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, didChangeAssetDetailPage indexPath: IndexPath, photoKitAsset: PHAsset)
}
open class NohanaImagePickerController: UIViewController {
open var maximumNumberOfSelection: Int = 21 // set 0 to no limit
open var numberOfColumnsInPortrait: Int = 4
open var numberOfColumnsInLandscape: Int = 7
@ -46,12 +46,12 @@ open class NohanaImagePickerController: UIViewController {
open var shouldShowMoment: Bool = true
open var shouldShowEmptyAlbum: Bool = false
open var toolbarHidden: Bool = false
open var canPickAsset = { (asset:Asset) -> Bool in
open var canPickAsset = { (asset: Asset) -> Bool in
return true
}
open var config: Config = Config()
lazy var assetBundle:Bundle = {
lazy var assetBundle: Bundle = {
let bundle = Bundle(for: type(of: self))
if let path = bundle.path(forResource: "NohanaImagePicker", ofType: "bundle") {
return Bundle(path: path)!
@ -62,7 +62,7 @@ open class NohanaImagePickerController: UIViewController {
let mediaType: MediaType
let enableExpandingPhotoAnimation: Bool
fileprivate let assetCollectionSubtypes: [PHAssetCollectionSubtype]
public init() {
assetCollectionSubtypes = [
.albumRegular,
@ -83,7 +83,7 @@ open class NohanaImagePickerController: UIViewController {
super.init(nibName: nil, bundle: nil)
self.pickedAssetList.nohanaImagePickerController = self
}
public init(assetCollectionSubtypes: [PHAssetCollectionSubtype], mediaType: MediaType, enableExpandingPhotoAnimation: Bool) {
self.assetCollectionSubtypes = assetCollectionSubtypes
self.mediaType = mediaType
@ -99,7 +99,7 @@ open class NohanaImagePickerController: UIViewController {
override open func viewDidLoad() {
super.viewDidLoad()
// show albumListViewController
let storyboard = UIStoryboard(name: "NohanaImagePicker", bundle: assetBundle)
let viewControllerId = enableExpandingPhotoAnimation ? "EnableAnimationNavigationController" : "DisableAnimationNavigationController"
@ -109,7 +109,7 @@ open class NohanaImagePickerController: UIViewController {
addChildViewController(navigationController)
view.addSubview(navigationController.view)
navigationController.didMove(toParentViewController: self)
// setup albumListViewController
guard let albumListViewController = navigationController.topViewController as? AlbumListViewController else {
fatalError("albumListViewController is not topViewController.")
@ -128,11 +128,11 @@ open class NohanaImagePickerController: UIViewController {
})
albumListViewController.nohanaImagePickerController = self
}
open func pickAsset(_ asset: Asset) {
_ = pickedAssetList.pick(asset: asset)
}
open func dropAsset(_ asset: Asset) {
_ = pickedAssetList.drop(asset: asset)
}
@ -146,7 +146,7 @@ extension NohanaImagePickerController {
public var separator: UIColor?
}
public var color = Color()
public struct Image {
public var pickedSmall: UIImage?
public var pickedLarge: UIImage?
@ -154,7 +154,7 @@ extension NohanaImagePickerController {
public var droppedLarge: UIImage?
}
public var image = Image()
public struct Strings {
public var albumListTitle: String?
public var albumListMomentTitle: String?

View File

@ -16,13 +16,13 @@
import Photos
public class PhotoKitAlbumList: ItemList {
private var albumList:[Item] = []
private var albumList: [Item] = []
private let assetCollectionTypes: [PHAssetCollectionType]
private let assetCollectionSubtypes: [PHAssetCollectionSubtype]
private let mediaType: MediaType
private var shouldShowEmptyAlbum: Bool
// MARK: - init
init(assetCollectionTypes: [PHAssetCollectionType], assetCollectionSubtypes: [PHAssetCollectionSubtype], mediaType: MediaType, shouldShowEmptyAlbum: Bool, handler:(() -> Void)?) {
@ -36,24 +36,24 @@ public class PhotoKitAlbumList: ItemList {
}
}
}
// MARK: - ItemList
public typealias Item = PhotoKitAssetList
open var title:String {
open var title: String {
return "PhotoKit"
}
open func update(_ handler:(() -> Void)?) {
DispatchQueue.global(qos: .default).async {
var albumListFetchResult: [PHFetchResult<PHAssetCollection>] = []
for type in self.assetCollectionTypes {
albumListFetchResult = albumListFetchResult + [PHAssetCollection.fetchAssetCollections(with: type, subtype: .any, options: nil)]
}
self.albumList = []
var tmpAlbumList:[Item] = []
var tmpAlbumList: [Item] = []
let isAssetCollectionSubtypeAny = self.assetCollectionSubtypes.contains(.any)
for fetchResult in albumListFetchResult {
fetchResult.enumerateObjects({ (album, index, stop) in
@ -65,29 +65,29 @@ public class PhotoKitAlbumList: ItemList {
})
}
if self.assetCollectionTypes == [.moment] {
self.albumList = tmpAlbumList.sorted{ $0.date!.timeIntervalSince1970 < $1.date!.timeIntervalSince1970 }
self.albumList = tmpAlbumList.sorted { $0.date!.timeIntervalSince1970 < $1.date!.timeIntervalSince1970 }
} else {
self.albumList = tmpAlbumList
}
if let handler = handler {
handler()
}
}
}
open subscript (index: Int) -> Item {
return albumList[index] as Item
}
// MARK: - CollectionType
open var startIndex: Int {
return albumList.startIndex
}
open var endIndex: Int {
return albumList.endIndex
}
}

View File

@ -15,25 +15,25 @@
*/
import Photos
public class PhotoKitAsset :Asset {
public class PhotoKitAsset: Asset {
let asset: PHAsset
public init(asset: PHAsset) {
self.asset = asset
}
public var originalAsset: PHAsset {
return asset as PHAsset
}
// MARK: - Asset
public var identifier:Int {
public var identifier: Int {
return asset.localIdentifier.hash
}
public func image(targetSize:CGSize, handler: @escaping (ImageData?) -> Void) {
public func image(targetSize: CGSize, handler: @escaping (ImageData?) -> Void) {
let option = PHImageRequestOptions()
option.isNetworkAccessAllowed = true

View File

@ -16,30 +16,30 @@
import Photos
open class PhotoKitAssetList :ItemList {
open class PhotoKitAssetList: ItemList {
fileprivate let mediaType: MediaType
open let assetList: PHAssetCollection
fileprivate var fetchResult: PHFetchResult<PHAsset>!
init(album: PHAssetCollection, mediaType: MediaType) {
self.assetList = album
self.mediaType = mediaType
update()
}
// MARK: - ItemList
public typealias Item = PhotoKitAsset
open var title: String {
return assetList.localizedTitle ?? ""
}
open var date: Date? {
return assetList.startDate
}
class func fetchOptions(_ mediaType: MediaType) -> PHFetchOptions {
let options = PHFetchOptions()
switch mediaType {
@ -50,24 +50,24 @@ open class PhotoKitAssetList :ItemList {
}
return options
}
open func update(_ handler: (() -> Void)? = nil) {
fetchResult = PHAsset.fetchAssets(in: assetList, options: PhotoKitAssetList.fetchOptions(mediaType))
if let handler = handler {
handler()
}
}
open subscript (index: Int) -> Item {
return Item(asset: fetchResult.object(at: index))
}
// MARK: - CollectionType
open var startIndex: Int {
return 0
}
open var endIndex: Int {
return fetchResult.count
}

View File

@ -17,46 +17,45 @@
import Foundation
class PickedAssetList: ItemList {
var assetlist: Array<Asset> = []
weak var nohanaImagePickerController: NohanaImagePickerController?
// MARK: - ItemList
typealias Item = Asset
var title: String {
return "Selected Assets"
}
func update(_ handler:(() -> Void)?) {
fatalError("not supported")
}
subscript (index: Int) -> Item {
return assetlist[index]
}
// MARK: - CollectionType
var startIndex: Int {
return 0
}
var endIndex: Int {
return assetlist.count
}
// MARK: - Manage assetlist
func pick(asset: Asset) -> Bool {
guard !isPicked(asset) else {
return false
}
let assetsCountBeforePicking = self.count
if asset is PhotoKitAsset {
if let canPick = nohanaImagePickerController!.delegate?.nohanaImagePicker?(nohanaImagePickerController!, willPickPhotoKitAsset: (asset as! PhotoKitAsset).originalAsset, pickedAssetsCount: assetsCountBeforePicking)
, !canPick {
if let canPick = nohanaImagePickerController!.delegate?.nohanaImagePicker?(nohanaImagePickerController!, willPickPhotoKitAsset: (asset as! PhotoKitAsset).originalAsset, pickedAssetsCount: assetsCountBeforePicking), !canPick {
return false
}
}
@ -80,17 +79,17 @@ class PickedAssetList: ItemList {
)
}
return true
}
func drop(asset: Asset) -> Bool {
let assetsCountBeforeDropping = self.count
if asset is PhotoKitAsset {
if let canDrop = nohanaImagePickerController!.delegate?.nohanaImagePicker?(nohanaImagePickerController!, willDropPhotoKitAsset: (asset as! PhotoKitAsset).originalAsset, pickedAssetsCount: assetsCountBeforeDropping) , !canDrop {
if let canDrop = nohanaImagePickerController!.delegate?.nohanaImagePicker?(nohanaImagePickerController!, willDropPhotoKitAsset: (asset as! PhotoKitAsset).originalAsset, pickedAssetsCount: assetsCountBeforeDropping), !canDrop {
return false
}
}
assetlist = assetlist.filter{ $0.identifier != asset.identifier }
assetlist = assetlist.filter { $0.identifier != asset.identifier }
let assetsCountAfterDropping = self.count
if asset is PhotoKitAsset {
let originalAsset = (asset as! PhotoKitAsset).originalAsset
@ -108,9 +107,9 @@ class PickedAssetList: ItemList {
}
return true
}
func isPicked(_ asset: Asset) -> Bool {
return assetlist.contains{ $0.identifier == asset.identifier }
return assetlist.contains { $0.identifier == asset.identifier }
}
}

View File

@ -15,22 +15,22 @@
*/
struct Size {
static var statusBarHeight: CGFloat {
if UIApplication.shared.isStatusBarHidden {
return 0
}
return UIApplication.shared.statusBarFrame.size.height
}
static func navigationBarHeight(_ viewController: UIViewController) -> CGFloat {
return viewController.navigationController?.navigationBar.frame.size.height ?? CGFloat(0)
}
static func appBarHeight(_ viewController: UIViewController) -> CGFloat {
return statusBarHeight + navigationBarHeight(viewController)
}
static func toolbarHeight(_ viewController: UIViewController) -> CGFloat {
guard let navigationController = viewController.navigationController else {
return 0
@ -40,7 +40,7 @@ struct Size {
}
return navigationController.toolbar.frame.size.height
}
static func screenRectWithoutAppBar(_ viewController: UIViewController) -> CGRect {
let appBarHeight = Size.appBarHeight(viewController)
let toolbarHeight = Size.toolbarHeight(viewController)

View File

@ -17,9 +17,9 @@
import UIKit
class SwipeInteractionController: UIPercentDrivenInteractiveTransition {
var viewController: UIViewController?
func attachToViewController(_ viewController: UIViewController) {
let count: Int? = viewController.navigationController?.viewControllers.count
guard count != nil && count! > 1 else {