123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- //
- // CommunityRecommendController.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/6/13.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- class CommunityRecommendController: BaseViewController {
-
- deinit {
- if observe != nil {
- NotificationCenter.default.removeObserver(observe!)
- }
- }
- weak var observe : NSObjectProtocol?
- // 帖子Id
- var id : Int = 0
- var communityPostDetailModel : CommunityPostDetailModel?
- // 评论
- var communityPostCommentsModel : CommunityPostCommentsModel?
- var communityPostCommentModels = Array<CommunityPostCommentModel>()
- var communityPostCommentModel : CommunityPostCommentModel?
- var keyBoardCommentView : KeyBoardCommentView?
- // 相关推荐
- var communityPostDataModels = Array<CommunityPostDataModel>()
- // 全部评论
- var count : Int = 0
-
- var indexPath : IndexPath?
- var heights = Array<CGFloat>()
-
- /// 相关推荐高度
- var heightModel = HeightModel()
- /// 内容高度
- var heightModel1 = HeightModel()
- /// 最后滚动的位置
- var lastContentOffset : CGFloat = 0
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setupViews()
- setupLayouts()
- setupData()
- }
-
- override func setupViews() {
-
- 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)
- view.addSubview(sharedButton)
- }
-
- 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+kSafeTabBarHeight)
- make.bottom.equalToSuperview()
- }
- tableView.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(kNavBarTotalHeight)
- make.left.right.equalToSuperview()
- make.bottom.equalTo(commentView.snp_top).offset(0)
- }
- sharedButton.snp.makeConstraints { (make) in
- make.bottom.equalTo(commentView.snp_top).offset(-20)
- make.height.equalTo(71)
- make.width.equalTo(78)
- make.right.equalTo(-14)
- }
- }
-
- 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)
- tableView.separatorStyle = .none
- tableView.backgroundColor = kf7f8faColor
- tableView.dataSource = self
- tableView.delegate = self
- tableView.estimatedSectionFooterHeight = 0
- tableView.estimatedSectionHeaderHeight = 0
- tableView.estimatedRowHeight = 0
- return tableView
- }()
- lazy var communityPostDetailTableViewHeaderView: CommunityPostDetailTableViewHeaderView = {
- let communityPostDetailTableViewHeaderView = CommunityPostDetailTableViewHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 0))
- return communityPostDetailTableViewHeaderView
- }()
-
- lazy var commentView: RecommendBottomCommentView = {
- let commentView = RecommendBottomCommentView()
- return commentView
- }()
-
- lazy var sharedButton: UIButton = {
- let sharedButton = UIButton(type: UIButton.ButtonType.custom)
- sharedButton.setImage(kImage(name: "share_pic_poster_floating"), for: UIControl.State.normal)
- return sharedButton
- }()
- 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)
- //分享
- navigationBar.onClickRightButton = {
- [weak self] in
- self?.share()
- }
- sharedButton.rx.tap.subscribe(onNext: { [weak self] _ in
- self?.share()
- }).disposed(by: disposeBag)
-
- tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {
- [weak self] (page) in
- self?.communityPostDetailApi()
- self?.communityPostCommentApi(page: page)
- self?.communityPostsApi(page: page)
- }
- tableView.addFooterWithWithHeader(withAutomaticallyRefresh: true) {
- [weak self] (page) in
- self?.communityPostsApi(page: page)
- }
-
- commentView.bottomClickClosure = {
- [weak self] (clickType) in
- switch clickType {
- case BottomClickType.typeComment:
- self?.showKeyBoardCommentView(placeholder: "添加评论...")
- self?.hiddenKeyBoardCommentView()
- case BottomClickType.typeLike:
- VirusViewModel.shared.virueRecordAddApiPraise(communityPostDetailModel: self?.communityPostDetailModel,commentView: (self?.commentView)!)
- case BottomClickType.typeCollect:
- VirusViewModel.shared.virueRecordAddApiCollection(communityPostDetailModel: self?.communityPostDetailModel,commentView: (self?.commentView)!)
- }
- }
-
- 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?.communityPostDetailModel?.uid == followStatusModel?.uid {
- self?.communityPostDetailModel?.isFollow = followStatusModel?.isFollowStatus
- self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
- CommunityFollowUserViewModel.shared.setFollowType(followButton: (self?.followButton)!, followType: FollowType(rawValue: self?.communityPostDetailModel?.isFollow ?? 0) ?? .futureFollow)
- 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?.communityPostDetailModel?.uid == followStatusModel?.uid {
- self?.communityPostDetailModel?.isDislike = followStatusModel?.isFollowStatus
- self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
- 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?.communityPostDetailModel?.uid == followStatusModel?.uid {
- self?.communityPostDetailModel?.isDislike = followStatusModel?.isFollowStatus
- self?.commentView.communityPostDetailModel = self?.communityPostDetailModel
- }
-
- if !(self?.communityPostCommentModels.isEmpty ?? true) {
- for communityPostDataModel in (self?.communityPostDataModels)! {
- if communityPostDataModel.uid == followStatusModel?.uid {
- communityPostDataModel.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?.communityPostDetailModel?.uid == followStatusModel?.uid {
- self?.communityPostDetailModel?.isCollect = followStatusModel?.isFollowStatus
- self?.commentView.communityPostDetailModel = self?.communityPostDetailModel
- self?.tableView.reloadData()
- }
- self?.tableView.reloadData()
- }
- }
-
- /// 显示键盘
- func showKeyBoardCommentView(placeholder:String) {
- keyBoardCommentView = KeyBoardCommentView.keyBoardCommentView(placeholder:placeholder,sendClosure: {
- [weak self] text in
- self?.communityPostCommentApi(text: text, complete: {
- self?.keyBoardCommentView?.dismisskeyBoardCommentView()
- })
- })
- }
- /// 隐藏键盘
- func hiddenKeyBoardCommentView() {
- keyBoardCommentView?.hiddenViewClosure = {
- [weak self] in
- self?.communityPostCommentModel = nil
- }
- }
-
-
- /// 分享
- func share() {
- var title = self.communityPostDetailModel?.title?.prefix(12)
- if title == nil || title == "" {
- title = self.communityPostDetailModel?.content?.prefix(12) ?? ""
- }
- let shareCommunityView = ShareCommunityView.shareCommunityView(
- title: "向好友传递美好生活,送TA 500彩虹豆",
- detailTitle: "越多好友看到,收获彩虹豆越多",
- h5Str: (self.communityPostDetailModel?.h5url ?? "" + "\(UserModel.shared().getModel()?.inviteCode ?? "")"),
- thumbnailImg: UIImage.imageUrl(self.communityPostDetailModel?.img),
- sharedTitle: String(title ?? ""),
- sharedDetailTitle: kCommunityPostDetailTitleShare,
- shareCommunityViewType: ShareCommunityViewType.postDetail,
- completion: {
- VirusViewModel.shared.forwarVirueRecordAddApi(postId: self.communityPostDetailModel?.id, postAuthorUid: "\(self.communityPostDetailModel?.uid ?? 0)", title: self.communityPostDetailModel?.title, content: self.communityPostDetailModel?.content, postType: self.communityPostDetailModel?.type, postCover: self.communityPostDetailModel?.img)
- })
- shareCommunityView.saveCompletion = {
- [weak self] in
- let vc = CommunityShareContentViewController()
- vc.imgUrl = self?.communityPostDetailModel?.img
- let communityPostDetailTopicModel = self?.communityPostDetailModel?.topic?[0]
- vc.topicStr = communityPostDetailTopicModel?.name ?? ""
- if self?.communityPostDetailModel?.title == "" || self?.communityPostDetailModel?.title == nil {
- vc.titleStr =
- String(self?.communityPostDetailModel?.content?.prefix(20) ?? "")
- }else {
- vc.titleStr = String(self?.communityPostDetailModel?.title?.prefix(20) ?? "")
- }
- vc.avatarStr = self?.communityPostDetailModel?.avatar
- vc.nameStr = self?.communityPostDetailModel?.username
- vc.H5UrlStr = (self?.communityPostDetailModel?.h5url ?? "" + "\(UserModel.shared().getModel()?.inviteCode ?? "")")
- vc.bean = self?.communityPostDetailModel?.willCollectBean
- vc.postId = self?.communityPostDetailModel?.id
- vc.uid = self?.communityPostDetailModel?.uid
- vc.type = self?.communityPostDetailModel?.type
- vc.contentStr = self?.communityPostDetailModel?.content
- self?.navigationController?.pushViewController(vc, animated: true)
- }
- }
-
- }
- 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)
- if self?.communityPostDetailModel?.uid == UserModel.shared().getModel()?.uid {
- self?.followButton.isHidden = true
- }else {
- self?.followButton.isHidden = false
- }
- CommunityFollowUserViewModel.shared.setFollowType(followButton: (self?.followButton)!, followType: FollowType(rawValue: self?.communityPostDetailModel?.isFollow ?? 0) ?? .futureFollow)
- self?.commentView.communityPostDetailModel = self?.communityPostDetailModel
- if PostType(rawValue: self?.communityPostDetailModel?.type ?? "html") == .html {
- self?.avatarButton.isHidden = true
- self?.nameButton.isHidden = true
- self?.followButton.isHidden = true
- }else {
- if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid {
- self?.followButton.isHidden = false
- }else {
- self?.followButton.isHidden = true
- }
- if !(self?.communityPostDetailModel?.imgs?.isEmpty ?? true) {
- let height = getImageHeight(imgStr: (self?.communityPostDetailModel?.imgs?[0])!)
- let width = getImageWidth(imgStr: (self?.communityPostDetailModel?.imgs?[0])!)
- self?.communityPostDetailTableViewHeaderView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth*height/width)
- self?.communityPostDetailTableViewHeaderView.tableView = self?.tableView
- self?.tableView.tableHeaderView = self?.communityPostDetailTableViewHeaderView
-
- }else {
- if self?.communityPostDetailModel?.img != nil || self?.communityPostDetailModel?.img != "" {
- let height = getImageHeight(imgStr: (self?.communityPostDetailModel?.img)!)
- let width = getImageWidth(imgStr: (self?.communityPostDetailModel?.img)!)
- self?.communityPostDetailTableViewHeaderView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth*height/width)
- self?.communityPostDetailTableViewHeaderView.tableView = self?.tableView
- self?.tableView.tableHeaderView = self?.communityPostDetailTableViewHeaderView
- }
- }
- self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
- }
-
- self?.tableView.reloadData()
- VirusViewModel.shared.read(communityPostDetailModel: (self?.communityPostDetailModel)!)
- }
- }
-
- /// 评论列表
- ///
- /// - Parameters:
- /// - postId: 内容id
- /// - page: 分页
- func communityPostCommentApi(page:Int) {
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentsApi(postId: id, page: page) {
- [weak self] (communityPostCommentsModel) -> (Void) in
- self?.communityPostCommentsModel = communityPostCommentsModel as? CommunityPostCommentsModel
- self?.count = self?.communityPostCommentsModel?.pagination?.total ?? 0
- if self?.communityPostCommentsModel?.pagination?.currentPage == 1{
- self?.communityPostCommentModels.removeAll()
- }
- self?.communityPostCommentModels = (self?.communityPostCommentModels)! + (self?.communityPostCommentsModel?.data!)!
- self?.tableView.reloadData()
- }
- }
-
- /// 相关推荐
- ///
- /// - 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)
- }
- }
- }
-
-
- /// 评论
- func communityPostCommentApi(text:String,complete: @escaping () -> ()) {
- let communityCustomCommnetModel = CommunityCustomCommnetModel()
- communityCustomCommnetModel.postId = communityPostDetailModel?.id ?? 0
- communityCustomCommnetModel.content = text
- if communityPostCommentModel != nil {
- communityCustomCommnetModel.parentId = communityPostCommentModel?.id
- communityCustomCommnetModel.replyUid = communityPostCommentModel?.uid
- communityCustomCommnetModel.replyUsername = communityPostCommentModel?.username
- }
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
- [weak self] (communityPostCommentIdModel) -> (Void) in
-
- let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
-
- if self?.communityPostCommentModel == nil { //评
- let communityPostCommentModel = CommunityPostCommentModel()
- communityPostCommentModel.avatar = UserModel.shared().getModel()?.avatarurl
- communityPostCommentModel.content = text
- communityPostCommentModel.createdAt = "刚刚"
- communityPostCommentModel.id = communityPostCommentIdModel?.id
- communityPostCommentModel.username = UserModel.shared().getModel()?.username
- communityPostCommentModel.uid = UserModel.shared().getModel()?.uid
- self?.communityPostCommentModels.insert(communityPostCommentModel, at: 0)
- VirusViewModel.shared.comment(communityPostDetailModel: (self?.communityPostDetailModel)!, id: communityPostCommentIdModel?.id ?? 0)
- self?.count += 1
- self?.communityPostDetailModel?.commentCount = self?.count
- self?.commentView.communityPostDetailModel = self?.communityPostDetailModel
- self?.tableView.reloadData()
- }else { //回评论
- let communityPostReplyModel = CommunityPostReplyModel()
- communityPostReplyModel.avatar = UserModel.shared().getModel()?.avatarurl
- communityPostReplyModel.content = text
- communityPostReplyModel.createdAt = "刚刚"
- communityPostReplyModel.id = communityPostCommentIdModel?.id
- communityPostReplyModel.username = UserModel.shared().getModel()?.username
- communityPostReplyModel.uid = UserModel.shared().getModel()?.uid
- let count = self?.communityPostCommentModel?.replyCount ?? 0 + 1
- self?.communityPostCommentModel?.replyCount = count
- if self?.communityPostCommentModel?.reply == nil {
- self?.communityPostCommentModel?.reply = Array<CommunityPostReplyModel>()
- }
- self?.communityPostCommentModel?.reply?.insert(communityPostReplyModel, at: 0)
- VirusViewModel.shared.comment(communityPostDetailModel: (self?.communityPostDetailModel)!, id: communityPostCommentIdModel?.id ?? 0, communityPostCommentModel: self?.communityPostCommentModel)
- self?.tableView.reloadData()
- }
- complete()
- }
- }
- }
- // MARK: - tableView dataSource && delegate
- extension CommunityRecommendController: UITableViewDataSource, UITableViewDelegate {
-
- func numberOfSections(in tableView: UITableView) -> Int {
- return 3
- }
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- switch section {
- case 0:
- if communityPostDetailModel != nil {
- return 1
- }else {
- return 0
- }
- case 1:
- return communityPostCommentModels.isEmpty ? 1 : communityPostCommentModels.count
- case 2:
- return 1
- default:
- return 0
- }
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- switch indexPath.section {
- case 0:
-
- if PostType(rawValue: communityPostDetailModel?.type ?? "html") == .html {
- let cell = CommunityRecommendDetailHTMLTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityPostDetailModel = communityPostDetailModel
- cell.frame = tableView.bounds
- cell.layoutIfNeeded()
- cell.reloadData()
- cell.heightModel = heightModel1
- cell.tableView = tableView
- return cell
- }else {
- let cell = RecommendDetailContentCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityPostDetailModel = communityPostDetailModel
- cell.frame = tableView.bounds
- cell.layoutIfNeeded()
- cell.reloadData()
- cell.heightModel = heightModel1
- return cell
- }
-
- case 1:
- if communityPostCommentModels.isEmpty {
- let cell = RecommendNoneCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityPostDetailModel = communityPostDetailModel
- cell.commentClosure = {
- [weak self] in
- self?.showKeyBoardCommentView(placeholder: "添加评论...")
- self?.hiddenKeyBoardCommentView()
- }
- cell.userClosure = {
- [weak self] in
- if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid {
- let vc = OtherPersonalCenterViewController()
- vc.uid = self?.communityPostDetailModel?.uid ?? 0
- self?.navigationController?.pushViewController(vc, animated: true)
- }
- }
- return cell
- }else {
- let cell = RecommendMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityPostDetailModel = communityPostDetailModel
- cell.communityPostCommentModel = communityPostCommentModels[indexPath.row]
- cell.frame = tableView.bounds
- cell.layoutIfNeeded()
- cell.reloadData()
- return cell
- }
- case 2:
- let cell = RecommendSimilarCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.heights = heights
- cell.communityPostDataModels = communityPostDataModels
- cell.frame = tableView.bounds
- cell.layoutIfNeeded()
- cell.reloadData()
- cell.heightModel = heightModel
- return cell
- default:
- return UITableViewCell()
- }
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- switch indexPath.section {
- case 0:
-
- if PostType(rawValue: communityPostDetailModel?.type ?? "html") == .html {
-
- }else {
- }
- case 1:
- if communityPostCommentModels.isEmpty {
- break
- }else {
- communityPostCommentModel = self.communityPostCommentModels[indexPath.row]
- self.indexPath = indexPath
- AlertSheetView.sheetCommentReplyView(userName: communityPostCommentModel?.username ?? "", content: communityPostCommentModel?.content ?? "") {
- [weak self] in
- self?.communityPostCommentModel = self?.communityPostCommentModels[indexPath.row]
- self?.showKeyBoardCommentView(placeholder: "回复:@\(self?.communityPostCommentModel?.username ?? "")")
- self?.hiddenKeyBoardCommentView()
- }
- break
- }
- case 2:
- break
- default:
- break
- }
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- switch indexPath.section {
- case 0:
- return heightModel1.height ?? 0
- case 1:
- if communityPostCommentModels.isEmpty {
- return 132
- }else {
- return communityPostCommentModels[indexPath.row].height ?? 0
- }
- case 2:
- return heightModel.height ?? 0
- default:
- return 0
- }
-
-
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- switch section {
- case 0:
- return 0.000001
- case 1:
- if communityPostCommentModels.isEmpty {
- return 0.000001
- }else {
- return 64
- }
- case 2:
- return 52
- default:
- return 0.000001
- }
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- switch section {
- case 0:
- return UIView()
- case 1:
- if communityPostCommentModels.isEmpty {
- return UIView()
- }else {
- let headerView = RecommendCommentHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 64))
- headerView.count = count
- return headerView
- }
- case 2:
- return RecommendSimilarHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 52))
- default:
- return UIView()
- }
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- switch section {
- case 0:
- return 10
- case 1:
- if communityPostCommentModels.isEmpty {
- return 0.000001
- }else {
- if communityPostCommentsModel?.pagination?.currentPage ?? 0 >= communityPostCommentsModel?.pagination?.totalPages ?? 0 {
- return 0.000001
- }else {
- return 51
- }
- }
- case 2:
- return 0.000001
- default:
- return 0.000001
- }
- }
-
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- switch section {
- case 0:
- return UIView()
- case 1:
- if communityPostCommentModels.isEmpty {
- return UIView()
- }else {
-
- if communityPostCommentsModel?.pagination?.currentPage ?? 0 >= communityPostCommentsModel?.pagination?.totalPages ?? 0 {
- return UIView()
- }else {
- let footerView = RecommendCommentFooter(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 51))
- footerView.unfoldClosure = {
- [weak self] in
- self?.communityPostCommentApi(page: (self?.communityPostCommentsModel?.pagination?.currentPage ?? 0) + 1)
- }
- return footerView
- }
- }
- case 2:
- return UIView()
- default:
- return UIView()
- }
- }
-
- }
- // MARK: - scrollView
- extension CommunityRecommendController {
- func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
- lastContentOffset = scrollView.contentOffset.y
- }
-
- func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
- if lastContentOffset < scrollView.contentOffset.y {
- sharedButton.isHidden = true
- }else{
- sharedButton.isHidden = false
- }
- }
-
- func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
- sharedButton.isHidden = false
- }
- }
|