Skip to content

Commit

Permalink
updated for redbooth
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-yilun-li committed Jul 30, 2018
1 parent cabbc4f commit c10e3fe
Show file tree
Hide file tree
Showing 73 changed files with 1,443 additions and 1,332 deletions.
Binary file added .DS_Store
Binary file not shown.
76 changes: 46 additions & 30 deletions ImagePicker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>ExampleApp.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>ImagePicker.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Binary file added ImagePicker/.DS_Store
Binary file not shown.
30 changes: 15 additions & 15 deletions ImagePicker/AVPreviewView.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,51 @@ enum VideoDisplayMode {
/// output from a capture session.
///
final class AVPreviewView: UIView {

deinit {
log("deinit: \(String(describing: self))")
}

var previewLayer: AVCaptureVideoPreviewLayer {
return layer as! AVCaptureVideoPreviewLayer
}

var session: AVCaptureSession? {
get { return previewLayer.session }
set {
if previewLayer.session === newValue {
return
}
previewLayer.session = newValue

}
}

var displayMode: VideoDisplayMode = .aspectFill {
didSet { applyVideoDisplayMode() }
}

override class var layerClass: AnyClass {
return AVCaptureVideoPreviewLayer.self
}

override init(frame: CGRect) {
super.init(frame: frame)
applyVideoDisplayMode()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
applyVideoDisplayMode()
}

// MARK: Private Methods

private func applyVideoDisplayMode() {
switch displayMode {
case .aspectFill: previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
case .aspectFit: previewLayer.videoGravity = AVLayerVideoGravity.resizeAspect
case .resize: previewLayer.videoGravity = AVLayerVideoGravity.resize

private func applyVideoDisplayMode() { switch displayMode {
case .aspectFill: previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
case .aspectFit: previewLayer.videoGravity = AVLayerVideoGravityResizeAspect
case .resize: previewLayer.videoGravity = AVLayerVideoGravityResize
}
}
}

39 changes: 24 additions & 15 deletions ImagePicker/ActionCell.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,38 @@
import Foundation
import UIKit

final class ActionCell : UICollectionViewCell {

@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var imageView: UIImageView!

public final class ActionCell : UICollectionViewCell {

@IBOutlet public weak var backgroundImageView: UIImageView!
@IBOutlet public weak var titleLabel: UILabel!
@IBOutlet public weak var imageView: UIImageView!

@IBOutlet var leadingOffset: NSLayoutConstraint!
@IBOutlet var trailingOffset: NSLayoutConstraint!
@IBOutlet var topOffset: NSLayoutConstraint!
@IBOutlet var bottomOffset: NSLayoutConstraint!
override func awakeFromNib() {

override public func awakeFromNib() {
super.awakeFromNib()
imageView.backgroundColor = UIColor.clear
}

}

extension ActionCell {


public func setupOffsets() {
topOffset.constant = 5
bottomOffset.constant = 5
leadingOffset.constant = 5
trailingOffset.constant = 5
}

func update(withIndex index: Int, layoutConfiguration: LayoutConfiguration) {

let layoutModel = LayoutModel(configuration: layoutConfiguration, assets: 0)
let actionCount = layoutModel.numberOfItems(in: layoutConfiguration.sectionIndexForActions)

titleLabel.textColor = UIColor.black
switch index {
case 0:
Expand All @@ -43,10 +51,10 @@ extension ActionCell {
imageView.image = UIImage(named: "button-photo-library", in: Bundle(for: type(of: self)), compatibleWith: nil)
default: break
}

let isFirst = index == 0
let isLast = index == actionCount - 1

switch layoutConfiguration.scrollDirection {
case .horizontal:
topOffset.constant = isFirst ? 10 : 5
Expand All @@ -59,7 +67,8 @@ extension ActionCell {
leadingOffset.constant = isFirst ? 10 : 5
trailingOffset.constant = isLast ? 10 : 5
}

}

}

1 change: 1 addition & 0 deletions ImagePicker/Appearance.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ public class Appearance {
///
public var backgroundColor: UIColor = UIColor(red: 208/255, green: 213/255, blue: 218/255, alpha: 1)
}

69 changes: 35 additions & 34 deletions ImagePicker/AssetCell.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import Photos
/// Each image picker asset cell must conform to this protocol.
///
public protocol ImagePickerAssetCell : class {

/// This image view will be used when setting an asset's image
var imageView: UIImageView! { get }

/// This is a helper identifier that is used when properly displaying cells asynchronously
var representedAssetIdentifier: String? { get set }
}
Expand All @@ -28,43 +28,43 @@ public protocol ImagePickerAssetCell : class {
/// - selected icon when isSelected is true
///
class VideoAssetCell : AssetCell {

var durationLabel: UILabel
var iconView: UIImageView
var gradientView: UIImageView

override init(frame: CGRect) {

durationLabel = UILabel(frame: .zero)
gradientView = UIImageView(frame: .zero)
iconView = UIImageView(frame: .zero)

super.init(frame: frame)

gradientView.isHidden = true

iconView.tintColor = UIColor.white
iconView.contentMode = .center

durationLabel.textColor = UIColor.white
durationLabel.font = UIFont.systemFont(ofSize: 12, weight: .semibold)
durationLabel.font = UIFont.systemFont(ofSize: 12, weight: UIFontWeightSemibold)
durationLabel.textAlignment = .right

contentView.addSubview(gradientView)
contentView.addSubview(durationLabel)
contentView.addSubview(iconView)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()

gradientView.frame.size = CGSize(width: bounds.width, height: 40)
gradientView.frame.origin = CGPoint(x: 0, y: bounds.height-40)

let margin: CGFloat = 5
durationLabel.frame.size = CGSize(width: 50, height: 20)
durationLabel.frame.origin = CGPoint(
Expand All @@ -77,17 +77,17 @@ class VideoAssetCell : AssetCell {
y: contentView.bounds.height - iconView.frame.height - margin
)
}

static let durationFormatter: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .positional
formatter.allowedUnits = [.minute, .second]
formatter.zeroFormattingBehavior = .pad
return formatter
}()

func update(with asset: PHAsset) {

switch asset.mediaType {
case .image:
if asset.mediaSubtypes.contains(.photoLive) {
Expand All @@ -111,9 +111,9 @@ class VideoAssetCell : AssetCell {
durationLabel.text = VideoAssetCell.durationFormatter.string(from: asset.duration)
default: break
}

}

}

///
Expand All @@ -122,12 +122,12 @@ class VideoAssetCell : AssetCell {
/// default icon for selected state.
///
class AssetCell : UICollectionViewCell, ImagePickerAssetCell {

var imageView: UIImageView! = UIImageView(frame: .zero)
fileprivate var selectedImageView = CheckView(frame: .zero)

var representedAssetIdentifier: String?

override var isSelected: Bool {
didSet {
selectedImageView.isHidden = !isSelected
Expand All @@ -137,28 +137,28 @@ class AssetCell : UICollectionViewCell, ImagePickerAssetCell {
}
}
}

override init(frame: CGRect) {
super.init(frame: frame)
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
contentView.addSubview(imageView)

selectedImageView.frame = CGRect(x: 0, y: 0, width: 31, height: 31)

contentView.addSubview(selectedImageView)
selectedImageView.isHidden = true
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func prepareForReuse() {
super.prepareForReuse()
imageView.image = nil
}

override func layoutSubviews() {
super.layoutSubviews()
imageView.frame = bounds
Expand All @@ -168,31 +168,32 @@ class AssetCell : UICollectionViewCell, ImagePickerAssetCell {
y: margin
)
}

}

private final class CheckView : UIImageView {

var foregroundImage: UIImage? {
get { return foregroundView.image }
set { foregroundView.image = newValue }
}

private let foregroundView = UIImageView(frame: .zero)

override init(frame: CGRect) {
super.init(frame: frame)
addSubview(foregroundView)
contentMode = .center
foregroundView.contentMode = .center
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()
foregroundView.frame = bounds
}
}

Loading

0 comments on commit c10e3fe

Please sign in to comment.