Преглед на файлове

Merge branch 'feature/jeremy' into develop

# Conflicts:
#	RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj
南鑫林 преди 5 години
родител
ревизия
4acc024a48
променени са 24 файла, в които са добавени 746 реда и са изтрити 154 реда
  1. 16 0
      RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj
  2. 94 0
      RainbowPlanet/RainbowPlanet/Model/CommunityModel/CommunityPostDetailModel.swift
  3. 1 1
      RainbowPlanet/RainbowPlanet/Model/CommunityModel/CommunityRecommendFeedModel.swift
  4. 3 8
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/View/Cell/CardContent/Comment/CardContentCommnetTableViewCell.swift
  5. 1 1
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/View/Cell/FollowStatus/CommunityFollowStatusTableViewCell.swift
  6. 1 1
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Follow/CommunityFollowViewController.swift
  7. 8 4
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Main/CommunityViewController.swift
  8. 3 2
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Recommend/CommunityRecommnendViewController.swift
  9. 4 1
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityFeaturedTopics/ViewController/CommunityFeaturedTopicsViewController.swift
  10. 14 0
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/Controller/CollectionViewHeightModel.swift
  11. 282 88
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/Controller/CommunityRecommendController.swift
  12. 61 0
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/CommunityPostDetailFSPagerViewCell.swift
  13. 92 0
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/CommunityPostDetailTableViewHeaderView.swift
  14. 14 5
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/RecommendBottomCommentView.swift
  15. 55 32
      RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/RecommendSimilarCell.swift
  16. 18 4
      RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/View/SearchContentListCollectionCell.swift
  17. 2 2
      RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/ViewController/SearchContentListViewController.swift
  18. 16 0
      RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceCommunity/SwiftMoyaNetWorkServiceCommunity.swift
  19. 16 4
      RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceCommunity/SwiftMoyaServiceCommunityApi.swift
  20. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/Assets.xcassets/NavigationBarIcons/nav_share_black.imageset/Contents.json
  21. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/Assets.xcassets/NavigationBarIcons/nav_share_black.imageset/nav_share_black@2x.png
  22. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/Assets.xcassets/NavigationBarIcons/nav_share_black.imageset/nav_share_black@3x.png
  23. 1 1
      RainbowPlanet/RainbowPlanet/Tools/WaterFallLayout/WaterFallLayout.h
  24. 22 0
      RainbowPlanet/RainbowPlanet/ViewModel/Community/CommunityFollowUserViewModel.swift

+ 16 - 0
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -318,6 +318,10 @@
 		A7C0FDFB22B6672F00BC1E86 /* PopularVideoTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C0FDFA22B6672F00BC1E86 /* PopularVideoTableViewCell.swift */; };
 		A7C0FE0022B66E5A00BC1E86 /* CommunityFeaturedTopicsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C0FDFF22B66E5A00BC1E86 /* CommunityFeaturedTopicsViewController.swift */; };
 		A7C0FE0222B682DB00BC1E86 /* CommunityFeaturedTopicsHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C0FE0122B682DB00BC1E86 /* CommunityFeaturedTopicsHeaderView.swift */; };
+		A7C2566F22CB7A0C00420828 /* CommunityPostDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C2566E22CB7A0C00420828 /* CommunityPostDetailModel.swift */; };
+		A7C2567122CC895F00420828 /* CommunityPostDetailTableViewHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C2567022CC895F00420828 /* CommunityPostDetailTableViewHeaderView.swift */; };
+		A7C2567322CC8BB000420828 /* CommunityPostDetailFSPagerViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C2567222CC8BB000420828 /* CommunityPostDetailFSPagerViewCell.swift */; };
+		A7C2567622CCB38D00420828 /* CollectionViewHeightModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C2567522CCB38D00420828 /* CollectionViewHeightModel.swift */; };
 		A7C3DD1A226422BF00FA262E /* SwiftMoyaServiceSMSApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C3DD19226422BF00FA262E /* SwiftMoyaServiceSMSApi.swift */; };
 		A7C3DD1C226422D200FA262E /* SwiftMoyaNetWorkServiceSMS.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C3DD1B226422D200FA262E /* SwiftMoyaNetWorkServiceSMS.swift */; };
 		A7CC74DE22703B4A003C4F38 /* MineModule.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A7CC74DD22703B4A003C4F38 /* MineModule.xcassets */; };
@@ -994,6 +998,10 @@
 		A7C0FDFA22B6672F00BC1E86 /* PopularVideoTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopularVideoTableViewCell.swift; sourceTree = "<group>"; };
 		A7C0FDFF22B66E5A00BC1E86 /* CommunityFeaturedTopicsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityFeaturedTopicsViewController.swift; sourceTree = "<group>"; };
 		A7C0FE0122B682DB00BC1E86 /* CommunityFeaturedTopicsHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityFeaturedTopicsHeaderView.swift; sourceTree = "<group>"; };
+		A7C2566E22CB7A0C00420828 /* CommunityPostDetailModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommunityPostDetailModel.swift; sourceTree = "<group>"; };
+		A7C2567022CC895F00420828 /* CommunityPostDetailTableViewHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityPostDetailTableViewHeaderView.swift; sourceTree = "<group>"; };
+		A7C2567222CC8BB000420828 /* CommunityPostDetailFSPagerViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityPostDetailFSPagerViewCell.swift; sourceTree = "<group>"; };
+		A7C2567522CCB38D00420828 /* CollectionViewHeightModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewHeightModel.swift; sourceTree = "<group>"; };
 		A7C3DD19226422BF00FA262E /* SwiftMoyaServiceSMSApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftMoyaServiceSMSApi.swift; sourceTree = "<group>"; };
 		A7C3DD1B226422D200FA262E /* SwiftMoyaNetWorkServiceSMS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftMoyaNetWorkServiceSMS.swift; sourceTree = "<group>"; };
 		A7CC74DD22703B4A003C4F38 /* MineModule.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = MineModule.xcassets; sourceTree = "<group>"; };
@@ -3889,6 +3897,7 @@
 				BD981A8E22C9FEEF0043D951 /* CommunityPublishModel.swift */,
 				BD0F61F722CAFC8B004650FB /* CommunityVideoAuthModel.swift */,
 				BDE8AD1522CC59EE00E03C65 /* CommunityVideoListModel.swift */,
+				A7C2566E22CB7A0C00420828 /* CommunityPostDetailModel.swift */,
 			);
 			path = CommunityModel;
 			sourceTree = "<group>";
@@ -4667,6 +4676,7 @@
 			isa = PBXGroup;
 			children = (
 				BD2FCBE122B21CF70006D974 /* CommunityRecommendController.swift */,
+				A7C2567522CCB38D00420828 /* CollectionViewHeightModel.swift */,
 			);
 			path = Controller;
 			sourceTree = "<group>";
