- 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
110 lines
3.5 KiB
Swift
110 lines
3.5 KiB
Swift
//
|
|
// MoreVM.swift
|
|
// WOKA
|
|
//
|
|
// Created by MacBook Pro on 10/06/24.
|
|
//
|
|
|
|
import UIKit
|
|
import AVFoundation
|
|
|
|
class MoreVM{
|
|
|
|
weak var vc : MoreVC!
|
|
|
|
var blogData = [BlogDM.Blog]()
|
|
|
|
var songData = [SongBlogDM.PaintDatum]()
|
|
var player: AVPlayer?
|
|
|
|
func initView(){
|
|
getBLogs()
|
|
getSong()
|
|
setupCell()
|
|
vc.homeBtn.addTapGesture {
|
|
self.vc.dismiss(animated: true)
|
|
}
|
|
}
|
|
|
|
|
|
func playSong(urlString: String) {
|
|
guard let url = URL(string: urlString) else {
|
|
print("Invalid URL string.")
|
|
return
|
|
}
|
|
|
|
player = AVPlayer(url: url)
|
|
player?.play()
|
|
}
|
|
|
|
func setupCell(){
|
|
vc.blogsCollectionView.register(UINib(nibName: K.CellIdentifier.Home.blogsCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Home.blogsCell)
|
|
vc.blogsCollectionView.delegate = vc.self
|
|
vc.blogsCollectionView.dataSource = vc.self
|
|
|
|
vc.songTableView.register(UINib(nibName: K.CellIdentifier.Home.songListCell, bundle: nil), forCellReuseIdentifier: K.CellIdentifier.Home.songListCell)
|
|
vc.songTableView.delegate = vc.self
|
|
vc.songTableView.dataSource = vc.self
|
|
}
|
|
|
|
|
|
// MARK: - Get BLogs Data
|
|
|
|
func getBLogs(){
|
|
Utilities.startProgressHUD()
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Home.blogs, method: .get) {(result : Result<BaseResponseModel<BlogDM>, NetworkManager.APIError>) in
|
|
switch result{
|
|
case .success(let data):
|
|
switch data.success{
|
|
case 0:
|
|
/*
|
|
Error
|
|
*/
|
|
Utilities.dismissProgressHUD()
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
case 1:
|
|
Utilities.dismissProgressHUD()
|
|
guard let data = data.data?.blogs else{return}
|
|
self.blogData = data
|
|
self.blogData.append(contentsOf: data)
|
|
self.vc.blogsCollectionView.reloadData()
|
|
//Fetched Blogs
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
case .failure(let error):
|
|
Utilities.dismissProgressHUD()
|
|
self.vc.toast(msg: error.localizedDescription , time: 2)
|
|
}
|
|
}
|
|
}
|
|
|
|
func getSong(){
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Home.song_listing, method: .post) {(result : Result<BaseResponseModel<SongBlogDM>, NetworkManager.APIError>) in
|
|
switch result{
|
|
case .success(let data):
|
|
switch data.success{
|
|
case 0:
|
|
/*
|
|
Error
|
|
*/
|
|
Utilities.dismissProgressHUD()
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
case 1:
|
|
Utilities.dismissProgressHUD()
|
|
guard let data = data.data?.paintData else{return}
|
|
self.songData = data
|
|
self.vc.songTableView.reloadData()
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
case .failure(let error):
|
|
Utilities.dismissProgressHUD()
|
|
self.vc.toast(msg: error.localizedDescription , time: 2)
|
|
}
|
|
}
|
|
}
|
|
}
|