Files
Woka_Native_iOS/WOKA/WebSeries/Controller/WebSeriesSeasonVC.swift
BilalKhanWDI 95495dc414 - Added native shimmer effect.
- Updated my list for handling the comma separated language.
- Added shimmer to manila , language , list table
- Added action for dropdown, if user clicks outside the dropdown it ill dismiss and change the arrow direction
- Handled shimmer with api call, removed the progress hud
- Updated Lingual file for webSeries VC
2024-06-20 19:51:39 +05:30

159 lines
5.8 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!
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) {
}
@IBAction func btnTapped(_ sender: LocalisedElementsButton) {
}
}
// 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: indexPath.row == vm.selectedCateogory)
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath.row)
}
}
// 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) // You can adjust the font size as needed
// Calculate the width of the text
let textWidth = randomText.size(withAttributes: [.font: font]).width
// Set the cell width based on the text width and any additional padding
let cellWidth = textWidth + 25 // Add any additional spacing you want
return CGSize(width: cellWidth, height: 50)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
section == 0 ? 15 : 5
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
}
}
// Helper method to calculate text width
extension String {
func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [.font: font], context: nil)
return ceil(boundingBox.width)
}
}
@IBDesignable
class VerticalButton: UIButton {
@IBInspectable public var padding: CGFloat = 20.0 {
didSet {
setNeedsLayout()
}
}
override var intrinsicContentSize: CGSize {
let maxSize = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
if let titleSize = titleLabel?.sizeThatFits(maxSize), let imageSize = imageView?.sizeThatFits(maxSize) {
let width = ceil(max(imageSize.width, titleSize.width))
let height = ceil(imageSize.height + titleSize.height + padding)
return CGSize(width: width, height: height)
}
return super.intrinsicContentSize
}
override func layoutSubviews() {
if let image = imageView?.image, let title = titleLabel?.attributedText {
let imageSize = image.size
let titleSize = title.size()
if effectiveUserInterfaceLayoutDirection == .leftToRight {
titleEdgeInsets = UIEdgeInsets(top: 0.0, left: -imageSize.width, bottom: -(imageSize.height + padding), right: 0.0)
imageEdgeInsets = UIEdgeInsets(top: -(titleSize.height + padding), left: 0.0, bottom: 0.0, right: -titleSize.width)
}
else {
titleEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: -(imageSize.height + padding), right: -imageSize.width)
imageEdgeInsets = UIEdgeInsets(top: -(titleSize.height + padding), left: -titleSize.width, bottom: 0.0, right: 0.0)
}
}
super.layoutSubviews()
}
}