Skip to content

Instantly share code, notes, and snippets.

@atulkhatri
atulkhatri / DetailBackdropView2.swift
Created July 12, 2021 17:41
tvOS Bootcamp Detail Backdrop View 2
class DetailBackdropView: UICollectionReusableView {
/// Some Code omitted
@IBOutlet weak var playButton: UIButton!
@IBOutlet weak var wishlistButton: UIButton!
private let focusGuide = UIFocusGuide()
override func awakeFromNib() {
super.awakeFromNib()
setupView()
@atulkhatri
atulkhatri / DetailViewController3.swift
Created July 12, 2021 17:37
tvOS Bootcamp Detail Screen 3
private func openPlayer(with asset: AssetModel) {
if let playbackUrl = asset.url.toUrl {
let player = AVPlayer(url: playbackUrl)
let controller = AVPlayerViewController()
controller.player = player
present(controller, animated: true) {
player.play()
}
}
}
@atulkhatri
atulkhatri / DetailBackdropView.swift
Created July 12, 2021 17:36
tvOS Bootcamp Detail Backdrop View
class DetailBackdropView: UICollectionReusableView {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var summaryLabel: UILabel!
typealias ButtonTapClosure = (() -> Void)
public var onPlay: ButtonTapClosure?
public var onWishlist: ButtonTapClosure?
@IBAction func playButtonTapped(_ sender: Any) {
@atulkhatri
atulkhatri / DetailViewController2.swift
Created July 12, 2021 17:35
tvOS Bootcamp Detail Screen 2
extension DetailViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let collectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: kRailCellIdentifier, for: indexPath) as? RailCell
guard let cell = collectionCell else {
return UICollectionViewCell()
}
@atulkhatri
atulkhatri / DetailViewController.swift
Created July 12, 2021 17:34
tvOS Bootcamp Detail Screen
class DetailViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
var asset: AssetModel!
var rail: RailModel!
override func viewDidLoad() {
super.viewDidLoad()
setupView()
}
@atulkhatri
atulkhatri / AssetCell.swift
Created July 12, 2021 17:25
tvOS Bootcamp Asset Cell
private let kPostViewTag = 1100
class AssetCell: UICollectionViewCell {
override func prepareForReuse() {
super.prepareForReuse()
if let view = contentView.viewWithTag(kPostViewTag) {
view.removeFromSuperview()
}
}
@atulkhatri
atulkhatri / RailCell3.swift
Created July 12, 2021 17:25
tvOS Bootcamp Rail Cell 3
func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool {
return true
}
@atulkhatri
atulkhatri / RailCell2.swift
Created July 12, 2021 17:24
tvOS Bootcamp Rail Cell 2
extension RailCell: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return rail.list.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let collectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: kAssetCellIdentifier, for: indexPath) as? AssetCell
guard let asset = rail?.list[indexPath.item], let cell = collectionCell else {
return UICollectionViewCell()
}
@atulkhatri
atulkhatri / RailCell.swift
Created July 12, 2021 17:24
tvOS Bootcamp Rail Cell
class RailCell: UICollectionViewCell {
@IBOutlet weak var collectionView: UICollectionView!
private var rail: RailModel!
typealias CellSelectionClosure = ((RailModel, AssetModel) -> Void)
public var onSelect: CellSelectionClosure?
override func awakeFromNib() {
super.awakeFromNib()
setupView()
}
@atulkhatri
atulkhatri / HomeViewController5.swift
Created July 12, 2021 17:23
tvOS Bootcamp Home Screen 5
private func loadData(page: PageModel) {
pageModel = page
collectionView.reloadData()
}