Files
Woka_Native_iOS/WOKA/Games/Controller/GamesListVC.swift
BilalKhanWDI 41e770f991 - Completed lingual file
- Completed the default top header set as per the selcection on user, first load will select 0th index
- Completed player for audio books
- Handled error response for audio listing
- AudioBook Details View added like fav
- Fixed the nav bar color issue.
- Finished games module
2024-07-04 19:48:15 +05:30

166 lines
5.7 KiB
Swift

//
// GamesListVC.swift
// WOKA
//
// Created by MacBook Pro on 04/07/24.
//
import UIKit
class GamesListVC: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var headerHeight: NSLayoutConstraint!
@IBOutlet weak var gamesListingTableView: UITableView!
@IBOutlet weak var tableHeight: NSLayoutConstraint!
@IBOutlet weak var headerView: ShimmerEffectView!
@IBOutlet weak var headerImage: UIImageView!
@IBOutlet weak var headerTitleLabel: UILabel!
@IBOutlet weak var gamesLoadingView: ShimmerEffectView!
var vm = GamesListVM()
override func viewDidLoad() {
super.viewDidLoad()
vm.vc = self
vm.initView()
scrollView.delegate = self
self.title = "Games".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
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)
}
override func viewDidLayoutSubviews() {
vm.updateTableHeight()
}
}
// MARK: - TableView DataSource , Delegates
extension GamesListVC : TableViewSRC{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return vm.gameData.count == 0 ? 2 : vm.gameData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: K.CellIdentifier.WebSeries.webSeriesShowListingCell) as! WebSeriesShowListingCell
if vm.gameData.count == 0{
cell.showShimmer()
}else{
let data = vm.gameData[indexPath.row]
cell.setGameData(data: data)
cell.stopShimmer()
}
cell.btnTapped = { [self] (type) -> Void in
vm.updateFavLikes(type: type, index: indexPath.row)
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
/*
Updated the top header data
*/
vm.indexToLoad = indexPath.row
vm.setHeaderData()
let data = vm.gameData[indexPath.row]
let sb = UIStoryboard(name: K.StoryBoard.Games, bundle: nil)
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Games.gamesDetailVC) as! GamesDetailVC
vcPush.modalPresentationStyle = .overCurrentContext
vcPush.modalTransitionStyle = .crossDissolve
vcPush.gameIndex = indexPath.row
vcPush.gameData = data
vcPush.delegate = self
self.present(vcPush, animated: true)
}
}
extension GamesListVC : ReloadSeriesFavLike{
func updateRows(index: Int, type: FavCellCLick, isFav: Bool?, isLike: Bool?) {
if let isFav{
switch isFav{
case true:
vm.gameData[index].markAsFavourite = true
gamesListingTableView.reloadRows(at: [IndexPath(row: index, section: 0)],with: .none)
case false:
vm.gameData[index].markAsFavourite = false
gamesListingTableView.reloadRows(at: [IndexPath(row: index, section: 0)],with: .none)
}
K.GVar.reloadMyList = true
}
if let isLike{
switch isLike{
case true:
vm.gameData[index].isLiked = true
vm.gameData[index].likesCount! += 1
gamesListingTableView.reloadRows(at: [IndexPath(row: index, section: 0)],with: .none)
case false:
vm.gameData[index].isLiked = false
vm.gameData[index].likesCount! -= 1
gamesListingTableView.reloadRows(at: [IndexPath(row: index, section: 0)],with: .none)
}
K.GVar.reloadMyList = true
}
}
}
// MARK: - Animating scrollView
extension GamesListVC: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// Get the current vertical offset of the scroll view
let y = scrollView.contentOffset.y
// Define the height range for the header view
let minHeaderHeight: CGFloat = 0.0 // Height at which the header becomes invisible
let maxHeaderHeight: CGFloat = 200.0 // Maximum height when fully visible
// Calculate the new height for the header view based on the scroll position
let newHeaderHeight: CGFloat
if y < 0 {
// When scrolling up beyond the top, ensure the header view is fully expanded
newHeaderHeight = maxHeaderHeight
} else {
// Calculate the new height for the header view, ensuring it doesn't go below the minimum height
newHeaderHeight = max(minHeaderHeight, maxHeaderHeight - y)
}
// Update the header view's height constraint with the new height
headerHeight.constant = newHeaderHeight
// Animate the layout changes to smoothly transition the header height
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
}