@@ -4681,6 +4691,8 @@
 				BD2FCBE922B267280006D974 /* RecommendNoneCommentCell.swift */,
 				BDAF83A122B330540004BCC3 /* RecommendSimilarCell.swift */,
 				BDAF83A722B343C50004BCC3 /* RecommendBottomCommentView.swift */,
+				A7C2567022CC895F00420828 /* CommunityPostDetailTableViewHeaderView.swift */,
+				A7C2567222CC8BB000420828 /* CommunityPostDetailFSPagerViewCell.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -5950,6 +5962,7 @@
 				A771F07C226D4E1C007999DB /* AddressPOITableViewCell.swift in Sources */,
 				A70B842E228F97EC00882BC5 /* ProcuctDetailSelectSkuTableViewCell.swift in Sources */,
 				A72A72AE22321DE000B21995 /* CountdownButton.swift in Sources */,
+				A7C2567322CC8BB000420828 /* CommunityPostDetailFSPagerViewCell.swift in Sources */,
 				BD929CCE22B904A30098C139 /* PublishViewController.swift in Sources */,
 				A71738AD228AB7B2000AEA6A /* ProductCommentListModel.swift in Sources */,
 				A7C0FDF822B6671C00BC1E86 /* PopularVideoCollectionViewCell.swift in Sources */,
@@ -5998,6 +6011,7 @@
 				A7F2D6BD22B09F930093000B /* CommunityNavigationBarView.swift in Sources */,
 				A7274C5C228EE636000E3A07 /* LBXScanLineAnimation.swift in Sources */,
 				A739121A229F75F50033177E /* JXPagingMainTableView.swift in Sources */,
+				A7C2566F22CB7A0C00420828 /* CommunityPostDetailModel.swift in Sources */,
 				A7CC7524227190FB003C4F38 /* AccountSecurityView.swift in Sources */,
 				A7931E1422AF9E4000297D0A /* TopicSelectionCollectionViewCell.swift in Sources */,
 				BD0FAA4922C4663100DDFB37 /* AlivcEditItemModel.m in Sources */,
@@ -6065,6 +6079,7 @@
 				A7A98E3C228036D7005306E9 /* ShoppingMallCategoryCollectionViewCell.swift in Sources */,
 				A7C0FDEB22B4C6C300BC1E86 /* CardContentCommentListFooterView.swift in Sources */,
 				BD3AA45822AE63EC00EF4F20 /* MessageMainViewController.swift in Sources */,
+				A7C2567122CC895F00420828 /* CommunityPostDetailTableViewHeaderView.swift in Sources */,
 				A71AF0AA226EDDF5001730FE /* SearchView.swift in Sources */,
 				A7FF1583228C843700A85748 /* OrderDetailExpressSelfMentionTableViewCell.swift in Sources */,
 				A7A98E0E227EC0C6005306E9 /* CategoryTableViewCell.swift in Sources */,
@@ -6076,6 +6091,7 @@
 				A7B4E72F2281773F0012914A /* ProductFloorCenterTitleView.swift in Sources */,
 				A7AA9F5822C5F6150086498B /* SwiftMoyaServiceVirusApi.swift in Sources */,
 				A7284A542252FB5C000BAEC4 /* PaginationModel.swift in Sources */,
+				A7C2567622CCB38D00420828 /* CollectionViewHeightModel.swift in Sources */,
 				A7D5F26122C0C2F300F8E9AF /* UserFollowsModel.swift in Sources */,
 				A72A72D022321E2700B21995 /* FontMacro.swift in Sources */,
 				A74322A022B8D1F30017C367 /* MyFollowAndFanViewController.swift in Sources */,

+ 94 - 0
RainbowPlanet/RainbowPlanet/Model/CommunityModel/CommunityPostDetailModel.swift

@@ -0,0 +1,94 @@
+//
+//	CommunityPostDetailModel.swift
+//	Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport
+
+import Foundation 
+import ObjectMapper
+
+
+class CommunityPostDetailModel : NSObject, Mappable{
+
+	var availableBean : Int?
+	var avatar : String?
+	var commentCount : Int?
+	var content : String?
+	var createdAt : String?
+	var descUrl : String?
+	var h5url : String?
+	var id : Int?
+	var img : String?
+	var imgs : [String]?
+	var isCollect : Int?
+	var isDislike : Int?
+	var isFollow : Int?
+	var isLike : Int?
+	var location : String?
+	var praiseCount : Int?
+	var pv : Int?
+	var title : String?
+	var topic : [CommunityPostDetailTopicModel]?
+	var type : String?
+	var uid : Int?
+	var username : String?
+	var video : String?
+	var willCollectBean : Int?
+
+
+	class func newInstance(map: Map) -> Mappable?{
+		return CommunityPostDetailModel()
+	}
+	required init?(map: Map){}
+	private override init(){}
+
+	func mapping(map: Map)
+	{
+		availableBean <- map["available_bean"]
+		avatar <- map["avatar"]
+		commentCount <- map["comment_count"]
+		content <- map["content"]
+		createdAt <- map["created_at"]
+		descUrl <- map["desc_url"]
+		h5url <- map["h5url"]
+		id <- map["id"]
+		img <- map["img"]
+		imgs <- map["imgs"]
+		isCollect <- map["is_collect"]
+		isDislike <- map["is_dislike"]
+		isFollow <- map["is_follow"]
+		isLike <- map["is_like"]
+		location <- map["location"]
+		praiseCount <- map["praise_count"]
+		pv <- map["pv"]
+		title <- map["title"]
+		topic <- map["topic"]
+		type <- map["type"]
+		uid <- map["uid"]
+		username <- map["username"]
+		video <- map["video"]
+		willCollectBean <- map["will_collect_bean"]
+		
+	}
+
+}
+
+class CommunityPostDetailTopicModel : NSObject, Mappable{
+    
+    var id : Int?
+    var name : String?
+    
+    
+    class func newInstance(map: Map) -> Mappable?{
+        return CommunityPostDetailTopicModel()
+    }
+    required init?(map: Map){}
+    private override init(){}
+    
+    func mapping(map: Map)
+    {
+        id <- map["id"]
+        name <- map["name"]
+        
+    }
+    
+}
+

+ 1 - 1
RainbowPlanet/RainbowPlanet/Model/CommunityModel/CommunityRecommendFeedModel.swift

