123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744 |
- //
- // CommunityRecommnendViewController.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/6/28.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import JXSegmentedView
- import Kingfisher
- import SwiftyMediator
- class CommunityRecommnendViewController: UIViewController {
-
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- KingfisherManager.shared.cache.clearDiskCache()
- KingfisherManager.shared.cache.clearMemoryCache()
- }
-
- deinit {
- NXLLog("deinit")
- if observe != nil {
- NotificationCenter.default.removeObserver(observe!)
- }
- }
- weak var observe : NSObjectProtocol?
-
- var communityRecommendDataModels = Array<CommunityRecommendDataModel>()
- /// 评论需要的模型
- var communityRecommendDataModel : CommunityRecommendDataModel?
-
- var communityRecommendCategoryModel : CommunityRecommendCategoryModel?
-
- var navigationBarIsHidden: Bool = false
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setupViews()
- setupLayouts()
- setupData()
- }
-
- func setupViews() {
- view.backgroundColor = kf7f8faColor
- view.addSubview(tableView)
- }
-
- func setupLayouts() {
- tableView.snp.makeConstraints { (make) in
- make.top.left.right.equalToSuperview()
- make.height.equalTo(kScreenHeight-44-kNavBarTotalHeight-kTabBarTotalHeight-40)
- }
- tableView.reloadData()
- }
-
- func setupData() {
- //下拉刷新
- tableView.addHeader(withBeginRefresh: true, animation: true) {
- [weak self] (page) in
- self?.communityPostSuggestApi(page:page)
- }
- tableView.addAutoNormalFooter(withAutomaticallyRefresh: true, loadMoreBlock: {
- [weak self] (page) in
- self?.communityPostSuggestApi(page:page)
- })
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("login"), object: nil, queue: OperationQueue.main, using: {
- [weak self] (notification) in
- self?.tableView.mj_header?.beginRefreshing()
- })
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("loginOut"), object: nil, queue: OperationQueue.main, using: {
- [weak self] (notification) in
- self?.tableView.mj_header?.beginRefreshing()
- })
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("followApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let followStatusModel = notification.object as? FollowStatusModel
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.uid == followStatusModel?.uid {
- communityRecommendDataModel.isFollow = followStatusModel?.isFollowStatus
- }
- }
- }
- self?.tableView.reloadData()
- }
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("unlikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let followStatusModel = notification.object as? FollowStatusModel
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.id == followStatusModel?.postId {
- communityRecommendDataModel.isDislike = followStatusModel?.isFollowStatus
- }
- }
- }
- self?.tableView.reloadData()
- }
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("islikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let followStatusModel = notification.object as? FollowStatusModel
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.id == followStatusModel?.postId {
- communityRecommendDataModel.isLike = followStatusModel?.isFollowStatus
- }
- }
- }
- self?.tableView.reloadData()
- }
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("isCollectApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let followStatusModel = notification.object as? FollowStatusModel
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.id == followStatusModel?.postId {
- communityRecommendDataModel.isCollect = followStatusModel?.isFollowStatus
- }
- }
- }
- self?.tableView.reloadData()
- }
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("isCommnetLikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let followStatusModel = notification.object as? FollowStatusModel
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.id == followStatusModel?.postId {
- if !(communityRecommendDataModel.comment?.isEmpty ?? true ){
- for communityRecommendCommentModel in communityRecommendDataModel.comment! {
- if communityRecommendCommentModel.id == followStatusModel?.commnetId {
- communityRecommendCommentModel.isLike = followStatusModel?.isFollowStatus
- communityRecommendCommentModel.likeCount = followStatusModel?.commentLikeCount
- }
- }
- }
- }
- }
- }
- self?.tableView.reloadData()
- }
-
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("communityDeletePostApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let postId = notification.object as? Int
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- for (index,communityRecommendDataModel) in (self?.communityRecommendDataModels)!.enumerated() {
- if communityRecommendDataModel.id == postId {
- self?.communityRecommendDataModels.remove(at: index)
- }
- }
- self?.tableView.reloadData()
- }
- }
-
- // observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("CommunityModuleRecommendTop"), object: nil, queue: OperationQueue.main, using: {
- // [weak self] (notification) in
- // if self?.isViewLoaded ?? true && ((self?.view.window) != nil) {
- // if self?.tableView.contentOffset == CGPoint(x: 0, y: 0) {
- // self?.tableView.mj_header.beginRefreshing()
- // }else {
- // self?.tableView.scrollToTop()
- // }
- // }
- // })
-
- }
-
- private lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
- tableView.separatorStyle = .none
- tableView.backgroundColor = kf7f8faColor
- tableView.dataSource = self
- tableView.delegate = self
- tableView.contentInset = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
- return tableView
- }()
-
- private lazy var followTableHeaderView: CommunityFollowTableHeaderView = {
- let followTableHeaderView = CommunityFollowTableHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 286))
- return followTableHeaderView
- }()
-
- /// 显示键盘
- func showKeyBoardCommentView() {
-
- KeyBoardInputView.show(inputViewResultClosure: {
- [weak self] (text) in
- self?.communityPostCommentApi(text: text, complete: {
- [weak self] in
- self?.communityRecommendDataModel = nil
- })
- }) {
- [weak self] in
- self?.communityRecommendDataModel = nil
- }
- }
-
- }
- extension CommunityRecommnendViewController {
-
- /// 推荐feed流
- ///
- /// - Parameter page: 分页
- func communityPostSuggestApi(page:Int) {
-
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostSuggestApi(page:page,categoryId:communityRecommendCategoryModel?.id ?? 0,completion: {
- [weak self] (communityRecommendFeedModel) -> (Void) in
- DIYEmptyView.emptyNoDataTableView(tableView: self?.tableView, imageStr: DIYEmptyViewImageStr.one, detailStr: DIYEmptyViewDetailString.one)
- let communityRecommendFeedModel = communityRecommendFeedModel as? CommunityRecommendFeedModel
- if communityRecommendFeedModel?.pagination?.currentPage == 1{
- self?.communityRecommendDataModels.removeAll()
- self?.tableView.resetNoMoreData()
- }
- self?.communityRecommendDataModels = (self?.communityRecommendDataModels)! + (communityRecommendFeedModel?.data!)!
- self?.tableView.reloadData()
- MJRefreshManager.mjRefreshManagerNoHiddenFooter(tableView: self?.tableView, pagination: communityRecommendFeedModel?.pagination)
- }) {
- [weak self] (loadingStatus) in
- MJRefreshManager.mjRefreshManagerLoadingStatus(tableView: self?.tableView,loadingStatus: loadingStatus)
- }
-
- }
-
- /// 评论
- func communityPostCommentApi(text:String,complete:@escaping () -> ()) {
- let communityCustomCommnetModel = CommunityCustomCommnetModel()
- communityCustomCommnetModel.postId = communityRecommendDataModel?.id ?? 0
- communityCustomCommnetModel.content = text
-
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
- [weak self] (communityPostCommentIdModel) -> (Void) in
-
- let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
-
- let communityRecommendCommentModel = CommunityRecommendCommentModel()
- communityRecommendCommentModel.content = text
- communityRecommendCommentModel.id = communityPostCommentIdModel?.id
- communityRecommendCommentModel.username = UserModel.shared().getModel()?.username
- communityRecommendCommentModel.uid = UserModel.shared().getModel()?.uid
-
- if self?.communityRecommendDataModel?.comment?.isEmpty ?? true {
- self?.communityRecommendDataModel?.comment = Array<CommunityRecommendCommentModel>()
- }
-
- self?.communityRecommendDataModel?.comment?.insert(communityRecommendCommentModel, at: 0)
-
- VirusViewModel.shared.comment(communityRecommendDataModel: self?.communityRecommendDataModel, id: communityPostCommentIdModel?.id ?? 0,content: text)
-
- let count = (1 + (self?.communityRecommendDataModel?.commentCount ?? 0))
- self?.communityRecommendDataModel?.commentCount = count
- self?.tableView.reloadData()
- complete()
-
- }
- }
-
-
- /// 删除帖子
- func communityDeleteApi(postId:Int,section:Int) {
- SwiftMoyaNetWorkServiceCommunity.shared().communityDeleteApi(postId: postId) { [weak self] (data) -> (Void) in
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- self?.communityRecommendDataModels.remove(at: section)
- }
- self?.tableView.reloadData()
- }
- }
- }
- extension CommunityRecommnendViewController : UITableViewDelegate,UITableViewDataSource {
- func numberOfSections(in tableView: UITableView) -> Int {
- return communityRecommendDataModels.isEmpty ? 0 : communityRecommendDataModels.count
- }
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- let communityRecommendDataModel = communityRecommendDataModels[section]
- if CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "") == .post {
- return 6
- }else {
- return 1
- }
-
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-
- let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
- let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
- switch communityPostSuggestCType {
- case .banner?: //banner
- let cell = CommunityBannerTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- cell.communityRecommendTypeDataModels = communityRecommendDataModel.data
- }
- return cell
- case .user?: //推荐用户
- let cell = CommunityRecommendFollowTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.type = .recommend
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- cell.communityRecommendTypeDataModels = communityRecommendDataModel.data
- cell.followClosure1 = {
- [weak self] (isFollow,communityRecommendTypeDataModel) in
- for (_,model) in (self?.communityRecommendDataModels.enumerated())! {
- let communityPostSuggestCType = CommunityPostSuggestType(rawValue: model.showType ?? "")
- if communityPostSuggestCType == .post {
- if model.uid == communityRecommendTypeDataModel.uid {
- model.isFollow = isFollow
- tableView.reloadData()
- }
- }
- }
- }
- }
- return cell
- case .video?: //推荐视频
- let cell = PopularVideoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- cell.communityRecommendTypeDataModels = communityRecommendDataModel.data
- }
- return cell
- case .topic?: //推荐话题
- let cell = FeaturedTopicsTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- cell.communityRecommendTypeDataModels = communityRecommendDataModel.data
- }
- return cell
- case .post?: //贴子
- switch indexPath.row {
- //贴子用户
- case 0:
- let cell = CardContentUserTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- cell.followClosure = {
- [weak self] in
- CommunityFollowUserViewModel.shared.follow(communityRecommendDataModel: communityRecommendDataModel, communityRecommendDataModels: (self?.communityRecommendDataModels)!, tableView: tableView)
- }
- cell.likeClosure = { y in
- if UserModel.shared().isEqualUid(uid: communityRecommendDataModel.uid ?? 0) {
- CardContentUserDeleteView.sheetDeleteView(y: y, sureClosure: { [weak self] (cardContentUserDeleteView) in
- self?.communityDeleteApi(postId: communityRecommendDataModel.id ?? 0, section: indexPath.section)
- })
- }else {
- VirusViewModel.shared.like(communityRecommendDataModel: communityRecommendDataModel, y: y, tableView: tableView)
- }
- }
- return cell
- //内容标题
- case 1:
-
- if PostType(rawValue: communityRecommendDataModel.type ?? "html") == .html {
- let cell = CardTitleHTMLTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- return cell
- }else {
- let cell = CardContentTitleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- return cell
- }
- //图片视频
- case 2:
- if PostType(rawValue: communityRecommendDataModel.type ?? "html") == .html {
- let cell = CardContentPicHTMLTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- return cell
- }else {
- let cell = CardContentPicVideoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.type = .recommend
- cell.communityRecommendDataModel = communityRecommendDataModel
- return cell
- }
-
- //点赞,收藏,分享
- case 3:
- let cell = CardContentActionTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- cell.praiseClosureName = { (button:UIButton) in
- VirusViewModel.shared.praise(communityRecommendDataModel: communityRecommendDataModel, tableView: tableView)
- }
- cell.collectClosureName = {
- (button:UIButton) in
- VirusViewModel.shared.collection(communityRecommendDataModel: communityRecommendDataModel, tableView: tableView)
- }
- return cell
- //评论列表
- case 4:
- let cell = CardContentCommentListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- return cell
- //评论
- case 5:
- let cell = CardContentCommnetTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.addCommnetClosureName = {
- [weak self] in
- self?.communityRecommendDataModel = self?.communityRecommendDataModels[indexPath.section]
- self?.showKeyBoardCommentView()
- }
- cell.isAvatar = true
- return cell
- default:
- return UITableViewCell()
- }
- default:
- return UITableViewCell()
- }
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
- let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
- switch communityPostSuggestCType {
- //banner
- case .banner?:
- break
- //推荐用户
- case .user?:
- break
- //推荐视频
- case .video?:
- break
- //推荐话题
- case .topic?:
- break
- //贴子
- case .post?:
- switch indexPath.row {
- //贴子用户
- case 0:
- break
- //图片视频/内容标题/评论列表
- case 1,2:
- if PostType(rawValue: communityRecommendDataModel.type ?? "video") == .video {
- Mediator.push(CommunityRouterModuleType.pushPostDetailVoide(postId: "\(communityRecommendDataModel.id ?? 0)", departType: .others, topicId: 0))
- }else {
- Mediator.push(CommunityRouterModuleType.pushPostDetailContent(postId: "\(communityRecommendDataModel.id ?? 0)"))
- }
- break
- //点赞,收藏,分享
- case 3:
- break
- //评论
- case 5:
- break
- default:
- break
- }
- break
- default:
- break
- }
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
-
- let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
- let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
- switch communityPostSuggestCType {
- //banner
- case .banner?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return 160 * kScaleWidth
- }
- return 0
- //推荐用户
- case .user?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return 191
- }
- return 0
- //推荐视频
- case .video?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return 241
- }
- return 0
- //推荐话题
- case .topic?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return 173
- }
- return 0
- //贴子
- case .post?:
- switch indexPath.row {
- //贴子用户
- case 0:
- if communityRecommendDataModel.uid != nil {
- return 80
- }
- return 0
- //内容标题
- case 1:
-
- if PostType(rawValue: communityRecommendDataModel.type ?? "html") == .html {
- var titleStr = communityRecommendDataModel.title ?? ""
- titleStr = titleStr.replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\r", with: "")
- let subtitleLabelHeight = titleStr.heightForComment(font: kMediumFont16!, width: kScreenWidth-28, maxHeight: 44.0)
- return subtitleLabelHeight
- }else {
- var titleStr = communityRecommendDataModel.title ?? ""
- titleStr = titleStr.replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\r", with: "")
-
- var str = communityRecommendDataModel.content ?? ""
- str = str.replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\r", with: "")
-
- let subtitleLabelHeight = str.heightForComment(font: kRegularFont14!, width: kScreenWidth-28, maxHeight: 40.0)
-
- if titleStr == "" {
- return subtitleLabelHeight
- }else {
- return 22 + 6 + subtitleLabelHeight
- }
- }
-
-
- //图片视频
- case 2:
-
- if PostType(rawValue: communityRecommendDataModel.type ?? "html") == .html {
- return 82
- }else {
- let cardContentPicVideoModel = CardContentPicVideoModel()
- cardContentPicVideoModel.postType = PostType(rawValue: communityRecommendDataModel.type ?? "html")
-
- let imgStr = communityRecommendDataModel.img
- if communityRecommendDataModel.imgs?.count ?? 0 == 0 {
- if communityRecommendDataModel.img != "" && communityRecommendDataModel.img != nil {
- cardContentPicVideoModel.number = 1
- cardContentPicVideoModel.width = getImageWidth(imgStr: (imgStr)!)
- cardContentPicVideoModel.height = getImageHeight(imgStr: (imgStr)!)
- return cardContentPicVideoModel.collectionViewHeight() + 12
- }else {
- return 0
- }
- }else {
- if communityRecommendDataModel.imgs?.count ?? 0 == 1 {
- if communityRecommendDataModel.img != "" || communityRecommendDataModel.img != nil {
- cardContentPicVideoModel.number = 1
- cardContentPicVideoModel.width = getImageWidth(imgStr: (imgStr)!)
- cardContentPicVideoModel.height = getImageHeight(imgStr: (imgStr)!)
- return cardContentPicVideoModel.collectionViewHeight() + 12
- }else {
- return 0
- }
- }else {
- cardContentPicVideoModel.number = communityRecommendDataModel.imgs?.count ?? 0
- return cardContentPicVideoModel.collectionViewHeight() + 12
- }
- }
- }
- //点赞,收藏,分享
- case 3:
- return 54
- //评论列表
- case 4:
- if !(communityRecommendDataModel.comment?.isEmpty ?? true) {
-
- var height : CGFloat?
- for communityRecommendCommentModel in communityRecommendDataModel.comment!.prefix(2) {
-
- let nameStr = "\(communityRecommendCommentModel.username ?? ""):"
- let contentStr = "\(communityRecommendCommentModel.content ?? "")"
-
- let likeCountStr = "\(communityRecommendCommentModel.likeCount ?? 0)"
- let likeWidth = likeCountStr.widthForComment(font: kRegularFont14!, height: 25.5)
-
- let str = nameStr + contentStr
- let strHeight = (str.heightForComment(font: kMediumFont14!, width: kScreenWidth-28-10-20-5-likeWidth) + 5)
- height = (height ?? 0) + strHeight
- }
-
- if (communityRecommendDataModel.commentCount ?? 0) <= 2 {
- return (height ?? 0)
- }else {
- return 23 + (height ?? 0)
- }
- }
- return 0
- //评论
- case 5:
- return 50
- default:
- return 0
- }
- default:
- return 0
- }
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
-
- let communityRecommendDataModel = communityRecommendDataModels[section]
- let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
- switch communityPostSuggestCType {
- //banner
- case .banner?:
-
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return 0.000001
- }
- return 0.000001
- //推荐用户
- case .user?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return 62
- }
- return 0.000001
- //推荐视频
- case .video?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return 62
- }
- return 0.000001
- //推荐话题
- case .topic?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return 62
- }
- return 0.000001
- //贴子
- case .post?:
- return 0.000001
- default:
- return 0.000001
- }
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 10
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
-
- let communityRecommendDataModel = communityRecommendDataModels[section]
- let communityPostSuggestCType = CommunityPostSuggestType(rawValue: communityRecommendDataModel.showType ?? "")
- let headerView = CommunityCommonSectionHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 62))
- switch communityPostSuggestCType {
- //banner
- case .banner?:
-
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- return nil
- }
- return nil
- //推荐用户
- case .user?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- headerView.communityCommonSectionHeaderViewType = .recommendFollow
- return headerView
- }
- return nil
- //推荐视频
- case .video?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- headerView.communityCommonSectionHeaderViewType = .popularVideo
- headerView.communityRecommendTypeDataModels = communityRecommendDataModel.data
- return headerView
- }
- return nil
- //推荐话题
- case .topic?:
- if !(communityRecommendDataModel.data?.isEmpty ?? true) {
- headerView.communityCommonSectionHeaderViewType = .featuredTopics
- return headerView
- }
- return nil
- //贴子
- case .post?:
- return nil
- default:
- return nil
- }
- }
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- return nil
- }
- }
- extension CommunityRecommnendViewController {
-
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
-
- let point = scrollView.panGestureRecognizer.translation(in: self.view)
-
- if point.y < 0 {
- //向上
- if communityNavigationBarIsHidden == false {
- NotificationCenter.default.post(name: NSNotification.Name("CommunityViewControllerScrollView"), object: true)
- tableView.snp.updateConstraints { (make) in
- make.height.equalTo(kScreenHeight-44-kSafeStatusBarHeight-kTabBarTotalHeight)
- }
- communityNavigationBarIsHidden = true
- }
- } else {
- //向下
-
- if communityNavigationBarIsHidden {
- NotificationCenter.default.post(name: NSNotification.Name("CommunityViewControllerScrollView"), object: false)
- tableView.snp.updateConstraints { (make) in
- make.height.equalTo(kScreenHeight-44-kNavBarTotalHeight-kTabBarTotalHeight)
- }
- communityNavigationBarIsHidden = false
- }
- }
- self.view.layoutIfNeeded()
- }
- }
- extension CommunityRecommnendViewController : JXSegmentedListContainerViewListDelegate {
- func listView() -> UIView {
- return view
- }
-
- func listDidAppear() {
- if communityNavigationBarIsHidden {
- tableView.snp.updateConstraints { (make) in
- make.height.equalTo(kScreenHeight-44-kSafeStatusBarHeight-kTabBarTotalHeight)
- }
- }else {
- tableView.snp.updateConstraints { (make) in
- make.height.equalTo(kScreenHeight-44-kNavBarTotalHeight-kTabBarTotalHeight)
- }
- }
- }
- }
|