Files
Woka_Native_iOS/WOKA/Theme/Controller/MoreVC.swift
BilalKhanWDI 5a7750d012 - Completed My oders. Rest will be completed when shop module is finished.
- Internet issue
- Added api to get blogs, with data model decoding, inflating the collection view
- Added api to get the songs, with data model decoding , inflated tableview with dynamic height
- Added inline player for song list
2024-06-10 19:45:36 +05:30

103 lines
3.5 KiB
Swift

//
// MoreVC.swift
// WOKA
//
// Created by MacBook Pro on 10/06/24.
//
import UIKit
import AVFoundation
class MoreVC: UIViewController {
@IBOutlet weak var blogsCollectionView: UICollectionView!
@IBOutlet weak var homeBtn: UIView!
@IBOutlet weak var songTableView: UITableView!
var vm = MoreVM()
override func viewDidLoad() {
super.viewDidLoad()
vm.vc = self
vm.initView()
}
}
// MARK: - TableView DataSource , Delegates
extension MoreVC : TableViewSRC{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return vm.songData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: K.CellIdentifier.Home.songListCell) as! SongListCell
let data = vm.songData[indexPath.row]
cell.setData(data: data)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let data = vm.songData[indexPath.row]
if let url = data.contentMoreDetails?.first?.url{
vm.player = AVPlayer()
vm.playSong(urlString: url)
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60
}
}
// MARK: - CollectionView DataSource Delegate
extension MoreVC : CollectionViewSRC{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return vm.blogData.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: K.CellIdentifier.Home.blogsCell, for: indexPath) as! BlogsCell
cell.setData(data : vm.blogData[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath.row)
}
}
// MARK: - Collection Flow Layout
extension MoreVC : UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 5
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 5
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemsPerRow: CGFloat = 2
let paddingSpace = 5 * (itemsPerRow + 1)
let availableWidth = collectionView.frame.width - paddingSpace
let widthPerItem = availableWidth / itemsPerRow
return CGSize(width: widthPerItem, height: widthPerItem - 20)
}
// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
// return UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
// }
}