Browse Source

Merge branch 'develop' into feature/jeremy

# Conflicts:
#	RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/View/CommunityAllCommentView.swift
南鑫林 5 years ago
parent
commit
bfb7918c63

+ 20 - 17
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/View/CommunityAllCommentView.swift

@@ -132,7 +132,6 @@ class CommunityAllCommentView: FWPopupView {
         tableView.estimatedRowHeight = 0.000001
         tableView.estimatedSectionFooterHeight = 0.000001
         tableView.estimatedSectionHeaderHeight = 0.000001
-        tableView.isScrollEnabled = false
         return tableView
     }()
     
@@ -141,15 +140,18 @@ class CommunityAllCommentView: FWPopupView {
 extension CommunityAllCommentView : UITableViewDelegate, UITableViewDataSource {
     
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return 3
+        return communityPostCommentModels.isEmpty ? 1 : communityPostCommentModels.count
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        if indexPath.row == 0 {
-            let cell = CommunityMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
-            return cell
+        if communityPostCommentModels.isEmpty {
+            return UITableViewCell()
         } else {
-            let cell = CommunityReplyCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
+            let cell = RecommendMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.communityPostCommentModel = communityPostCommentModels[indexPath.row]
+            cell.frame = tableView.bounds
+            cell.layoutIfNeeded()
+            cell.reloadData()
             return cell
         }
     }
@@ -159,7 +161,11 @@ extension CommunityAllCommentView : UITableViewDelegate, UITableViewDataSource {
     }
     
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
-        return UITableView.automaticDimension
+        if communityPostCommentModels.isEmpty {
+            return 0
+        }else {
+            return communityPostCommentModels[indexPath.row].height ?? 0
+        }
     }
     
     func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
@@ -188,10 +194,15 @@ extension CommunityAllCommentView {
     func communityPostCommentApi(page:Int) {
         SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentsApi(postId: postId ?? 0, page: page) {
             [weak self] (communityPostCommentsModel) -> (Void) in
-            
             let commentsMdl = communityPostCommentsModel as? CommunityPostCommentsModel
             self?.communityPostCommentsModel = commentsMdl
             
+            if self?.communityPostCommentsModel?.pagination?.currentPage == 1{
+                self?.communityPostCommentModels.removeAll()
+            }
+            self?.communityPostCommentModels = (self?.communityPostCommentModels)! + (self?.communityPostCommentsModel?.data!)!
+            self?.tableView.reloadData()
+            
             let totalComments: Int = commentsMdl?.pagination?.total ?? 0
             self?.titleLabel.text = "全部评论 \(totalComments)"
             if totalComments == 0 {
@@ -201,15 +212,7 @@ extension CommunityAllCommentView {
                 self?.tableView.isHidden = false
                 self?.noCommentsLabel.isHidden = true
             }
-            
-            
-            
-//            if self?.communityPostCommentsModel?.pagination?.currentPage == 1{
-//                self?.communityPostCommentModels.removeAll()
-//            }
-//            self?.communityPostCommentModels = (self?.communityPostCommentModels)! + (self?.communityPostCommentsModel?.data!)!
-//            self?.tableView.reloadData()
-            
         }
+        
     }
 }

+ 41 - 12
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/View/CommunityVideoCoverCollectionCell.swift

@@ -33,9 +33,20 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
             avatarButton.kf.setImage(with: kURLImage(name: self.videoItemMdl?.avatar ?? ""), for: .normal, placeholder: kImage(name: "default_avatar"))
             personLabel.text = self.videoItemMdl?.username
             
-            commentBtn.titleLabel?.text = "\(self.videoItemMdl?.commentCount ?? 0)"
-            collectBtn.titleLabel?.text = "\(self.videoItemMdl?.collectCount ?? 0)"
-            likeBtn.titleLabel?.text = "\(self.videoItemMdl?.praiseCount ?? 0)"
+            // 点赞
+            if self.videoItemMdl?.isLike == 0 {
+                likeBtn.setTitle("\(self.videoItemMdl?.praiseCount ?? 0)", for: .normal)
+            } else {
+                likeBtn.setTitle("\(self.videoItemMdl?.praiseCount ?? 0)", for: .selected)
+            }
+            // 收藏
+            if self.videoItemMdl?.isCollect == 0 {
+                collectBtn.setTitle("\(self.videoItemMdl?.collectCount ?? 0)", for: .normal)
+            } else {
+                collectBtn.setTitle("\(self.videoItemMdl?.collectCount ?? 0)", for: .selected)
+            }
+            // 评论
+            commentBtn.setTitle("\(self.videoItemMdl?.commentCount ?? 0)", for: .normal)
             
             collectBtn.isSelected = self.videoItemMdl?.isCollect == 0 ? false : true
             likeBtn.isSelected = self.videoItemMdl?.isLike == 0 ? false : true
@@ -74,7 +85,7 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
     typealias ShareClosure = () -> Void
     var shareClosure : ShareClosure?
     
-    typealias ButtonClickClosure = (_ clickType: videoBtnClickType, _ uid: Int) -> Void
+    typealias ButtonClickClosure = (_ clickType: videoBtnClickType, _ uid: Int, _ postId: Int) -> Void
     var buttonClickClosure : ButtonClickClosure?
     
     class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> CommunityVideoCoverCollectionCell {
@@ -428,7 +439,7 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
         commentBtn.titleLabel?.font = kRegularFont14
         commentBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
             if let buttonClickClosure = self?.buttonClickClosure {
-                buttonClickClosure(videoBtnClickType.typeComment, self?.videoItemMdl?.uid ?? 0)
+                buttonClickClosure(videoBtnClickType.typeComment, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
             }
         }).disposed(by: disposeBag)
         return commentBtn
@@ -436,15 +447,24 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
     
     private lazy var collectBtn: UIButton = {
         let collectBtn = UIButton(type: UIButton.ButtonType.custom)
-        collectBtn.setTitle("0", for: UIControl.State.normal)
         collectBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
         collectBtn.setImage(kImage(name: "video_btn_collect_white"), for: UIControl.State.normal)
         collectBtn.setImage(kImage(name: "btn_collect_pre"), for: UIControl.State.selected)        
         collectBtn.titleLabel?.font = kRegularFont14
         collectBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
             collectBtn.isSelected = !collectBtn.isSelected
+            // 本地修改收藏数据
+            var collectCount = self?.videoItemMdl?.collectCount ?? 0
+            if self?.videoItemMdl?.isCollect == 0 {
+                collectBtn.setTitle("\(collectCount)", for: .normal)
+                collectBtn.setTitle("\(collectCount+1)", for: .selected)
+            } else {
+                collectBtn.setTitle("\(collectCount)", for: .selected)
+                collectBtn.setTitle("\(collectCount-1)", for: .normal)
+            }
+            // 点击回调
             if let buttonClickClosure = self?.buttonClickClosure {
-                buttonClickClosure(videoBtnClickType.typeCollect, self?.videoItemMdl?.uid ?? 0)
+                buttonClickClosure(videoBtnClickType.typeCollect, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
             }
         }).disposed(by: disposeBag)
         return collectBtn
@@ -452,15 +472,24 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
     
     private lazy var likeBtn: UIButton = {
         let likeBtn = UIButton(type: UIButton.ButtonType.custom)
-        likeBtn.setTitle("0", for: UIControl.State.normal)
         likeBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
         likeBtn.setImage(kImage(name: "video_btn_praise_white"), for: UIControl.State.normal)
         likeBtn.setImage(kImage(name: "btn_praise_pre_36px"), for: UIControl.State.selected)
         likeBtn.titleLabel?.font = kRegularFont14
         likeBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
             likeBtn.isSelected = !likeBtn.isSelected
+            // 本地修改点赞数据
+            var praiseCount = self?.videoItemMdl?.praiseCount ?? 0
+            if self?.videoItemMdl?.isLike == 0 {
+                likeBtn.setTitle("\(praiseCount)", for: .normal)
+                likeBtn.setTitle("\(praiseCount+1)", for: .selected)
+            } else {
+                likeBtn.setTitle("\(praiseCount)", for: .selected)
+                likeBtn.setTitle("\(praiseCount-1)", for: .normal)
+            }
+            // 点击回调
             if let buttonClickClosure = self?.buttonClickClosure {
-                buttonClickClosure(videoBtnClickType.typeLike, self?.videoItemMdl?.uid ?? 0)
+                buttonClickClosure(videoBtnClickType.typeLike, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
             }
         }).disposed(by: disposeBag)
         return likeBtn
@@ -486,7 +515,7 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
         let textBtn = UIButton(type: UIButton.ButtonType.custom)
         textBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
             if let buttonClickClosure = self?.buttonClickClosure {
-                buttonClickClosure(videoBtnClickType.typeComment, self?.videoItemMdl?.uid ?? 0)
+                buttonClickClosure(videoBtnClickType.typeComment, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
             }
         }).disposed(by: disposeBag)
         return textBtn
@@ -540,7 +569,7 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
         avatarButton.rx.tap.subscribe(onNext: {
             [weak self] (data) in
             if let buttonClickClosure = self?.buttonClickClosure {
-                buttonClickClosure(videoBtnClickType.typePerson, self?.videoItemMdl?.uid ?? 0)
+                buttonClickClosure(videoBtnClickType.typePerson, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
             }
         }).disposed(by: disposeBag)
         return avatarButton
@@ -561,7 +590,7 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
         followButton.setTitleColor(kffffffColor, for: .normal)
         followButton.rx.tap.subscribe(onNext: {[weak self] (data) in
             if let buttonClickClosure = self?.buttonClickClosure {
-                buttonClickClosure(videoBtnClickType.typeFollow, self?.videoItemMdl?.uid ?? 0)
+                buttonClickClosure(videoBtnClickType.typeFollow, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
             }
         }).disposed(by: disposeBag)
         return followButton

+ 8 - 7
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/ViewController/CommunityVideoListController.swift

@@ -136,15 +136,16 @@ extension CommunityVideoListController: UICollectionViewDelegateFlowLayout,UICol
             print("------点击了[分享]")
         }
         cell.buttonClickClosure = {
-            [weak self] (clickType, uid) in
+            [weak self] (clickType, uid, postId) in
             switch clickType {
             case videoBtnClickType.typeComment:
-                self?.showCommentView(uid: uid)
+                self?.showCommentView(postId: postId)
                 
             case videoBtnClickType.typeLike:
-                print("添加喜欢")
-            case videoBtnClickType.typeCollect:
-                print("添加收藏")
+                VirusViewModel.shared.praise(communityVideoItemModel: (self?.videoItemList?[indexPath.row])!)
+                
+            case videoBtnClickType.typeCollect:                VirusViewModel.shared.collection(communityVideoItemModel: (self?.videoItemList?[indexPath.row])!)
+                
             case videoBtnClickType.typePerson:
                 let vc = OtherPersonalCenterViewController()
                 vc.uid = uid
@@ -217,9 +218,9 @@ extension CommunityVideoListController {
         }
     }
     
-    func showCommentView(uid: Int) {
+    func showCommentView(postId: Int) {
         
-        AlertSheetView.commentAlertSheetView(postId: uid, cancelClosure: {
+        AlertSheetView.commentAlertSheetView(postId: postId, cancelClosure: {
             [weak self] in
             
         }) {

+ 104 - 0
RainbowPlanet/RainbowPlanet/ViewModel/Virus/VirusViewModel.swift

@@ -328,3 +328,107 @@ extension VirusViewModel {
         })
     }
 }
+
+
+// MARK: - CommunityVideoItemModel
+extension VirusViewModel {
+    
+    /// 点赞
+    ///
+    /// - Parameters:
+    ///   - communityVideoItemModel: 帖子模型
+    ///   - completion: 回调
+    func virueRecordAddApiPraise(communityVideoItemModel:CommunityVideoItemModel,completion: @escaping (Int) -> Void) {
+        let virueRecordAddParameterModel = VirueRecordAddParameterModel()
+        virueRecordAddParameterModel.behaviorId = (ConfigModel.shared.object()?.virus?.like ?? "")
+        virueRecordAddParameterModel.behaviorFlag = BehaviorFlagType.like.rawValue
+        if communityVideoItemModel.isLike == 0 {
+            virueRecordAddParameterModel.behaviorValue = 1
+        }else {
+            virueRecordAddParameterModel.behaviorValue = 0
+        }
+        virueRecordAddParameterModel.postId = communityVideoItemModel.id
+        virueRecordAddParameterModel.postAuthorUid = "\(communityVideoItemModel.uid!)"
+        if communityVideoItemModel.title == nil ||  communityVideoItemModel.title == "" {
+            virueRecordAddParameterModel.postDesc = String(describing: communityVideoItemModel.content!.prefix(20))
+        }else {
+            virueRecordAddParameterModel.postDesc = communityVideoItemModel.title
+        }
+        virueRecordAddParameterModel.postType = communityVideoItemModel.type
+        virueRecordAddParameterModel.postCover = communityVideoItemModel.img
+        virueRecordAddParameterModel.actionId = "\(communityVideoItemModel.id!)"
+        
+        SwiftMoyaNetWorkServiceVirus.shared().virueRecordAddApi(virueRecordAddParameterModel: virueRecordAddParameterModel, completion: {(data) -> (Void) in
+            if communityVideoItemModel.isLike == 0 {
+                completion(1)
+            }else {
+                completion(0)
+            }
+        })
+    }
+    
+    /// 点赞
+    ///
+    /// - Parameters:
+    ///   - communityVideoItemModel: 帖子模型
+    func praise(communityVideoItemModel: CommunityVideoItemModel) {
+        virueRecordAddApiPraise(communityVideoItemModel: communityVideoItemModel, completion: {(isLike) in
+            let isLike = isLike as Int
+            var praiseCount : Int = communityVideoItemModel.praiseCount ?? 0
+            if isLike == 0 {
+                praiseCount = (communityVideoItemModel.praiseCount ?? 0) - 1
+            }else {
+                praiseCount = (communityVideoItemModel.praiseCount ?? 0) + 1
+            }
+            communityVideoItemModel.praiseCount = praiseCount
+            communityVideoItemModel.isLike = isLike
+        })
+    }
+    
+    
+    /// 收藏
+    ///
+    /// - Parameters:
+    ///   - communityVideoItemModel: 帖子模型
+    ///   - completion: 回调
+    func virueRecordAddApiCollection(communityVideoItemModel:CommunityVideoItemModel,completion: @escaping (Int) -> Void) {
+        let virueRecordAddParameterModel = VirueRecordAddParameterModel()
+        virueRecordAddParameterModel.behaviorId = (ConfigModel.shared.object()?.virus?.collect ?? "")
+        virueRecordAddParameterModel.behaviorFlag = BehaviorFlagType.collect.rawValue
+        if communityVideoItemModel.isCollect == 0 {
+            virueRecordAddParameterModel.behaviorValue = 1
+        }else {
+            virueRecordAddParameterModel.behaviorValue = 0
+        }
+        virueRecordAddParameterModel.postId = communityVideoItemModel.id
+        virueRecordAddParameterModel.postAuthorUid = "\(communityVideoItemModel.uid!)"
+        if communityVideoItemModel.title == nil ||  communityVideoItemModel.title == "" {
+            virueRecordAddParameterModel.postDesc = String(describing: communityVideoItemModel.content!.prefix(20))
+        }else {
+            virueRecordAddParameterModel.postDesc = communityVideoItemModel.title
+        }
+        virueRecordAddParameterModel.postType = communityVideoItemModel.type
+        virueRecordAddParameterModel.postCover = communityVideoItemModel.img
+        virueRecordAddParameterModel.actionId = "\(communityVideoItemModel.id!)"
+        virueRecordAddParameterModel.targetId = "\((UserModel.shared().getModel()?.uid)!)"
+        
+        SwiftMoyaNetWorkServiceVirus.shared().virueRecordAddApi(virueRecordAddParameterModel: virueRecordAddParameterModel, completion: {(data) -> (Void) in
+            if communityVideoItemModel.isCollect == 0 {
+                completion(1)
+            }else {
+                completion(0)
+            }
+        })
+    }
+    
+    /// 收藏
+    ///
+    /// - Parameters:
+    ///   - communityVideoItemModel: 帖子模型
+    func collection(communityVideoItemModel: CommunityVideoItemModel) {
+        virueRecordAddApiCollection(communityVideoItemModel: communityVideoItemModel, completion: {(isCollect) in
+            let isCollect = isCollect as Int
+            communityVideoItemModel.isCollect = isCollect
+        })
+    }
+}