|
@@ -7,8 +7,6 @@
|
|
|
|
|
|
import BFFramework
|
|
|
class MVHomeController: MVBaseController {
|
|
|
-
|
|
|
-
|
|
|
private var banner: MVBanner = {
|
|
|
let banner = MVBanner(frame: .zero, margin: 30, lineSpacing: 12, minScale: MVBanner.Scale(scale: 1))
|
|
|
banner.backgroundColor = UIColor.white
|
|
@@ -50,7 +48,7 @@ class MVHomeController: MVBaseController {
|
|
|
settingBtn.tag = 3000
|
|
|
return settingBtn
|
|
|
}()
|
|
|
-
|
|
|
+
|
|
|
// 标签分类
|
|
|
lazy var collectionView: UICollectionView = {
|
|
|
let flowLayout = UICollectionViewFlowLayout()
|
|
@@ -74,19 +72,18 @@ class MVHomeController: MVBaseController {
|
|
|
collectionView.delaysContentTouches = false
|
|
|
return collectionView
|
|
|
}()
|
|
|
-
|
|
|
- var mVideos:Array = Array<MVHotVideoModel>.init()
|
|
|
-
|
|
|
- var mAllVideos:Array = Array<PQVideoListModel>.init()
|
|
|
-
|
|
|
- var lastBnnerSelectIndex:IndexPath = IndexPath.init()
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ var mVideos: Array = Array<MVHotVideoModel>.init()
|
|
|
+
|
|
|
+ var mAllVideos: Array = Array<PQVideoListModel>.init()
|
|
|
+
|
|
|
+ var lastBnnerSelectIndex: IndexPath = IndexPath()
|
|
|
+
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
|
super.viewWillDisappear(animated)
|
|
|
|
|
|
- //停止播放
|
|
|
- let cell: MVBannerCell? = banner.collectionView.cellForItem(at: lastBnnerSelectIndex) as? MVBannerCell
|
|
|
+ // 停止播放
|
|
|
+ let cell: MVBannerCell? = banner.collectionView.cellForItem(at: lastBnnerSelectIndex) as? MVBannerCell
|
|
|
cell?.pauseView.isHidden = false
|
|
|
PQSingletoVideoPlayer.shared.stopPlayer(isRemove: false)
|
|
|
}
|
|
@@ -99,23 +96,21 @@ class MVHomeController: MVBaseController {
|
|
|
}
|
|
|
MVHomeViewModel.getHomeHotVideos {[weak self] hotVideos, _ in
|
|
|
BFLog(message: "hotVideos count is :\(hotVideos.count)")
|
|
|
-
|
|
|
+
|
|
|
self?.mVideos = hotVideos
|
|
|
-
|
|
|
+
|
|
|
self?.collectionView.reloadData()
|
|
|
- if((self?.mVideos.count ?? 0) > 0 ){
|
|
|
-
|
|
|
+ if (self?.mVideos.count ?? 0) > 0 {
|
|
|
self?.mVideos[0].isSelected = true
|
|
|
- for hotModel in self!.mVideos{
|
|
|
+ for hotModel in self!.mVideos {
|
|
|
for video in hotModel.videos {
|
|
|
self?.mAllVideos.append(video)
|
|
|
}
|
|
|
}
|
|
|
BFLog(message: " self?.mAllVideos count is \(String(describing: self?.mAllVideos.count))")
|
|
|
}
|
|
|
-
|
|
|
- self?.banner.reloadData()
|
|
|
|
|
|
+ self?.banner.reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -143,26 +138,40 @@ class MVHomeController: MVBaseController {
|
|
|
self?.getData()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
PQSingletoVideoPlayer.shared.progressBloc = { [weak self] loadProgress, playProgress, duration in
|
|
|
-
|
|
|
+
|
|
|
BFLog(message: "loadProgress \(loadProgress) playProgress\(playProgress) \(duration)")
|
|
|
- let cell: MVBannerCell? = self?.banner.collectionView.cellForItem(at: self?.lastBnnerSelectIndex ?? IndexPath.init()) as? MVBannerCell
|
|
|
-
|
|
|
+ let cell: MVBannerCell? = self?.banner.collectionView.cellForItem(at: self?.lastBnnerSelectIndex ?? IndexPath()) as? MVBannerCell
|
|
|
+
|
|
|
cell?.progressView.progress = playProgress / loadProgress
|
|
|
-
|
|
|
}
|
|
|
PQSingletoVideoPlayer.shared.playStatusBloc = { [weak self] status in
|
|
|
|
|
|
- if(status == .PQVIDEO_PLAY_STATUS_END){
|
|
|
+ if status == .PQVIDEO_PLAY_STATUS_END {
|
|
|
PQSingletoVideoPlayer.shared.playVideoData!.playProgress = 0
|
|
|
PQSingletoVideoPlayer.shared.resetPlayer()
|
|
|
}
|
|
|
}
|
|
|
+ // 添加协议
|
|
|
+ let showProtocal: String? = getUserDefaults(key: cShowProtocal) as? String
|
|
|
+ if showProtocal == nil || showProtocal?.count ?? 0 <= 0 || showProtocal != "1" {
|
|
|
+ let protocalView: PQServerProtocalView = PQServerProtocalView(frame: view.frame)
|
|
|
+ protocalView.tag = cProtocalViewTag
|
|
|
+ protocalView.remindBlock = { [weak self] sender, webUrl in
|
|
|
+ if sender == nil, webUrl != nil {
|
|
|
+ let detail = PQBaseWebViewController()
|
|
|
+ detail.evaluateJavaScript = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='210%'"
|
|
|
+ detail.baseUrl = webUrl
|
|
|
+ self?.navigationController?.pushViewController(detail, animated: true)
|
|
|
+ }
|
|
|
+ // 移除继续播放
|
|
|
+ if sender != nil {
|
|
|
+ PQSingletoVideoPlayer.shared.resetPlayer()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UIApplication.shared.keyWindow?.addSubview(protocalView)
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
|
|
|
func addLayout() {
|
|
|
// mineBtn.snp.remakeConstraints { make in
|
|
@@ -202,7 +211,7 @@ class MVHomeController: MVBaseController {
|
|
|
|
|
|
@objc func btnClick(sender: UIButton) {
|
|
|
// 先判断是否登录
|
|
|
- if !BFLoginUserInfo.shared.isLogin() && sender.tag != 3000 {
|
|
|
+ if !BFLoginUserInfo.shared.isLogin(), sender.tag != 3000 {
|
|
|
let vc = MVLoginController()
|
|
|
vc.modalPresentationStyle = .fullScreen
|
|
|
present(vc, animated: true, completion: nil)
|
|
@@ -212,28 +221,24 @@ class MVHomeController: MVBaseController {
|
|
|
switch sender.tag {
|
|
|
case 1000:
|
|
|
navigationController?.pushViewController(MVMineController(), animated: true)
|
|
|
- break
|
|
|
case 2000:
|
|
|
navigationController?.pushViewController(PQStuckPointMaterialController(), animated: true)
|
|
|
- break
|
|
|
|
|
|
case 3000:
|
|
|
navigationController?.pushViewController(MVSettingController(), animated: true)
|
|
|
- break
|
|
|
|
|
|
default:
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //再创作视频
|
|
|
+
|
|
|
+ // 再创作视频
|
|
|
func createVideo(indexPath: IndexPath) {
|
|
|
// 无网
|
|
|
if !isNetConnected() {
|
|
|
-
|
|
|
- let remindData:PQBaseModel = PQBaseModel()
|
|
|
+ let remindData: PQBaseModel = PQBaseModel()
|
|
|
remindData.title = "似乎已断开与互联网的连接"
|
|
|
-
|
|
|
+
|
|
|
let remindView = PQRemindView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
|
|
|
UIApplication.shared.keyWindow?.addSubview(remindView)
|
|
|
remindView.remindData = remindData
|
|
@@ -243,21 +248,17 @@ class MVHomeController: MVBaseController {
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
if !BFLoginUserInfo.shared.isLogin() {
|
|
|
let vc = MVLoginController()
|
|
|
vc.modalPresentationStyle = .fullScreen
|
|
|
present(vc, animated: true, completion: nil)
|
|
|
-
|
|
|
- }else{
|
|
|
+
|
|
|
+ } else {
|
|
|
PQStuckPointViewModel.stuckPointProjectMusicInfo(projectId: mAllVideos[indexPath.row].reCreateVideoData?.projectId ?? "") { musicData, _ in
|
|
|
- if musicData != nil{
|
|
|
- let vc = PQStuckPointMaterialController.init()
|
|
|
+ if musicData != nil {
|
|
|
+ let vc = PQStuckPointMaterialController()
|
|
|
vc.reCreateMusicData = musicData
|
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
|
}
|
|
@@ -278,28 +279,24 @@ extension MVHomeController: MVBannerDataSource, MVBannerDelegate {
|
|
|
cell.contentView.layer.masksToBounds = true
|
|
|
cell.contentView.layer.cornerRadius = 10
|
|
|
cell.contentView.backgroundColor = UIColor.white
|
|
|
-
|
|
|
+
|
|
|
cell.videoData = mAllVideos[indexPath.row]
|
|
|
cell.reCreateBtnClicHandle = { [weak self] _, _ in
|
|
|
BFLog(message: "点击了创同款")
|
|
|
self?.createVideo(indexPath: indexPath)
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
|
|
|
return cell
|
|
|
}
|
|
|
-
|
|
|
- func changePlayerStatus(indexPath: IndexPath){
|
|
|
-
|
|
|
-
|
|
|
- let cell: MVBannerCell? = banner.collectionView.cellForItem(at: indexPath) as? MVBannerCell
|
|
|
-
|
|
|
- if(PQSingletoVideoPlayer.shared.player.isPlaying()){
|
|
|
+
|
|
|
+ func changePlayerStatus(indexPath: IndexPath) {
|
|
|
+ let cell: MVBannerCell? = banner.collectionView.cellForItem(at: indexPath) as? MVBannerCell
|
|
|
+
|
|
|
+ if PQSingletoVideoPlayer.shared.player.isPlaying() {
|
|
|
cell?.pauseView.isHidden = false
|
|
|
PQSingletoVideoPlayer.shared.stopPlayer(isRemove: false)
|
|
|
-
|
|
|
- }else{
|
|
|
+
|
|
|
+ } else {
|
|
|
PQSingletoVideoPlayer.shared.resetPlayer()
|
|
|
cell?.pauseView.isHidden = true
|
|
|
}
|
|
@@ -310,41 +307,37 @@ extension MVHomeController: MVBannerDataSource, MVBannerDelegate {
|
|
|
func banner(_: MVBanner, didSelectItemAt indexPath: IndexPath) {
|
|
|
NSLog("didSelectItemAt %d", indexPath.row)
|
|
|
lastBnnerSelectIndex = indexPath
|
|
|
-
|
|
|
- changePlayerStatus(indexPath: indexPath)
|
|
|
-
|
|
|
|
|
|
+ changePlayerStatus(indexPath: indexPath)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
func pageControl(currentPage page: Int) {
|
|
|
BFLog(message: "page is \(page)")
|
|
|
-
|
|
|
- let cell: MVBannerCell? = banner.collectionView.cellForItem(at: IndexPath.init(row: page, section: 0)) as? MVBannerCell
|
|
|
-
|
|
|
-
|
|
|
- if (mVideos.count > 0 && cell != nil) {
|
|
|
+
|
|
|
+ let cell: MVBannerCell? = banner.collectionView.cellForItem(at: IndexPath(row: page, section: 0)) as? MVBannerCell
|
|
|
+ let showProtocal: String? = getUserDefaults(key: cShowProtocal) as? String
|
|
|
+ if mVideos.count > 0, cell != nil, showProtocal != nil, showProtocal == "1" {
|
|
|
cell?.pauseView.isHidden = true
|
|
|
- PQSingletoVideoPlayer.shared.configPlyer(videoData: mAllVideos[page], controllerView: cell!.converView)
|
|
|
-
|
|
|
+ PQSingletoVideoPlayer.shared.configPlyer(videoData: mAllVideos[page], controllerView: cell!.converView)
|
|
|
+
|
|
|
let hotVides = mVideos.first(where: { (items) -> Bool in
|
|
|
- items.categoryName == mAllVideos[page].categoryName
|
|
|
+ items.categoryName == mAllVideos[page].categoryName
|
|
|
})
|
|
|
for hot in mVideos {
|
|
|
hot.isSelected = false
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
mVideos[(hotVides?.categoryId ?? 0) - 1].isSelected = true
|
|
|
collectionView.reloadData()
|
|
|
-
|
|
|
- lastBnnerSelectIndex = IndexPath.init(row: page, section: 0)
|
|
|
+
|
|
|
+ lastBnnerSelectIndex = IndexPath(row: page, section: 0)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// MARK: - 划动分类相关代理
|
|
|
|
|
|
-///
|
|
|
+///
|
|
|
extension MVHomeController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIScrollViewDelegate {
|
|
|
func collectionView(_: UICollectionView, numberOfItemsInSection _: Int) -> Int {
|
|
|
return mVideos.count
|
|
@@ -359,36 +352,28 @@ extension MVHomeController: UICollectionViewDelegate, UICollectionViewDataSource
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout _: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
|
let itemData: MVHotVideoModel = mVideos[indexPath.item]
|
|
|
- let width:CGFloat = CGFloat(CGFloat((itemData.categoryName ).ga_widthForComment(font:UIFont.boldSystemFont(ofSize: 17),height:17.0)) + 36.0 + 20.0)
|
|
|
-
|
|
|
+ let width: CGFloat = CGFloat(CGFloat(itemData.categoryName.ga_widthForComment(font: UIFont.boldSystemFont(ofSize: 17), height: 17.0)) + 36.0 + 20.0)
|
|
|
+
|
|
|
return CGSize(width: width, height: collectionView.frame.height)
|
|
|
}
|
|
|
-
|
|
|
|
|
|
func collectionView(_: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
-
|
|
|
for hot in mVideos {
|
|
|
hot.isSelected = false
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
let itemDataNew: MVHotVideoModel = mVideos[indexPath.item]
|
|
|
itemDataNew.isSelected = true
|
|
|
collectionView.reloadData()
|
|
|
-
|
|
|
- //找出当前选择分类之前的视频数量和
|
|
|
- var videosCount:Int = 0
|
|
|
- if(indexPath.row != 0){
|
|
|
-
|
|
|
- for i in 0...indexPath.row - 1 {
|
|
|
+
|
|
|
+ // 找出当前选择分类之前的视频数量和
|
|
|
+ var videosCount: Int = 0
|
|
|
+ if indexPath.row != 0 {
|
|
|
+ for i in 0 ... indexPath.row - 1 {
|
|
|
videosCount = videosCount + mVideos[i].videos.count
|
|
|
}
|
|
|
BFLog(message: "indexPath 选择\(indexPath.item) 之前的视频合\(videosCount)")
|
|
|
-
|
|
|
}
|
|
|
banner.scrollToItem(at: videosCount, animated: true)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|