Browse Source

全部完成

南鑫林 5 years ago
parent
commit
d79378d253

+ 11 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/View/Cell/CardContent/User/CardContentUserTableViewCell.swift

@@ -150,6 +150,11 @@ class CardContentUserTableViewCell: UITableViewCell {
             titleButton.setTitle(communityRecommendDataModel?.username, for: UIControl.State.normal)
             timeLabel.text = communityRecommendDataModel?.createdAt
             followType = FollowType(rawValue: communityRecommendDataModel?.isFollow ?? 0)
+            if communityRecommendDataModel?.uid == UserModel.shared().getModel()?.uid {
+                followButton.isHidden = true
+            }else {
+                followButton.isHidden = false
+            }
         }
     }
     
@@ -159,6 +164,12 @@ class CardContentUserTableViewCell: UITableViewCell {
             titleButton.setTitle(communityFollowDataModel?.relateData?.username, for: UIControl.State.normal)
             timeLabel.text = communityFollowDataModel?.relateData?.createdAt
             followType = FollowType(rawValue: communityFollowDataModel?.relateData?.isFollow ?? 0)
+
+            if communityFollowDataModel?.relateData?.uid == UserModel.shared().getModel()?.uid {
+                followButton.isHidden = true
+            }else {
+                followButton.isHidden = false
+            }
         }
     }
     

+ 6 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/View/Cell/FollowStatus/CommunityFollowStatusTableViewCell.swift

@@ -300,6 +300,7 @@ class CommunityFollowStatusTableViewCell: UITableViewCell {
             skittlesTitleLabel.text = "收获 \(communityFollowDataModel?.content?.beans ?? 0) 个彩虹豆"
 
             communityFollowType = CommunityFollowType(rawValue: communityFollowDataModel?.type ?? "1")
+
         }
     }
     
@@ -311,6 +312,11 @@ class CommunityFollowStatusTableViewCell: UITableViewCell {
                 timeStatusLabel.text = "\(communityFollowDataModel?.createdAt ?? "") 关注了"
                 avatarOtherButton.kf.setImage(with: kURLImage(name: communityFollowDataModel?.relateData?.avatar ?? ""), for: UIControl.State.normal , placeholder: kImage(name: "default_avatar"))
                 titleOtherButton.setTitle(communityFollowDataModel?.relateData?.username, for: UIControl.State.normal)
+                if communityFollowDataModel?.relateData?.uid == UserModel.shared().getModel()?.uid {
+                    followButton.isHidden = true
+                }else {
+                    followButton.isHidden = false
+                }
                 followType = FollowType(rawValue: communityFollowDataModel?.relateData?.isFollow ?? 0)
                 oneCardView.isHidden = false
                 twoCardView.isHidden = true

+ 1 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityFindFriends/ViewController/CommunityFindFriendsViewController.swift

@@ -64,6 +64,7 @@ class CommunityFindFriendsViewController: BaseViewController {
                         cmsMemberModel.followStatus = followStatusModel?.isFollowStatus
                     }
                 }
+                self?.tableView.reloadData()
             }
         }
     }

+ 13 - 2
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/Controller/CommunityRecommendController.swift

@@ -221,7 +221,6 @@ class CommunityRecommendController: BaseViewController {
                 self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
                 self?.tableView.reloadData()
             }
