Skip to content

Swift 3 Renaming #5

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

Merged
merged 6 commits into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage:
status:
project: yes
patch: no
changes: no
12 changes: 6 additions & 6 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

# Sometimes it's a README fix, or something like that - which isn't relevant for
# including in a project's CHANGELOG for example
declared_trivial = (github.pr_title + github.pr_body).include?("#trivial")
declared_trivial = (github.pr_title + github.pr_body).include? "#trivial"

# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
warn("PR is classed as Work in Progress") if pr_title.include? "[WIP]"
warn "PR is classed as Work in Progress" if github.pr_title.include? "[WIP]"

# Warn when there is a big PR
warn("Big PR") if lines_of_code > 500
warn "Big PR" if git.lines_of_code > 500

# Ensure there is a summary for a PR
fail "Please provide a summary in the Pull Request description" if github.pr_body.length < 5

# Add a CHANGELOG entry for app changes
if git.lines_of_code > 50 && !github.modified_files.include?("CHANGELOG.md") && !declared_trivial
fail("Please update [CHANGELOG.md](https://github.com/polydice/iCook-tvOS/blob/develop/CHANGELOG.md).")
if git.lines_of_code > 50 && !git.modified_files.include?("CHANGELOG.md") && !declared_trivial
fail "Please update [CHANGELOG.md](https://github.com/polydice/iCook-tvOS/blob/develop/CHANGELOG.md).", sticky: true
end

# Ensure a clean commits history
if git.commits.any? { |c| c.message =~ /^Merge branch/ }
fail('Please rebase to get rid of the merge commits in this PR')
fail "Please rebase to get rid of the merge commits in this PR", sticky: true
end
20 changes: 9 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
CFPropertyList (2.3.3)
CFPropertyList (2.3.4)
RubyInline (3.12.4)
ZenTest (~> 4.3)
ZenTest (4.11.1)
Expand All @@ -12,7 +12,6 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
babosa (1.0.2)
claide (1.0.1)
claide-plugins (0.9.2)
cork
Expand Down Expand Up @@ -64,7 +63,7 @@ GEM
commander (>= 4.3.5)
highline (>= 1.7.1)
security
danger (4.0.0)
danger (4.0.1)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored (~> 1.2)
Expand All @@ -82,8 +81,7 @@ GEM
multipart-post (>= 1.2, < 3)
faraday-http-cache (1.3.1)
faraday (~> 0.8)
fastlane_core (0.53.0)
babosa
fastlane_core (0.57.2)
colored
commander (>= 4.4.0, <= 5.0.0)
credentials_manager (>= 0.16.2, < 1.0.0)
Expand All @@ -102,13 +100,13 @@ GEM
highline (1.7.8)
i18n (0.7.0)
json (1.8.3)
kramdown (1.12.0)
kramdown (1.13.1)
mini_portile2 (2.1.0)
minitest (5.9.1)
molinillo (0.5.2)
minitest (5.10.1)
molinillo (0.5.4)
multi_json (1.12.1)
multipart-post (2.0.0)
nanaimo (0.2.2)
nanaimo (0.2.3)
nap (1.1.0)
netrc (0.7.8)
nokogiri (1.6.8.1)
Expand All @@ -124,8 +122,8 @@ GEM
sawyer (0.7.0)
addressable (>= 2.3.5, < 2.5)
faraday (~> 0.8, < 0.10)
scan (0.14.1)
fastlane_core (>= 0.53.0, < 1.0.0)
scan (0.14.2)
fastlane_core (>= 0.57.0, < 1.0.0)
slack-notifier (~> 1.3)
terminal-table (>= 1.4.5, < 2.0.0)
xcpretty (>= 0.2.4, < 1.0.0)
Expand Down
2 changes: 1 addition & 1 deletion iCookTV/Controllers/CategoriesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CategoriesViewController: UIViewController,

// MARK: - BlurBackgroundPresentable

let imageAnimationQueue = ImageAnimationQueue(imageView: UIImageView())
let backgroundImageView = UIImageView()

// MARK: - Initialization

Expand Down
2 changes: 1 addition & 1 deletion iCookTV/Controllers/HistoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HistoryViewController: UIViewController,

// MARK: - BlurBackgroundPresentable

let imageAnimationQueue = ImageAnimationQueue(imageView: UIImageView())
let backgroundImageView = UIImageView()

// MARK: - DropdownMenuPresentable

Expand Down
2 changes: 1 addition & 1 deletion iCookTV/Controllers/VideosViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class VideosViewController: UIViewController,

// MARK: - BlurBackgroundPresentable

let imageAnimationQueue = ImageAnimationQueue(imageView: UIImageView())
let backgroundImageView = UIImageView()

// MARK: - DataFetching

Expand Down
13 changes: 7 additions & 6 deletions iCookTV/Extensions/CGRect+Grid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@

import UIKit

enum Grid: Int {
enum Grid: Int, Equatable {
case topLeft, topRight, bottomLeft, bottomRight

static let numberOfGrids: Int = {
var count = 0
while let _ = Grid(rawValue: count) { count += 1 }
return count
}()
}

func == (lhs: Grid, rhs: Grid) -> Bool {
return lhs.rawValue == rhs.rawValue
static func == (lhs: Grid, rhs: Grid) -> Bool {
return lhs.rawValue == rhs.rawValue
}

}

extension CGRect {

func rect(bySize size: CGSize, atCorner corner: Grid) -> CGRect {
func rect(with size: CGSize, in grid: Grid) -> CGRect {
let target = CGSize(width: min(width, size.width), height: min(height, size.height))
switch corner {
switch grid {
case .topLeft:
return divided(atDistance: target.height, from: .maxYEdge).remainder.divided(atDistance: target.width, from: .maxXEdge).remainder
case .topRight:
Expand Down
20 changes: 10 additions & 10 deletions iCookTV/Extensions/UIFont+TV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,50 @@ extension UIFont {

// MARK: - Private Methods

private class func tvFontOfSize(_ fontSize: CGFloat) -> UIFont {
private class func tvFont(ofSize fontSize: CGFloat) -> UIFont {
return UIFont(name: FontFamily.PingFangTCRegular, size: fontSize) ?? UIFont.systemFont(ofSize: fontSize)
}

private class func tvBoldFontOfSize(_ fontSize: CGFloat) -> UIFont {
private class func tvBoldFont(ofSize fontSize: CGFloat) -> UIFont {
return UIFont(name: FontFamily.PingFangTCMedium, size: fontSize) ?? UIFont.boldSystemFont(ofSize: fontSize)
}

// MARK: - Public Methods

class func tvFontForTagline() -> UIFont {
return UIFont.tvFontOfSize(44)
return UIFont.tvFont(ofSize: 44)
}

class func tvFontForCategoryCell() -> UIFont {
return UIFont.tvFontOfSize(35)
return UIFont.tvFont(ofSize: 35)
}

class func tvFontForFocusedCategoryCell() -> UIFont {
return UIFont.tvFontOfSize(40)
return UIFont.tvFont(ofSize: 40)
}

class func tvFontForVideoCell() -> UIFont {
return UIFont.tvFontOfSize(29)
return UIFont.tvFont(ofSize: 29)
}

class func tvFontForFocusedVideoCell() -> UIFont {
return UIFont.tvBoldFontOfSize(29)
return UIFont.tvBoldFont(ofSize: 29)
}

class func tvFontForVideoLength() -> UIFont {
return UIFont.systemFont(ofSize: 20)
}

class func tvFontForLogo() -> UIFont {
return UIFont.tvFontOfSize(65)
return UIFont.tvFont(ofSize: 65)
}

class func tvFontForMenuButton() -> UIFont {
return UIFont.tvFontOfSize(30)
return UIFont.tvFont(ofSize: 30)
}

class func tvFontForHeaderTitle() -> UIFont {
return UIFont.tvFontOfSize(35)
return UIFont.tvFont(ofSize: 35)
}

}
8 changes: 4 additions & 4 deletions iCookTV/Extensions/UIImage+Grid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import UIKit

extension UIImage {

func image(byReplacingImage image: UIImage, atCorner corner: Grid) -> UIImage? {
func image(byReplacingImage image: UIImage, in grid: Grid) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, true, 0)

let canvas = CGRect(origin: CGPoint.zero, size: size)
self.draw(in: canvas)

let rect = canvas.rect(bySize: image.size, atCorner: corner)
let rect = canvas.rect(with: image.size, in: grid)
image.draw(in: rect)

let newImage = UIGraphicsGetImageFromCurrentImageContext()
Expand All @@ -43,7 +43,7 @@ extension UIImage {
return newImage
}

class func placeholderImage(withSize size: CGSize) -> UIImage? {
class func placeholderImage(with size: CGSize) -> UIImage? {
let layer = CAGradientLayer()
layer.frame = CGRect(origin: CGPoint.zero, size: size)
layer.colors = [UIColor.white.cgColor, UIColor.Palette.LightGray.cgColor]
Expand All @@ -63,7 +63,7 @@ extension UIImage {
return image
}

class func resizableImage(withFillColor color: UIColor) -> UIImage? {
class func resizableImage(filledWith color: UIColor) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), true, 0)

color.setFill()
Expand Down
8 changes: 4 additions & 4 deletions iCookTV/Helpers/CoverBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ class CoverBuilder {

// MARK: - Public Methods

func addImage(_ image: UIImage, atCorner corner: Grid, categoryID id: String? = nil, completion: @escaping (_ newCover: UIImage?) -> Void) {
func add(image: UIImage, to grid: Grid, categoryID id: String? = nil, completion: @escaping (_ newCover: UIImage?) -> Void) {
operationQueue.addOperation(BlockOperation { [weak self] in
let imageSize = CGSize(width: image.size.width * 2, height: image.size.height * 2)
var canvas: UIImage?

if let currentImage = self?.cover, currentImage.size == imageSize {
canvas = currentImage
} else {
canvas = UIImage.placeholderImage(withSize: imageSize)
canvas = UIImage.placeholderImage(with: imageSize)
}

let cover = canvas?.image(byReplacingImage: image, atCorner: corner)
let cover = canvas?.image(byReplacingImage: image, in: grid)
self?.cover = cover
self?.filledGrids.insert(corner)
self?.filledGrids.insert(grid)

if let key = id, let image = cover, self?.filledGrids.count == Grid.numberOfGrids {
self?.cacheImage(image, forKey: key)
Expand Down
2 changes: 1 addition & 1 deletion iCookTV/Models/CategoriesDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CategoriesDataSource: DataSource<CategoriesCollection> {

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(for: indexPath) as CategoryCell
cell.configure(withCategory: dataCollection[indexPath.row])
cell.configure(with: dataCollection[indexPath.row])
return cell
}

Expand Down
2 changes: 1 addition & 1 deletion iCookTV/Models/VideosDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class VideosDataSource: DataSource<VideosCollection> {

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(for: indexPath) as VideoCell
cell.configure(withVideo: dataCollection[indexPath.row])
cell.configure(with: dataCollection[indexPath.row])
return cell
}

Expand Down
25 changes: 9 additions & 16 deletions iCookTV/Protocols/BlurBackgroundPresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import UIKit

protocol BlurBackgroundPresentable: class {
/// A reference to the ImageAnimationQueue object that handles image transition.
var imageAnimationQueue: ImageAnimationQueue { get }
/// A reference to the background image view.
var backgroundImageView: UIImageView { get }

/// Sets up the background image view with a blur effect on top of it.
func setUpBlurBackground()
Expand All @@ -43,7 +43,6 @@ extension BlurBackgroundPresentable where Self: UIViewController {
func setUpBlurBackground() {
view.backgroundColor = UIColor.tvBackgroundColor()

let backgroundImageView = imageAnimationQueue.imageView
backgroundImageView.frame = view.bounds
backgroundImageView.contentMode = .scaleAspectFill
backgroundImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
Expand All @@ -58,9 +57,9 @@ extension BlurBackgroundPresentable where Self: UIViewController {

func animateBackgroundTransition(to image: UIImage?) {
// Throttle background image transition to avoid extensive changes in a short period of time.
let selector = #selector(ImageAnimationQueue.animateBackgroundTransition(to:))
NSObject.cancelPreviousPerformRequests(withTarget: imageAnimationQueue, selector: selector, object: nil)
imageAnimationQueue.perform(selector, with: image, afterDelay: 0.2)
let selector = #selector(UIImageView.transition(to:))
NSObject.cancelPreviousPerformRequests(withTarget: backgroundImageView)
backgroundImageView.perform(selector, with: image, afterDelay: 0.2)
}

}
Expand All @@ -69,22 +68,16 @@ extension BlurBackgroundPresentable where Self: UIViewController {
////////////////////////////////////////////////////////////////////////////////


class ImageAnimationQueue: NSObject {
extension UIImageView {

fileprivate let imageView: UIImageView

init(imageView: UIImageView) {
self.imageView = imageView
}

@objc fileprivate func animateBackgroundTransition(to image: UIImage?) {
@objc fileprivate func transition(to image: UIImage?) {
Debug.print(#function)
UIView.transition(
with: imageView,
with: self,
duration: 0.5,
options: [.beginFromCurrentState, .transitionCrossDissolve, .curveEaseIn],
animations: {
self.imageView.image = image
self.image = image
}, completion: nil
)
}
Expand Down
2 changes: 1 addition & 1 deletion iCookTV/Protocols/VideosGridLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protocol VideosGridLayout: class {
var collectionView: UICollectionView { get }

/// Returns a configured collection view.
static func defaultLoadingIndicator() -> UIActivityIndicatorView
static func defaultCollectionView(dataSource: UICollectionViewDataSource, delegate: UICollectionViewDelegate) -> UICollectionView

/// Sets up the collection view in the view hierarchy.
func setUpCollectionView()
Expand Down
Loading