ソースを参照

1,编辑封面和标题 UI 2, 删除不使用代码 3,封面+标题更新逻辑

jsonwang 3 年 前
コミット
f635cb7d2c

+ 295 - 60
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointPublicController.swift

@@ -35,7 +35,7 @@ class PQStuckPointPublicController: PQBaseViewController {
     // 最大的宽度
     private var maxWidth: CGFloat = cScreenWidth
     // 最大的高度
-    private var maxHeight: CGFloat = cScreenHeigth - cDevice_iPhoneNavBarAndStatusBarHei - cSafeAreaHeight - cDefaultMargin * 5 - cDefaultMargin * 12 - cDefaultMargin * 5
+    private var maxHeight: CGFloat = 385
     // 开始导出的时间
     private let startExportDate: Float64 = Date().timeIntervalSince1970
     // 导出结束的时间
@@ -209,60 +209,148 @@ class PQStuckPointPublicController: PQBaseViewController {
         return progressView
     }()
 
+    //提示
     lazy var remindLab: UILabel = {
         let remindLab = UILabel()
-        remindLab.isHidden = true
-        remindLab.font = UIFont.systemFont(ofSize: 14)
+        remindLab.font = UIFont.boldSystemFont(ofSize: 18)
         remindLab.textColor = PQBFConfig.shared.styleTitleColor
         remindLab.textAlignment = .center
-        remindLab.numberOfLines = 3
-        let arr = NSMutableAttributedString(string: "制作完成啦🎉\n\n快分享秀一下")
-        arr.addAttributes([.font: UIFont.systemFont(ofSize: 30, weight: .semibold)], range: NSRange(location: arr.length - 6, length: 6))
-        remindLab.attributedText = arr
+        remindLab.numberOfLines = 2
+        remindLab.backgroundColor = .clear
+        remindLab.text = "为你的大作起个响亮的标题\n分享秀一下🎉"
         return remindLab
     }()
-
+    
+    //输入框背景
+    lazy var inputBackView: UIView = {
+        let inputBackView = UIView()
+        inputBackView.backgroundColor = .clear
+        inputBackView.layer.cornerRadius = 7
+        inputBackView.layer.borderWidth = 2
+        inputBackView.layer.borderColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
+        return inputBackView
+    }()
+    // 手势提示
+    lazy var pinView: UIImageView = {
+        let pinView = UIImageView()
+        pinView.kf.setImage(with: URL(fileURLWithPath: Bundle().BF_mainbundle().path(forResource: "editCoverPin", ofType: ".gif")!))
+        return pinView
+    }()
+    //封面
+    lazy var coverImageView: UIImageView = {
+        let coverImageView = UIImageView()
+        coverImageView.isUserInteractionEnabled = true
+        coverImageView.backgroundColor = .clear
+        coverImageView.contentMode = .scaleToFill
+        return coverImageView
+    }()
+    //封面标题
+    lazy var coverImageTitle: UILabel = {
+        let coverImageTitle = UILabel()
+        coverImageTitle.text = "换封面"
+        coverImageTitle.textAlignment = .center
+        coverImageTitle.backgroundColor = UIColor(red: 0.22, green: 0.26, blue: 0.35, alpha: 0.5)
+        coverImageTitle.textColor = .white
+        coverImageTitle.font = UIFont.boldSystemFont(ofSize: 12)
+        return coverImageTitle
+    
+    }()
+    
+    //标题
+    lazy var titleLabel: UILabel = {
+        let titleLabel = UILabel()
+        titleLabel.numberOfLines = 2
+        titleLabel.isUserInteractionEnabled = true
+        titleLabel.textColor = UIColor.hexColor(hexadecimal: "#ABABAB")
+        titleLabel.textAlignment = .left
+        titleLabel.font = UIFont.systemFont(ofSize: 17)
+        let ges = UITapGestureRecognizer(target: self, action: #selector(titleLabelClick))
+        titleLabel.addGestureRecognizer(ges)
+        return titleLabel
+    }()
+    
+    //编辑发布标题
+    lazy var publicTitleView: PQEditPublicTitleView = {
+        let publicTitleView = PQEditPublicTitleView()
+        publicTitleView.isHidden = true
+        publicTitleView.confirmBtnClock = { [weak self] title in
+            BFLog(message: "传出的 title  is :\(String(describing: title))")
+            self?.setTitleText(text: title ?? "",textColor: .black)
+            //更新数据
+            self?.videoData?.title = title
+            self?.updateCoverImagegOrTitle()
+        }
+        
+        return publicTitleView
+    }()
+    
+    //编辑发布封面
+    lazy var publicEditCoverView: PQEditPublicCoverImageView = {
+        let publicEditCoverView = PQEditPublicCoverImageView.init(frame: CGRect.init(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
+        publicEditCoverView.isHidden = true
+        return publicEditCoverView
+    }()
+ 
+    //分享到朋友圈
     lazy var shareWechatBtn: UIButton = {
         let shareWechatBtn = UIButton(type: .custom)
         shareWechatBtn.frame = CGRect(x: 0, y: 0, width: 70, height: 70)
         shareWechatBtn.setImage(UIImage().BF_Image(named: "reCreate_opration_wechat"), for: .normal)
         shareWechatBtn.backgroundColor = PQBFConfig.shared.styleBackGroundColor
         shareWechatBtn.addCorner(corner: 6)
-        shareWechatBtn.tag = 1
+        shareWechatBtn.tag = 2
         shareWechatBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
         return shareWechatBtn
     }()
-
+    //分享到好友
     lazy var shareFriendBtn: UIButton = {
         let shareFriendBtn = UIButton(type: .custom)
         shareFriendBtn.frame = CGRect(x: 0, y: 0, width: 70, height: 70)
         shareFriendBtn.setImage(UIImage().BF_Image(named: "reCreate_opration_friend"), for: .normal)
         shareFriendBtn.backgroundColor = PQBFConfig.shared.styleBackGroundColor
         shareFriendBtn.addCorner(corner: 6)
-        shareFriendBtn.tag = 2
+        shareFriendBtn.tag = 1
         shareFriendBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
         return shareFriendBtn
     }()
-
+    
+    //关闭
     lazy var finishedBtn: UIButton = {
         let finishedBtn = UIButton(type: .custom)
-        finishedBtn.setTitle("完成", for: .normal)
-        finishedBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#999999"), for: .normal)
-        finishedBtn.setTitleColor(UIColor.white, for: .selected)
-        finishedBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .medium)
-        finishedBtn.backgroundColor = PQBFConfig.shared.otherTintColor
+        finishedBtn.setTitle("暂不分享", for: .normal)
+        finishedBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#BDBDBD"), for: .normal)
+        finishedBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium)
+        finishedBtn.backgroundColor = .clear
         finishedBtn.tag = 3
         finishedBtn.addCorner(corner: 3)
         finishedBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
         return finishedBtn
+        
     }()
 
     /// 背景View
     lazy var oprationBgView: UIView = {
         let oprationBgView = UIView(frame: CGRect(x: 0, y: cDevice_iPhoneNavBarAndStatusBarHei, width: cScreenWidth, height: view.frame.height - cDevice_iPhoneNavBarAndStatusBarHei))
-        oprationBgView.backgroundColor = cShadowColor
+        oprationBgView.backgroundColor = .clear
         return oprationBgView
     }()
+    
+    //除了播放器以外的 下半部分操作区
+    lazy var bottomOprationBgView: UIView = {
+        let bottomOprationBgView = UIView(frame: CGRect(x: 0, y: cDevice_iPhoneNavBarAndStatusBarHei + maxHeight, width: cScreenWidth, height: view.frame.height - cDevice_iPhoneNavBarAndStatusBarHei - maxHeight))
+        bottomOprationBgView.backgroundColor = .clear
+        bottomOprationBgView.isHidden = true
+        return bottomOprationBgView
+    }()
+    
+    ///编辑标题部分
+    lazy var editTitleBgView: UIView = {
+        let editTitleBgView = UIView(frame: CGRect(x: 0, y: cDevice_iPhoneNavBarAndStatusBarHei, width: cScreenWidth, height: view.frame.height - cDevice_iPhoneNavBarAndStatusBarHei))
+        editTitleBgView.backgroundColor = cShadowColor
+        return editTitleBgView
+    }()
+    
+ 
 
     override func backBtnClick() {
         if isExportSuccess {
@@ -309,12 +397,25 @@ class PQStuckPointPublicController: PQBaseViewController {
         }
         playerHeaderView.addSubview(playBtn)
         playerHeaderView.addSubview(progressView)
-        view.addSubview(remindLab)
-        view.addSubview(shareWechatBtn)
-        view.addSubview(shareFriendBtn)
-        navHeadImageView?.addSubview(finishedBtn)
         view.addSubview(oprationBgView)
         oprationBgView.addSubview(progressTipsLab)
+        
+        view.addSubview(bottomOprationBgView)
+        bottomOprationBgView.addSubview(remindLab)
+        bottomOprationBgView.addSubview(shareWechatBtn)
+        bottomOprationBgView.addSubview(shareFriendBtn)
+        bottomOprationBgView.addSubview(finishedBtn)
+        bottomOprationBgView.addSubview(inputBackView)
+        bottomOprationBgView.addSubview(pinView)
+        inputBackView.addSubview(coverImageView)
+        coverImageView.addSubview(coverImageTitle)
+        inputBackView.addSubview(titleLabel)
+        
+        view.addSubview(publicTitleView)
+        view.addSubview(publicEditCoverView)
+   
+        coverImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(settingCoverImage)))
+        
         progressView.snp.makeConstraints { make in
             make.left.right.centerY.equalTo(playerHeaderView)
             make.height.equalTo(3)
@@ -326,25 +427,76 @@ class PQStuckPointPublicController: PQBaseViewController {
             make.height.equalTo(90)
         }
         finishedBtn.snp.makeConstraints { make in
-            make.centerY.equalTo(backButton!)
-            make.width.equalTo(cDefaultMargin * 5)
-            make.height.equalTo(cDefaultMargin * 3)
-            make.right.equalToSuperview().offset(-12)
+            make.centerX.equalToSuperview()
+            make.bottom.equalToSuperview().offset(-cSafeAreaHeight)
+            make.width.equalTo(100)
+            make.height.equalTo(22)
         }
         shareWechatBtn.snp.makeConstraints { make in
             make.right.equalTo(view.snp_centerX).offset(-cDefaultMargin)
-            make.width.equalTo(70)
-            make.height.equalTo(cDefaultMargin * 7)
-            make.bottom.equalToSuperview().offset(-(cSafeAreaHeight + 32))
+            make.width.equalTo(164)
+            make.height.equalTo(52)
+            make.bottom.equalTo(finishedBtn.snp_top).offset(-34)
         }
         shareFriendBtn.snp.makeConstraints { make in
             make.left.equalTo(view.snp_centerX).offset(cDefaultMargin)
             make.width.bottom.height.equalTo(shareWechatBtn)
         }
+     
+        inputBackView.snp.makeConstraints { make in
+            make.centerX.equalToSuperview()
+            make.bottom.equalTo(shareWechatBtn.snp_top).offset(-16)
+            make.width.equalTo(343)
+            make.height.equalTo(109)
+            
+        }
+        
+        //根据横竖屏设置不同的 UI
+        let isWidth:Bool = (Float(editProjectModel?.sData?.videoMetaData?.videoWidth ?? 0) /  Float(editProjectModel?.sData?.videoMetaData?.videoHeight ?? 0) ) >= 1
+        var coverImageViewHeight = 50.0 * Float(editProjectModel?.sData?.videoMetaData?.videoHeight ?? 0) / Float(editProjectModel?.sData?.videoMetaData?.videoWidth ?? 0)
+        if(coverImageViewHeight > 89){
+            coverImageViewHeight = 89
+        }
+        
+        coverImageView.snp.makeConstraints { make in
+            make.left.equalToSuperview().offset(12)
+            make.width.equalTo(50)
+            make.top.equalToSuperview().offset(10)
+            make.height.equalTo(coverImageViewHeight)
+        }
+        
+        coverImageTitle.snp.makeConstraints { make in
+            make.left.equalToSuperview()
+            make.width.equalTo(50)
+            make.top.equalTo(coverImageView.snp_bottom).offset(isWidth ? 0 : -23)
+            make.height.equalTo(23)
+        }
+        
         remindLab.snp.makeConstraints { make in
             make.centerX.equalToSuperview()
-            make.bottom.equalTo(shareWechatBtn.snp_top).offset(-cDefaultMargin * 2)
+            make.bottom.equalTo(inputBackView.snp_top).offset(-16)
         }
+ 
+        titleLabel.snp.makeConstraints { make in
+            make.height.equalTo(48)
+            make.left.equalTo(coverImageView.snp_right).offset(12)
+            make.right.equalToSuperview().offset(-14)
+            make.top.equalToSuperview().offset(10)
+        }
+        
+        pinView.snp.makeConstraints { make in
+            make.height.width.equalTo(72)
+            make.right.equalToSuperview()
+            make.bottom.equalTo(inputBackView.snp_bottom)
+        }
+        
+        publicTitleView.snp.makeConstraints { make in
+            make.height.equalTo(cScreenHeigth)
+            make.width.equalTo(cScreenWidth)
+            make.bottom.equalToSuperview()
+        }
+        
+        
         // 取消所有的导出
         PQSingletoMemoryUtil.shared.allExportSession.forEach { _, exportSession in
             exportSession.cancelExport()
@@ -355,6 +507,9 @@ class PQStuckPointPublicController: PQBaseViewController {
         saveDraftbox()
         // 曝光上报:窗口曝光
         PQEventTrackViewModel.baseReportUpload(businessType: .bt_windowView, objectType: .ot_view_publishSyncedUp, pageSource: .sp_stuck_publishSyncedUp, extParams: nil, remindmsg: "卡点视频数据上报-(曝光上报:窗口曝光)")
+        
+        //取推荐标题
+        getTitles()
     }
 
     override func viewWillAppear(_ animated: Bool) {
@@ -619,6 +774,7 @@ extension PQStuckPointPublicController {
             }
             if uploadData?.image != nil {
                 playerHeaderView.image = uploadData?.image
+                coverImageView.image = uploadData?.image
             }
             if isExportSuccess, exportLocalURL != nil {
                 let size = try! exportLocalURL?.resourceValues(forKeys: [.fileSizeKey])
@@ -756,26 +912,6 @@ extension PQStuckPointPublicController {
         tempModel.stsToken = uploadData?.stsToken
         tempModel.projectId = projectId
 
-//        let tempTitleH: CGFloat = sizeWithText(text: title, font: UIFont.systemFont(ofSize: 16), size: CGSize(width: (cScreenWidth - cDefaultMargin * 3) / 2, height: cDefaultMargin * 4)).height
-//        let rate: CGFloat = ((uploadData?.image?.size.height ?? 1) / (uploadData?.image?.size.width ?? 1))
-//        tempModel.itemHeight = (cScreenWidth - cDefaultMargin * 3) / 2 * rate + tempTitleH + cDefaultMargin * 4.5
-
-//        let isContains = PQSingletoMemoryUtil.shared.uploadDatas.contains { (item) -> Bool in
-//            item.uplpadBucketKey == tempModel.uplpadBucketKey
-//        }
-//        if !isContains {
-//            BFLog(message: "添加正在上传数据===\(tempModel)")
-//            PQSingletoMemoryUtil.shared.uploadDatas.insert(tempModel, at: 0)
-//        }
-//        currentController().dismiss(animated: false) {
-//            currentController().navigationController?.viewControllers = [currentController().navigationController?.viewControllers.first ?? PQBaseViewController()]
-//            rootViewController()?.selectedIndex = 4
-//            if !isContains {
-//                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5) {
-//                    postNotification(name: cPublishSuccessKey)
-//                }
-//            }
-//        }
         /// fp8 - 发布视频
         publicVideo(videoData: tempModel)
     }
@@ -818,6 +954,7 @@ extension PQStuckPointPublicController {
 //                            BFLog(message: "开始发布==\(videoData.title ?? ""),uplpadBucketKey = \(videoData.uplpadBucketKey ?? ""),objectKey =\(objectKey),ossObjectKey = \(ossObjectKey)")
             PQUploadViewModel.publishVideo(projectId: videoData.projectId, fileExtensions: videoData.localPath?.pathExtension, title: videoData.title ?? "", videoPath: videoData.uplpadBucketKey ?? "", coverImgPath: nil, descr: videoData.summary ?? "", videoFromScene: .stuckPoint, reCreateData: videoData.reCreateVideoData, eventTrackData: videoData.eventTrackData) { [weak self] newVideoData, _, _ in
                 self?.videoData = newVideoData
+                self?.videoData?.title = self?.titleLabel.text
                 if self?.videoData?.reCreateVideoData == nil {
                     let reCreateVideo = PQReCreateModel()
                     reCreateVideo.reProduceVideoFlag = 1
@@ -850,14 +987,12 @@ extension PQStuckPointPublicController {
         progressTipsLab.removeFromSuperview()
         oprationBgView.removeFromSuperview()
         playBtn.isHidden = true
-        finishedBtn.isSelected = true
-        finishedBtn.backgroundColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
         avPlayer.replaceCurrentItem(with: AVPlayerItem(url: URL(fileURLWithPath: (exportLocalURL?.absoluteString ?? "").replacingOccurrences(of: "file:///", with: ""))))
         avPlayer.play()
         if isError {
             cShowHUB(superView: nil, msg: "视频发布失败,请重新合成")
         } else {
-            remindLab.isHidden = false
+            bottomOprationBgView.isHidden = false
             /// fp2-1-1 - 请求权限
             authorizationStatus()
         }
@@ -956,13 +1091,16 @@ extension PQStuckPointPublicController {
             // 点击上报:分享朋友圈
             PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_shareWechatMoment, pageSource: .sp_stuck_publishSyncedUp, extParams: ["videoId": videoData?.uniqueId ?? ""], remindmsg: "卡点视频数据上报-(点击上报:分享朋友圈)")
         case 3:
-            if sender.isSelected {
-                // 点击上报:完成
-                PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_finished, pageSource: .sp_stuck_publishSyncedUp, extParams: ["videoId": videoData?.uniqueId ?? ""], remindmsg: "卡点视频数据上报-(点击上报:完成)")
-                navigationController?.viewControllers = [(navigationController?.viewControllers.first)!]
-                // 发送通知
-                postNotification(name: cFinishedPublishedNotiKey)
-            }
+            
+            backBtnClick()
+            
+//            if sender.isSelected {
+//                // 点击上报:完成
+//                PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_finished, pageSource: .sp_stuck_publishSyncedUp, extParams: ["videoId": videoData?.uniqueId ?? ""], remindmsg: "卡点视频数据上报-(点击上报:完成)")
+//                navigationController?.viewControllers = [(navigationController?.viewControllers.first)!]
+//                // 发送通知
+//                postNotification(name: cFinishedPublishedNotiKey)
+//            }
         default:
             break
         }
@@ -1020,4 +1158,101 @@ extension PQStuckPointPublicController {
         attributedText.addAttributes([.font: UIFont.systemFont(ofSize: 34)], range: NSRange(location: 0, length: "\(exportProgrss)%".count))
         progressTipsLab.attributedText = attributedText
     }
+    
+    @objc func titleLabelClick()  {
+        BFLog(message: "点击输入框")
+        pinView.isHidden = true
+        publicTitleView.isHidden = false
+    }
+    
+    @objc func settingCoverImage() {
+  
+        if(exportLocalURL == nil){
+            BFLog(message: "导出的视频地址错误???。。。")
+            return
+        }
+        let asset = AVURLAsset(url: exportLocalURL!, options: nil)
+
+        publicEditCoverView.show(videoURL: exportLocalURL!, duration: CMTimeGetSeconds(asset.duration))
+        
+        publicEditCoverView.selectImageCallBack = { [weak self] imageData in
+            
+            self?.coverImageView.image = imageData
+            self?.uploadData?.image  = imageData
+            self?.updateCoverImagegOrTitle()
+        }
+   
+    }
+    
+    //更新标题或封面
+    func updateCoverImagegOrTitle() {
+        
+        PQLoadingHUB.shared.showHUB()
+        
+        PQBaseViewModel.ossTempToken { [weak self] response, msg in
+            let image: UIImage = (self?.uploadData?.image)!
+            let data = image.jpegData(compressionQuality: 1)
+            let accessKeyId: String = "\(response?["accessKeyId"] ?? "")"
+            let secretKeyId: String = "\(response?["accessKeySecret"] ?? "")"
+            let securityToken: String = "\(response?["securityToken"] ?? "")"
+            let endpoint: String = "\(response?["endPoint"] ?? "")"
+            let bucketName: String = "\(response?["bucketName"] ?? "")"
+            let objectKey: String = "\(response?["objectKey"] ?? "")"
+            PQAliOssUtil.shared
+                .startClient(
+                    accessKeyId: accessKeyId,
+                    secretKeyId: secretKeyId,
+                    securityToken: securityToken,
+                    endpoint: endpoint
+                )
+
+                .uploadObjectAsync(bucketName: bucketName, objectKey: objectKey, data: data!, fileExtensions: "png", imageUploadBlock: { _, code, ossObjectKey, _ in
+                    if code == 1 && ossObjectKey == objectKey && ossObjectKey.count > 0 {
+                        PQUploadViewModel.updateVideo(title: self?.videoData?.title ?? "", videoId: self?.videoData?.uniqueId ?? "", coverImgPath: objectKey, descr: "") { newVideoData, msg in
+                            PQLoadingHUB.shared.dismissHUB()
+                            if newVideoData == nil {
+                                cShowHUB(superView: self?.view, msg: msg)
+                                return
+                            }
+//                            self?.navigationController?.popToRootViewController(animated: true)
+//                            postNotification(name: cUpdateVideoSuccessKey, userInfo: ["videoData": newVideoData!])
+                        }
+                    } else {
+                        PQLoadingHUB.shared.dismissHUB()
+                    }
+                })
+        
+        }}
+    func  setTitleText(text:String ,textColor:UIColor = UIColor.hexColor(hexadecimal: "#ABABAB"))  {
+//        if(text.count > 15){
+//            self?.titleLabel.numberOfLines = 2
+//            self?.titleLabel.frame = CGRect.init(x: self?.titleLabel.frame.origin.x ?? 0, y: self?.titleLabel.frame.origin.y ?? 0, width: self?.titleLabel.frame.width ?? 0, height: 48)
+//        }else{
+//            self?.titleLabel.frame = CGRect.init(x: self?.titleLabel.frame.origin.x ?? 0, y: self?.titleLabel.frame.origin.y ?? 0, width: self?.titleLabel.frame.width ?? 0, height: 24)
+//        }
+//
+        //更新 UI
+        titleLabel.text = text
+        titleLabel.textColor = textColor
+        publicTitleView.inputTV.placeHolder = text
+        //更新数据
+        videoData?.title = text
+        
+
+    }
+    //取推荐的10个标题
+    func getTitles(){
+        PQBaseViewModel.getBaseConfig(completeHander: {[weak self] titles in
+             
+            if((titles?.count ?? 0) > 0){
+                self?.publicTitleView.titles = titles!
+            
+                let numberRandom: UInt32 = UInt32(arc4random_uniform(UInt32(titles!.count)))
+                BFLog(message: "接收到的 titles\(String(describing: titles))")
+                self?.setTitleText(text: titles?[Int(numberRandom)] ?? "")
+        
+            }
+    
+        })
+    }
 }