Skip to content

Commit

Permalink
Some minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Mar 14, 2022
1 parent 5f9578a commit 9ed2cd5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Sources/General/ZLPhotoConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ZLPhotoConfiguration: NSObject {
@objc public var statusBarStyle: UIStatusBarStyle = .lightContent

/// text: Cancel. image: 'x'. Default to text.
@objc public var navCancelButtonStyle: ZLPhotoConfiguration.CancelButtonStyle = .text
@objc public var navCancelButtonStyle: ZLPhotoConfiguration.CancelButtonStyle = .image

/// Photo sorting method, the preview interface is not affected by this parameter. Defaults to true.
@objc public var sortAscending = true
Expand Down
27 changes: 14 additions & 13 deletions Sources/General/ZLPhotoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Photos
public class ZLPhotoManager: NSObject {

/// Save image to album.
@objc public class func saveImageToAlbum(image: UIImage, completion: ( (Bool, PHAsset?) -> Void )? ) {
@objc public class func saveImageToAlbum(image: UIImage, completion: ((Bool, PHAsset?) -> Void)? ) {
let status = PHPhotoLibrary.authorizationStatus()

if status == .denied || status == .restricted {
Expand All @@ -55,7 +55,7 @@ public class ZLPhotoManager: NSObject {
}

/// Save video to album.
@objc public class func saveVideoToAlbum(url: URL, completion: ( (Bool, PHAsset?) -> Void )? ) {
@objc public class func saveVideoToAlbum(url: URL, completion: ((Bool, PHAsset?) -> Void )?) {
let status = PHPhotoLibrary.authorizationStatus()

if status == .denied || status == .restricted {
Expand Down Expand Up @@ -117,7 +117,7 @@ public class ZLPhotoManager: NSObject {
}

/// Fetch all album list.
@objc public class func getPhotoAlbumList(ascending: Bool, allowSelectImage: Bool, allowSelectVideo: Bool, completion: ( ([ZLAlbumListModel]) -> Void )) {
@objc public class func getPhotoAlbumList(ascending: Bool, allowSelectImage: Bool, allowSelectVideo: Bool, completion: ([ZLAlbumListModel]) -> Void) {
let option = PHFetchOptions()
if !allowSelectImage {
option.predicate = NSPredicate(format: "mediaType == %ld", PHAssetMediaType.video.rawValue)
Expand Down Expand Up @@ -164,7 +164,7 @@ public class ZLPhotoManager: NSObject {
}

/// Fetch camera roll album.
@objc public class func getCameraRollAlbum(allowSelectImage: Bool, allowSelectVideo: Bool, completion: @escaping ( (ZLAlbumListModel) -> Void )) {
@objc public class func getCameraRollAlbum(allowSelectImage: Bool, allowSelectVideo: Bool, completion: @escaping (ZLAlbumListModel) -> Void) {
let option = PHFetchOptions()
if !allowSelectImage {
option.predicate = NSPredicate(format: "mediaType == %ld", PHAssetMediaType.video.rawValue)
Expand Down Expand Up @@ -246,18 +246,18 @@ public class ZLPhotoManager: NSObject {
}

@discardableResult
@objc public class func fetchImage(for asset: PHAsset, size: CGSize, progress: ( (CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void )? = nil, completion: @escaping ( (UIImage?, Bool) -> Void )) -> PHImageRequestID {
@objc public class func fetchImage(for asset: PHAsset, size: CGSize, progress: ((CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void)? = nil, completion: @escaping (UIImage?, Bool) -> Void) -> PHImageRequestID {
return self.fetchImage(for: asset, size: size, resizeMode: .fast, progress: progress, completion: completion)
}

@discardableResult
@objc public class func fetchOriginalImage(for asset: PHAsset, progress: ( (CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void )? = nil, completion: @escaping ( (UIImage?, Bool) -> Void)) -> PHImageRequestID {
@objc public class func fetchOriginalImage(for asset: PHAsset, progress: ((CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void)? = nil, completion: @escaping (UIImage?, Bool) -> Void) -> PHImageRequestID {
return self.fetchImage(for: asset, size: PHImageManagerMaximumSize, resizeMode: .fast, progress: progress, completion: completion)
}

/// Fetch asset data.
@discardableResult
@objc public class func fetchOriginalImageData(for asset: PHAsset, progress: ( (CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void )? = nil, completion: @escaping ( (Data, [AnyHashable: Any]?, Bool) -> Void)) -> PHImageRequestID {
@objc public class func fetchOriginalImageData(for asset: PHAsset, progress: ((CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void)? = nil, completion: @escaping (Data, [AnyHashable: Any]?, Bool) -> Void) -> PHImageRequestID {
let option = PHImageRequestOptions()
if (asset.value(forKey: "filename") as? String)?.hasSuffix("GIF") == true {
option.version = .original
Expand All @@ -281,7 +281,7 @@ public class ZLPhotoManager: NSObject {
}

/// Fetch image for asset.
private class func fetchImage(for asset: PHAsset, size: CGSize, resizeMode: PHImageRequestOptionsResizeMode, progress: ( (CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void )? = nil, completion: @escaping ( (UIImage?, Bool) -> Void )) -> PHImageRequestID {
private class func fetchImage(for asset: PHAsset, size: CGSize, resizeMode: PHImageRequestOptionsResizeMode, progress: ((CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void)? = nil, completion: @escaping (UIImage?, Bool) -> Void) -> PHImageRequestID {
let option = PHImageRequestOptions()
option.resizeMode = resizeMode
option.isNetworkAccessAllowed = true
Expand All @@ -303,7 +303,7 @@ public class ZLPhotoManager: NSObject {
}
}

@objc public class func fetchLivePhoto(for asset: PHAsset, completion: @escaping ( (PHLivePhoto?, [AnyHashable: Any]?, Bool) -> Void )) -> PHImageRequestID {
@objc public class func fetchLivePhoto(for asset: PHAsset, completion: @escaping (PHLivePhoto?, [AnyHashable: Any]?, Bool) -> Void) -> PHImageRequestID {
let option = PHLivePhotoRequestOptions()
option.version = .current
option.deliveryMode = .opportunistic
Expand All @@ -315,7 +315,7 @@ public class ZLPhotoManager: NSObject {
}
}

@objc public class func fetchVideo(for asset: PHAsset, progress: ( (CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void )? = nil, completion: @escaping ( (AVPlayerItem?, [AnyHashable: Any]?, Bool) -> Void )) -> PHImageRequestID {
@objc public class func fetchVideo(for asset: PHAsset, progress: ((CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void)? = nil, completion: @escaping (AVPlayerItem?, [AnyHashable: Any]?, Bool) -> Void) -> PHImageRequestID {
let option = PHVideoRequestOptions()
option.isNetworkAccessAllowed = true
option.progressHandler = { (pro, error, stop, info) in
Expand All @@ -325,7 +325,6 @@ public class ZLPhotoManager: NSObject {
}

// https://github.com/longitachi/ZLPhotoBrowser/issues/369#issuecomment-728679135

if asset.isInCloud {
return PHImageManager.default().requestExportSession(forVideo: asset, options: option, exportPreset: AVAssetExportPresetHighestQuality, resultHandler: { (session, info) in
// iOS11 and earlier, callback is not on the main thread.
Expand All @@ -334,6 +333,8 @@ public class ZLPhotoManager: NSObject {
if let avAsset = session?.asset {
let item = AVPlayerItem(asset: avAsset)
completion(item, info, isDegraded)
} else {
completion(nil, nil, true)
}
}
})
Expand All @@ -358,7 +359,7 @@ public class ZLPhotoManager: NSObject {
return false
}

@objc public class func fetchAVAsset(forVideo asset: PHAsset, completion: @escaping ( (AVAsset?, [AnyHashable: Any]?) -> Void )) -> PHImageRequestID {
@objc public class func fetchAVAsset(forVideo asset: PHAsset, completion: @escaping (AVAsset?, [AnyHashable: Any]?) -> Void) -> PHImageRequestID {
let options = PHVideoRequestOptions()
options.version = .original
options.deliveryMode = .automatic
Expand All @@ -385,7 +386,7 @@ public class ZLPhotoManager: NSObject {
}

/// Fetch asset local file path.
@objc public class func fetchAssetFilePath(asset: PHAsset, completion: @escaping (String?) -> Void ) {
@objc public class func fetchAssetFilePath(asset: PHAsset, completion: @escaping (String?) -> Void) {
asset.requestContentEditingInput(with: nil) { (input, info) in
var path = input?.fullSizeImageURL?.absoluteString
if path == nil, let dir = asset.value(forKey: "directory") as? String, let name = asset.value(forKey: "filename") as? String {
Expand Down
6 changes: 3 additions & 3 deletions Sources/General/ZLPhotoPreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ class ZLPhotoPreviewController: UIViewController {
}

@objc func originalPhotoClick() {
originalBtn.isSelected.toggle()

let config = ZLPhotoConfiguration.default()

let nav = (navigationController as? ZLImageNavController)
Expand All @@ -515,7 +517,7 @@ class ZLPhotoPreviewController: UIViewController {
selectBtnClick()
} else if config.maxSelectCount == 1,
!config.showSelectBtnWhenSingleSelect,
originalBtn.isSelected,
!originalBtn.isSelected,
nav?.arrSelectedModels.count == 1,
let currentModel = nav?.arrSelectedModels.first {
currentModel.isSelected = false
Expand All @@ -529,8 +531,6 @@ class ZLPhotoPreviewController: UIViewController {
collectionView.reloadItems(at: [IndexPath(row: index, section: 0)])
}
}

originalBtn.isSelected.toggle()
}

@objc func doneBtnClick() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/General/ZLThumbnailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class ZLThumbnailViewController: UIViewController {
self.previewBtn.frame = CGRect(x: 15, y: btnY, width: min(btnMaxWidth, previewBtnW), height: btnH)

let originalTitle = localLanguageTextValue(.originalPhoto)
let originBtnW = originalTitle.boundingRect(font: ZLLayout.bottomToolTitleFont, limitSize: CGSize(width: CGFloat.greatestFiniteMagnitude, height: 30)).width + 30
let originBtnW = originalTitle.boundingRect(font: ZLLayout.bottomToolTitleFont, limitSize: CGSize(width: CGFloat.greatestFiniteMagnitude, height: 30)).width + (originalBtn.currentImage?.size.width ?? 18) + 12
let originBtnMaxW = min(btnMaxWidth, originBtnW)
self.originalBtn.frame = CGRect(x: (self.bottomView.bounds.width - originBtnMaxW) / 2 - 5, y: btnY, width: originBtnMaxW, height: btnH)

Expand Down

0 comments on commit 9ed2cd5

Please sign in to comment.