Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
Update for Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
danylokos committed Dec 14, 2016
1 parent baa6abd commit 3725b78
Show file tree
Hide file tree
Showing 30 changed files with 415 additions and 380 deletions.
15 changes: 14 additions & 1 deletion PopcornTime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,13 @@
CLASSPREFIX = "";
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = PopcornTime;
TargetAttributes = {
7F8824C61A227A0100E2710A = {
CreatedOnToolsVersion = 6.1;
DevelopmentTeam = DBR2MMCRF5;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -550,8 +552,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -561,6 +565,7 @@
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -594,8 +599,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -604,6 +611,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -613,6 +621,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -625,6 +634,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = DBR2MMCRF5;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand All @@ -639,6 +649,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "PopcornTime/PopcornTime-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALID_ARCHS = "arm64 armv7 armv7s";
};
Expand All @@ -652,6 +663,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = DBR2MMCRF5;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand All @@ -664,6 +676,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.popcorntime.ios.dk;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "PopcornTime/PopcornTime-Bridging-Header.h";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALID_ARCHS = "arm64 armv7 armv7s";
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
13 changes: 7 additions & 6 deletions PopcornTime/Controllers/AnimeDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class AnimeDetailsViewController: BaseDetailsViewController {
// MARK: - BaseDetailsViewController

override func reloadData() {
PTAPIManager.sharedManager().showInfoWithType(.Anime, withId: item.identifier, success: { (item) -> Void in
PTAPIManager.shared().showInfo(with: .anime, withId: item.identifier, success: { (item) -> Void in
guard let item = item else { return }
self.anime.update(item)
self.collectionView?.reloadData()
}, failure: nil)
Expand All @@ -36,25 +37,25 @@ class AnimeDetailsViewController: BaseDetailsViewController {
return anime.seasons.count
}

override func numberOfEpisodesInSeason(seasonsIndex: Int) -> Int {
override func numberOfEpisodesInSeason(_ seasonsIndex: Int) -> Int {
return anime.seasons[seasonsIndex].episodes.count
}

override func setupCell(cell: EpisodeCell, seasonIndex: Int, episodeIndex: Int) {
override func setupCell(_ cell: EpisodeCell, seasonIndex: Int, episodeIndex: Int) {
let episode = anime.seasons[seasonIndex].episodes[episodeIndex]
cell.titleLabel.text = "\(episode.episodeNumber)"
}

override func setupSeasonHeader(header: SeasonHeader, seasonIndex: Int) {
override func setupSeasonHeader(_ header: SeasonHeader, seasonIndex: Int) {

}

override func cellWasPressed(cell: UICollectionViewCell, seasonIndex: Int, episodeIndex: Int) {
override func cellWasPressed(_ cell: UICollectionViewCell, seasonIndex: Int, episodeIndex: Int) {
let episode = anime.seasons[seasonIndex].episodes[episodeIndex]
showVideoPickerPopupForEpisode(episode, basicInfo: self.item, fromView: cell)
}

override func cellWasLongPressed(cell: UICollectionViewCell, seasonIndex: Int, episodeIndex: Int) {
override func cellWasLongPressed(_ cell: UICollectionViewCell, seasonIndex: Int, episodeIndex: Int) {
// let episode = anime.episodeFor(seasonIndex: seasonIndex, episodeIndex: episodeIndex)
// let seasonEpisodes = anime.episodesFor(seasonIndex: seasonIndex)
}
Expand Down
22 changes: 11 additions & 11 deletions PopcornTime/Controllers/AnimeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ class AnimeViewController: PagedViewController {

override var showType: PTItemType {
get {
return .Anime
return .anime
}
}

override func map(response: [AnyObject]) -> [BasicInfo] {
return response.map({ Anime(dictionary: $0 as! NSDictionary) })
override func map(_ response: [AnyObject]) -> [BasicInfo] {
return response.map({ Anime(dictionary: $0 as! [AnyHashable: Any]) })
}

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
func collectionView(_ collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: IndexPath) {

if let cell = collectionView.cellForItemAtIndexPath(indexPath){
if let cell = collectionView.cellForItem(at: indexPath){
//Check if cell is MoreShowsCell
if let _ = cell as? MoreShowsCollectionViewCell{
loadMore()
} else {
performSegueWithIdentifier("showDetails", sender: cell)
performSegue(withIdentifier: "showDetails", sender: cell)
}
}
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
super.prepareForSegue(segue, sender: sender)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)

if segue.identifier == "showDetails"{
if let episodesVC = segue.destinationViewController as? AnimeDetailsViewController{
if let episodesVC = segue.destination as? AnimeDetailsViewController{
if let senderCell = sender as? UICollectionViewCell{
if let indexPath = collectionView!.indexPathForCell(senderCell){
if let indexPath = collectionView!.indexPath(for: senderCell){
var item: BasicInfo!
if (searchController!.active) {
if (searchController!.isActive) {
item = searchResults[indexPath.row]
} else {
item = items[indexPath.row]
Expand Down
10 changes: 5 additions & 5 deletions PopcornTime/Controllers/BarHidingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import UIKit

class BarHidingViewController: UIViewController {

private var barsVisible:Bool = true {
fileprivate var barsVisible:Bool = true {
willSet {
self.tabBarController?.tabBar.hidden = !newValue
self.navigationController?.navigationBar.hidden = !newValue
UIApplication.sharedApplication().setStatusBarHidden(!newValue, withAnimation: .Fade)
self.tabBarController?.tabBar.isHidden = !newValue
self.navigationController?.navigationBar.isHidden = !newValue
UIApplication.shared.setStatusBarHidden(!newValue, with: .fade)
}
}

Expand All @@ -23,7 +23,7 @@ class BarHidingViewController: UIViewController {
//Hide bars if needed
let sizeClass = (horizontal: self.view.traitCollection.horizontalSizeClass, vertical: self.view.traitCollection.verticalSizeClass)
switch sizeClass{
case (_,.Compact):
case (_,.compact):
self.barsVisible = false
default: self.barsVisible = true
}
Expand Down
40 changes: 20 additions & 20 deletions PopcornTime/Controllers/BaseCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let reuseIdentifierMore = "MoreShowsCell"
///Base class for displaying collection of shows, subclass MUST override reloadData() and set self.shows in it
class BaseCollectionViewController: BarHidingViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UICollectionViewDelegate {

private struct Constants{
fileprivate struct Constants{
static let desirediPadCellWidth = 160
static let desirediPadCellHeight = 205
static let numberOfLinesiPhonePortrait = 2
Expand All @@ -40,44 +40,44 @@ class BaseCollectionViewController: BarHidingViewController, UICollectionViewDel
override func viewDidLoad() {
super.viewDidLoad()

self.collectionView!.registerNib(UINib(nibName: "ShowCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: reuseIdentifierShow)
self.collectionView!.registerNib(UINib(nibName: "MoreShowsCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: reuseIdentifierMore)
self.collectionView!.register(UINib(nibName: "ShowCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: reuseIdentifierShow)
self.collectionView!.register(UINib(nibName: "MoreShowsCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: reuseIdentifierMore)
self.collectionView?.delegate = self
self.collectionView?.collectionViewLayout.invalidateLayout()

self.reloadData()
}

// MARK: UICollectionViewDataSource
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let additionalCellsCount = self.showLoadMoreCell ? 1 : 0
return (items.count + additionalCellsCount)
}

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

if (self.showLoadMoreCell && indexPath.row == items.count) {
//Last cell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifierMore, forIndexPath: indexPath) as! MoreShowsCollectionViewCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierMore, for: indexPath) as! MoreShowsCollectionViewCell
return cell
} else {
//Ordinary show cell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifierShow, forIndexPath: indexPath) as! ShowCollectionViewCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierShow, for: indexPath) as! ShowCollectionViewCell

let item = items[indexPath.row]
cell.title = item.title

let imageItem = item.smallImage
switch imageItem?.status {
case .New?:
imageItem?.status = .Downloading
case .new?:
imageItem?.status = .downloading
ImageProvider.sharedInstance.imageFromURL(URL: imageItem?.URL) { (downloadedImage) -> () in
imageItem?.image = downloadedImage
imageItem?.status = .Finished
imageItem?.status = .finished

collectionView.reloadItemsAtIndexPaths([indexPath])
collectionView.reloadItems(at: [indexPath])
}
case .Finished?:
case .finished?:
cell.image = imageItem?.image
default: break
}
Expand All @@ -87,26 +87,26 @@ class BaseCollectionViewController: BarHidingViewController, UICollectionViewDel
}

// MARK: UICollectionViewDelegateFlowLayout & UICollectionViewDelegate
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

let visibleAreaHeight = collectionView.bounds.height - navigationController!.navigationBar.bounds.height - UIApplication.sharedApplication().statusBarFrame.height - self.tabBarController!.tabBar.bounds.height
let visibleAreaHeight = collectionView.bounds.height - navigationController!.navigationBar.bounds.height - UIApplication.shared.statusBarFrame.height - self.tabBarController!.tabBar.bounds.height
let visibleAreaWidth = collectionView.bounds.width

//Set cell size based on size class.
let sizeClass = (horizontal: self.view.traitCollection.horizontalSizeClass, vertical: self.view.traitCollection.verticalSizeClass)

if let flowLayout = collectionViewLayout as? UICollectionViewFlowLayout{
switch sizeClass{
case (.Compact,.Regular):
case (.compact,.regular):
//iPhone portrait
let cellWidth = ((visibleAreaWidth - CGFloat(Constants.numberOfItemsiPhonePortrait - 1)*flowLayout.minimumInteritemSpacing - flowLayout.sectionInset.top - flowLayout.sectionInset.bottom)/CGFloat(Constants.numberOfItemsiPhonePortrait))
let cellHeight = ((visibleAreaHeight - CGFloat(Constants.numberOfLinesiPhonePortrait - 1)*flowLayout.minimumLineSpacing - flowLayout.sectionInset.left - flowLayout.sectionInset.right)/CGFloat(Constants.numberOfLinesiPhonePortrait))
return CGSizeMake(cellWidth, cellHeight)
case (_,.Compact):
return CGSize(width: cellWidth, height: cellHeight)
case (_,.compact):
//iPhone landscape
let cellWidth = ((collectionView.bounds.width - CGFloat(Constants.numberOfItemsiPhoneLandscape - 1)*flowLayout.minimumInteritemSpacing - flowLayout.sectionInset.top - flowLayout.sectionInset.bottom)/CGFloat(Constants.numberOfItemsiPhoneLandscape))
let cellHeight = ((collectionView.bounds.height - CGFloat(Constants.numberOfLinesiPhoneLandscape - 1)*flowLayout.minimumLineSpacing - flowLayout.sectionInset.left - flowLayout.sectionInset.right)/CGFloat(Constants.numberOfLinesiPhoneLandscape))
return CGSizeMake(cellWidth, cellHeight)
return CGSize(width: cellWidth, height: cellHeight)
case (_,_):
// iPad. Calculate cell size based on desired size
let numberOfLines = Int(visibleAreaHeight) / Constants.desirediPadCellHeight
Expand All @@ -116,11 +116,11 @@ class BaseCollectionViewController: BarHidingViewController, UICollectionViewDel
let adjustedHeight = (visibleAreaHeight - betweenLinesSpaceSum - sectionInsetsVerticalSum)/CGFloat(numberOfLines)
let adjustedWidth = adjustedHeight * CGFloat(Constants.desirediPadCellWidth) / CGFloat(Constants.desirediPadCellHeight)

return CGSizeMake(adjustedWidth, adjustedHeight)
return CGSize(width: adjustedWidth, height: adjustedHeight)
}
}

return CGSizeMake(50, 50)
return CGSize(width: 50, height: 50)
}

// MARK: - ShowsCollectionViewController
Expand Down
Loading

0 comments on commit 3725b78

Please sign in to comment.