CommunityRecommnendViewController.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. //
  2. // CommunityRecommnendViewController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/6/28.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import JXSegmentedView
  10. import Kingfisher
  11. class CommunityRecommnendViewController: UIViewController {
  12. override func didReceiveMemoryWarning() {
  13. super.didReceiveMemoryWarning()
  14. KingfisherManager.shared.cache.clearDiskCache()
  15. KingfisherManager.shared.cache.clearMemoryCache()
  16. }
  17. deinit {
  18. NXLLog("deinit")
  19. if observe != nil {
  20. NotificationCenter.default.removeObserver(observe!)
  21. }
  22. }
  23. weak var observe : NSObjectProtocol?
  24. var communityRecommendDataModels = Array<CommunityRecommendDataModel>()
  25. /// 评论需要的模型
  26. var communityRecommendDataModel : CommunityRecommendDataModel?
  27. var communityRecommendCategoryModel : CommunityRecommendCategoryModel?
  28. var navigationBarIsHidden: Bool = false
  29. override func viewDidLoad() {
  30. super.viewDidLoad()
  31. setupViews()
  32. setupLayouts()
  33. setupData()
  34. }
  35. func setupViews() {
  36. view.backgroundColor = kf7f8faColor
  37. view.addSubview(tableView)
  38. }
  39. func setupLayouts() {
  40. tableView.snp.makeConstraints { (make) in
  41. make.top.left.right.equalToSuperview()
  42. make.height.equalTo(kScreenHeight-44-kNavBarTotalHeight-kTabBarTotalHeight-40)
  43. }
  44. tableView.reloadData()
  45. }
  46. func setupData() {
  47. //下拉刷新
  48. tableView.addHeader(withBeginRefresh: true, animation: true) {
  49. [weak self] (page) in
  50. self?.communityPostSuggestApi(page:page)
  51. }
  52. tableView.addAutoNormalFooter(withAutomaticallyRefresh: true, loadMoreBlock: {
  53. [weak self] (page) in
  54. self?.communityPostSuggestApi(page:page)
  55. })
  56. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("login"), object: nil, queue: OperationQueue.main, using: {
  57. [weak self] (notification) in
  58. self?.tableView.mj_header.beginRefreshing()
  59. })
  60. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("loginOut"), object: nil, queue: OperationQueue.main, using: {
  61. [weak self] (notification) in
  62. self?.tableView.mj_header.beginRefreshing()
  63. })
  64. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("followApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  65. let followStatusModel = notification.object as? FollowStatusModel
  66. if !(self?.communityRecommendDataModels.isEmpty ?? true) {
  67. for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
  68. if communityRecommendDataModel.uid == followStatusModel?.uid {
  69. communityRecommendDataModel.isFollow = followStatusModel?.isFollowStatus
  70. }
  71. }
  72. }
  73. self?.tableView.reloadData()
  74. }
  75. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("unlikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  76. let followStatusModel = notification.object as? FollowStatusModel
  77. if !(self?.communityRecommendDataModels.isEmpty ?? true) {
  78. for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
  79. if communityRecommendDataModel.id == followStatusModel?.postId {
  80. communityRecommendDataModel.isDislike = followStatusModel?.isFollowStatus
  81. }
  82. }
  83. }
  84. self?.tableView.reloadData()
  85. }
  86. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("islikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  87. let followStatusModel = notification.object as? FollowStatusModel
  88. if !(self?.communityRecommendDataModels.isEmpty ?? true) {
  89. for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
  90. if communityRecommendDataModel.id == followStatusModel?.postId {
  91. communityRecommendDataModel.isLike = followStatusModel?.isFollowStatus
  92. }
  93. }
  94. }
  95. self?.tableView.reloadData()
  96. }
  97. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("isCollectApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  98. let followStatusModel = notification.object as? FollowStatusModel
  99. if !(self?.communityRecommendDataModels.isEmpty ?? true) {
  100. for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
  101. if communityRecommendDataModel.id == followStatusModel?.postId {
  102. communityRecommendDataModel.isCollect = followStatusModel?.isFollowStatus
  103. }
  104. }
  105. }
  106. self?.tableView.reloadData()
  107. }
  108. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("communityDeletePostApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
  109. let postId = notification.object as? Int
  110. if !(self?.communityRecommendDataModels.isEmpty ?? true) {
  111. for (index,communityRecommendDataModel) in (self?.communityRecommendDataModels)!.enumerated() {
  112. if communityRecommendDataModel.id == postId {
  113. self?.communityRecommendDataModels.remove(at: index)
  114. }
  115. }
  116. self?.tableView.reloadData()
  117. }
  118. }
  119. }
  120. private lazy var tableView: UITableView = {
  121. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  122. tableView.separatorStyle = .none
  123. tableView.backgroundColor = kf7f8faColor
  124. tableView.dataSource = self
  125. tableView.delegate = self
  126. tableView.contentInset = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
  127. return tableView
  128. }()
  129. private lazy var followTableHeaderView: CommunityFollowTableHeaderView = {
  130. let followTableHeaderView = CommunityFollowTableHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 286))
  131. return followTableHeaderView
  132. }()
  133. /// 显示键盘
  134. func showKeyBoardCommentView() {
  135. KeyBoardInputView.show(inputViewResultClosure: {
  136. [weak self] (text) in
  137. self?.communityPostCommentApi(text: text, complete: {
  138. [weak self] in
  139. self?.communityRecommendDataModel = nil
  140. })
  141. }) {
  142. [weak self] in
  143. self?.communityRecommendDataModel = nil
  144. }
  145. }
  146. }
  147. extension CommunityRecommnendViewController {
  148. /// 推荐feed流
  149. ///
  150. /// - Parameter page: 分页
  151. func communityPostSuggestApi(page:Int) {
  152. SwiftMoyaNetWorkServiceCommunity.shared().communityPostSuggestApi(page:page,categoryId:communityRecommendCategoryModel?.id ?? 0,completion: {
  153. [weak self] (communityRecommendFeedModel) -> (Void) in
  154. DIYEmptyView.emptyNoDataTableView(tableView: self?.tableView)
  155. let communityRecommendFeedModel = communityRecommendFeedModel as? CommunityRecommendFeedModel
  156. if communityRecommendFeedModel?.pagination?.currentPage == 1{
  157. self?.communityRecommendDataModels.removeAll()
  158. self?.tableView.resetNoMoreData()
  159. }
  160. self?.communityRecommendDataModels = (self?.communityRecommendDataModels)! + (communityRecommendFeedModel?.data!)!
  161. self?.tableView.reloadData()
  162. MJRefreshManager.mjRefreshManagerPaginationNoHiddenFooter(tableView: self?.tableView, pagination: communityRecommendFeedModel?.pagination)
  163. }) {
  164. [weak self] (loadingStatus) in
  165. MJRefreshManager.mjRefreshManagerLoadingStatus(tableView: self?.tableView,loadingStatus: loadingStatus)
  166. }
  167. }
  168. /// 评论
  169. func communityPostCommentApi(text:String,complete:@escaping () -> ()) {
  170. let communityCustomCommnetModel = CommunityCustomCommnetModel()
  171. communityCustomCommnetModel.postId = communityRecommendDataModel?.id ?? 0
  172. communityCustomCommnetModel.content = text
  173. SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
  174. [weak self] (communityPostCommentIdModel) -> (Void) in
  175. let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
  176. let communityRecommendCommentModel = CommunityRecommendCommentModel()
  177. communityRecommendCommentModel.content = text
  178. communityRecommendCommentModel.id = communityPostCommentIdModel?.id
  179. communityRecommendCommentModel.username = UserModel.shared().getModel()?.username
  180. if self?.communityRecommendDataModel?.comment?.isEmpty ?? true {
  181. self?.communityRecommendDataModel?.comment = Array<CommunityRecommendCommentModel>()
  182. }
  183. self?.communityRecommendDataModel?.comment?.insert(communityRecommendCommentModel, at: 0)
  184. VirusViewModel.shared.comment(communityRecommendDataModel: self?.communityRecommendDataModel, id: communityPostCommentIdModel?.id ?? 0,content: text)
  185. let count = (1 + (self?.communityRecommendDataModel?.commentCount ?? 0))
  186. self?.communityRecommendDataModel?.commentCount = count
  187. self?.tableView.reloadData()
  188. complete()
  189. }
  190. }
  191. /// 删除帖子
  192. func communityDeleteApi(postId:Int,section:Int) {
  193. SwiftMoyaNetWorkServiceCommunity.shared().communityDeleteApi(postId: postId) { [weak self] (data) -> (Void) in
  194. if !(self?.communityRecommendDataModels.isEmpty ?? true) {
  195. self?.communityRecommendDataModels.remove(at: section)
  196. }
  197. self?.tableView.reloadData()
  198. }
  199. }
  200. }
  201. extension CommunityRecommnendViewController : UITableViewDelegate,UITableViewDataSource {
  202. func numberOfSections(in tableView: UITableView) -> Int {
  203. return communityRecommendDataModels.isEmpty ? 0 : communityRecommendDataModels.count
  204. }
  205. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  206. let communityRecommendDataModel = communityRecommendDataModels[section]
  207. if CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "") == .post {
  208. return 6
  209. }else {
  210. return 1
  211. }
  212. }
  213. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  214. let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
  215. let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
  216. switch communityPostSuggestCType {
  217. case .banner?: //banner
  218. let cell = CommunityBannerTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  219. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  220. cell.communityRecommendTypeDataModels = communityRecommendDataModel.data
  221. }
  222. return cell
  223. case .user?: //推荐用户
  224. let cell = CommunityRecommendFollowTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  225. cell.type = .recommend
  226. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  227. cell.communityRecommendTypeDataModels = communityRecommendDataModel.data
  228. cell.followClosure1 = {
  229. [weak self] (isFollow,communityRecommendTypeDataModel) in
  230. for (_,model) in (self?.communityRecommendDataModels.enumerated())! {
  231. let communityPostSuggestCType = CommunityPostSuggestType(rawValue: model.showType ?? "")
  232. if communityPostSuggestCType == .post {
  233. if model.uid == communityRecommendTypeDataModel.uid {
  234. model.isFollow = isFollow
  235. tableView.reloadData()
  236. }
  237. }
  238. }
  239. }
  240. }
  241. return cell
  242. case .video?: //推荐视频
  243. let cell = PopularVideoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  244. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  245. cell.communityRecommendTypeDataModels = communityRecommendDataModel.data
  246. }
  247. return cell
  248. case .topic?: //推荐话题
  249. let cell = FeaturedTopicsTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  250. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  251. cell.communityRecommendTypeDataModels = communityRecommendDataModel.data
  252. }
  253. return cell
  254. case .post?: //贴子
  255. switch indexPath.row {
  256. //贴子用户
  257. case 0:
  258. let cell = CardContentUserTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  259. cell.communityRecommendDataModel = communityRecommendDataModel
  260. cell.followClosure = {
  261. [weak self] in
  262. CommunityFollowUserViewModel.shared.follow(communityRecommendDataModel: communityRecommendDataModel, communityRecommendDataModels: (self?.communityRecommendDataModels)!, tableView: tableView)
  263. }
  264. cell.likeClosure = { y in
  265. if UserModel.shared().isEqualUid(uid: communityRecommendDataModel.uid ?? 0) {
  266. CardContentUserDeleteView.sheetDeleteView(y: y, sureClosure: { [weak self] (cardContentUserDeleteView) in
  267. self?.communityDeleteApi(postId: communityRecommendDataModel.id ?? 0, section: indexPath.section)
  268. })
  269. }else {
  270. VirusViewModel.shared.like(communityRecommendDataModel: communityRecommendDataModel, y: y, tableView: tableView)
  271. }
  272. }
  273. return cell
  274. //图片视频
  275. case 1:
  276. let cell = CardContentPicVideoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  277. cell.type = .recommend
  278. cell.communityRecommendDataModel = communityRecommendDataModel
  279. return cell
  280. //内容标题
  281. case 2:
  282. let cell = CardContentTitleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  283. cell.communityRecommendDataModel = communityRecommendDataModel
  284. return cell
  285. //点赞,收藏,分享
  286. case 3:
  287. let cell = CardContentActionTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  288. cell.communityRecommendDataModel = communityRecommendDataModel
  289. cell.praiseClosureName = { (button:UIButton) in
  290. VirusViewModel.shared.praise(communityRecommendDataModel: communityRecommendDataModel, tableView: tableView)
  291. }
  292. cell.collectClosureName = {
  293. (button:UIButton) in
  294. VirusViewModel.shared.collection(communityRecommendDataModel: communityRecommendDataModel, tableView: tableView)
  295. }
  296. return cell
  297. //评论列表
  298. case 4:
  299. let cell = CardContentCommentListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  300. cell.communityRecommendDataModel = communityRecommendDataModel
  301. return cell
  302. //评论
  303. case 5:
  304. let cell = CardContentCommnetTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  305. cell.addCommnetClosureName = {
  306. [weak self] in
  307. self?.communityRecommendDataModel = self?.communityRecommendDataModels[indexPath.section]
  308. self?.showKeyBoardCommentView()
  309. }
  310. return cell
  311. default:
  312. return UITableViewCell()
  313. }
  314. default:
  315. return UITableViewCell()
  316. }
  317. }
  318. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  319. let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
  320. let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
  321. switch communityPostSuggestCType {
  322. //banner
  323. case .banner?:
  324. break
  325. //推荐用户
  326. case .user?:
  327. break
  328. //推荐视频
  329. case .video?:
  330. break
  331. //推荐话题
  332. case .topic?:
  333. break
  334. //贴子
  335. case .post?:
  336. switch indexPath.row {
  337. //贴子用户
  338. case 0:
  339. break
  340. //图片视频/内容标题/评论列表
  341. case 1,2,4:
  342. if PostType(rawValue: communityRecommendDataModel.type ?? "video") == .video {
  343. NotificationCenter.default.post(name: NSNotification.Name("CommunityContentVideoClosure"), object: communityRecommendDataModel.id)
  344. }else {
  345. NotificationCenter.default.post(name: NSNotification.Name("CommunityContentDetailClosure"), object: communityRecommendDataModel.id)
  346. }
  347. break
  348. //点赞,收藏,分享
  349. case 3:
  350. break
  351. //评论
  352. case 5:
  353. break
  354. default:
  355. break
  356. }
  357. break
  358. default:
  359. break
  360. }
  361. }
  362. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  363. let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
  364. let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
  365. switch communityPostSuggestCType {
  366. //banner
  367. case .banner?:
  368. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  369. return 160 * kScaleWidth
  370. }
  371. return 0
  372. //推荐用户
  373. case .user?:
  374. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  375. return 191
  376. }
  377. return 0
  378. //推荐视频
  379. case .video?:
  380. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  381. return 241
  382. }
  383. return 0
  384. //推荐话题
  385. case .topic?:
  386. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  387. return 173
  388. }
  389. return 0
  390. //贴子
  391. case .post?:
  392. switch indexPath.row {
  393. //贴子用户
  394. case 0:
  395. if communityRecommendDataModel.uid != nil {
  396. return 80
  397. }
  398. return 0
  399. //图片视频
  400. case 1:
  401. let cardContentPicVideoModel = CardContentPicVideoModel()
  402. cardContentPicVideoModel.postType = PostType(rawValue: communityRecommendDataModel.type ?? "html")
  403. let imgStr = communityRecommendDataModel.img
  404. if communityRecommendDataModel.imgs?.count ?? 0 == 0 {
  405. if communityRecommendDataModel.img != "" && communityRecommendDataModel.img != nil {
  406. cardContentPicVideoModel.number = 1
  407. cardContentPicVideoModel.width = getImageWidth(imgStr: (imgStr)!)
  408. cardContentPicVideoModel.height = getImageHeight(imgStr: (imgStr)!)
  409. return cardContentPicVideoModel.collectionViewHeight() + 15
  410. }else {
  411. return 0
  412. }
  413. }else {
  414. if communityRecommendDataModel.imgs?.count ?? 0 == 1 {
  415. if communityRecommendDataModel.img != "" || communityRecommendDataModel.img != nil {
  416. cardContentPicVideoModel.number = 1
  417. cardContentPicVideoModel.width = getImageWidth(imgStr: (imgStr)!)
  418. cardContentPicVideoModel.height = getImageHeight(imgStr: (imgStr)!)
  419. return cardContentPicVideoModel.collectionViewHeight() + 15
  420. }else {
  421. return 0
  422. }
  423. }else {
  424. cardContentPicVideoModel.number = communityRecommendDataModel.imgs?.count ?? 0
  425. return cardContentPicVideoModel.collectionViewHeight() + 15
  426. }
  427. }
  428. //内容标题
  429. case 2:
  430. var str = communityRecommendDataModel.content ?? ""
  431. str = str.replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\r", with: "")
  432. if (communityRecommendDataModel.title == "" || communityRecommendDataModel.title == nil) {
  433. if str.count >= 45 {
  434. str = str.prefix(45) + "...更多"
  435. let contentHeight = "\(str)".heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
  436. return contentHeight
  437. }else {
  438. let contentHeight = "\(str)".heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
  439. return contentHeight
  440. }
  441. }else {
  442. if PostType(rawValue: communityRecommendDataModel.type ?? "html") == .html {
  443. return 22
  444. }else {
  445. if communityRecommendDataModel.content?.count ?? 0 >= 45 {
  446. str = str.prefix(45) + "...更多"
  447. let contentHeight = "\(str)".heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
  448. return (22 + 6 + contentHeight)
  449. }else {
  450. let contentHeight = "\(str)".heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
  451. return 22 + 6 + contentHeight
  452. }
  453. }
  454. }
  455. //点赞,收藏,分享
  456. case 3:
  457. return 54
  458. //评论列表
  459. case 4:
  460. if !(communityRecommendDataModel.comment?.isEmpty ?? true) {
  461. var height : CGFloat?
  462. for communityRecommendCommentModel in communityRecommendDataModel.comment!.prefix(2) {
  463. let nameStr = "\(communityRecommendCommentModel.username ?? ""):"
  464. let contentStr = "\(communityRecommendCommentModel.content ?? "")"
  465. let str = nameStr + contentStr
  466. let strHeight = str.heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
  467. height = (height ?? 0) + strHeight
  468. }
  469. if (communityRecommendDataModel.commentCount ?? 0) <= 2 {
  470. return (height ?? 0)
  471. }else {
  472. return 23 + (height ?? 0)
  473. }
  474. }
  475. return 0
  476. //评论
  477. case 5:
  478. return 58
  479. default:
  480. return 0
  481. }
  482. default:
  483. return 0
  484. }
  485. }
  486. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  487. let communityRecommendDataModel = communityRecommendDataModels[section]
  488. let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
  489. switch communityPostSuggestCType {
  490. //banner
  491. case .banner?:
  492. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  493. return 0.000001
  494. }
  495. return 0.000001
  496. //推荐用户
  497. case .user?:
  498. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  499. return 62
  500. }
  501. return 0.000001
  502. //推荐视频
  503. case .video?:
  504. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  505. return 62
  506. }
  507. return 0.000001
  508. //推荐话题
  509. case .topic?:
  510. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  511. return 62
  512. }
  513. return 0.000001
  514. //贴子
  515. case .post?:
  516. return 0.000001
  517. default:
  518. return 0.000001
  519. }
  520. }
  521. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  522. return 10
  523. }
  524. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  525. let communityRecommendDataModel = communityRecommendDataModels[section]
  526. let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
  527. let headerView = CommunityCommonSectionHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 62))
  528. switch communityPostSuggestCType {
  529. //banner
  530. case .banner?:
  531. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  532. return nil
  533. }
  534. return nil
  535. //推荐用户
  536. case .user?:
  537. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  538. headerView.communityCommonSectionHeaderViewType = .recommendFollow
  539. return headerView
  540. }
  541. return nil
  542. //推荐视频
  543. case .video?:
  544. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  545. headerView.communityCommonSectionHeaderViewType = .popularVideo
  546. headerView.communityRecommendTypeDataModels = communityRecommendDataModel.data
  547. return headerView
  548. }
  549. return nil
  550. //推荐话题
  551. case .topic?:
  552. if !(communityRecommendDataModel.data?.isEmpty ?? true) {
  553. headerView.communityCommonSectionHeaderViewType = .featuredTopics
  554. return headerView
  555. }
  556. return nil
  557. //贴子
  558. case .post?:
  559. return nil
  560. default:
  561. return nil
  562. }
  563. }
  564. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  565. return nil
  566. }
  567. }
  568. extension CommunityRecommnendViewController {
  569. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  570. let point = scrollView.panGestureRecognizer.translation(in: self.view)
  571. if point.y < 0 {
  572. //向上
  573. if communityNavigationBarIsHidden == false && communityIndex != 2 {
  574. NotificationCenter.default.post(name: NSNotification.Name("CommunityViewControllerScrollView"), object: true)
  575. tableView.snp.updateConstraints { (make) in
  576. make.height.equalTo(kScreenHeight-44-kSafeStatusBarHeight-kTabBarTotalHeight-40)
  577. }
  578. communityNavigationBarIsHidden = true
  579. }
  580. } else {
  581. //向下
  582. if communityNavigationBarIsHidden && communityIndex != 2 {
  583. NotificationCenter.default.post(name: NSNotification.Name("CommunityViewControllerScrollView"), object: false)
  584. tableView.snp.updateConstraints { (make) in
  585. make.height.equalTo(kScreenHeight-44-kNavBarTotalHeight-kTabBarTotalHeight-40)
  586. }
  587. communityNavigationBarIsHidden = false
  588. }
  589. }
  590. self.view.layoutIfNeeded()
  591. }
  592. }
  593. extension CommunityRecommnendViewController : JXSegmentedListContainerViewListDelegate {
  594. func listView() -> UIView {
  595. return view
  596. }
  597. }