CommunityFollowViewController.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. //
  2. // CommunityListViewController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/6/11.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import JXSegmentedView
  10. class CommunityFollowViewController: UIViewController {
  11. deinit {
  12. if observe != nil {
  13. NotificationCenter.default.removeObserver(observe!)
  14. }
  15. }
  16. weak var observe : NSObjectProtocol?
  17. var cellHeightsDictionary = Dictionary<IndexPath, Any>()
  18. var communityFollowDataModels = Array<CommunityFollowDataModel>()
  19. var communityFollowDataModel : CommunityFollowDataModel?
  20. var keyBoardCommentView : KeyBoardCommentView?
  21. /// 关注数组
  22. var cmsMemberModels = Array<CMSMemberModel>()
  23. override func viewDidLoad() {
  24. super.viewDidLoad()
  25. setupViews()
  26. setupLayouts()
  27. setupData()
  28. }
  29. func setupViews() {
  30. view.backgroundColor = kf7f8faColor
  31. view.addSubview(tableView)
  32. }
  33. func setupLayouts() {
  34. tableView.snp.makeConstraints { (make) in
  35. make.top.left.right.equalToSuperview()
  36. make.height.equalTo(kScreenHeight-48-kNavBarTotalHeight-kTabBarTotalHeight)
  37. }
  38. }
  39. private lazy var tableView: UITableView = {
  40. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  41. tableView.separatorStyle = .none
  42. tableView.backgroundColor = kf7f8faColor
  43. tableView.dataSource = self
  44. tableView.delegate = self
  45. return tableView
  46. }()
  47. private lazy var followTableHeaderView: CommunityFollowTableHeaderView = {
  48. let followTableHeaderView = CommunityFollowTableHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 286))
  49. return followTableHeaderView
  50. }()
  51. func setupData() {
  52. //下拉刷新
  53. tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {
  54. [weak self] (page) in
  55. self?.loadData(page:page)
  56. }
  57. tableView.addFooterWithWithHeader(withAutomaticallyRefresh: false) {
  58. [weak self] (page) in
  59. SwiftProgressHUD.shared().showWait()
  60. self?.communityFollowFeedApi(page: page)
  61. }
  62. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("followApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  63. let followStatusModel = notification.object as? FollowStatusModel
  64. if !(self?.cmsMemberModels.isEmpty ?? true) {
  65. for cmsMemberModel in (self?.cmsMemberModels)! {
  66. if cmsMemberModel.uid == followStatusModel?.uid {
  67. cmsMemberModel.followStatus = followStatusModel?.isFollowStatus
  68. }
  69. }
  70. }
  71. if !(self?.communityFollowDataModels.isEmpty ?? true) {
  72. for communityFollowDataModel in (self?.communityFollowDataModels)! {
  73. if communityFollowDataModel.relateData?.uid == followStatusModel?.uid {
  74. communityFollowDataModel.relateData?.isFollow = followStatusModel?.isFollowStatus
  75. }
  76. }
  77. }
  78. self?.tableView.reloadData()
  79. }
  80. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("unlikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  81. let followStatusModel = notification.object as? FollowStatusModel
  82. if !(self?.communityFollowDataModels.isEmpty ?? true) {
  83. for communityFollowDataModel in (self?.communityFollowDataModels)! {
  84. if communityFollowDataModel.relateData?.uid == followStatusModel?.uid {
  85. communityFollowDataModel.relateData?.isDislike = followStatusModel?.isFollowStatus
  86. }
  87. }
  88. }
  89. self?.tableView.reloadData()
  90. }
  91. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("islikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  92. let followStatusModel = notification.object as? FollowStatusModel
  93. if !(self?.communityFollowDataModels.isEmpty ?? true) {
  94. for communityFollowDataModel in (self?.communityFollowDataModels)! {
  95. if communityFollowDataModel.relateData?.uid == followStatusModel?.uid {
  96. communityFollowDataModel.relateData?.isLike = followStatusModel?.isFollowStatus
  97. }
  98. }
  99. }
  100. self?.tableView.reloadData()
  101. }
  102. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("isCollectApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  103. let followStatusModel = notification.object as? FollowStatusModel
  104. if !(self?.communityFollowDataModels.isEmpty ?? true) {
  105. for communityFollowDataModel in (self?.communityFollowDataModels)! {
  106. if communityFollowDataModel.relateData?.uid == followStatusModel?.uid {
  107. communityFollowDataModel.relateData?.isCollect = followStatusModel?.isFollowStatus
  108. }
  109. }
  110. }
  111. self?.tableView.reloadData()
  112. }
  113. }
  114. /// 显示键盘
  115. func showKeyBoardCommentView() {
  116. keyBoardCommentView = KeyBoardCommentView.keyBoardCommentView(sendClosure: {
  117. [weak self] text in
  118. self?.communityPostCommentApi(text: text, complete: {
  119. self?.keyBoardCommentView?.dismisskeyBoardCommentView()
  120. })
  121. })
  122. }
  123. /// 隐藏键盘
  124. func hiddenKeyBoardCommentView() {
  125. keyBoardCommentView?.hiddenViewClosure = {
  126. [weak self] in
  127. self?.communityFollowDataModel = nil
  128. }
  129. }
  130. }
  131. extension CommunityFollowViewController {
  132. /// 加载首页数据
  133. ///
  134. /// - Parameter page: <#page description#>
  135. func loadData(page:Int) {
  136. SwiftProgressHUD.shared().showWait()
  137. //获取系统存在的全局队列
  138. let queue = DispatchQueue.global(qos: .default)
  139. //定义一个group
  140. let group = DispatchGroup()
  141. //并发任务,顺序执行
  142. queue.async(group: group) { [weak self] in
  143. self?.cmsMemberListApi()
  144. }
  145. queue.async(group: group) { [weak self] in
  146. self?.communityFollowFeedApi(page: page)
  147. }
  148. }
  149. /// 获取关注用户列表
  150. func cmsMemberListApi() {
  151. SwiftMoyaNetWorkServiceCMS.shared().cmsMemberListApi(takeCount: 20) {
  152. [weak self] (cmsMemberListModel) -> (Void) in
  153. let cmsMemberListModel = cmsMemberListModel as? CMSMemberListModel
  154. self?.cmsMemberModels = (cmsMemberListModel?.list)!
  155. self?.tableView.reloadData()
  156. SwiftProgressHUD.shared().hide()
  157. }
  158. }
  159. /// 关注feed流
  160. ///
  161. /// - Parameter page: 分页
  162. func communityFollowFeedApi(page:Int) {
  163. SwiftMoyaNetWorkServiceCommunity.shared().communityFollowFeedApi(page:page) {
  164. [weak self] (communityFollowFeedModel) -> (Void) in
  165. let communityFollowFeedModel = communityFollowFeedModel as? CommunityFollowFeedModel
  166. if communityFollowFeedModel?.pagination?.currentPage ?? 1 <= communityFollowFeedModel?.pagination?.totalPages ?? 1 {
  167. if communityFollowFeedModel?.pagination?.currentPage == 1{
  168. self?.communityFollowDataModels.removeAll()
  169. }
  170. self?.communityFollowDataModels = (self?.communityFollowDataModels)! + (communityFollowFeedModel?.data!)!
  171. if (self?.communityFollowDataModels.isEmpty)! {
  172. self?.tableView.tableHeaderView = self?.followTableHeaderView
  173. }
  174. self?.tableView.reloadData()
  175. SwiftProgressHUD.shared().hide()
  176. if self?.communityFollowDataModels.count ?? 0 >= communityFollowFeedModel?.pagination?.total ?? 0 {
  177. self?.tableView.endFooterNoMoreData()
  178. }
  179. }else {
  180. self?.tableView.endFooterNoMoreData()
  181. }
  182. }
  183. }
  184. /// 评论
  185. func communityPostCommentApi(text:String,complete:@escaping (() -> Void)) {
  186. let communityCustomCommnetModel = CommunityCustomCommnetModel()
  187. communityCustomCommnetModel.postId = self.communityFollowDataModel?.relateId ?? 0
  188. communityCustomCommnetModel.content = text
  189. SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
  190. [weak self] (communityPostCommentIdModel) -> (Void) in
  191. let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
  192. let communityFollowPostCommentModel = CommunityFollowPostCommentModel()
  193. communityFollowPostCommentModel.content = text
  194. communityFollowPostCommentModel.id = communityPostCommentIdModel?.id
  195. communityFollowPostCommentModel.username = UserModel.shared().getModel()?.username
  196. if self?.communityFollowDataModel?.relateData?.postComment?.isEmpty ?? true {
  197. self?.communityFollowDataModel?.relateData?.postComment = Array<CommunityFollowPostCommentModel>()
  198. }
  199. self?.communityFollowDataModel?.relateData?.postComment?.insert(communityFollowPostCommentModel, at: 0)
  200. VirusViewModel.shared.comment(communityFollowDataModel: self?.communityFollowDataModel, id: communityPostCommentIdModel?.id ?? 0)
  201. let count = 1 + (self?.communityFollowDataModel?.relateData?.commentCount ?? 0)
  202. self?.communityFollowDataModel?.relateData?.commentCount = count
  203. self?.tableView.reloadData()
  204. complete()
  205. }
  206. }
  207. }
  208. extension CommunityFollowViewController : UITableViewDelegate,UITableViewDataSource {
  209. func numberOfSections(in tableView: UITableView) -> Int {
  210. if communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty {
  211. return 0
  212. }else if communityFollowDataModels.isEmpty && !cmsMemberModels.isEmpty {
  213. return 1
  214. }else if !communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty {
  215. return communityFollowDataModels.isEmpty ? 0 : communityFollowDataModels.count
  216. }else {
  217. return communityFollowDataModels.count + 1
  218. }
  219. }
  220. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  221. if communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty {
  222. return 0
  223. }else if communityFollowDataModels.isEmpty && !cmsMemberModels.isEmpty {
  224. return 1
  225. }else if !communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty {
  226. let communityFollowDataModel = communityFollowDataModels[section]
  227. if CommunityFollowType(rawValue:communityFollowDataModel.type ?? "1") == .post {
  228. return 6
  229. }else {
  230. return 1
  231. }
  232. }else {
  233. if section == 0 {
  234. return 1
  235. }else {
  236. let communityFollowDataModel = communityFollowDataModels[section - 1]
  237. if CommunityFollowType(rawValue: communityFollowDataModel.type ?? "1") == .post {
  238. return 6
  239. }else {
  240. return 1
  241. }
  242. }
  243. }
  244. }
  245. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  246. if communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty {
  247. return UITableViewCell()
  248. }else if communityFollowDataModels.isEmpty && !cmsMemberModels.isEmpty { //推荐关注
  249. let cell = CommunityRecommendFollowTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  250. cell.type = .follow
  251. cell.cmsMemberModels = cmsMemberModels
  252. return cell
  253. }else if !communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty { //关注列表
  254. let communityFollowDataModel = communityFollowDataModels[indexPath.section]
  255. if CommunityFollowType(rawValue:communityFollowDataModel.type ?? "1") == .post { //帖子
  256. return postCell(indexPath: indexPath, communityFollowDataModel: communityFollowDataModel)
  257. }else { //关注
  258. let cell = CommunityFollowStatusTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  259. cell.followClosure = {
  260. [weak self] in
  261. CommunityFollowUserViewModel.shared.follow(communityFollowDataModel: communityFollowDataModel, communityFollowDataModels: (self?.communityFollowDataModels)!, tableView: (self?.tableView)!)
  262. }
  263. return cell
  264. }
  265. }else {
  266. if indexPath.section == 0 { //推荐关注
  267. let cell = CommunityRecommendFollowTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  268. cell.type = .follow
  269. cell.cmsMemberModels = cmsMemberModels
  270. cell.followClosure = {
  271. [weak self] (isFollow,cmsMemberModel) in
  272. for (_,model) in (self?.communityFollowDataModels.enumerated())! {
  273. if model.relateData?.uid == cmsMemberModel.uid {
  274. model.relateData?.isFollow = isFollow
  275. tableView.reloadData()
  276. }
  277. }
  278. }
  279. return cell
  280. }else {//关注列表
  281. let communityFollowDataModel = communityFollowDataModels[indexPath.section - 1]
  282. if CommunityFollowType(rawValue: communityFollowDataModel.type ?? "1") == .post { //帖子
  283. return postCell(indexPath: indexPath, communityFollowDataModel: communityFollowDataModel)
  284. }else {//关注
  285. let cell = CommunityFollowStatusTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  286. cell.communityFollowDataModel = communityFollowDataModel
  287. cell.followClosure = {
  288. [weak self] in
  289. CommunityFollowUserViewModel.shared.follow(communityFollowDataModel: communityFollowDataModel, communityFollowDataModels: (self?.communityFollowDataModels)!, tableView: (self?.tableView)!)
  290. }
  291. return cell
  292. }
  293. }
  294. }
  295. }
  296. func postCell(indexPath:IndexPath,communityFollowDataModel:CommunityFollowDataModel) -> UITableViewCell {
  297. switch indexPath.row {
  298. //贴子用户
  299. case 0:
  300. let cell = CardContentUserTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  301. cell.communityFollowDataModel = communityFollowDataModel
  302. cell.followClosure = {
  303. [weak self] in
  304. CommunityFollowUserViewModel.shared.follow(communityFollowDataModel: communityFollowDataModel, communityFollowDataModels: (self?.communityFollowDataModels)!, tableView: (self?.tableView)!)
  305. }
  306. cell.likeClosure = {
  307. [weak self] y in
  308. VirusViewModel.shared.like(communityFollowDataModel: communityFollowDataModel, y: y, tableView: (self?.tableView)!)
  309. }
  310. return cell
  311. //图片视频
  312. case 1:
  313. let cell = CardContentPicVideoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  314. cell.type = .follow
  315. cell.communityFollowDataModel = communityFollowDataModel
  316. return cell
  317. //内容标题
  318. case 2:
  319. let cell = CardContentTitleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  320. cell.communityFollowDataModel = communityFollowDataModel
  321. return cell
  322. //点赞,收藏,分享
  323. case 3:
  324. let cell = CardContentActionTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  325. cell.communityFollowDataModel = communityFollowDataModel
  326. cell.praiseClosureName = { [weak self] (button:UIButton) in
  327. VirusViewModel.shared.praise(communityFollowDataModel: communityFollowDataModel, tableView: (self?.tableView)!)
  328. }
  329. cell.collectClosureName = {
  330. [weak self] (button:UIButton) in
  331. VirusViewModel.shared.collection(communityFollowDataModel: communityFollowDataModel, tableView: (self?.tableView)!)
  332. }
  333. return cell
  334. //评论列表
  335. case 4:
  336. let cell = CardContentCommentListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  337. cell.communityFollowDataModel = communityFollowDataModel
  338. cell.communityType = .follow
  339. cell.frame = tableView.bounds
  340. cell.layoutIfNeeded()
  341. cell.reloadData()
  342. return cell
  343. //评论
  344. case 5:
  345. let cell = CardContentCommnetTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  346. cell.addCommnetClosureName = {
  347. [weak self] in
  348. self?.communityFollowDataModel = communityFollowDataModel
  349. self?.showKeyBoardCommentView()
  350. self?.hiddenKeyBoardCommentView()
  351. }
  352. return cell
  353. default:
  354. return UITableViewCell()
  355. }
  356. }
  357. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  358. if communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty {
  359. }else if communityFollowDataModels.isEmpty && !cmsMemberModels.isEmpty { //推荐关注
  360. }else if !communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty { //关注列表
  361. let communityFollowDataModel = communityFollowDataModels[indexPath.section]
  362. if CommunityFollowType(rawValue:communityFollowDataModel.type ?? "1") == .post { //帖子
  363. switch indexPath.row {
  364. //贴子用户
  365. case 0:
  366. break
  367. //图片视频/内容标题/评论列表
  368. case 1,2,4:
  369. if PostType(rawValue: communityFollowDataModel.relateData?.type ?? "video") == .video {
  370. NotificationCenter.default.post(name: NSNotification.Name("CommunityContentVideoClosure"), object: communityFollowDataModel.relateData?.id)
  371. }else {
  372. NotificationCenter.default.post(name: NSNotification.Name("CommunityContentDetailClosure"), object: communityFollowDataModel.relateData?.id)
  373. }
  374. break
  375. //点赞,收藏,分享
  376. case 3:
  377. break
  378. //评论
  379. case 5:
  380. break
  381. default:
  382. break
  383. }
  384. }else { //关注
  385. }
  386. }else {
  387. if indexPath.section == 0 { //推荐关注
  388. }else {//关注列表
  389. let communityFollowDataModel = communityFollowDataModels[indexPath.section - 1]
  390. if CommunityFollowType(rawValue: communityFollowDataModel.type ?? "1") == .post { //帖子
  391. switch indexPath.row {
  392. //贴子用户
  393. case 0:
  394. break
  395. //图片视频/内容标题/评论列表
  396. case 1,2,4:
  397. if PostType(rawValue: communityFollowDataModel.relateData?.type ?? "video") == .video {
  398. NotificationCenter.default.post(name: NSNotification.Name("CommunityContentVideoClosure"), object: communityFollowDataModel.relateData?.id)
  399. }else {
  400. NotificationCenter.default.post(name: NSNotification.Name("CommunityContentDetailClosure"), object: communityFollowDataModel.relateData?.id)
  401. }
  402. break
  403. //点赞,收藏,分享
  404. case 3:
  405. break
  406. //评论
  407. case 5:
  408. break
  409. default:
  410. break
  411. }
  412. }else {//关注
  413. }
  414. }
  415. }
  416. }
  417. /// 状态的高度
  418. func followStatusHeight(communityFollowDataModel:CommunityFollowDataModel) -> CGFloat {
  419. let communityFollowType = CommunityFollowType(rawValue: communityFollowDataModel.type ?? "1")
  420. switch communityFollowType {
  421. case .follow?:
  422. return 160
  423. case .comment?:
  424. return 193
  425. case .forward?:
  426. return 182
  427. case .like?:
  428. return 182
  429. case .collection?:
  430. return 182
  431. default:
  432. return 0
  433. }
  434. }
  435. /// 帖子的高度
  436. func postCellHeight(indexPath:IndexPath,communityFollowDataModel:CommunityFollowDataModel) -> CGFloat {
  437. switch indexPath.row {
  438. //贴子用户
  439. case 0:
  440. if communityFollowDataModel.relateData?.uid != nil {
  441. return 80
  442. }
  443. return 0
  444. //图片视频
  445. case 1:
  446. let cardContentPicVideoModel = CardContentPicVideoModel()
  447. cardContentPicVideoModel.postType = PostType(rawValue: communityFollowDataModel.relateData?.type ?? "image")!
  448. let imgStr = communityFollowDataModel.relateData?.img
  449. if communityFollowDataModel.relateData?.imgs?.isEmpty ?? true {
  450. if imgStr != "" && imgStr != nil {
  451. cardContentPicVideoModel.number = 1
  452. cardContentPicVideoModel.width = getImageWidth(imgStr: (imgStr)!)
  453. cardContentPicVideoModel.height = getImageHeight(imgStr: (imgStr)!)
  454. return cardContentPicVideoModel.collectionViewHeight() + 20
  455. }else {
  456. return 0
  457. }
  458. }else {
  459. if communityFollowDataModel.relateData?.imgs?.count ?? 0 == 1 {
  460. if imgStr != "" || imgStr != nil {
  461. cardContentPicVideoModel.number = 1
  462. cardContentPicVideoModel.width = getImageWidth(imgStr: (imgStr)!)
  463. cardContentPicVideoModel.height = getImageHeight(imgStr: (imgStr)!)
  464. return cardContentPicVideoModel.collectionViewHeight() + 20
  465. }else {
  466. return 0
  467. }
  468. }else {
  469. cardContentPicVideoModel.number = communityFollowDataModel.relateData?.imgs?.count ?? 0
  470. return cardContentPicVideoModel.collectionViewHeight() + 20
  471. }
  472. }
  473. //内容标题
  474. case 2:
  475. return UITableView.automaticDimension
  476. //点赞,收藏,分享
  477. case 3:
  478. return 54
  479. //评论列表
  480. case 4:
  481. if !(communityFollowDataModel.relateData?.postComment?.isEmpty ?? true) {
  482. return UITableView.automaticDimension
  483. }
  484. return 0
  485. //评论
  486. case 5:
  487. return 74
  488. default:
  489. return 0
  490. }
  491. }
  492. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  493. if communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty {
  494. return 0
  495. }else if communityFollowDataModels.isEmpty && !cmsMemberModels.isEmpty {
  496. return 191
  497. }else if !communityFollowDataModels.isEmpty && cmsMemberModels.isEmpty {
  498. let communityFollowDataModel = communityFollowDataModels[indexPath.section]
  499. if CommunityFollowType(rawValue:communityFollowDataModel.type ?? "1") == .post {
  500. return postCellHeight(indexPath: indexPath, communityFollowDataModel: communityFollowDataModel)
  501. }else {
  502. return followStatusHeight(communityFollowDataModel: communityFollowDataModel)
  503. }
  504. }else if !communityFollowDataModels.isEmpty && !cmsMemberModels.isEmpty {
  505. if indexPath.section == 0 {
  506. return 191
  507. }else {
  508. let communityFollowDataModel = communityFollowDataModels[indexPath.section - 1]
  509. if CommunityFollowType(rawValue: communityFollowDataModel.type ?? "1") == .post {
  510. return postCellHeight(indexPath: indexPath, communityFollowDataModel: communityFollowDataModel)
  511. }else {
  512. return followStatusHeight(communityFollowDataModel: communityFollowDataModel)
  513. }
  514. }
  515. }else {
  516. return 0
  517. }
  518. }
  519. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  520. switch section {
  521. case 0:
  522. if !cmsMemberModels.isEmpty {
  523. return 62
  524. }
  525. return 0
  526. default:
  527. return 0
  528. }
  529. }
  530. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  531. switch section {
  532. case 0:
  533. if !cmsMemberModels.isEmpty {
  534. return 20
  535. }
  536. return 10
  537. default:
  538. return 10
  539. }
  540. }
  541. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  542. switch section {
  543. case 0:
  544. if !cmsMemberModels.isEmpty {
  545. let headerView = CommunityCommonSectionHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 62))
  546. headerView.communityCommonSectionHeaderViewType = .recommendFollow
  547. return headerView
  548. }
  549. return nil
  550. default:
  551. return nil
  552. }
  553. }
  554. func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  555. cellHeightsDictionary.updateValue(cell.frame.size.height, forKey: indexPath)
  556. }
  557. func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
  558. let height = cellHeightsDictionary[indexPath]
  559. if let height = height {
  560. return height as! CGFloat
  561. }
  562. return UITableView.automaticDimension
  563. }
  564. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  565. return nil
  566. }
  567. }
  568. extension CommunityFollowViewController : JXSegmentedListContainerViewListDelegate {
  569. func listView() -> UIView {
  570. return view
  571. }
  572. }