-            self?.tableView.reloadData()
         }
         
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("islikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
@@ -229,7 +228,14 @@ class CommunityRecommendController: BaseViewController {
             if self?.communityPostDetailModel?.uid == followStatusModel?.uid {
                 self?.communityPostDetailModel?.isDislike = followStatusModel?.isFollowStatus
                 self?.commentView.communityPostDetailModel = self?.communityPostDetailModel
-                self?.tableView.reloadData()
+            }
+            
+            if !(self?.communityPostCommentModels.isEmpty ?? true) {
+                for communityPostDataModel in (self?.communityPostDataModels)! {
+                    if communityPostDataModel.uid == followStatusModel?.uid {
+                        communityPostDataModel.isLike = followStatusModel?.isFollowStatus
+                    }
+                }
             }
             self?.tableView.reloadData()
         }
@@ -316,6 +322,11 @@ extension CommunityRecommendController {
             self?.communityPostDetailModel = communityPostDetailModel as? CommunityPostDetailModel
             self?.avatarButton.kf.setImage(with: kURLImage(name: self?.communityPostDetailModel?.avatar ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
             self?.nameButton.setTitle(self?.communityPostDetailModel?.username, for: UIControl.State.normal)
+            if self?.communityPostDetailModel?.uid == UserModel.shared().getModel()?.uid {
+                self?.followButton.isHidden = true
+            }else {
+                self?.followButton.isHidden = false
+            }
             CommunityFollowUserViewModel.shared.setFollowType(followButton: (self?.followButton)!, followType: FollowType(rawValue: self?.communityPostDetailModel?.isFollow ?? 0) ?? .futureFollow)
             self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
             self?.commentView.communityPostDetailModel = self?.communityPostDetailModel

+ 5 - 43
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/View/SearchContentListCollectionCell.swift

@@ -11,6 +11,9 @@ import RxSwift
 
 class SearchContentListCollectionCell: UICollectionViewCell {
     
+    
+
+    
     let disposeBag = DisposeBag()
     
     typealias LikeSelectBlock = (_ isLiked: Int) -> Void
@@ -144,14 +147,14 @@ class SearchContentListCollectionCell: UICollectionViewCell {
         return nameButton
     }()
     
-    private lazy var likeBtn: UIButton = {
+    lazy var likeBtn: UIButton = {
         let likeBtn = UIButton(type: UIButton.ButtonType.custom)
         likeBtn.setTitleColor(k999999Color, for: UIControl.State.normal)
         likeBtn.setImage(kImage(name: "btn_praise"), for: UIControl.State.normal)
         likeBtn.setImage(kImage(name: "btn_praise_pre_36px"), for: UIControl.State.selected)
         likeBtn.titleLabel?.font = kRegularFont12
         likeBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-            self?.virueRecordAddApi(communityPostDataModel: (self?.communityPostDataModel!)!)
+            VirusViewModel.shared.virueRecordAddApi(communityPostDataModel: (self?.communityPostDataModel!)!, cell: self!)
         }).disposed(by: disposeBag)
         return likeBtn
     }()
@@ -198,44 +201,3 @@ class SearchContentListCollectionCell: UICollectionViewCell {
     }
 }
 
-extension SearchContentListCollectionCell {
-    func virueRecordAddApi(communityPostDataModel:CommunityPostDataModel) {
-        let virueRecordAddParameterModel = VirueRecordAddParameterModel()
-        virueRecordAddParameterModel.behaviorId = (ConfigModel.shared.object()?.virus?.like ?? "")
-        virueRecordAddParameterModel.behaviorFlag = BehaviorFlagType.like.rawValue
-        if communityPostDataModel.isLike == 0 {
-            virueRecordAddParameterModel.behaviorValue = 1
-        }else {
-            virueRecordAddParameterModel.behaviorValue = 0
-        }
-        virueRecordAddParameterModel.postId = communityPostDataModel.id
-        virueRecordAddParameterModel.postAuthorUid = "\(communityPostDataModel.uid!)"
-        virueRecordAddParameterModel.postDesc = communityPostDataModel.title
-        virueRecordAddParameterModel.postCover = communityPostDataModel.img
-        virueRecordAddParameterModel.actionId = "\(communityPostDataModel.id!)"
-        virueRecordAddParameterModel.targetId = "\((UserModel.shared().getModel()?.uid)!)"
-        virueRecordAddParameterModel.postType = communityPostDataModel.type
-        
-        SwiftMoyaNetWorkServiceVirus.shared().virueRecordAddApi(virueRecordAddParameterModel: virueRecordAddParameterModel, completion: {
-            [weak self] (data) -> (Void) in
-            if communityPostDataModel.isLike == 0 {
-                self?.communityPostDataModel?.isLike = 1
-                self?.likeBtn.isSelected = true
-                let praiseCount = (communityPostDataModel.praiseCount ?? 0) + 1
-                self?.likeBtn.setTitle("\(praiseCount)", for: UIControl.State.normal)
-                self?.communityPostDataModel?.praiseCount = praiseCount
-
-            }else {
-                self?.communityPostDataModel?.isLike = 0
-                self?.likeBtn.isSelected = false
-                let praiseCount = (communityPostDataModel.praiseCount ?? 0) - 1
-
-                self?.likeBtn.setTitle("\(praiseCount)", for: UIControl.State.normal)
-                self?.communityPostDataModel?.praiseCount = praiseCount
-
-            }
-            self?.likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
-        })
-
-    }
-}

+ 19 - 1
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/ViewController/SearchContentListViewController.swift

@@ -9,7 +9,14 @@
 import UIKit
 import JXSegmentedView
 class SearchContentListViewController: UIViewController {
-
+    
+    deinit {
+        if observe != nil {
+            NotificationCenter.default.removeObserver(observe!)
+        }
+    }
+    weak var observe : NSObjectProtocol?
+    
     var keyWord : String = ""
     var communityPostDataModels = Array<CommunityPostDataModel>()
     var heights = Array<CGFloat>()
@@ -49,6 +56,17 @@ class SearchContentListViewController: UIViewController {
             [weak self] (page) in
             self?.communityPostsApi(page: page)
         }
+        observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("islikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
+            let followStatusModel = notification.object as? FollowStatusModel
+            if !(self?.communityPostDataModels.isEmpty ?? true) {
+                for communityPostDataModel in (self?.communityPostDataModels)! {
+                    if communityPostDataModel.uid == followStatusModel?.uid {
+                        communityPostDataModel.isLike = followStatusModel?.isFollowStatus
+                    }
+                }
+            }
+            self?.collectionView.reloadData()
+        }
     }
     
     private lazy var collectionView: UICollectionView = {

+ 21 - 0
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchUser/ViewController/SearchUserListViewController.swift

@@ -9,6 +9,13 @@
 import UIKit
 import JXSegmentedView
 class SearchUserListViewController: UIViewController {
+    
+    deinit {
+        if observe != nil {
+            NotificationCenter.default.removeObserver(observe!)
+        }
+    }
+    weak var observe : NSObjectProtocol?
 
     var keyWord : String = ""
     var searchMemberModels = Array<SearchMemberModel>()
@@ -46,6 +53,20 @@ class SearchUserListViewController: UIViewController {
             [weak self] (page) in
             self?.userMemberSearchMemberApi(page: page)
         }
+        
+        observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("followApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
+            let followStatusModel = notification.object as? FollowStatusModel
+            
+            if !(self?.searchMemberModels.isEmpty ?? true) {
+                for searchMemberModel in (self?.searchMemberModels)! {
+                    if searchMemberModel.uid == followStatusModel?.uid {
+                        searchMemberModel.followStatus = followStatusModel?.isFollowStatus
+                    }
+                }
+                self?.tableView.reloadData()
+            }
+        }
+        
     }
     
     lazy var tableView: UITableView = {

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

@@ -771,3 +771,53 @@ extension VirusViewModel {
         })
     }
 }
+
+extension VirusViewModel {
+    func virueRecordAddApi(communityPostDataModel:CommunityPostDataModel,cell:SearchContentListCollectionCell) {
+        let virueRecordAddParameterModel = VirueRecordAddParameterModel()
+        virueRecordAddParameterModel.behaviorId = (ConfigModel.shared.object()?.virus?.like ?? "")
+        virueRecordAddParameterModel.behaviorFlag = BehaviorFlagType.like.rawValue
+        if communityPostDataModel.isLike == 0 {
+            virueRecordAddParameterModel.behaviorValue = 1
+        }else {
+            virueRecordAddParameterModel.behaviorValue = 0
+        }
+        virueRecordAddParameterModel.postId = communityPostDataModel.id
+        virueRecordAddParameterModel.postAuthorUid = "\(communityPostDataModel.uid!)"
+        virueRecordAddParameterModel.postDesc = communityPostDataModel.title
+        virueRecordAddParameterModel.postCover = communityPostDataModel.img
+        virueRecordAddParameterModel.actionId = "\(communityPostDataModel.id!)"
+        virueRecordAddParameterModel.targetId = "\((UserModel.shared().getModel()?.uid)!)"
+        virueRecordAddParameterModel.postType = communityPostDataModel.type
+        
+        SwiftMoyaNetWorkServiceVirus.shared().virueRecordAddApi(virueRecordAddParameterModel: virueRecordAddParameterModel, completion: {
+            (data) -> (Void) in
+            let followStatusModel = FollowStatusModel()
+            followStatusModel.uid = communityPostDataModel.uid
+            if communityPostDataModel.isLike == 0 {
+                communityPostDataModel.isLike = 1
+                followStatusModel.isFollowStatus = 1
+
+                cell.likeBtn.isSelected = true
+                let praiseCount = (communityPostDataModel.praiseCount ?? 0) + 1
+                cell.likeBtn.setTitle("\(praiseCount)", for: UIControl.State.normal)
+                communityPostDataModel.praiseCount = praiseCount
+                
+            }else {
+                communityPostDataModel.isLike = 0
+                followStatusModel.isFollowStatus = 0
+                cell.likeBtn.isSelected = false
+                let praiseCount = (communityPostDataModel.praiseCount ?? 0) - 1
+                
+                cell.likeBtn.setTitle("\(praiseCount)", for: UIControl.State.normal)
+                communityPostDataModel.praiseCount = praiseCount
+                
+            }
+            cell.likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "isLikeApi"), object: followStatusModel)
+
+        })
+
+        
+    }
+}