@@ -100,7 +100,7 @@ class CommunityRecommendTypeDataModel : NSObject, Mappable{
     
     // banner
     var image : String?
-    var linkContentId : Int?
+    var linkContentId : String?
     var postType : String?
     var type : Int?
     

+ 3 - 8
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/View/Cell/CardContent/Comment/CardContentCommnetTableViewCell.swift

@@ -84,16 +84,11 @@ class CardContentCommnetTableViewCell: UITableViewCell {
         return addCommnetButton
     }()
     
-    var communityRecommendDataModel: CommunityRecommendDataModel? {
+    var loadAvatar : Bool? {
         didSet {
-        }
-    }
-    
-    var communityFollowDataModel : CommunityFollowDataModel? {
-        didSet {
-            avatarButton.kf.setImage(with: kURLImage(name: communityFollowDataModel?.relateData?.avatar ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
+            avatarButton.kf.setImage(with: kURLImage(name: UserModel.shared().getModel()?.avatarurl ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
 
         }
     }
-    
+
 }

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

@@ -439,7 +439,7 @@ class CommunityFollowStatusTableViewCell: UITableViewCell {
     
     /// 内容详情页面
     @objc func contentDetail() {
-        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "CommunityContentDetailClosure"), object: nil)
+        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "CommunityContentDetailClosure"), object: communityFollowDataModel?.id)
     }
     
 }

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Follow/CommunityFollowViewController.swift

@@ -273,7 +273,7 @@ extension CommunityFollowViewController : UITableViewDelegate,UITableViewDataSou
         //评论
         case 5:
             let cell = CardContentCommnetTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
-            cell.communityFollowDataModel = communityFollowDataModel
+            cell.loadAvatar = true
             cell.addCommnetClosureName = {
                 
             }

+ 8 - 4
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Main/CommunityViewController.swift

@@ -99,7 +99,9 @@ class CommunityViewController: BaseViewController {
         // 内容详情页面
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("CommunityContentDetailClosure"), object: nil, queue: OperationQueue.main) {
             [weak self] (notification) in
+            let id = notification.object as? Int
             let vc = CommunityRecommendController()
+            vc.id = id ?? 0
             self?.navigationController?.pushViewController(vc, animated: true)
         }
         
@@ -115,10 +117,12 @@ class CommunityViewController: BaseViewController {
                 switch postType {
                 case .image?:
                     let vc = CommunityRecommendController()
+                    vc.id = Int(communityRecommendTypeDataModel?.linkContentId ?? "0") ?? 0
                     self?.navigationController?.pushViewController(vc, animated: true)
                     break
                 case .html?:
                     let vc = CommunityRecommendController()
+                    vc.id = Int(communityRecommendTypeDataModel?.linkContentId ?? "0") ?? 0
                     self?.navigationController?.pushViewController(vc, animated: true)
                     break
                 case .video?:
@@ -128,22 +132,22 @@ class CommunityViewController: BaseViewController {
                 }
                 break
             case .user?: //找朋友
-                if communityRecommendTypeDataModel?.linkContentId != UserModel.shared().getModel()?.uid {
+                if Int(communityRecommendTypeDataModel?.linkContentId ?? "0") ?? 0 != UserModel.shared().getModel()?.uid {
                     let vc = OtherPersonalCenterViewController()
-                    vc.uid = communityRecommendTypeDataModel?.linkContentId ?? 0
+                    vc.uid = Int(communityRecommendTypeDataModel?.linkContentId ?? "0") ?? 0
                     self?.navigationController?.pushViewController(vc, animated: true)
                 }
                 
                 break
             case .activity?: //活动
-                let url = kH5ActivityUrl + "id=\(communityRecommendTypeDataModel?.linkContentId ?? 0)"
+                let url = kH5ActivityUrl + "id=\(communityRecommendTypeDataModel?.linkContentId ?? "")"
                 let vc = H5CommonViewController()
                 vc.URLString = url
                 self?.navigationController?.pushViewController(vc, animated: true)
                 break
             case .topic?: //话题
                 let vc = CommunityFeaturedTopicsViewController()
-                vc.id = communityRecommendTypeDataModel?.linkContentId ?? 0
+                vc.id = Int(communityRecommendTypeDataModel?.linkContentId ?? "0") ?? 0
                 self?.navigationController?.pushViewController(vc, animated: true)
                 break
             default:

+ 3 - 2
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Recommend/CommunityRecommnendViewController.swift

@@ -201,7 +201,8 @@ extension CommunityRecommnendViewController : UITableViewDelegate,UITableViewDat
             //评论
             case 5:
                 let cell = CardContentCommnetTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
-                cell.communityRecommendDataModel = communityRecommendDataModel
+                cell.loadAvatar = true
+
                 cell.addCommnetClosureName = {
                     
                 }
@@ -238,7 +239,7 @@ extension CommunityRecommnendViewController : UITableViewDelegate,UITableViewDat
                 break
             //图片视频/内容标题/评论列表
             case 1,2,4:
-                   NotificationCenter.default.post(name: NSNotification.Name("CommunityContentDetailClosure"), object: nil)
+                   NotificationCenter.default.post(name: NSNotification.Name("CommunityContentDetailClosure"), object: communityRecommendDataModel.id)
                 break
             //点赞,收藏,分享
             case 3:

+ 4 - 1
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityFeaturedTopics/ViewController/CommunityFeaturedTopicsViewController.swift

@@ -316,7 +316,7 @@ extension CommunityFeaturedTopicsViewController : UITableViewDelegate,UITableVie
         //评论
         case 5:
             let cell = CardContentCommnetTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
-            cell.communityRecommendDataModel = communityRecommendDataModel
+            cell.loadAvatar = true
             cell.addCommnetClosureName = {
                 
             }
@@ -328,6 +328,8 @@ extension CommunityFeaturedTopicsViewController : UITableViewDelegate,UITableVie
     }
     
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
+
         switch indexPath.row {
         //贴子用户
         case 0:
@@ -335,6 +337,7 @@ extension CommunityFeaturedTopicsViewController : UITableViewDelegate,UITableVie
         //图片视频/内容标题/评论列表
         case 1,2,4:
             let vc = CommunityRecommendController()
+            vc.id = communityRecommendDataModel.id ?? 0
             self.navigationController?.pushViewController(vc, animated: true)
             break
         //点赞,收藏,分享

+ 14 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/Controller/CollectionViewHeightModel.swift

@@ -0,0 +1,14 @@
+//
+//  CollectionViewHeightModel.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/7/3.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+
+class CollectionViewHeightModel: NSObject {
+    var height : CGFloat?
+    
+}

+ 282 - 88
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/Controller/CommunityRecommendController.swift

@@ -10,25 +10,58 @@ import UIKit
 
 class CommunityRecommendController: BaseViewController {
     
+    
+
+    // 帖子Id
+    var id : Int = 0
+    var communityPostDetailModel : CommunityPostDetailModel?
+    // 相关推荐
+    var communityPostDataModels = Array<CommunityPostDataModel>()
+    var heights = Array<CGFloat>()
+    var cellHeightsDictionary = Dictionary<IndexPath, Any>()
+    var collectionViewHeightModel = CollectionViewHeightModel()
+
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         setupViews()
         setupLayouts()
+        setupData()
     }
     
     override func setupViews() {
-        navigationBar.title = "推荐详情"
-        view.backgroundColor = kf7f8faColor
         
+        view.backgroundColor = kf7f8faColor
+        navigationBar.addSubview(avatarButton)
+        navigationBar.addSubview(nameButton)
+        navigationBar.addSubview(followButton)
+        navigationBar.wr_setRightButton(image: kImage(name: "nav_share_black")!)
         view.addSubview(commentView)
         view.addSubview(tableView)
     }
     
     override func setupLayouts() {
+
+        avatarButton.snp.makeConstraints { (make) in
+            make.left.equalTo(navigationBar.leftButton.snp_right)
+            make.size.equalTo(30)
+            make.centerY.equalTo(navigationBar.leftButton)
+        }
+        nameButton.snp.makeConstraints { (make) in
+            make.centerY.equalTo(avatarButton)
+            make.left.equalTo(avatarButton.snp_right).offset(4)
+        }
+        followButton.snp_makeConstraints { (make) in
+            make.right.equalTo(navigationBar.rightButton.snp_left)
+            make.height.equalTo(24)
+            make.width.equalTo(60)
+            make.centerY.equalTo(navigationBar.leftButton)
+        }
+        
         commentView.snp.makeConstraints { (make) in
             make.left.right.equalToSuperview()
-            make.height.equalTo(48)
-            make.bottom.equalToSuperview().offset(-kSafeTabBarHeight)
+            make.height.equalTo(48+kSafeTabBarHeight)
+            make.bottom.equalToSuperview()
         }
         tableView.snp.makeConstraints { (make) in
             make.top.equalToSuperview().offset(kNavBarTotalHeight)
@@ -37,9 +70,31 @@ class CommunityRecommendController: BaseViewController {
         }        
     }
     
-    override func setupData() {
-        
-    }
+    lazy var avatarButton: UIButton = {
+        let avatarButton = UIButton(type: UIButton.ButtonType.custom)
+        avatarButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal)
+        avatarButton.cornerRadius = 15
+        avatarButton.masksToBounds = true
+        return avatarButton
+    }()
+    
+    lazy var nameButton: UIButton = {
+        let nameButton = UIButton(type: UIButton.ButtonType.custom)
+        nameButton.setTitle("昵称", for: UIControl.State.normal)
+        nameButton.setTitleColor(k262626Color, for: UIControl.State.normal)
+        nameButton.titleLabel?.font = kRegularFont14
+        return nameButton
+    }()
+    
+    lazy var followButton: UIButton = {
+        let followButton = UIButton(type: UIButton.ButtonType.custom)
+        followButton.titleLabel?.font = kMediumFont13
+        followButton.cornerRadius = 12
+        followButton.masksToBounds = true
+        followButton.layer.borderWidth = 0.5
+        followButton.isHidden = true
+        return followButton
+    }()
     
     lazy var tableView: UITableView = {
         let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
@@ -47,14 +102,54 @@ class CommunityRecommendController: BaseViewController {
         tableView.backgroundColor = kf7f8faColor
         tableView.dataSource = self
         tableView.delegate = self
-        tableView.estimatedRowHeight = 200
-        tableView.estimatedSectionFooterHeight = 0.000001
-        tableView.estimatedSectionHeaderHeight = 0.000001
+        tableView.estimatedRowHeight = 0
+        tableView.estimatedSectionHeaderHeight = 0
+        tableView.estimatedSectionFooterHeight = 0
         return tableView
     }()
+    lazy var communityPostDetailTableViewHeaderView: CommunityPostDetailTableViewHeaderView = {
+        let communityPostDetailTableViewHeaderView = CommunityPostDetailTableViewHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 211))
+        return communityPostDetailTableViewHeaderView
+    }()
     
     lazy var commentView: RecommendBottomCommentView = {
         let commentView = RecommendBottomCommentView()
+        return commentView
+    }()
+    
+    
+    
+    override func setupData() {
+        //头像
+        avatarButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid {
+                let vc = OtherPersonalCenterViewController()
+                vc.uid = self?.communityPostDetailModel?.uid ?? 0
+                self?.navigationController?.pushViewController(vc, animated: true)
+            }
+        }).disposed(by: disposeBag)
+        //用户昵称
+        nameButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid {
+                let vc = OtherPersonalCenterViewController()
+                vc.uid = self?.communityPostDetailModel?.uid ?? 0
+                self?.navigationController?.pushViewController(vc, animated: true)
+            }
+        }).disposed(by: disposeBag)
+        // 关注
+        followButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            CommunityFollowUserViewModel.shared.follow(communityPostDetailModel: (self?.communityPostDetailModel)!, button: (self?.followButton)!)
+        }).disposed(by: disposeBag)
+        
+        tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {
+            [weak self] (page) in
+            self?.communityPostsApi(page: page)
+            self?.communityPostDetailApi()
+        }
+        tableView.addFooterWithWithHeader(withAutomaticallyRefresh: false) {
+            [weak self] (page) in
+            self?.communityPostsApi(page: page)
+        }
         commentView.bottomClickClosure = {
             [weak self] (clickType) in
             switch clickType {
@@ -68,118 +163,217 @@ class CommunityRecommendController: BaseViewController {
                 print("添加收藏")
             }
         }
-        return commentView
-    }()
+    }
+    
+}
+
+extension CommunityRecommendController {
+    
+    func communityPostDetailApi() {
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPostDetailApi(id: id) { [weak self] (communityPostDetailModel) -> (Void) in
+            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)
+            CommunityFollowUserViewModel.shared.setFollowType(followButton: (self?.followButton)!, followType: FollowType(rawValue: self?.communityPostDetailModel?.isFollow ?? 0) ?? .futureFollow)
+            self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
+
+            if !(self?.communityPostDetailModel?.imgs?.isEmpty ?? true) {
+                self?.communityPostDetailTableViewHeaderView.tableView = self?.tableView
+                self?.tableView.tableHeaderView = self?.communityPostDetailTableViewHeaderView
+                
+            }else {
+                if self?.communityPostDetailModel?.img != nil ||  self?.communityPostDetailModel?.img != "" {
+                    self?.communityPostDetailTableViewHeaderView.tableView = self?.tableView
+                    self?.tableView.tableHeaderView = self?.communityPostDetailTableViewHeaderView
+                }
+            }
+            
+            if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid {
+                self?.followButton.isHidden = false
+            }else {
+                self?.followButton.isHidden = true
+            }
+
+        }
+    }
+    
+    /// 相关推荐
+    ///
+    /// - Parameter page: 分页
+    func communityPostsApi(page:Int) {
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPostsApi(page: page) {
+            [weak self] (communityPostsModel) -> (Void) in
+            let communityPostsModel = communityPostsModel as? CommunityPostsModel
+            if communityPostsModel?.pagination?.currentPage ?? 1  <= communityPostsModel?.pagination?.totalPages ?? 1 {
+                if communityPostsModel?.pagination?.currentPage == 1{
+                    self?.communityPostDataModels.removeAll()
+                }
+                self?.communityPostDataModels = (self?.communityPostDataModels)! + (communityPostsModel?.data!)!
+                self?.heightList()
+                self?.tableView.reloadData()
+                if  self?.communityPostDataModels.count ?? 0 >= communityPostsModel?.pagination?.total ?? 0 {
+                    self?.tableView.endFooterNoMoreData()
+                }
+            }else {
+                self?.tableView.endFooterNoMoreData()
+            }
+        }
+    }
     
