浏览代码

1.添加权限提示

wenweiwei 4 年之前
父节点
当前提交
b513b62765

+ 12 - 8
MusicVideoPlus/MusicVideoPlus.xcodeproj/project.pbxproj

@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		2D076756266DF8E300E64472 /* PQServerProtocalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D076755266DF8E300E64472 /* PQServerProtocalView.swift */; };
 		2D1EC138266B4F4900CBACE4 /* MVUMApiUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D1EC137266B4F4900CBACE4 /* MVUMApiUtil.swift */; };
 		4112DD832669BFA600A5AFD9 /* MVBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4112DD822669BFA600A5AFD9 /* MVBanner.swift */; };
 		4112DD862669BFFA00A5AFD9 /* MVBannerFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4112DD852669BFFA00A5AFD9 /* MVBannerFlowLayout.swift */; };
@@ -29,6 +30,7 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+		2D076755266DF8E300E64472 /* PQServerProtocalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PQServerProtocalView.swift; sourceTree = "<group>"; };
 		2D1EC137266B4F4900CBACE4 /* MVUMApiUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVUMApiUtil.swift; sourceTree = "<group>"; };
 		3FA19A38D145C54301B3CD85 /* Pods_MusicVideoPlus.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MusicVideoPlus.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		4112DCF02668C45B00A5AFD9 /* MusicVideoPlus.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MusicVideoPlus.entitlements; sourceTree = "<group>"; };
@@ -68,6 +70,14 @@
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
+		2D076754266DF8C000E64472 /* Views */ = {
+			isa = PBXGroup;
+			children = (
+				2D076755266DF8E300E64472 /* PQServerProtocalView.swift */,
+			);
+			path = Views;
+			sourceTree = "<group>";
+		};
 		2D1EC136266B4F3300CBACE4 /* Utils */ = {
 			isa = PBXGroup;
 			children = (
@@ -327,10 +337,10 @@
 		41CA6E52266782C900874B19 /* Base */ = {
 			isa = PBXGroup;
 			children = (
+				2D076754266DF8C000E64472 /* Views */,
 				41CA6E53266782C900874B19 /* ViewModels */,
 				41CA6E54266782C900874B19 /* Models */,
 				41CA6E55266782C900874B19 /* Controllers */,
-				41CA6E56266782C900874B19 /* Views */,
 			);
 			path = Base;
 			sourceTree = "<group>";
@@ -357,13 +367,6 @@
 			path = Controllers;
 			sourceTree = "<group>";
 		};
-		41CA6E56266782C900874B19 /* Views */ = {
-			isa = PBXGroup;
-			children = (
-			);
-			path = Views;
-			sourceTree = "<group>";
-		};
 		41CA6E57266782C900874B19 /* Player */ = {
 			isa = PBXGroup;
 			children = (
@@ -569,6 +572,7 @@
 				4149C8932669FE6F0055CAA2 /* MVTagsCell.swift in Sources */,
 				4112DD832669BFA600A5AFD9 /* MVBanner.swift in Sources */,
 				2D1EC138266B4F4900CBACE4 /* MVUMApiUtil.swift in Sources */,
+				2D076756266DF8E300E64472 /* PQServerProtocalView.swift in Sources */,
 				41CA6E69266788C000874B19 /* MVLoginController.swift in Sources */,
 				41CA6E662667887C00874B19 /* MVMineController.swift in Sources */,
 				41CA6F4B26689F4400874B19 /* PQMineViewModel.swift in Sources */,

+ 137 - 0
MusicVideoPlus/MusicVideoPlus/Classes/Modules/Base/Views/PQServerProtocalView.swift

@@ -0,0 +1,137 @@
+//
+//  PQServerProtocalView.swift
+//  MusicVideoPlus
+//
+//  Created by SanW on 2021/6/7.
+//
+
+import BFFramework
+import UIKit
+
+// MARK: - 应用服务协议
+
+/// 应用服务协议
+class PQServerProtocalView: UIView {
+    public var remindBlock: ((_ sender: UIButton?, _ webUrl: String?) -> Void)?
+
+    public lazy var contentView: UIView = {
+        let contentView = UIView()
+        contentView.backgroundColor = UIColor.white
+        contentView.addCorner(corner: 4)
+        return contentView
+    }()
+
+    public lazy var titleLab: UILabel = {
+        let titleLab = UILabel()
+        titleLab.font = UIFont.systemFont(ofSize: 18, weight: .medium)
+        titleLab.textAlignment = .center
+        titleLab.numberOfLines = 0
+        titleLab.textColor = UIColor.black
+        return titleLab
+    }()
+
+    public lazy var confirmBtn: UIButton = {
+        let confirmBtn = UIButton(type: .custom)
+        confirmBtn.setTitle("确定", for: .normal)
+        confirmBtn.setTitleColor(UIColor.black, for: .normal)
+        confirmBtn.tag = 2
+        confirmBtn.addTarget(self, action: #selector(btnClck(sender:)), for: .touchUpInside)
+        confirmBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium)
+        return confirmBtn
+    }()
+
+    lazy var protocolLab: TYAttributedLabel = {
+        let protocolLab = TYAttributedLabel()
+        protocolLab.highlightedLinkBackgroundColor = UIColor.white
+        protocolLab.delegate = self
+        protocolLab.numberOfLines = 0
+        protocolLab.font = UIFont(name: "PingFang SC", size: 15)
+        protocolLab.text = "感谢您选择闪音APP\n我们非常重视您的个人信息安全和隐私保护。依据最新法律要求,使用我们的产品前,请仔细阅读并同意"
+        protocolLab.textColor = UIColor.black
+        protocolLab.appendLink(withText: "《软件许可及服务协议》", linkFont: UIFont(name: "PingFang SC", size: 15), linkColor: UIColor.hexColor(hexadecimal: "#07C160"), underLineStyle: CTUnderlineStyle(), linkData: cUserProtocol)
+        protocolLab.appendLink(withText: "和", linkFont: UIFont(name: "PingFang SC", size: 15), linkColor: UIColor.black, underLineStyle: CTUnderlineStyle(), linkData: nil)
+        protocolLab.appendLink(withText: "《隐私政策》", linkFont: UIFont(name: "PingFang SC", size: 15), linkColor: UIColor.hexColor(hexadecimal: "#07C160"), underLineStyle: CTUnderlineStyle(), linkData: cPrivacy)
+        protocolLab.appendLink(withText: ",以便我们向您提供更优质的服务!\n\n我们承诺将尽全力保护您的个人信息及合法权益,再次感谢您的信任!", linkFont: UIFont(name: "PingFang SC", size: 15), linkColor: UIColor.black, underLineStyle: CTUnderlineStyle(), linkData: nil)
+        return protocolLab
+    }()
+
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        contentView.addSubview(protocolLab)
+        titleLab.text = "服务协议与隐私政策"
+        titleLab.textAlignment = .center
+        confirmBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
+        confirmBtn.setTitle("同意", for: .normal)
+        confirmBtn.setTitleColor(UIColor.white, for: .normal)
+        confirmBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#07C160")
+        confirmBtn.addCorner(corner: cDefaultMargin * 2.5)
+    }
+
+    override func layoutSubviews() {
+        super.layoutSubviews()
+        addLayout()
+    }
+
+    func addLayout() {
+        let normalH: CGFloat = cDefaultMargin * 2.5
+        var protocolH: CGFloat = protocolLab.getSizeWithWidth(cScreenWidth - cDefaultMargin * 12).height
+
+        if cScreenHeigth <= 568.0 {
+            protocolH = protocolH + cDefaultMargin * 4
+        }
+        let contentH: CGFloat = normalH + cDefaultMargin * 2 + cDefaultMargin + protocolH + cDefaultMargin * 2 + cDefaultMargin * 5 + cDefaultMargin * 2
+
+        contentView.snp.makeConstraints { make in
+            make.left.equalTo(self).offset(cDefaultMargin * 4)
+            make.right.equalTo(self).offset(-cDefaultMargin * 4)
+            make.height.equalTo(contentH)
+            make.center.equalTo(self)
+        }
+        contentView.addCorner(corner: 4)
+        titleLab.snp.makeConstraints { make in
+            make.left.equalTo(contentView).offset(normalH)
+            make.right.equalTo(contentView).offset(-normalH)
+            make.height.equalTo(cDefaultMargin * 2)
+            make.top.equalTo(contentView).offset(normalH)
+        }
+        protocolLab.snp.makeConstraints { make in
+            make.top.equalTo(titleLab.snp.bottom).offset(cDefaultMargin)
+            make.left.right.equalTo(titleLab)
+            make.height.equalTo(protocolH)
+        }
+        confirmBtn.snp.makeConstraints { make in
+            make.left.right.equalTo(titleLab)
+            make.height.equalTo(cDefaultMargin * 5)
+            make.bottom.equalToSuperview().offset(-cDefaultMargin * 2)
+        }
+    }
+
+    required init?(coder _: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    @objc func btnClck(sender: UIButton) {
+        removeFromSuperview()
+        if remindBlock != nil {
+            remindBlock!(sender, nil)
+        }
+        saveUserDefaults(key: cShowProtocal, value: "1")
+    }
+}
+
+extension PQServerProtocalView: TYAttributedLabelDelegate {
+    func attributedLabel(_: TYAttributedLabel!, textStorageClicked textStorage: TYTextStorageProtocol!, at _: CGPoint) {
+        var link: String? = (textStorage as? TYLinkTextStorage)?.linkData as? String ?? ""
+        if link == nil || (link?.count ?? 0) <= 0 {
+            let range = (textStorage as? TYLinkTextStorage)?.range
+            if range?.length == 11 {
+                link = cUserProtocol
+            } else if range?.length == 6 {
+                link = cPrivacy
+            }
+        }
+        if link != nil, (link?.count ?? 0) > 0, remindBlock != nil {
+            remindBlock!(nil, link)
+        }
+    }
+}

+ 76 - 92
MusicVideoPlus/MusicVideoPlus/Classes/Modules/Home/MVHomeController.swift

@@ -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)
     }
@@ -104,45 +101,56 @@ class MVHomeController: MVBaseController {
         banner.reloadData()
 
         addLayout()
- 
-        MVHomeViewModel.getHomeHotVideos {[weak self] hotVideos, _ in
+
+        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()
         }
-  
+
         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)
+                }
+            }
+            UIApplication.shared.keyWindow?.addSubview(protocalView)
+        }
     }
-    
 
     func addLayout() {
 //        mineBtn.snp.remakeConstraints { make in
@@ -182,7 +190,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)
@@ -192,28 +200,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
@@ -223,21 +227,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)
                 }
@@ -258,28 +258,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
         }
@@ -290,41 +286,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
+
+        if mVideos.count > 0, cell != nil {
             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
@@ -339,36 +331,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)
-        
-        
-       
     }
- 
 }