Skip to content

Commit

Permalink
Now asset supports remote url.
Browse files Browse the repository at this point in the history
  • Loading branch information
CocoaBob committed Jun 12, 2018
1 parent caab7c8 commit 49a9324
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
16 changes: 12 additions & 4 deletions TLPhotoPicker/Classes/TLAssetsCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PhotosUI
import MobileCoreServices

public class TLPHAsset {

enum CloudDownloadState {
case ready, progress, complete, failed
}
Expand All @@ -32,9 +33,9 @@ public class TLPHAsset {
guard let phAsset = self.phAsset else { return .photo }
if phAsset.mediaSubtypes.contains(.photoLive) {
return .livePhoto
}else if phAsset.mediaType == .video {
} else if phAsset.mediaType == .video {
return .video
}else {
} else {
return .photo
}
}
Expand All @@ -46,14 +47,16 @@ public class TLPHAsset {
_fullResolutionImage = newValue
}
get {
if let _ = _fullResolutionImage {
return _fullResolutionImage
if let image = _fullResolutionImage {
return image
}
guard let phAsset = self.phAsset else { return nil }
return TLPhotoLibrary.fullResolutionImageData(asset: phAsset)
}
}

public var url: URL?

public func extType() -> ImageExtType {
var ext = ImageExtType.png
if let fileName = self.originalFileName, let extention = URL(string: fileName)?.pathExtension.lowercased() {
Expand Down Expand Up @@ -209,6 +212,11 @@ public class TLPHAsset {
self.init(asset: nil)
self.fullResolutionImage = image
}

public convenience init(url: URL) {
self.init(asset: nil)
self.url = url
}
}

extension TLPHAsset: Equatable {
Expand Down
1 change: 1 addition & 0 deletions TLPhotoPicker/Classes/TLBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

class TLBundle {

class func podBundleImage(named: String) -> UIImage? {
let podBundle = Bundle(for: TLBundle.self)
if let url = podBundle.url(forResource: "TLPhotoPickerController", withExtension: "bundle") {
Expand Down
14 changes: 12 additions & 2 deletions TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Photos
import PhotosUI
import MobileCoreServices
import UIKit.UIGestureRecognizerSubclass
import SDWebImage

public protocol TLPhotosPickerViewControllerDelegate: class {
func willDismissPhotoPicker(with phAssets: [PHAsset])
Expand Down Expand Up @@ -810,8 +811,17 @@ extension TLPhotosPickerViewController: UICollectionViewDelegate,UICollectionVie
} else {
cell.indicator?.stopAnimating()
}
if let customCollection = customCollection, collection == customCollection, let image = asset.fullResolutionImage {
cell.imageView?.image = image
if let customCollection = customCollection, collection == customCollection {
if let image = asset.fullResolutionImage {
cell.imageView?.image = image
} else if let url = asset.url {
cell.imageView?.sd_setImage(with: url,
placeholderImage: self.configure.placeholderIcon,
options: [.continueInBackground, .allowInvalidSSLCertificates, .highPriority],
completed: { (image, error, type, url) -> Void in
asset.fullResolutionImage = image
})
}
} else if let phAsset = asset.phAsset {
if self.usedPrefetch {
let options = PHImageRequestOptions()
Expand Down

0 comments on commit 49a9324

Please sign in to comment.