+    /// 获取高度
+    func heightList() {
+        heights.removeAll()
+        if !(communityPostDataModels.isEmpty) {
+            for (index,communityPostDataModel) in (communityPostDataModels.enumerated()) {
+                //图片高度
+                var imageHeight : CGFloat!
+                if index == 0 {
+                    imageHeight = (kScreenWidth - 15)/2
+                }else {
+                    imageHeight = 240 * kScaleWidth
+                }
+                
+                //label高度
+                var labelHeight : CGFloat = 0
+                //总间距
+                let spacingHeght : CGFloat!
+                
+                if communityPostDataModel.title == "" || communityPostDataModel.title == nil  {
+                    labelHeight = 0
+                    spacingHeght = 25
+                }else {
+                    labelHeight = (communityPostDataModel.title?.heightForComment(font: kMediumFont13!, width: (((kScreenWidth - 15)/2) - 20)))!
+                    spacingHeght = 35
+                }
+                
+                //button高度
+                let buttonHeight = 18
+                let totalHeight = CGFloat(imageHeight!) + CGFloat(labelHeight) + CGFloat(spacingHeght) + CGFloat(buttonHeight)
+                heights.append(totalHeight)
+            }
+        }
+    }
 }
 
 // MARK: - tableView dataSource && delegate
 extension CommunityRecommendController: UITableViewDataSource, UITableViewDelegate {
     
     func numberOfSections(in tableView: UITableView) -> Int {
-        return 5
+        return 1
     }
     
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
         switch section {
         case 0:
             return 1
-        case 1:
-            return 1
-        case 2:
-            return 1
-        case 3:
-            return 3
         default:
-            return 1
+            return 0
         }
+
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        switch indexPath.section {
-        case 0:
-            let cell = RecommendDetailContentCell.cellWith(tableView: tableView, indexPath: indexPath)
-            cell.layoutIfNeeded()
-            cell.reloadData()
-            return cell
-        case 1:
-            let cell = RecommendNoneCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
-            return cell
-        case 2:
-            let cell = RecommendDefaultBackCell.cellWith(tableView: tableView, indexPath: indexPath)
-            cell.jumpClosure = {
-                [weak self] in
-                print("跳转至首页")
-            }
-            return cell
-        case 3:
-            let cell = RecommendMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
-            if indexPath.row == 2 || indexPath.row == 0 {
-                cell.subCommentCount = 3
-            }
-            cell.frame = tableView.bounds
-            cell.layoutIfNeeded()
-            cell.reloadData()
-            return cell
-        case 4:
-            let cell = RecommendSimilarCell.cellWith(tableView: tableView, indexPath: indexPath)
-            cell.frame = tableView.bounds
-            cell.layoutIfNeeded()
-            cell.reloadData()
-            return cell
-        default:
-            return UITableViewCell()
-        }
+        let cell =  RecommendSimilarCell.cellWith(tableView: tableView, indexPath: indexPath)
+        cell.heights = heights
+        cell.communityPostDataModels = communityPostDataModels
+        cell.frame = tableView.bounds
+        cell.layoutIfNeeded()
+        cell.reloadData()
+        cell.collectionViewHeightModel =  collectionViewHeightModel
+        return cell
     }
     
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
-        print("点击了----\(indexPath.row)")
+        
     }
     
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
-        // testt
-        if indexPath.section == 2 {
-            return 312
-        }
-        return UITableView.automaticDimension
+        return collectionViewHeightModel.height ?? 0
     }
     
     func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
