buildable
This commit is contained in:
parent
4381c4e614
commit
567ee0d93d
|
|
@ -16,12 +16,12 @@
|
|||
|
||||
public protocol ActivityIndicatable {
|
||||
func isProgressing() -> Bool
|
||||
func updateVisibility(of activityIndicator: UIView)
|
||||
func updateVisibilityOfActivityIndicator(_ activityIndicator: UIView)
|
||||
}
|
||||
|
||||
public extension ActivityIndicatable where Self: UIViewController {
|
||||
|
||||
func updateVisibility(of activityIndicator: UIView) {
|
||||
func updateVisibilityOfActivityIndicator(_ activityIndicator: UIView) {
|
||||
if isProgressing() {
|
||||
if !view.subviews.contains(activityIndicator) {
|
||||
view.addSubview(activityIndicator)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
|||
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||
title = NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
||||
setUpToolbarItems()
|
||||
navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden ?? false, animated: false)
|
||||
navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden ,animated: false)
|
||||
}
|
||||
setUpEmptyIndicator()
|
||||
setUpActivityIndicator()
|
||||
|
|
@ -153,8 +153,10 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
|||
width: cell.thumbnailImageView.frame.size.width * UIScreen.main.scale,
|
||||
height: cell.thumbnailImageView.frame.size.width * UIScreen.main.scale
|
||||
)
|
||||
if let lastAsset = albumList.last {
|
||||
lastAsset.image(imageSize, handler: { (imageData) -> Void in
|
||||
let albumCount = albumList.count
|
||||
if albumCount > 0 {
|
||||
let lastAsset = albumList[albumCount - 1]
|
||||
lastAsset.image(targetSize: imageSize, handler: { (imageData) -> Void in
|
||||
DispatchQueue.main.async(execute: { () -> Void in
|
||||
if let imageData = imageData {
|
||||
if cell.tag == (indexPath as NSIndexPath).row {
|
||||
|
|
@ -262,7 +264,8 @@ extension UIViewController {
|
|||
}
|
||||
|
||||
func setToolbarTitle(_ nohanaImagePickerController:NohanaImagePickerController) {
|
||||
guard toolbarItems?.count >= 2 else {
|
||||
let count: Int? = toolbarItems?.count
|
||||
guard count != nil && count! >= 2 else {
|
||||
return
|
||||
}
|
||||
guard let infoButton = toolbarItems?[1] else {
|
||||
|
|
@ -283,8 +286,8 @@ extension UIViewController {
|
|||
// MARK: - Notification
|
||||
|
||||
func addPickPhotoKitAssetNotificationObservers() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didPickPhotoKitAsset(_:)), name: NSNotification.Name(rawValue: NotificationInfo.Asset.PhotoKit.didPick), object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didDropPhotoKitAsset(_:)), name: NSNotification.Name(rawValue: NotificationInfo.Asset.PhotoKit.didDrop), object: nil)
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ class AssetCell: UICollectionViewCell {
|
|||
func update(asset: AssetType, nohanaImagePickerController: NohanaImagePickerController) {
|
||||
self.asset = asset
|
||||
self.nohanaImagePickerController = nohanaImagePickerController
|
||||
self.pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset) ?? false
|
||||
self.pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset)
|
||||
self.overlayView.isHidden = !pickButton.isSelected
|
||||
self.pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) ?? true)
|
||||
self.pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) )
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,13 +67,14 @@ class AssetDetailListViewController: AssetListViewController {
|
|||
return
|
||||
}
|
||||
let asset = photoKitAssetList[(indexPath as NSIndexPath).item]
|
||||
pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset) ?? false
|
||||
pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) ?? true)
|
||||
pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset)
|
||||
pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) )
|
||||
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetDetailListViewController: self, didChangeAssetDetailPage: indexPath, photoKitAsset: asset.originalAsset)
|
||||
}
|
||||
|
||||
override func scrollCollectionView(to indexPath: IndexPath) {
|
||||
guard photoKitAssetList?.count > 0 else {
|
||||
let count: Int? = photoKitAssetList?.count
|
||||
guard count != nil && count! > 0 else {
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
|
|
@ -121,7 +122,7 @@ class AssetDetailListViewController: AssetListViewController {
|
|||
height: cellSize.height * UIScreen.main.scale
|
||||
)
|
||||
let asset = photoKitAssetList[(indexPath as NSIndexPath).item]
|
||||
asset.image(imageSize) { (imageData) -> Void in
|
||||
asset.image(targetSize: imageSize) { (imageData) -> Void in
|
||||
DispatchQueue.main.async(execute: { () -> Void in
|
||||
if let imageData = imageData {
|
||||
if cell.tag == (indexPath as NSIndexPath).item {
|
||||
|
|
|
|||
|
|
@ -79,7 +79,8 @@ class AssetListViewController: UICollectionViewController {
|
|||
}
|
||||
|
||||
func scrollCollectionView(to indexPath: IndexPath) {
|
||||
guard photoKitAssetList?.count > 0 else {
|
||||
let count: Int? = photoKitAssetList?.count
|
||||
guard count != nil && count! > 0 else {
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
|
|
@ -116,14 +117,14 @@ class AssetListViewController: UICollectionViewController {
|
|||
fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")")
|
||||
}
|
||||
cell.tag = indexPath.item
|
||||
cell.update(photoKitAssetList[indexPath.row], nohanaImagePickerController: nohanaImagePickerController)
|
||||
cell.update(asset: photoKitAssetList[indexPath.row], nohanaImagePickerController: nohanaImagePickerController)
|
||||
|
||||
let imageSize = CGSize(
|
||||
width: cellSize.width * UIScreen.main.scale,
|
||||
height: cellSize.height * UIScreen.main.scale
|
||||
)
|
||||
let asset = photoKitAssetList[indexPath.item]
|
||||
asset.image(imageSize) { (imageData) -> Void in
|
||||
asset.image(targetSize: imageSize) { (imageData) -> Void in
|
||||
DispatchQueue.main.async(execute: { () -> Void in
|
||||
if let imageData = imageData {
|
||||
if cell.tag == indexPath.item {
|
||||
|
|
|
|||
|
|
@ -46,8 +46,7 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
|
|||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard
|
||||
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as? AssetDetailListViewController,
|
||||
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as? AssetListViewController,
|
||||
let containerView = transitionContext.containerView
|
||||
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as? AssetListViewController
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
|
@ -69,8 +68,8 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
|
|||
contractingImageView.clipsToBounds = true
|
||||
contractingImageView.frame = Size.contractingAnimationFromCellRect(fromVC, fromCell: fromCell, contractingImageSize: contractingImageView.image!.size)
|
||||
|
||||
containerView.addSubview(toVC.view)
|
||||
containerView.addSubview(contractingImageView)
|
||||
transitionContext.containerView.addSubview(toVC.view)
|
||||
transitionContext.containerView.addSubview(contractingImageView)
|
||||
toVC.view.alpha = 0
|
||||
fromCell.alpha = 0
|
||||
toCell.alpha = 0
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
public protocol EmptyIndicatable {
|
||||
func isEmpty() -> Bool
|
||||
func updateVisibility(of emptyIndicator: UIView)
|
||||
func updateVisibilityOfEmptyIndicator(_ emptyIndicator: UIView)
|
||||
}
|
||||
|
||||
public extension EmptyIndicatable where Self: UIViewController {
|
||||
func updateVisibility(of emptyIndicator: UIView) {
|
||||
func updateVisibilityOfEmptyIndicator(_ emptyIndicator: UIView) {
|
||||
if isEmpty(){
|
||||
if !view.subviews.contains(emptyIndicator) {
|
||||
view.addSubview(emptyIndicator)
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransition
|
|||
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as? AssetListViewController,
|
||||
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as? AssetDetailListViewController,
|
||||
let containerView = transitionContext.containerView
|
||||
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as? AssetDetailListViewController
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
|
@ -53,8 +52,8 @@ class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransition
|
|||
expandingImageView.clipsToBounds = true
|
||||
expandingImageView.frame = Size.expandingAnimationFromCellRect(fromVC, fromCell: fromCell)
|
||||
|
||||
containerView.addSubview(toVC.view)
|
||||
containerView.addSubview(expandingImageView)
|
||||
transitionContext.containerView.addSubview(toVC.view)
|
||||
transitionContext.containerView.addSubview(expandingImageView)
|
||||
toVC.view.alpha = 0
|
||||
toVC.collectionView?.isHidden = true
|
||||
toVC.view.backgroundColor = UIColor.black
|
||||
|
|
|
|||
|
|
@ -21,9 +21,15 @@ public protocol ItemListType: Collection {
|
|||
subscript (index: Int) -> Item { get }
|
||||
}
|
||||
|
||||
extension ItemListType {
|
||||
public func index(after i: Int) -> Int {
|
||||
return i + 1
|
||||
}
|
||||
}
|
||||
|
||||
public protocol AssetType {
|
||||
var identifier:Int { get }
|
||||
func image(targetSize:CGSize, handler: (ImageData?) -> Void)
|
||||
func image(targetSize:CGSize, handler: @escaping (ImageData?) -> Void)
|
||||
}
|
||||
|
||||
public struct ImageData {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
|
|||
}
|
||||
|
||||
override func scrollCollectionView(to indexPath: IndexPath) {
|
||||
guard momentAlbumList?.count > 0 else {
|
||||
let count: Int? = momentAlbumList?.count
|
||||
guard count != nil && count! > 0 else {
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
|
|
@ -78,13 +79,13 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
|
|||
|
||||
let asset = momentAlbumList[indexPath.section][indexPath.row]
|
||||
cell.tag = indexPath.item
|
||||
cell.update(asset, nohanaImagePickerController: nohanaImagePickerController)
|
||||
cell.update(asset: asset, nohanaImagePickerController: nohanaImagePickerController)
|
||||
|
||||
let imageSize = CGSize(
|
||||
width: cellSize.width * UIScreen.main.scale,
|
||||
height: cellSize.height * UIScreen.main.scale
|
||||
)
|
||||
asset.image(imageSize) { (imageData) -> Void in
|
||||
asset.image(targetSize: imageSize) { (imageData) -> Void in
|
||||
DispatchQueue.main.async(execute: { () -> Void in
|
||||
if let imageData = imageData {
|
||||
if cell.tag == indexPath.item {
|
||||
|
|
|
|||
|
|
@ -128,11 +128,11 @@ open class NohanaImagePickerController: UIViewController {
|
|||
}
|
||||
|
||||
open func pickAsset(_ asset: AssetType) {
|
||||
pickedAssetList.pickAsset(asset)
|
||||
_ = pickedAssetList.pickAsset(asset)
|
||||
}
|
||||
|
||||
open func dropAsset(_ asset: AssetType) {
|
||||
pickedAssetList.dropAsset(asset)
|
||||
_ = pickedAssetList.dropAsset(asset)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@
|
|||
struct NotificationInfo {
|
||||
struct Asset {
|
||||
struct PhotoKit {
|
||||
static let didPick = "jp.co.nohana.NotificationName.Asset.PhotoKit.didPick"
|
||||
static let didPick = Notification.Name("jp.co.nohana.NotificationName.Asset.PhotoKit.didPick")
|
||||
static let didPickUserInfoKeyAsset = "asset"
|
||||
static let didPickUserInfoKeyPickedAssetsCount = "pickedAssetsCount"
|
||||
static let didDrop = "jp.co.nohana.NotificationName.Asset.PhotoKit.didDrop"
|
||||
static let didDrop = Notification.Name("jp.co.nohana.NotificationName.Asset.PhotoKit.didDrop")
|
||||
static let didDropUserInfoKeyAsset = "asset"
|
||||
static let didDropUserInfoKeyPickedAssetsCount = "pickedAssetsCount"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ public class PhotoKitAlbumList: ItemListType {
|
|||
}
|
||||
|
||||
open func update(_ handler:(() -> Void)?) {
|
||||
DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async { () -> Void in
|
||||
var albumListFetchResult: [PHFetchResult] = [] as! [PHFetchResult]
|
||||
DispatchQueue.global(qos: .default).async {
|
||||
var albumListFetchResult: [PHFetchResult<PHAssetCollection>] = []
|
||||
for type in self.assetCollectionTypes {
|
||||
albumListFetchResult = albumListFetchResult + [PHAssetCollection.fetchAssetCollections(with: type, subtype: .any, options: nil)]
|
||||
}
|
||||
|
|
@ -58,19 +58,16 @@ public class PhotoKitAlbumList: ItemListType {
|
|||
var tmpAlbumList:[Item] = []
|
||||
let isAssetCollectionSubtypeAny = self.assetCollectionSubtypes.contains(.any)
|
||||
for fetchResult in albumListFetchResult {
|
||||
fetchResult.enumerateObjects { (album, index, stop) -> Void in
|
||||
guard let album = album as? PHAssetCollection else {
|
||||
return
|
||||
}
|
||||
fetchResult.enumerateObjects({ (album, index, stop) in
|
||||
if self.assetCollectionSubtypes.contains(album.assetCollectionSubtype) || isAssetCollectionSubtypeAny {
|
||||
if self.shouldShowEmptyAlbum || PHAsset.fetchAssets(in: album, options: PhotoKitAssetList.fetchOptions(self.mediaType)).count != 0 {
|
||||
tmpAlbumList.append(PhotoKitAssetList(album: album, mediaType: self.mediaType))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
import Photos
|
||||
|
||||
open class PhotoKitAsset: AssetType {
|
||||
public class PhotoKitAsset :AssetType {
|
||||
|
||||
let asset: PHAsset
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ open class PhotoKitAsset: AssetType {
|
|||
self.asset = asset
|
||||
}
|
||||
|
||||
open var originalAsset: PHAsset {
|
||||
public var originalAsset: PHAsset {
|
||||
get {
|
||||
return asset as PHAsset
|
||||
}
|
||||
|
|
@ -31,17 +31,17 @@ open class PhotoKitAsset: AssetType {
|
|||
|
||||
// MARK: - AssetType
|
||||
|
||||
open var identifier:Int {
|
||||
public var identifier:Int {
|
||||
get {
|
||||
return asset.localIdentifier.hash
|
||||
}
|
||||
}
|
||||
|
||||
open func image(targetSize:CGSize, handler: @escaping (ImageData?) -> Void) {
|
||||
public func image(targetSize:CGSize, handler: @escaping (ImageData?) -> Void) {
|
||||
let option = PHImageRequestOptions()
|
||||
option.isNetworkAccessAllowed = true
|
||||
|
||||
PHImageManager.default().requestImage(
|
||||
|
||||
_ = PHImageManager.default().requestImage(
|
||||
for: self.asset,
|
||||
targetSize: targetSize,
|
||||
contentMode: .aspectFit,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ open class PhotoKitAssetList :ItemListType {
|
|||
|
||||
fileprivate let mediaType: MediaType
|
||||
open let assetList: PHAssetCollection
|
||||
fileprivate var fetchResult: PHFetchResult<AnyObject>!
|
||||
fileprivate var fetchResult: PHFetchResult<PHAsset>!
|
||||
|
||||
init(album: PHAssetCollection, mediaType: MediaType) {
|
||||
self.assetList = album
|
||||
|
|
@ -63,12 +63,7 @@ open class PhotoKitAssetList :ItemListType {
|
|||
}
|
||||
|
||||
open subscript (index: Int) -> Item {
|
||||
get {
|
||||
guard let asset = fetchResult[index] as? PHAsset else {
|
||||
fatalError("invalid index")
|
||||
}
|
||||
return Item(asset: asset)
|
||||
}
|
||||
return Item(asset: fetchResult.object(at: index))
|
||||
}
|
||||
|
||||
// MARK: - CollectionType
|
||||
|
|
|
|||
|
|
@ -21,11 +21,12 @@ class SwipeInteractionController: UIPercentDrivenInteractiveTransition {
|
|||
var viewController: UIViewController?
|
||||
|
||||
func attachToViewController(_ viewController: UIViewController) {
|
||||
guard viewController.navigationController?.viewControllers.count > 1 else {
|
||||
let count: Int? = viewController.navigationController?.viewControllers.count
|
||||
guard count != nil && count! > 1 else {
|
||||
return
|
||||
}
|
||||
let target = viewController.navigationController?.value(forKey: "_cachedInteractionController")
|
||||
let gesture = UIScreenEdgePanGestureRecognizer(target: target, action: Selector("handleNavigationTransition:"))
|
||||
let gesture = UIScreenEdgePanGestureRecognizer(target: target, action: Selector(("handleNavigationTransition:")))
|
||||
gesture.edges = .left
|
||||
viewController.view.addGestureRecognizer(gesture)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue