Browse Source

首页模板增加分享功能

huzhiqiang 3 years ago
parent
commit
7c7a656b04

+ 22 - 0
MusicVideoPlus/Assets.xcassets/Home/b_pyq.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "b_pyq@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "b_pyq@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
MusicVideoPlus/Assets.xcassets/Home/b_pyq.imageset/b_pyq@2x.png


BIN
MusicVideoPlus/Assets.xcassets/Home/b_pyq.imageset/b_pyq@3x.png


+ 22 - 0
MusicVideoPlus/Assets.xcassets/Home/b_wx.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "b_wx@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "b_wx@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
MusicVideoPlus/Assets.xcassets/Home/b_wx.imageset/b_wx@2x.png


BIN
MusicVideoPlus/Assets.xcassets/Home/b_wx.imageset/b_wx@3x.png


+ 22 - 0
MusicVideoPlus/Assets.xcassets/Home/people.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "people@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "people@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
MusicVideoPlus/Assets.xcassets/Home/people.imageset/people@2x.png


BIN
MusicVideoPlus/Assets.xcassets/Home/people.imageset/people@3x.png


+ 22 - 0
MusicVideoPlus/Assets.xcassets/Home/pyq.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "pyq@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "pyq@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
MusicVideoPlus/Assets.xcassets/Home/pyq.imageset/pyq@2x.png


BIN
MusicVideoPlus/Assets.xcassets/Home/pyq.imageset/pyq@3x.png


+ 22 - 0
MusicVideoPlus/Assets.xcassets/Home/wechat.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "wechat@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "wechat@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
MusicVideoPlus/Assets.xcassets/Home/wechat.imageset/wechat@2x.png


BIN
MusicVideoPlus/Assets.xcassets/Home/wechat.imageset/wechat@3x.png


+ 69 - 0
MusicVideoPlus/Classes/Modules/Home/Controllers/MVHomeController.swift

@@ -561,10 +561,79 @@ extension MVHomeController: MVBannerDataSource, MVBannerDelegate {
             BFLog(message: "点击了创同款")
             self?.createVideo(indexPath: indexPath)
         }
+        cell.sharedBtnClicHandle = {[weak self, weak cell] type in
+            if type == 1 {
+                // 分享朋友圈
+                if !isNetConnected() {
+                    cShowHUB(superView: self?.view, msg: "没有网络连接")
+                    return
+                }
+                if !PQSingletoWXApiUtil.shared.isInstallWX() {
+                    cShowHUB(superView: self?.view, msg: "您还未安装微信客户端!")
+                    return
+                }
+                let shareId = getUniqueId(desc: "\(cell?.videoData?.reCreateVideoData?.videoId ?? "")shareId")
+                PQBaseViewModel.h5ShareLinkInfo(videoId: (cell?.videoData?.uniqueId ?? ""), pageSource: cell?.videoData?.pageSource ?? .sp_category) { [weak self] path, _ in
+                    cHiddenHUB(superView: nil)
+                    if path != nil {
+                        
+                        //判断shareText是否有效
+                        var shareText = ""
+                        shareText =  cell?.videoData?.title?.replacingOccurrences(of: "\n", with: "") ?? ""
+                        shareText = shareText.replacingOccurrences(of: " ", with: "")
+                        if(shareText.count == 0){
+                            shareText = "\(BFLoginUserInfo.shared.nickName)made a music video for you"
+                        }
+                        
+                        PQSingletoWXApiUtil.shared.share(type: 1, scene: 1, title:shareText , description: "", imageUrl: cell?.videoData?.shareImgPath, path: path, videoId: (cell?.videoData?.uniqueId)!, pageSource: cell?.videoData?.pageSource ?? .sp_category, shareId: shareId).wxApiUtilHander = { _, _ in
+                            
+                        }
+                    } else {
+                        cShowHUB(superView: self?.view, msg: "没有网络连接")
+                    }
+                }
+                // 分享朋友圈上报
+                self?.reportUpload(isFriend: false, openId: "", shareId: shareId, videoData: cell?.videoData!)
+            }else if type == 2 {
+                // 分享微信好友
+                if !isNetConnected() {
+                    cShowHUB(superView: self?.view, msg: "没有网络连接")
+                    return
+                }
+                if !PQSingletoWXApiUtil.shared.isInstallWX() {
+                    cShowHUB(superView: self?.view, msg: "您还未安装微信客户端!")
+                    return
+                }
+                cShowHUB(superView: nil, msg: nil)
+                let shareId = getUniqueId(desc: "\(cell?.videoData?.uniqueId ?? "")shareId")
+                PQBaseViewModel.wxFriendShareInfo(videoId: (cell?.videoData?.uniqueId)!) { [weak self] imagePath, title, shareWeappRawId, msg in
+                    if msg != nil {
+                        cShowHUB(superView: self?.view, msg: "网络不佳哦")
+                        return
+                    }
+                    PQSingletoWXApiUtil.shared.share(type: 3, scene: 0, shareWeappRawId: shareWeappRawId, title: title, description: title, imageUrl: imagePath, path: cell?.videoData?.videoPath, videoId: (cell?.videoData?.uniqueId)!, pageSource: cell?.videoData?.pageSource ?? .sp_category, shareId: shareId).wxApiUtilHander = { _, _ in
+                    }
+                    cHiddenHUB(superView: nil)
+                }
+                // 分享好友上报
+                self?.reportUpload(isFriend: true, openId: "", shareId: shareId, videoData: cell?.videoData!)
+     
+            }
+        }
 
         return cell
     }
 
+    func reportUpload(isFriend: Bool, openId _: String, shareId: String, videoData: PQVideoListModel?) {
+        // 分享上报
+        PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: videoData, pageSource: nil, businessType: isFriend ? .bt_videoShareFriend : .bt_videoShareH5, objectType: nil, extParams: nil, shareId: shareId, videoIds: nil, playId: PQSingletoVideoPlayer.shared.playId)
+        if isFriend {
+            PQEventTrackViewModel.shareReportUpload(videoId: videoData?.uniqueId ?? "0", pageSource: videoData!.pageSource, recommendId: videoData?.recommendId, recommendLogVO: videoData?.recommendLogVO, abInfoData: videoData?.abInfoData, measureType: videoData?.measureType, measureId: videoData?.measureId, businessType: isFriend ? .bt_videoShareFriend : .bt_videoShareH5, targetUid: videoData?.userInfo?.uid, shareId: shareId)
+            PQEventTrackViewModel.shareReportUpload(screenType: 3, videoId: videoData?.uniqueId ?? "0", pageSource: videoData!.pageSource, recommendId: videoData?.recommendId, recommendLogVO: videoData?.recommendLogVO, abInfoData: videoData?.abInfoData, measureType: videoData?.measureType, measureId: videoData?.measureId, businessType: isFriend ? .bt_videoShareFriend : .bt_videoShareH5, targetUid: videoData?.userInfo?.uid, shareId: shareId)
+        } else {
+            PQEventTrackViewModel.shareReportUpload(screenType: 2, videoId: videoData?.uniqueId ?? "0", pageSource: videoData!.pageSource, recommendId: videoData?.recommendId, recommendLogVO: videoData?.recommendLogVO, abInfoData: videoData?.abInfoData, measureType: videoData?.measureType, measureId: videoData?.measureId, businessType: isFriend ? .bt_videoShareFriend : .bt_videoShareH5, targetUid: videoData?.userInfo?.uid, shareId: shareId)
+        }
+    }
     // MARK: - GXBannerDelegate
 
     func banner(_: MVBanner, didSelectItemAt indexPath: IndexPath) {

+ 64 - 0
MusicVideoPlus/Classes/Modules/Home/Views/Banner/MVBannerUsageView.swift

@@ -0,0 +1,64 @@
+//
+//  MVBannerUsageView.swift
+//  MusicVideoPlus
+//
+//  Created by Harry Hu on 2021/10/8.
+//
+
+import Foundation
+
+class MVBannerUsageView: UIView {
+    var amount:Int = 0 {
+        didSet {
+            contentL.text = "使用量 \(amount)"
+            contentL.sizeToFit()
+        }
+    }    // 使用量
+    
+    lazy var contentL:UILabel = {
+        let contentL = UILabel(frame: .zero)
+        contentL.textColor = UIColor.white
+        contentL.font = UIFont(name: "PingFangSC-Regular", size: 12)
+        contentL.textAlignment = .left
+        contentL.text = "使用量 0"
+        return contentL
+    }()
+    
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        
+        self.backgroundColor = .clear
+        
+        let backV = UIView()
+        backV.backgroundColor = UIColor.black
+        backV.alpha = 0.3
+        backV.layer.cornerRadius = 5
+        addSubview(backV)
+        backV.snp.makeConstraints { make in
+            make.edges.equalToSuperview()
+        }
+        let iconIV = UIImageView(image: UIImage(named: "people"))
+        iconIV.frame = CGRect(x: 6, y: 7, width: 12, height: 12)
+        addSubview(iconIV)
+        
+        
+        addSubview(contentL)
+        
+        contentL.snp.makeConstraints { make in
+            make.left.equalTo(iconIV.snp.right).offset(6.5)
+            make.top.bottom.equalToSuperview()
+            make.right.equalToSuperview().offset(-6).priorityHigh()
+        }
+
+    }
+    
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+//    override func layoutSubviews() {
+//        super.layoutSubviews()
+//        self.layer.backgroundColor = UIColor.black.cgColor
+//        self.layer.cornerRadius = 5
+//    }
+}

+ 85 - 26
MusicVideoPlus/Classes/Modules/Home/Views/MVBannerCell.swift

@@ -12,6 +12,7 @@ import UIKit
 class MVBannerCell: UICollectionViewCell {
     // 做同款
     var reCreateBtnClicHandle: ((_ sender: UIButton, _ videoInfo: PQVideoListModel?) -> Void)?
+    var sharedBtnClicHandle: ((_ type:Int) -> Void)?
     let musicWidth: CGFloat = (9.0 / 16.0 * (cScreenHeigth - (cDevice_iPhoneStatusBarHei + 45 + 60 + (cDefaultMargin * 2 + cSafeAreaHeight) + cDefaultMargin * 3 + 15))) - 15 - (16 + cDefaultMargin) * 2 - (10 + 106 + 10)
     // 封面
     lazy var converView: UIImageView = {
@@ -121,7 +122,37 @@ class MVBannerCell: UICollectionViewCell {
         typeLab.textColor = UIColor.white
         return typeLab
     }()
+    
+    lazy var usageAmountL:MVBannerUsageView = {
+        let v = MVBannerUsageView()
+        return v
+    }()
+    
+    lazy var friendIV:UIButton = {
+//        let iv = UIImageView(image: UIImage(named: "b_pyq"))
+        let iv = UIButton(type: .custom)
+        iv.setImage(UIImage(named: "b_pyq"), for: .normal)
+        iv.tag = 2201
+        iv.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
+        //        iv.layer.backgroundColor = UIColor.black.cgColor
+//        iv.layer.cornerRadius = 22
+//        iv.alpha = 0.3
+        return iv
+    }()
 
+    lazy var wxIV:UIButton = {
+//        let iv = UIImageView(image: UIImage(named: "b_wx"))
+        let iv = UIButton(type: .custom)
+        iv.setImage(UIImage(named: "b_wx"), for: .normal)
+        iv.tag = 2202
+        iv.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
+//        iv.layer.backgroundColor = UIColor.black.cgColor
+//        iv.layer.cornerRadius = 22
+//        iv.alpha = 0.3
+        return iv
+    }()
+
+    
     override func prepareForReuse() {
         musicNameLab.stop()
     }
@@ -145,11 +176,14 @@ class MVBannerCell: UICollectionViewCell {
         contentView.addSubview(bottmMaskView)
         contentView.addSubview(pauseView)
         bottmMaskView.addSubview(progressView)
-        bottmMaskView.addSubview(typeImage)
+//        bottmMaskView.addSubview(typeImage)
+//        bottmMaskView.addSubview(typeLab)
         bottmMaskView.addSubview(titleLabel)
+        bottmMaskView.addSubview(usageAmountL)
+        bottmMaskView.addSubview(friendIV)
+        bottmMaskView.addSubview(wxIV)
+
         
-        
-        bottmMaskView.addSubview(typeLab)
         bottmMaskView.addSubview(reCreateBtn)
         bottmMaskView.addSubview(musicContenView)
         musicContenView.addSubview(musicBgView)
@@ -176,11 +210,13 @@ class MVBannerCell: UICollectionViewCell {
    
 
         
-        if videoData?.categoryImage != nil {
-            typeImage.setNetImage(url: "\(videoData?.categoryImage ?? "")", placeholder: UIImage(named: "categary_icon")!)
-        } else {
-            typeImage.image = UIImage(named: "categary_icon")
-        }
+//        if videoData?.categoryImage != nil {
+//            typeImage.setNetImage(url: "\(videoData?.categoryImage ?? "")", placeholder: UIImage(named: "categary_icon")!)
+//        } else {
+//            typeImage.image = UIImage(named: "categary_icon")
+//        }
+        usageAmountL.amount = videoData?.reCreateVideoData?.reProduceCount ?? 0
+        
         let coverImg = (videoData?.videoCoverSnapshotPath != nil && (videoData?.videoCoverSnapshotPath?.count ?? 0) > 0) ? videoData?.videoCoverSnapshotPath ?? "" : (videoData?.coverImg?["coverImgPath"] as? String ?? "")
         BFLog(message: "coverImg url is \(coverImg)")
         netImage(url: coverImg, mainView: converView)
@@ -255,29 +291,52 @@ class MVBannerCell: UICollectionViewCell {
             make.right.top.height.equalToSuperview()
         }
 
-        if(videoData?.title?.count ?? 0 > 0){
-            typeImage.snp.remakeConstraints { make in
-                make.left.equalTo(musicContenView.snp_left)
-                make.height.width.equalTo(18)
-                make.bottom.equalTo(titleLabel.snp_top).offset(-8)
-            }
-        }else{
-            typeImage.snp.remakeConstraints { make in
-                make.left.equalTo(musicContenView.snp_left)
-                make.height.width.equalTo(18)
-                make.bottom.equalTo(musicContenView.snp_top).offset(-cDefaultMargin)
-            }
+//        if(videoData?.title?.count ?? 0 > 0){
+//            typeImage.snp.remakeConstraints { make in
+//                make.left.equalTo(musicContenView.snp_left)
+//                make.height.width.equalTo(18)
+//                make.bottom.equalTo(titleLabel.snp_top).offset(-8)
+//            }
+//        }else{
+//            typeImage.snp.remakeConstraints { make in
+//                make.left.equalTo(musicContenView.snp_left)
+//                make.height.width.equalTo(18)
+//                make.bottom.equalTo(musicContenView.snp_top).offset(-cDefaultMargin)
+//            }
+//        }
+//
+//        typeLab.snp.remakeConstraints { make in
+//            make.left.equalTo(typeImage.snp_right).offset(5)
+//            make.centerY.equalTo(typeImage)
+//            make.right.equalTo(musicContenView)
+//        }
+        wxIV.snp.makeConstraints { make in
+            make.right.equalTo(-12)
+            make.bottom.equalTo(titleLabel.snp_top).offset(-9)
+            make.width.height.equalTo(44)
         }
-   
-        typeLab.snp.remakeConstraints { make in
-            make.left.equalTo(typeImage.snp_right).offset(5)
-            make.centerY.equalTo(typeImage)
-            make.right.equalTo(musicContenView)
+        friendIV.snp.makeConstraints { make in
+            make.right.equalTo(wxIV.snp_left).offset(-8)
+            make.width.height.bottom.equalTo(wxIV)
+        }
+        usageAmountL.snp.remakeConstraints { make in
+            make.left.equalTo(12)
+            make.height.equalTo(26)
+            make.bottom.equalTo(titleLabel.snp_top).offset(-13)
+            make.right.lessThanOrEqualTo(friendIV.snp_left).offset(-8)
         }
     }
 
     @objc func btnClick(sender: UIButton) {
-        if reCreateBtnClicHandle != nil {
+        if sender.tag == 2201 {
+            // 分享朋友圈
+//            cShowHUB(superView: nil, msg: "分享朋友圈")
+            sharedBtnClicHandle?(1)
+        }else if sender.tag == 2202 {
+            // 分享给微信好友
+//            cShowHUB(superView: nil, msg: "分享微信好友")
+            sharedBtnClicHandle?(2)
+        }else if reCreateBtnClicHandle != nil {
             reCreateBtnClicHandle!(sender, videoData)
         }
     }