-        if section == 3 {
-            return 64
-        } else {
-            return 10
-        }
+        return 0
     }
     
-    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
-        if section == 3 {
-            return 51
-        } else {
-            return 0
-        }
+    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
+        return nil
     }
     
-    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
-        if section == 3 {
-            let headerView = RecommendCommentHeader(frame: CGRect.zero)
-            return headerView
-        } else {
-            return nil
-        }
+    func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
+        return 0
     }
     
     func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
-        if section == 3 {
-            let footerView = RecommendCommentFooter(frame: CGRect.zero)
-            footerView.unfoldClosure = {
-                [weak self] in
-                print("----点击了展开")
-            }
-            return footerView
-        } else {
-            return nil
-        }
+        return nil
     }
     
 }
+
+extension CommunityRecommendController {
+    
+    //        switch indexPath.section {
+    //        case 0:
+    //            let cell = RecommendDetailContentCell.cellWith(tableView: tableView, indexPath: indexPath)
+    //            cell.layoutIfNeeded()
+    //            cell.reloadData()
+    //            return cell
+    //        case 1:
+    //            let cell = RecommendNoneCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
+    //            return cell
+    //        case 2:
+    //            let cell = RecommendDefaultBackCell.cellWith(tableView: tableView, indexPath: indexPath)
+    //            cell.jumpClosure = {
+    //                [weak self] in
+    //                print("跳转至首页")
+    //            }
+    //            return cell
+    //        case 3:
+    //            let cell = RecommendMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
+    //            if indexPath.row == 2 || indexPath.row == 0 {
+    //                cell.subCommentCount = 3
+    //            }
+    //            cell.frame = tableView.bounds
+    //            cell.layoutIfNeeded()
+    //            cell.reloadData()
+    //            return cell
+    //        case 4:
+    //    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
+    ////        if section == 3 {
+    ////            return 64
+    ////        } else {
+    ////            return 10
+    ////        }
+    //        return 10
+    //    }
+    
+    //    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
+    ////        if section == 3 {
+    ////            return 51
+    ////        } else {
+    ////            return 0
+    ////        }
+    //        return 0
+    //    }
+    
+    //    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
+    //        if section == 3 {
+    //            let headerView = RecommendCommentHeader(frame: CGRect.zero)
+    //            return headerView
+    //        } else {
+    //            return nil
+    //        }
+    //    }
+    //
+    //    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
+    //        if section == 3 {
+    //            let footerView = RecommendCommentFooter(frame: CGRect.zero)
+    //            footerView.unfoldClosure = {
+    //                [weak self] in
+    //                print("----点击了展开")
+    //            }
+    //            return footerView
+    //        } else {
+    //            return nil
+    //        }
+    //    }
+}

+ 61 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/CommunityPostDetailFSPagerViewCell.swift

@@ -0,0 +1,61 @@
+//
+//  CommunityPostDetailFSPagerViewCell.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/7/3.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import FSPagerView
+class CommunityPostDetailFSPagerViewCell: FSPagerViewCell {
+    class func cellWith(collectionView:FSPagerView,index:Int) -> CommunityPostDetailFSPagerViewCell {
+        let ID = "CommunityPostDetailFSPagerViewCell"
+        collectionView.register(CommunityPostDetailFSPagerViewCell.self, forCellWithReuseIdentifier: ID)
+        let cell : CommunityPostDetailFSPagerViewCell =
+            collectionView.dequeueReusableCell(withReuseIdentifier: ID, at: index) as! CommunityPostDetailFSPagerViewCell
+        cell.index = index
+        return cell
+    }
+    //MARK: - indexPath
+    var index: Int?{
+        didSet {
+            
+        }
+    }
+    //MARK: - 初始化
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        setupViews()
+        setupLayouts()
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    //MARK: - 设置view
+    private func setupViews() {
+        addSubview(bgImageView)
+    }
+    
+    private func setupLayouts() {
+        bgImageView.snp.makeConstraints { (make) in
+            make.top.bottom.left.right.equalToSuperview()
+        }
+    }
+    
+    private lazy var bgImageView: UIImageView = {
+        let bgImageView = UIImageView()
+        bgImageView.isUserInteractionEnabled = true
+        bgImageView.image = kImage(name: "pic_preload")
+        return bgImageView
+    }()
+    
+    var img : String? {
+        didSet {
+            bgImageView.kf.setImage(with: kURLImage(name: img ?? ""), placeholder: kImage(name: "pic_preload"))
+
+        }
+    }
+}

+ 92 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/CommunityPostDetailTableViewHeaderView.swift

@@ -0,0 +1,92 @@
+//
+//  CommunityPostDetailTableViewHeaderView.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/7/3.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import FSPagerView
+
+class CommunityPostDetailTableViewHeaderView: BaseView {
+    
+    override func setupViews() {
+         addSubview(pagerView)
+    }
+    
+    override func setupLayouts() {
+        pagerView.snp.makeConstraints { (make) in
+            make.edges.equalToSuperview()
+        }
+    }
+    
+    private lazy var pagerView: FSPagerView = {
+        let pagerView = FSPagerView(frame: CGRect.zero)
+        pagerView.backgroundColor = kf7f8faColor
+        pagerView.delegate = self
+        pagerView.dataSource = self
+        pagerView.scrollDirection = .horizontal
+        pagerView.bounces = false
+        return pagerView
+    }()
+    
+    lazy var numberLabel: UILabel = {
+        let numberLabel = UILabel()
+        numberLabel.cornerRadius = 10
+        return numberLabel
+    }()
+    
+    var communityPostDetailModel : CommunityPostDetailModel? {
+        didSet {
+            if !(communityPostDetailModel?.imgs?.isEmpty ?? true) {
+                imgs = (communityPostDetailModel?.imgs)!
+            }else {
+                if communityPostDetailModel?.img != nil || communityPostDetailModel?.img != "" {
+                    imgs.append(communityPostDetailModel?.img ?? "")
+                }
+            }
+        }
+    }
+    
+    var imgs = Array<String>()
+    var height1 = 0.0
+    
+    var tableView:UITableView?
+
+}
+
+extension CommunityPostDetailTableViewHeaderView:FSPagerViewDataSource,FSPagerViewDelegate {
+    func numberOfItems(in pagerView: FSPagerView) -> Int {
+        return imgs.isEmpty ? 0 : imgs.count
+    }
+    func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
+        let cell  = CommunityPostDetailFSPagerViewCell.cellWith(collectionView: pagerView, index: index)
+        cell.img = imgs[index]
+        return cell
+    }
+    
+    func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int) {
+        pagerView.deselectItem(at: index, animated: true)
+    }
+    
+    func pagerViewWillBeginDragging(_ pagerView: FSPagerView) {
+        height1 += 20
+    }
+    
+    func pagerViewWillEndDragging(_ pagerView: FSPagerView, targetIndex: Int) {
+        
+    }
+    
+    func pagerViewDidEndScrollAnimation(_ pagerView: FSPagerView) {
+//        self.pageControl.currentPage = pagerView.currentIndex
+    }
+    func pagerViewDidScroll(_ pagerView: FSPagerView) {
+        
+        self.frame = CGRect(x: 0.0, y: 0.0, width: CGFloat(kScreenWidth), height: CGFloat(221+height1))
+        tableView?.reloadData()
+    }
+    
+}
+
+

+ 14 - 5
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/RecommendBottomCommentView.swift

