-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support video in the picker #44
Changes from 8 commits
b225632
d17c0a8
d78c367
8d010d0
97d1b62
9906e51
362075d
7f7eeb0
7924ab7
c4ee19a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "video-icon.pdf" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// This source file is part of the carousell/pickle open source project | ||
// | ||
// Copyright © 2017 Carousell and the project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See https://github.com/carousell/pickle/blob/master/LICENSE for license information | ||
// See https://github.com/carousell/pickle/graphs/contributors for the list of project authors | ||
// | ||
|
||
import UIKit | ||
import Photos | ||
|
||
internal final class GalleryVideoCell: GalleryPhotoCell { | ||
|
||
private let videoPropertyView = VideoPropertyView() | ||
|
||
override func prepareForReuse() { | ||
super.prepareForReuse() | ||
} | ||
|
||
override func setUpSubviews() { | ||
super.setUpSubviews() | ||
|
||
contentView.addSubview(videoPropertyView) | ||
videoPropertyView.translatesAutoresizingMaskIntoConstraints = false | ||
videoPropertyView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true | ||
videoPropertyView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true | ||
videoPropertyView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true | ||
videoPropertyView.heightAnchor.constraint(equalToConstant: 24).isActive = true | ||
} | ||
|
||
override func configure( | ||
with asset: PHAsset, | ||
taggedText: String? = nil, | ||
configuration: ImagePickerConfigurable?) { | ||
|
||
super.configure( | ||
with: asset, | ||
taggedText: taggedText, | ||
configuration: configuration) | ||
|
||
videoPropertyView.configure(duration: asset.duration) | ||
|
||
if taggedText != nil { | ||
videoPropertyView.setSelected(true) | ||
} else { | ||
videoPropertyView.setSelected(false) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. videoPropertyView.setSelected(taggedText != nil) It can be more concise, but it's a choice of coding style. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,18 @@ internal final class PhotoGalleryViewController: UIViewController, | |
internal private(set) lazy var fetchResult: PHFetchResult<PHAsset> = { | ||
let options = PHFetchOptions() | ||
options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] | ||
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) | ||
|
||
switch configuration?.mediaType { | ||
case .all?: | ||
options.predicate = nil | ||
case .image?: | ||
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) | ||
case .video?: | ||
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.rawValue) | ||
default: | ||
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) | ||
} | ||
|
||
return PHAsset.fetchAssets(in: self.album, options: options) | ||
}() | ||
|
||
|
@@ -108,7 +119,8 @@ internal final class PhotoGalleryViewController: UIViewController, | |
collectionView.delegate = self | ||
collectionView.backgroundColor = UIColor.white | ||
collectionView.register(PhotoGalleryCameraCell.self, forCellWithReuseIdentifier: String(describing: PhotoGalleryCameraCell.self)) | ||
collectionView.register(PhotoGalleryCell.self, forCellWithReuseIdentifier: String(describing: PhotoGalleryCell.self)) | ||
collectionView.register(GalleryPhotoCell.self, forCellWithReuseIdentifier: String(describing: GalleryPhotoCell.self)) | ||
collectionView.register(GalleryVideoCell.self, forCellWithReuseIdentifier: String(describing: GalleryVideoCell.self)) | ||
collectionView.register(PhotoGalleryLiveViewCell.self, forCellWithReuseIdentifier: String(describing: PhotoGalleryLiveViewCell.self)) | ||
collectionView.allowsMultipleSelection = true | ||
return collectionView | ||
|
@@ -164,15 +176,24 @@ internal final class PhotoGalleryViewController: UIViewController, | |
} | ||
} | ||
|
||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: PhotoGalleryCell.self), for: indexPath) | ||
let index = isCameraCompatible ? indexPath.row - 1 : indexPath.row | ||
let asset = fetchResult[index] | ||
|
||
if let text = delegate?.photoGalleryViewController(self, taggedTextForPhoto: asset) { | ||
(cell as? PhotoGalleryCell)?.configure(with: asset, taggedText: text, configuration: configuration) | ||
let text = delegate?.photoGalleryViewController(self, taggedTextForPhoto: asset) | ||
var cell: UICollectionViewCell | ||
if asset.mediaType == .video { | ||
cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: GalleryVideoCell.self), for: indexPath) | ||
(cell as? GalleryVideoCell)?.configure(with: asset, taggedText: text, configuration: configuration) | ||
collectionView.deselectItem(at: indexPath, animated: false) | ||
} else { | ||
cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: GalleryPhotoCell.self), for: indexPath) | ||
(cell as? GalleryPhotoCell)?.configure(with: asset, taggedText: text, configuration: configuration) | ||
collectionView.deselectItem(at: indexPath, animated: false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the This is already followed by: if text != nil {
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: [])
} else {
collectionView.deselectItem(at: indexPath, animated: false)
} |
||
} | ||
|
||
if text != nil { | ||
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: []) | ||
} else { | ||
(cell as? PhotoGalleryCell)?.configure(with: asset, configuration: configuration) | ||
collectionView.deselectItem(at: indexPath, animated: false) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,10 @@ internal extension UIColor { | |
|
||
internal enum Palette { | ||
static let blue = UIColor(hex: 0x2984C0) | ||
static let lightGray = UIColor(hex: 0x8F939C) | ||
static let gray = UIColor(hex: 0x8F939C) | ||
static let darkGray = UIColor(hex: 0x8F939C) | ||
static let lightGrey = UIColor(hex: 0x8F939C) | ||
static let grey = UIColor(hex: 0x8F939C) | ||
static let magnesium = UIColor(hex: 0xB2B2B2) | ||
static let darkGrey = UIColor(hex: 0x4B4D52) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's already a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that |
||
} | ||
|
||
internal convenience init(hex: Int) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is empty. It's nice to have it removed.