소스 검색

1,整理界面跳转方法 2, 修改 viewListView.currentIndex 值防止点击分类后 page 效果失效 3, 减少自动播放时间

jsonwang 4 년 전
부모
커밋
ef4d330589
1개의 변경된 파일91개의 추가작업 그리고 54개의 파일을 삭제
  1. 91 54
      MusicVideoPlus/MusicVideoPlus/Classes/Modules/Home/Controllers/MVHomeController.swift

+ 91 - 54
MusicVideoPlus/MusicVideoPlus/Classes/Modules/Home/Controllers/MVHomeController.swift

@@ -88,9 +88,11 @@ class MVHomeController: MVBaseController {
     @objc func loginSuccesss() {
         if isCreateVideo {
             isCreateVideo = false
-            createVideo(indexPath: lastBnnerSelectIndex)
+            let videoListModel = mAllVideos[lastBnnerSelectIndex.row]
+            jumpToDetailVc(type: 2, videoData: videoListModel)
         } else {
-            navigationController?.pushViewController(PQStuckPointMaterialController(), animated: true)
+            jumpToDetailVc(type: 3)
+          
         }
     }
 
@@ -163,6 +165,7 @@ class MVHomeController: MVBaseController {
 
         addLayout()
 
+        //网络监听有网后取一次数据
         manager?.startListening()
         manager?.listener = { [weak self] status in
 
@@ -171,6 +174,8 @@ class MVHomeController: MVBaseController {
                 self?.getData()
             }
         }
+    
+        //播放器进度和状态回调
         PQSingletoVideoPlayer.shared.progressBloc = { [weak self] loadProgress, playProgress, duration in
 
             BFLog(message: "loadProgress \(loadProgress) playProgress\(playProgress) \(duration)")
@@ -244,16 +249,11 @@ class MVHomeController: MVBaseController {
     @objc func btnClick(sender: UIButton) {
         switch sender.tag {
         case 1000:
-            if enableLogin() {
-                navigationController?.pushViewController(MVMineController(), animated: true)
-            }
+            jumpToDetailVc(type: 1)
         case 2000:
-            if enableLogin() {
-                controlPlayrPasueOrResume(isPause: true)
-                let nav = UINavigationController(rootViewController: PQStuckPointMaterialController())
-                nav.modalPresentationStyle = .overFullScreen
-                present(nav, animated: true, completion: nil)
-            }
+            
+            jumpToDetailVc(type: 2)
+              
         case 3000:
             navigationController?.pushViewController(MVSettingController(), animated: true)
         default:
@@ -261,8 +261,12 @@ class MVHomeController: MVBaseController {
         }
     }
 
-    // 判断是否可登录
-    func enableLogin() -> Bool {
+    
+    /// 判断是否可进入对就界面
+    /// - Parameters:
+    ///   - type: 进入界面  1, 个人中心 2,再创作进入相册 PQVideoListModel 不能为空要使用音乐数据  3,直接创作进入相机
+    ///   - videoData: type == 2 时必传
+    func jumpToDetailVc(type: Int, videoData: PQVideoListModel? = nil) {
         // 无网
         if !isNetConnected() {
             let remindData: PQBaseModel = PQBaseModel()
@@ -276,21 +280,21 @@ class MVHomeController: MVBaseController {
                     openAppSetting()
                 }
             }
-            return false
+            return
         }
         // 先判断是否登录
         if !BFLoginUserInfo.shared.isLogin() {
             let vc = MVLoginController()
             vc.modalPresentationStyle = .fullScreen
             present(vc, animated: true, completion: nil)
-            return false
+            return
         }
 
         // 用户被封禁
         BFLog(message: "userStatus is \(BFLoginUserInfo.shared.userStatus)")
         if BFLoginUserInfo.shared.userStatus == "3" {
             PQBandingPhoneRemindView.accountBlockRemindView(remindTitle: "无法上传视频")
-            return false
+            return
         }
 
         // 未绑定手机号
@@ -312,59 +316,63 @@ class MVHomeController: MVBaseController {
             }
             view.addSubview(remindView)
 
-            return false
+            return
         }
+        
+        //条件都满足转换到对就界面
+        switch type {
+        case 1:
+            navigationController?.pushViewController(MVMineController(), animated: true)
+            break
+        case 2:
 
-        return true
-    }
-
-    // 再创作视频
-    func createVideo(indexPath: IndexPath) {
-        if enableLogin() && mAllVideos.count > indexPath.row {
-            PQStuckPointViewModel.stuckPointProjectMusicInfo(projectId: mAllVideos[indexPath.row].reCreateVideoData?.projectId ?? "") { musicData, _ in
+            PQStuckPointViewModel.stuckPointProjectMusicInfo(projectId: videoData?.reCreateVideoData?.projectId ?? "") { musicData, _ in
                 if musicData != nil {
                     let vc = PQStuckPointMaterialController()
                     vc.reCreateMusicData = musicData
                     self.navigationController?.pushViewController(vc, animated: true)
-                }
+                }else{BFLog(message: "musicData is ni")}
             }
+            
+            break
+        case 3:
+            let nav = UINavigationController(rootViewController: PQStuckPointMaterialController())
+            nav.modalPresentationStyle = .overFullScreen
+            present(nav, animated: true, completion: nil)
+            
+            break
+ 
+          default:
+            break
+        }
+ 
+    }
+
+    // 再创作视频
+    func createVideo(indexPath: IndexPath) {
+        
+        if(mAllVideos.count > indexPath.row){
+            isCreateVideo = true
+            let videoListModel = mAllVideos[indexPath.row]
+            jumpToDetailVc(type: 2, videoData: videoListModel)
+        }else{
+            BFLog(message: "数据出错越界!!! mAllVideos.count: \(mAllVideos.count) indexPath.row: \(indexPath.row)")
         }
+  
     }
 
+    //这里是不是 不用了?
     @objc func stuckPointDismiss() {
         controlPlayrPasueOrResume(isPause: false)
     }
 }
 
-// MARK: - MVBannerDataSource
-
-extension MVHomeController: MVBannerDataSource, MVBannerDelegate {
-    func numberOfItems() -> Int {
-        return mAllVideos.count
-    }
-
-    func banner(_ banner: MVBanner, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-        let cell: MVBannerCell = banner.dequeueReusableCell(for: indexPath)
-        cell.videoData = mAllVideos[indexPath.row]
-        cell.reCreateBtnClicHandle = { [weak self] _, _ in
-            BFLog(message: "点击了创同款")
-            self?.isCreateVideo = true
-            self?.createVideo(indexPath: indexPath)
-        }
-
-        return cell
-    }
-
-    // MARK: - GXBannerDelegate
-
-    func banner(_: MVBanner, didSelectItemAt indexPath: IndexPath) {
-        NSLog("didSelectItemAt %d", indexPath.row)
-        lastBnnerSelectIndex = indexPath
-
-        controlPlayrPasueOrResume(isPause: PQSingletoVideoPlayer.shared.isPlaying)
-    }
+// MARK: - 播放器操作相关方法
+extension MVHomeController{
+    /// 播放指定位置的视频
+    /// - Parameter page: 视频数据位置
+    func playVideo(page: Int){
 
-    func playVideo(page: Int) {
         DispatchQueue.main.async {
             let cell: MVBannerCell? = self.viewListView.collectionView.cellForItem(at: IndexPath(row: page, section: 0)) as? MVBannerCell
             let showProtocal: String? = getUserDefaults(key: cShowProtocal) as? String
@@ -407,6 +415,34 @@ extension MVHomeController: MVBannerDataSource, MVBannerDelegate {
             PQSingletoVideoPlayer.shared.resumePlayer()
         }
     }
+}
+// MARK: - 视频列表相关代理
+
+extension MVHomeController: MVBannerDataSource, MVBannerDelegate {
+    func numberOfItems() -> Int {
+        return mAllVideos.count
+    }
+
+    func banner(_ banner: MVBanner, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
+        let cell: MVBannerCell = banner.dequeueReusableCell(for: indexPath)
+        cell.videoData = mAllVideos[indexPath.row]
+        cell.reCreateBtnClicHandle = { [weak self] _, _ in
+            BFLog(message: "点击了创同款")
+            self?.createVideo(indexPath: indexPath)
+        }
+
+        return cell
+    }
+
+    // MARK: - GXBannerDelegate
+
+    func banner(_: MVBanner, didSelectItemAt indexPath: IndexPath) {
+        NSLog("didSelectItemAt %d", indexPath.row)
+        lastBnnerSelectIndex = indexPath
+
+        controlPlayrPasueOrResume(isPause: PQSingletoVideoPlayer.shared.isPlaying)
+    }
+
 
     func pageControl(currentPage page: Int) {
         BFLog(message: "page is \(page)")
@@ -453,9 +489,10 @@ extension MVHomeController: UICollectionViewDelegate, UICollectionViewDataSource
             }
             BFLog(message: "indexPath 选择\(indexPath.item) 之前的视频合\(videosCount)")
         }
+        viewListView.currentIndex = videosCount
         viewListView.scrollToItem(at: videosCount, animated: false)
 
-        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.05) {
             self.playVideo(page: videosCount)
         }
     }