Skip to content

Commit

Permalink
TD-222 updated subspec 'TheDistanceFormsPhotosVideos' to swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Alexa committed Dec 8, 2016
1 parent c0e1d97 commit 8c23c1c
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 97 deletions.
20 changes: 13 additions & 7 deletions TheDistanceForms.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "TheDistanceForms"
s.version = "0.2.6"
s.version = "0.2.7"
s.summary = "An framework for creating flexible forms as generic collections of user input elements."
s.homepage = "https://github.com/thedistance"
s.license = "MIT"
Expand All @@ -9,12 +9,12 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/thedistance/TheDistanceForms.git", :tag => "#{s.version}" }

s.ios.deployment_target = '8.0'

s.requires_arc = true

#s.source_files = 'TheDistanceForms/Classes/**/*.swift'

s.module_name = "TheDistanceForms"
s.default_subspec = "TheDistanceForms"

s.requires_arc = true

s.subspec 'TheDistanceForms' do |c|
c.source_files = 'TheDistanceForms/Classes/**/*.swift'
Expand All @@ -25,11 +25,17 @@ Pod::Spec.new do |s|
c.dependency 'SwiftyJSON'
end

#s.subspec 'TheDistanceFormsPhotosVideos' do |pv|
#end
s.subspec 'TheDistanceFormsPhotosVideos' do |pv|
pv.source_files = 'TheDistanceFormsPhotosVideos/**/*.swift'
pv.dependency 'TheDistanceCore'
pv.dependency 'AdvancedOperationKit'
pv.dependency 'KeyboardResponder'
pv.dependency 'TDStackView'
pv.dependency 'SwiftyJSON'
end