@@ -22,16 +22,20 @@ class RecommendBottomCommentView: BaseView {
     
     override func setupViews() {
         self.backgroundColor = kffffffColor
-        
-        addSubview(commentView)
+        addSubview(bgView)
+        bgView.addSubview(commentView)
         commentView.addSubview(commentLabel)
         commentView.addSubview(textBtn)
-        addSubview(likeBtn)
-        addSubview(collectBtn)
-        addSubview(commentBtn)
+        bgView.addSubview(likeBtn)
+        bgView.addSubview(collectBtn)
+        bgView.addSubview(commentBtn)
     }
     
     override func setupLayouts() {
+        bgView.snp_makeConstraints { (make) in
+            make.top.left.right.equalToSuperview()
+            make.height.equalTo(48)
+        }
         commentBtn.snp.makeConstraints { (make) in
             make.right.equalToSuperview().offset(-14)
             make.centerY.equalToSuperview()
@@ -71,6 +75,11 @@ class RecommendBottomCommentView: BaseView {
         
     }
     
+    lazy var bgView: UIView = {
+        let bgView = UIView()
+        return bgView
+    }()
+    
     private lazy var commentView: UIView = {
         let commentView = UIView()
         commentView.backgroundColor = kfafafaColor

+ 55 - 32
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/RecommendSimilarCell.swift

@@ -38,35 +38,18 @@ class RecommendSimilarCell: UITableViewCell {
     private func setupViews() {
         self.selectionStyle = .none
         backgroundColor = kf7f8faColor
-        
-        addSubview(titleLabel)
         addSubview(collectionView)
     }
     
     private func setupLayouts() {
-        titleLabel.snp.makeConstraints { (make) in
-            make.top.equalTo(10)
-            make.left.equalTo(14)
-            make.right.equalTo(-14)            
-            make.height.equalTo(22)
-        }
         collectionView.snp.makeConstraints { (make) in
-            make.top.equalTo(titleLabel.snp_bottom).offset(20)
+            make.top.equalTo(0)
             make.left.equalTo(5)
             make.right.equalTo(-5)
-            make.bottom.equalTo(0)
+            make.height.equalTo(200)
         }
     }
     
-    private lazy var titleLabel: UILabel = {
-        let titleLabel = UILabel()
-        titleLabel.text = "相关推荐"
-        titleLabel.textColor = k333333Color
-        titleLabel.font = kMediumFont18
-        titleLabel.textAlignment = .left
-        return titleLabel
-    }()
-    
     private lazy var collectionView: UICollectionView = {
         let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
         collectionView.backgroundColor = kf7f8faColor
@@ -78,51 +61,91 @@ class RecommendSimilarCell: UITableViewCell {
         collectionView.isScrollEnabled = false
         return collectionView
     }()
-    
-    private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
-        let collectionViewLayout = UICollectionViewFlowLayout.init()
-        collectionViewLayout.minimumLineSpacing = 5
-        collectionViewLayout.minimumInteritemSpacing =  5
-                collectionViewLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
-        collectionViewLayout.scrollDirection = UICollectionView.ScrollDirection.vertical
-        collectionViewLayout.estimatedItemSize = CGSize(width: ((kScreenWidth - 10) - 5)/2, height: 250)
+    private lazy var collectionViewLayout: WaterFallLayout = {
+        let collectionViewLayout = WaterFallLayout()
+        collectionViewLayout.delegate = self
+        collectionViewLayout.scrollDirection = .horizontal
         return collectionViewLayout
     }()
     
+    var collectionViewHeight : CGFloat?
     //加载数据
     func reloadData() {
         //collectionView重新加载数据
         self.collectionView.reloadData()
         //更新collectionView的高度约束
         let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
-        collectionView.snp.makeConstraints { (make) in
-            make.top.equalTo(titleLabel.snp_bottom).offset(20)
+        collectionViewHeight = contentSize.height
+        self.collectionView.snp.remakeConstraints { (make) in
+            make.top.equalTo(0)
             make.left.equalTo(5)
             make.right.equalTo(-5)
-            make.bottom.equalTo(0)
             make.height.equalTo(contentSize.height)
+            make.bottom.lessThanOrEqualToSuperview()
+            
         }
         self.collectionView.collectionViewLayout.invalidateLayout()
     }
     
+    var heights : Array<CGFloat>?
+    var communityPostDataModels : Array<CommunityPostDataModel>? {
+        didSet {
+            self.collectionView.reloadData()
+        }
+    }
+    var collectionViewHeightModel : CollectionViewHeightModel?{
+        didSet {
+            collectionViewHeightModel?.height = collectionViewHeight!
+        }
+    }
+    
+    
 }
 
+extension RecommendSimilarCell : WaterFallLayoutDelegate {
+    func collectionView(_ collectionView: UICollectionView!, heightOfItemAt indexPath: IndexPath!) -> CGFloat {
+        return heights?.isEmpty ?? true ? 0 : heights?[indexPath.row] ?? 0
+    }
+    func contentInsets(for collectionView: UICollectionView!) -> UIEdgeInsets {
+        return UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
+    }
+    func columenCounts(for collectionView: UICollectionView!) -> Int32 {
+        return 2
+    }
+    func horizontalGap(for collectionView: UICollectionView!) -> CGFloat {
+        return 5
+    }
+    func verticalGap(for collectionView: UICollectionView!) -> CGFloat {
+        return 5
+    }
+}
+
+
 extension RecommendSimilarCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
+    
     func numberOfSections(in collectionView: UICollectionView) -> Int {
         return 1
+        
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return 5
+        return communityPostDataModels?.isEmpty ?? true ? 0 : communityPostDataModels?.count ?? 0
+        
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         let cell = SearchContentListCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+        cell.communityPostDataModel = communityPostDataModels?[indexPath.row]
+        cell.userClosure = {
+            NotificationCenter.default.post(name: NSNotification.Name("OtherPersonalCenter"), object: cell.communityPostDataModel?.uid)
+        }
         return cell
     }
     
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        print("点击了collection----\(indexPath.row)")
+//        let communityPostDataModel = communityPostDataModels[indexPath.row]
+//        NotificationCenter.default.post(name: NSNotification.Name("SearchContentList"), object: communityPostDataModel)
     }
     
 }
+

+ 18 - 4
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/View/SearchContentListCollectionCell.swift

@@ -76,13 +76,12 @@ class SearchContentListCollectionCell: UICollectionViewCell {
             make.left.equalToSuperview().offset(10)
             make.size.equalTo(18)
         }
-        nameButton.snp.makeConstraints { (make) in
+        nameButton.snp.remakeConstraints { (make) in
             make.centerY.equalTo(avatarButton)
             make.left.equalTo(avatarButton.snp_right).offset(5)
-            make.right.lessThanOrEqualTo(likeBtn.snp_left).offset(-5)
             make.height.equalTo(18)
         }
-        likeBtn.snp.makeConstraints { (make) in
+        likeBtn.snp.remakeConstraints { (make) in
             make.centerY.equalTo(avatarButton)
             make.right.equalTo(-13)
             make.height.equalTo(18)
@@ -156,14 +155,29 @@ class SearchContentListCollectionCell: UICollectionViewCell {
         didSet {
             contentImageView.kf.setImage(with: kURLImage(name: communityPostDataModel?.img ?? ""), placeholder: kImage(name: "pic_preload"))
             titleLabel.text = communityPostDataModel?.title
+            if communityPostDataModel?.title == "" || communityPostDataModel?.title == nil {
+                titleLabel.snp.remakeConstraints { (make) in
+                    make.top.equalTo(contentImageView.snp_bottom).offset(5)
+                    make.left.equalTo(contentImageView.snp_left).offset(10)
+                    make.right.equalTo(contentImageView.snp_right).offset(-10)
+                }
+            }else {
+                titleLabel.snp.remakeConstraints { (make) in
+                    make.top.equalTo(contentImageView.snp_bottom).offset(15)
+                    make.left.equalTo(contentImageView.snp_left).offset(10)
+                    make.right.equalTo(contentImageView.snp_right).offset(-10)
+                }
+            }
             avatarButton.kf.setImage(with: kURLImage(name: communityPostDataModel?.avatar ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
-            nameButton.setTitle(communityPostDataModel?.username, for: UIControl.State.normal)
             likeBtn.setTitle("\(communityPostDataModel?.praiseCount ?? 0)", for: UIControl.State.normal)
             if communityPostDataModel?.isLike == 0 {
                 likeBtn.isSelected = false
             }else {
                 likeBtn.isSelected = true
             }
+            likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
+            nameButton.setTitle(communityPostDataModel?.username, for: UIControl.State.normal)
+
         }
     }
 }

+ 2 - 2
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/ViewController/SearchContentListViewController.swift

@@ -71,7 +71,7 @@ class SearchContentListViewController: UIViewController {
 
 extension SearchContentListViewController {
     func communityPostsApi(page:Int) {
-        SwiftMoyaNetWorkServiceCommunity.shared().communityPostsApi(keyword: keyWord, page: page) {
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPostsApi(keyword: keyWord,page: page) {
             [weak self] (communityPostsModel) -> (Void) in
             let communityPostsModel = communityPostsModel as? CommunityPostsModel
             if communityPostsModel?.pagination?.currentPage ?? 1  <= communityPostsModel?.pagination?.totalPages ?? 1 {
@@ -82,7 +82,7 @@ extension SearchContentListViewController {
                 self?.heightList()
                 self?.collectionView.reloadData()
                 if  self?.communityPostDataModels.count ?? 0 >= communityPostsModel?.pagination?.total ?? 0 {
-                    self?.collectionView.isHiddenFooter(true)
+                    self?.collectionView.endFooterNoMoreData()
                 }
             }else {
                 self?.collectionView.endFooterNoMoreData()

+ 16 - 0
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceCommunity/SwiftMoyaNetWorkServiceCommunity.swift

@@ -294,5 +294,21 @@ public class SwiftMoyaNetWorkServiceCommunity: NSObject {
             completion(data)
         }
     }
+    
+    
+    /// 内容详情(前端)
+    ///
+    /// - Parameters:
+    ///   - id: 内容id
+    ///   - completion: 回调
+    func communityPostDetailApi(id:Int,completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        parameters.updateValue(id, forKey: "id")
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared.requestObject(CommunityPostDetailModel.self,target: MultiTarget(SwiftMoyaServiceCommunityApi.communityPostDetail(parameters: parameters))) {  (communityPostDetailModel) in
+            SwiftProgressHUD.shared().hide()
+            completion(communityPostDetailModel)
+        }
+    }
         
 }

+ 16 - 4
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceCommunity/SwiftMoyaServiceCommunityApi.swift

@@ -69,6 +69,10 @@ public let kCommunityMemberFollowTopicFollowApi = "/community/memberFollowTopic/
 /// 取消关注话题
 public let kCommunityMemberFollowTopicCancelFollowApi = "/community/memberFollowTopic/cancel"
 
+// MARK: - 内容详情
+/// 内容详情
+public let kCommunityPostDetailApi = "/community/post/detail"
+
 /// 社区
 ///
 /// - communityTopicCategory: 话题组列表
@@ -86,6 +90,7 @@ public let kCommunityMemberFollowTopicCancelFollowApi = "/community/memberFollow
 /// - communityMemberFollowTopicList: 我关注的话题列表
 /// - communityMemberFollowTopicFollow: 关注话题(单个)
 /// - communityMemberFollowTopicCancelFollow: 取消关注话题
+/// - communityPostDetail: 内容详情
 
 public enum SwiftMoyaServiceCommunityApi {
     case communityTopicCategory(parameters:Dictionary<String, Any>)
@@ -103,6 +108,7 @@ public enum SwiftMoyaServiceCommunityApi {
     case communityMemberFollowTopicList(parameters:Dictionary<String, Any>)
     case communityMemberFollowTopicFollow(parameters:Dictionary<String, Any>)
     case communityMemberFollowTopicCancelFollow(parameters:Dictionary<String, Any>)
+    case communityPostDetail(parameters:Dictionary<String, Any>)
 }
 
 extension SwiftMoyaServiceCommunityApi: TargetType {
@@ -123,7 +129,8 @@ extension SwiftMoyaServiceCommunityApi: TargetType {
              .communityPostTopic,
              .communityMemberFollowTopicList,
              .communityMemberFollowTopicFollow,
-             .communityMemberFollowTopicCancelFollow
+             .communityMemberFollowTopicCancelFollow,
+             .communityPostDetail
             :
             return URL(string: kApiDataPrefix())!
         }
@@ -161,6 +168,8 @@ extension SwiftMoyaServiceCommunityApi: TargetType {
             return kCommunityMemberFollowTopicFollowApi
         case .communityMemberFollowTopicCancelFollow:
             return kCommunityMemberFollowTopicCancelFollowApi
+        case .communityPostDetail:
+            return kCommunityPostDetailApi
         }
     }
     
@@ -181,7 +190,8 @@ extension SwiftMoyaServiceCommunityApi: TargetType {
              .communityPostSuggest,
              .communityTopicDetail,
              .communityPostTopic,
-             .communityMemberFollowTopicList
+             .communityMemberFollowTopicList,
+             .communityPostDetail
             :
             return .get
         case .communityMemberFollowTopicCancelFollow
@@ -208,7 +218,8 @@ extension SwiftMoyaServiceCommunityApi: TargetType {
              .communityPostTopic(var parameters),
              .communityMemberFollowTopicList(var parameters),
              .communityMemberFollowTopicFollow(var parameters),
-             .communityMemberFollowTopicCancelFollow(var parameters)
+             .communityMemberFollowTopicCancelFollow(var parameters),
+             .communityPostDetail(var parameters)
             :
             let sign = SwiftSign.shared().sign(signType:.AccessToken, parameters: parameters)
             parameters.updateValue(sign, forKey: "sign")
@@ -245,7 +256,8 @@ extension SwiftMoyaServiceCommunityApi: TargetType {
              .communityPostTopic,
              .communityMemberFollowTopicList,
              .communityMemberFollowTopicFollow,
-             .communityMemberFollowTopicCancelFollow
+             .communityMemberFollowTopicCancelFollow,
+             .communityPostDetail
             :
             return (headerParameters(headerType: .tokenHeader) as! [String : String])
         }

+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/Assets.xcassets/NavigationBarIcons/nav_share_black.imageset/Contents.json

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

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/Assets.xcassets/NavigationBarIcons/nav_share_black.imageset/nav_share_black@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/Assets.xcassets/NavigationBarIcons/nav_share_black.imageset/nav_share_black@3x.png


+ 1 - 1
RainbowPlanet/RainbowPlanet/Tools/WaterFallLayout/WaterFallLayout.h

@@ -36,7 +36,7 @@
 
 
 
-@interface WaterFallLayout : UICollectionViewLayout
+@interface WaterFallLayout : UICollectionViewFlowLayout
 
 @property (nonatomic) id<WaterFallLayoutDelegate> delegate;
 

+ 22 - 0
RainbowPlanet/RainbowPlanet/ViewModel/Community/CommunityFollowUserViewModel.swift

@@ -67,6 +67,28 @@ class CommunityFollowUserViewModel: NSObject {
     
 }
 
+// MARK: - communityPostDetailModel
+extension CommunityFollowUserViewModel {
+    /// 关注/取消关注
+    ///
+    /// - Parameter communityPostDetailModel: 帖子模型
+    func follow(communityPostDetailModel: CommunityPostDetailModel,button:UIButton) {
+        if communityPostDetailModel.isFollow == 0 {//加关注
+            self.userFollow(followUid:  communityPostDetailModel.uid ?? 0, completion: { (isFollow) -> Void in
+                communityPostDetailModel.isFollow = isFollow
+                CommunityFollowUserViewModel.shared.setFollowType(followButton: button, followType: FollowType(rawValue: communityPostDetailModel.isFollow ?? 0) ?? .futureFollow)
+
+            })
+        }else {//取消关注
+            self.userCancelFollow(followUid:  communityPostDetailModel.uid ?? 0, completion: { (isFollow) -> Void in
+                communityPostDetailModel.isFollow = isFollow
+                CommunityFollowUserViewModel.shared.setFollowType(followButton: button, followType: FollowType(rawValue: communityPostDetailModel.isFollow ?? 0) ?? .futureFollow)
+
+            })
+        }
+    }
+}
+
 // MARK: - CommunityRecommendDataModel
 extension CommunityFollowUserViewModel {