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