Skip to content

Commit

Permalink
Let asset support remote url.
Browse files Browse the repository at this point in the history
  • Loading branch information
CocoaBob committed May 31, 2018
1 parent 75ab30e commit 1c4bc55
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions TLPhotoPicker/Classes/TLAssetsCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class TLPHAsset {
}
}

public var remoteURL: 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 +211,11 @@ public class TLPHAsset {
self.init(asset: nil)
self.fullResolutionImage = image
}

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

extension TLPHAsset: Equatable {
Expand Down
4 changes: 4 additions & 0 deletions TLPhotoPicker/Classes/TLPhotoCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ open class TLPhotoCollectionViewCell: UICollectionViewCell {
self.selectedView?.layer.borderColor = self.configure.selectedColor.cgColor
self.orderBgView?.backgroundColor = self.configure.selectedColor
self.videoIconImageView?.image = self.configure.videoIcon
if self.imageView?.image == nil {
self.imageView?.image = self.configure.placeholderIcon
}
}
}

Expand Down Expand Up @@ -162,5 +165,6 @@ open class TLPhotoCollectionViewCell: UICollectionViewCell {
self.durationView?.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.6)
self.selectedHeight?.constant = 10
self.selectedAsset = false
self.imageView?.image = self.configure.placeholderIcon
}
}
15 changes: 13 additions & 2 deletions TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,19 @@ 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.remoteURL {
cell.imageView?.image = self.placeholderThumbnail
DispatchQueue.global().async {
if let data = try? Data(contentsOf: url), let image = UIImage(data: data) {
DispatchQueue.main.async {
cell.imageView?.image = image
}
}
}
}
} else if let phAsset = asset.phAsset {
if self.usedPrefetch {
let options = PHImageRequestOptions()
Expand Down

0 comments on commit 1c4bc55

Please sign in to comment.