s.subspec 'TheDistanceFormsThemed' do |t|
t.source_files = 'TheDistanceForms/Classes/**/*.swift', 'TheDistanceFormsThemed/ThemedClasses/*.swift'
t.source_files = 'TheDistanceFormsThemed/ThemedClasses/*.swift', 'TheDistanceForms/Classes/**/*.swift'
t.dependency 'ThemeKit'
t.dependency 'TheDistanceCore'
t.dependency 'AdvancedOperationKit'
Expand Down
114 changes: 76 additions & 38 deletions TheDistanceForms.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion TheDistanceForms/Classes/Dynamic Forms/Form.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ open class Form: KeyedValueElementContainer, KeyedView {
let json:JSON
if let date = value as? Date {
json = JSON(ServerDateFormatter.string(from: date))
} else if let valueObject = value as? AnyObject {
} else if let valueObject = value {
json = JSON(valueObject)
} else {
json = JSON(NSNull())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PhotoCollectionViewCell: UICollectionViewCell {
public func createViews() {

imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .ScaleAspectFill
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true

contentView.addSubview(imageView)
Expand All @@ -52,17 +52,17 @@ public class VideoCollectionViewCell: PhotoCollectionViewCell {
override public func createViews() {
super.createViews()

let whiteTint = UIColor.whiteColor().colorWithAlphaComponent(0.87)
let whiteTint = UIColor.white.withAlphaComponent(0.87)

videoIconView.image = UIImage(named: "ic_videocam_white.png")
videoIconView.tintColor = whiteTint

timeLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption1)
timeLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.caption1)
timeLabel.textColor = whiteTint

// configure stack
footerStack = CreateStackView([videoIconView, timeLabel])
footerStack.stackDistribution = .EqualSpacing
footerStack.stackDistribution = .equalSpacing

// add as subview
footerStack.view.translatesAutoresizingMaskIntoConstraints = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ import TheDistanceCore

public enum PhotosStackAsset: Equatable {

case Photo(UIImage)
case Movie(AVURLAsset, UIImage?)
case photo(UIImage)
case movie(AVURLAsset, UIImage?)

init?(pickerResult: UIImagePickerResultType) {

switch (pickerResult) {
case .Image(let img):
self = Photo(img)
case .Movie(let URL):
case .image(let img):
self = .photo(img)
case .movie(let URL):

let asset = AVURLAsset(URL:URL)
let asset = AVURLAsset(url:URL)
let generator = AVAssetImageGenerator(asset: asset)
generator.appliesPreferredTrackTransform = true

let thumbnailImage:UIImage?

if let thumbnail = try? generator.copyCGImageAtTime(CMTimeMakeWithSeconds(0.5, 4), actualTime: nil) {
thumbnailImage = UIImage(CGImage: thumbnail).orientationNeutralImage()
if let thumbnail = try? generator.copyCGImage(at: CMTimeMakeWithSeconds(0.5, 4), actualTime: nil) {
thumbnailImage = UIImage(cgImage: thumbnail).orientationNeutralImage()
} else {
thumbnailImage = nil
}
self = Movie(asset, thumbnailImage)
case .None:
self = .movie(asset, thumbnailImage)
case .none:
return nil
}

Expand All @@ -51,9 +51,9 @@ public enum PhotosStackAsset: Equatable {
public func ==(a1:PhotosStackAsset, a2:PhotosStackAsset) -> Bool {

switch (a1, a2) {
case (.Photo(let i1), .Photo(let i2)):
case (.photo(let i1), .photo(let i2)):
return i1 == i2
case (.Movie(let av1, _), .Movie(let av2, _)):
case (.movie(let av1, _), .movie(let av2, _)):
return av1 == av2
default:
return false
Expand All @@ -75,9 +75,9 @@ public class PhotosStackManager: NSObject, UICollectionViewDataSource, UICollect

public var context:UIViewController
public let collectionView:UICollectionView
public let operationQueue:OperationQueue
public let operationQueue:PSOperationQueue

public init(collectionView:UICollectionView, context:UIViewController, operationQueue:OperationQueue) {
public init(collectionView:UICollectionView, context:UIViewController, operationQueue:PSOperationQueue) {

self.context = context
self.collectionView = collectionView
Expand All @@ -88,35 +88,35 @@ public class PhotosStackManager: NSObject, UICollectionViewDataSource, UICollect
collectionView.dataSource = self
collectionView.delegate = self

collectionView.registerClass(PhotoCollectionViewCell.self, forCellWithReuseIdentifier: PhotoCollectionViewCellIdentifier)
collectionView.registerClass(VideoCollectionViewCell.self, forCellWithReuseIdentifier: MovieCollectionViewCellIdentifier)
collectionView.register(PhotoCollectionViewCell.self, forCellWithReuseIdentifier: PhotoCollectionViewCellIdentifier)
collectionView.register(VideoCollectionViewCell.self, forCellWithReuseIdentifier: MovieCollectionViewCellIdentifier)
}

public func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
public func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}

public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return mediaDataSource.count
}

public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let media = mediaDataSource[indexPath.row]

switch (media) {
case .Photo(let image):
case .photo(let image):

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(PhotoCollectionViewCellIdentifier, forIndexPath: indexPath)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoCollectionViewCellIdentifier, for: indexPath as IndexPath)
if let photoCell = cell as? PhotoCollectionViewCell {
photoCell.imageView.image = image
}

return cell

case .Movie(let asset, let thumbnail):
case .movie(let asset, let thumbnail):

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(MovieCollectionViewCellIdentifier, forIndexPath: indexPath)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MovieCollectionViewCellIdentifier, for: indexPath as IndexPath)

if let videoCell = cell as? VideoCollectionViewCell {
let duration = CMTimeGetSeconds(asset.duration)
Expand All @@ -142,13 +142,13 @@ public class PhotosStackManager: NSObject, UICollectionViewDataSource, UICollect
}
}

public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// show detail to allow deleting
}

public func newAssetFromSource(source:AdvancedOperationKit.UIPopoverSourceType) {

guard let op = imageSelectionOperation(source) else { return }
guard let op = imageSelectionOperation(source: source) else { return }
operationQueue.addOperation(op)

}
Expand All @@ -168,19 +168,19 @@ public class PhotosStackManager: NSObject, UICollectionViewDataSource, UICollect
var chosenMedia = self.mediaDataSource

switch (media) {
case .Image(_), .Movie(_):
case .image(_), .movie(_):
if let asset = PhotosStackAsset(pickerResult: media) {
chosenMedia.insert(asset, atIndex: 0)
chosenMedia.insert(asset, at: 0)
self.mediaDataSource = chosenMedia
self.collectionView.insertItemsAtIndexPaths([NSIndexPath(forItem: 0, inSection: 0)])
self.collectionView.insertItems(at: [IndexPath(item: 0, section: 0)])

self.delegate?.photosStackManager(self, selectedAsset: asset)
self.delegate?.photosStackManager(stack: self, selectedAsset: asset)
}

case .None:
case .none:
let _ = "Cancelled Media selection"
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.delegate?.photosStackManagerCancelled(self)
DispatchQueue.main.async(execute: { () -> Void in
self.delegate?.photosStackManagerCancelled(stack: self)
})
// print(str)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
import AdvancedOperationKit
import TDStackView
import TheDistanceCore
import TheDistanceForms


public class PhotosStack: ErrorStack, ValueElement, PhotosStackManagerDelegate {

Expand All @@ -31,32 +31,32 @@ public class PhotosStack: ErrorStack, ValueElement, PhotosStackManagerDelegate {

public init(collectionView: UICollectionView,
manager:PhotosStackManager,
addButton: UIButton = UIButton(type: .System),
addButton: UIButton = UIButton(type: .system),
textField:UITextField = UITextField(),
errorLabel: UILabel = UILabel(),
errorImageView: UIImageView = UIImageView(),
iconImageView: UIImageView = UIImageView()) {

mediaCollectionView = collectionView
mediaCollectionView.backgroundColor = UIColor.clearColor()
mediaCollectionView.backgroundColor = UIColor.clear
mediaCollectionViewHeightConstraint = NSLayoutConstraint(item: mediaCollectionView,
attribute: .Height,
relatedBy: .Equal,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .NotAnAttribute,
attribute: .notAnAttribute,
multiplier: 0.0,
constant: 75.0)
mediaCollectionView.addConstraint(mediaCollectionViewHeightConstraint)

self.addButton = addButton
self.textField = textField

addButton.setTitle("Add Photo or Video", forState: .Normal)
textField.hidden = true
addButton.setTitle("Add Photo or Video", for: .normal)
textField.isHidden = true

mediaManager = manager
contentStack = CreateStackView([mediaCollectionView, addButton, textField])
contentStack.axis = .Vertical
contentStack.axis = .vertical
contentStack.spacing = 8.0

super.init(centerComponent: contentStack.view,
Expand All @@ -66,11 +66,11 @@ public class PhotosStack: ErrorStack, ValueElement, PhotosStackManagerDelegate {

mediaManager.delegate = self

addTarget = ObjectTarget<UIButton>(control: addButton, forControlEvents: .TouchUpInside, completion: addTapped)
addTarget = ObjectTarget<UIButton>(control: addButton, forControlEvents: .touchUpInside, completion: addTapped)
}

public func addTapped(sender:UIButton) {
mediaManager.newAssetFromSource(.View(sender))
mediaManager.newAssetFromSource(source: .view(sender))
}

public func photosStackManager(stack: PhotosStackManager, selectedAsset: PhotosStackAsset) {
Expand All @@ -80,7 +80,7 @@ public class PhotosStack: ErrorStack, ValueElement, PhotosStackManagerDelegate {
public func photosStackManagerCancelled(stack: PhotosStackManager) { }

public func updateMediaCollectionViewHeight() {
let contentSize = mediaCollectionView.collectionViewLayout.collectionViewContentSize()
let contentSize = mediaCollectionView.collectionViewLayout.collectionViewContentSize
if contentSize.height != mediaCollectionViewHeightConstraint.constant {
mediaCollectionViewHeightConstraint.constant = contentSize.height
}
Expand All @@ -90,7 +90,7 @@ public class PhotosStack: ErrorStack, ValueElement, PhotosStackManagerDelegate {
return mediaManager.mediaDataSource
}

public func setValue<T>(value: T?) -> Bool {
public func setValue<T>(_ value: T?) -> Bool {

guard let mediaObjects = value as? [PhotosStackAsset] else { return false }

Expand All @@ -102,9 +102,9 @@ public class PhotosStack: ErrorStack, ValueElement, PhotosStackManagerDelegate {
public func validateValue() -> ValidationResult {

let value = getValue() as? [PhotosStackAsset]
let result = validation?.validate(value: value) ?? .Valid
let result = validation?.validate(value) ?? .valid

if case .Invalid(let message) = result {
if case .invalid(let message) = result {
errorText = message
} else {
errorText = nil
Expand Down
File renamed without changes
File renamed without changes
6 changes: 6 additions & 0 deletions podfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ target 'TheDistanceFormsThemed' do

end

target 'TheDistanceFormsPhotosVideos' do

core_pods

end

0 comments on commit 8c23c1c

Please sign in to comment.