Files
Woka_Native_iOS/WOKA/WebSeries/Controller/WebSeriesSeasonVC.swift
Bilal 1f650bd2b7 - added api for fetching the episode as per the selected category
- made the category collection cells dynamic
- handled the category selection will call the episode api
- solved activity indicator view at the splash start-up
- handled the app lifecycle for live tv app going in foreground and background
- handled play pause while the live tv view apperas and disappears
- Made the likes and favourites dynamic on episode screen
2024-06-21 19:35:40 +05:30

133 lines
4.7 KiB
Swift

//
// WebSeriesSeasonVC.swift
// WOKA
//
// Created by MacBook Pro on 20/06/24.
//
import UIKit
class WebSeriesSeasonVC: UIViewController {
var vm = WebSeriesSeasonVM()
@IBOutlet weak var seasonImage: UIImageView!
@IBOutlet weak var seasonTitle: UILabel!
@IBOutlet weak var seasonDate: UILabel!
@IBOutlet weak var seasonEpisodes: UILabel!
@IBOutlet weak var seasonMediaType: UILabel!
@IBOutlet weak var seasonDesc: UILabel!
@IBOutlet weak var categoryCV: UICollectionView!
@IBOutlet weak var episodeTableView: UITableView!
@IBOutlet weak var tableHeight: NSLayoutConstraint!
@IBOutlet weak var addIcon: UIImageView!
@IBOutlet weak var addLabel: UILabel!
@IBOutlet weak var likeIcon: UIImageView!
@IBOutlet weak var likeLabel: UILabel!
@IBOutlet weak var totalLikes: UILabel!
@IBOutlet weak var addStack: UIStackView!
@IBOutlet weak var shareStack: UIStackView!
@IBOutlet weak var likeStack: UIStackView!
override func viewDidLoad() {
super.viewDidLoad()
vm.vc = self
vm.initView()
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationController?.setColor(color: .white)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// Customize the navigation bar's appearance
self.navigationController?.setColor(color: .black)
}
@IBAction func watchBtnTapped(_ sender: LocalisedElementsButton) {
}
}
// MARK: - TableView DataSource , Delegates
extension WebSeriesSeasonVC : TableViewSRC{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return vm.seasonEpisodeData.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: K.CellIdentifier.WebSeries.webSeriesEpisodeCell) as! WebSeriesEpisodeCell
let data = vm.seasonEpisodeData[indexPath.row]
cell.setData(data: data)
return cell
}
}
// MARK: - CollectionView Delegate
extension WebSeriesSeasonVC : CollectionViewSRC{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return vm.seasonListingData.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: K.CellIdentifier.WebSeries.seasonCategoryCell, for: indexPath) as! SeasonCategoryCell
let data = vm.seasonListingData[indexPath.row]
cell.setData(title: data.seasonNumber ?? "Season", iselected: data.id == vm.episodeSelectedCateogory)
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
vm.episodeSelectedCateogory = vm.seasonListingData[indexPath.row].id
vm.getSeasonEpisode()
self.categoryCV.reloadData()
}
}
// MARK: - Collection Flow Layout
extension WebSeriesSeasonVC : UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// Generate a random string for testing purposes
let randomText = vm.seasonListingData[indexPath.row].seasonNumber!
// Define the font for the text
let font = FontCustom.shareInstance.customFont(fontName: .Exo2_Bold, size: 18) // Adjust the font size as needed
// Calculate the width of the text
let attributes = [NSAttributedString.Key.font: font]
let textWidth = (randomText as NSString).size(withAttributes: attributes).width
// Set the cell width based on the text width and any additional padding
// 14 for container view + 10 for inside spacing.
let padding: CGFloat = 24 + 20 // Adjust padding as needed
let cellWidth = textWidth + padding
return CGSize(width: cellWidth , height: 60)
}
}