|
@@ -0,0 +1,252 @@
|
|
|
+//
|
|
|
+// CommunityVideoMajorCommentCell.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by Christopher on 2019/7/11.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+// 视频播放评论の主Cell
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import RxSwift
|
|
|
+
|
|
|
+class CommunityVideoMajorCommentCell: UITableViewCell {
|
|
|
+
|
|
|
+ let disposeBag = DisposeBag()
|
|
|
+
|
|
|
+ /// 相关推荐高度
|
|
|
+ var heightModel1 = HeightModel()
|
|
|
+
|
|
|
+ class func cellWith(tableView:UITableView,indexPath:IndexPath) -> CommunityVideoMajorCommentCell {
|
|
|
+ let ID = "CommunityVideoMajorCommentCell"
|
|
|
+ tableView.register(CommunityVideoMajorCommentCell.self, forCellReuseIdentifier: ID)
|
|
|
+ let cell : CommunityVideoMajorCommentCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! CommunityVideoMajorCommentCell
|
|
|
+ cell.indexPath = indexPath
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
+ super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
+ setupViews()
|
|
|
+ setupLayouts()
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ var indexPath: IndexPath? {
|
|
|
+ didSet {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //MRAK: - 设置View
|
|
|
+ private func setupViews() {
|
|
|
+ self.selectionStyle = .none
|
|
|
+ backgroundColor = kffffffColor
|
|
|
+
|
|
|
+ addSubview(iconButton)
|
|
|
+ addSubview(titleLabel)
|
|
|
+ addSubview(contentLabel)
|
|
|
+ addSubview(timeLabel)
|
|
|
+ addSubview(tableView)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func setupLayouts() {
|
|
|
+ iconButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(0)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.size.equalTo(24)
|
|
|
+ }
|
|
|
+ titleLabel.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(iconButton.snp_right).offset(10)
|
|
|
+ make.right.equalToSuperview().offset(-26)
|
|
|
+ make.centerY.equalTo(iconButton)
|
|
|
+ make.height.equalTo(17)
|
|
|
+ }
|
|
|
+
|
|
|
+ contentLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(iconButton.snp_bottom).offset(6)
|
|
|
+ make.left.equalTo(48)
|
|
|
+ make.right.equalToSuperview().offset(-14)
|
|
|
+ }
|
|
|
+ timeLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(contentLabel.snp_bottom).offset(8)
|
|
|
+ make.left.equalTo(titleLabel.snp_left)
|
|
|
+ make.right.equalTo(contentLabel.snp_right)
|
|
|
+ make.height.equalTo(15)
|
|
|
+ }
|
|
|
+ tableView.snp.remakeConstraints { (make) in
|
|
|
+ make.top.equalTo(timeLabel.snp_bottom).offset(10)
|
|
|
+ make.left.equalTo(contentLabel.snp_left)
|
|
|
+ make.right.equalTo(contentLabel.snp_right)
|
|
|
+ make.height.equalTo(20)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private lazy var iconButton : UIButton = {
|
|
|
+ let iconButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ iconButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal)
|
|
|
+ iconButton.cornerRadius = 12
|
|
|
+ iconButton.masksToBounds = true
|
|
|
+ iconButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ return iconButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var titleLabel: UILabel = {
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.textColor = k999999Color
|
|
|
+ titleLabel.font = kRegularFont14
|
|
|
+ titleLabel.textAlignment = .left
|
|
|
+ return titleLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var contentLabel: UILabel = {
|
|
|
+ let contentLabel = UILabel()
|
|
|
+ contentLabel.textColor = k333333Color
|
|
|
+ contentLabel.font = kRegularFont14
|
|
|
+ contentLabel.textAlignment = .left
|
|
|
+ contentLabel.numberOfLines = 0
|
|
|
+ return contentLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var timeLabel: UILabel = {
|
|
|
+ let timeLabel = UILabel()
|
|
|
+ timeLabel.textColor = kbbbbbbColor
|
|
|
+ timeLabel.font = kRegularFont12
|
|
|
+ timeLabel.textAlignment = .left
|
|
|
+ return timeLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ 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
|
|
|
+ tableView.isScrollEnabled = false
|
|
|
+ tableView.cornerRadius = 4
|
|
|
+ tableView.masksToBounds = true
|
|
|
+ return tableView
|
|
|
+ }()
|
|
|
+ var tableViewHeight : CGFloat?
|
|
|
+
|
|
|
+ //加载数据
|
|
|
+ func reloadData() {
|
|
|
+ //collectionView重新加载数据
|
|
|
+ self.tableView.reloadData()
|
|
|
+ //更新collectionView的高度约束
|
|
|
+ let contentSize = self.tableView.contentSize
|
|
|
+ tableViewHeight = contentSize.height
|
|
|
+ tableView.snp.remakeConstraints { (make) in
|
|
|
+ make.top.equalTo(timeLabel.snp_bottom).offset(10)
|
|
|
+ make.left.equalTo(contentLabel.snp_left)
|
|
|
+ make.right.equalTo(contentLabel.snp_right)
|
|
|
+ make.height.equalTo(contentSize.height)
|
|
|
+ }
|
|
|
+ let contentLabelHeight = communityPostCommentModel?.content?.heightForComment(font: kRegularFont14!, width: kScreenWidth - 14 - 48)
|
|
|
+ if communityPostCommentModel?.reply?.isEmpty ?? true {
|
|
|
+ let subViewHeight = 24.0 + (contentLabelHeight ?? 0) + 15.0
|
|
|
+ let spacHeight = 6.0 + 8.0 + 20.0
|
|
|
+ communityPostCommentModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
|
|
|
+ }else {
|
|
|
+ let autoHeight = (contentLabelHeight ?? 0) + (tableViewHeight ?? 0)
|
|
|
+ let subViewHeight = 24.0 + autoHeight + 15.0
|
|
|
+ let spacHeight = 6.0 + 8.0 + 10.0 + 20.0
|
|
|
+ communityPostCommentModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var communityPostCommentModel : CommunityPostCommentModel? {
|
|
|
+ didSet {
|
|
|
+ iconButton.kf.setImage(with: kURLImage(name: communityPostCommentModel?.avatar ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
|
|
|
+ titleLabel.text = communityPostCommentModel?.username
|
|
|
+ contentLabel.text = communityPostCommentModel?.content
|
|
|
+ timeLabel.text = communityPostCommentModel?.createdAt
|
|
|
+ reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 帖子Id
|
|
|
+ var communityVideoItemModel : CommunityVideoItemModel?
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// MARK: - tableView dataSource && delegate
|
|
|
+extension CommunityVideoMajorCommentCell: UITableViewDataSource, UITableViewDelegate {
|
|
|
+
|
|
|
+ func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
+ let reply = communityPostCommentModel?.reply?.prefix(2)
|
|
|
+ return reply?.count ?? 0
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
+
|
|
|
+ let reply = communityPostCommentModel?.reply?.prefix(2)
|
|
|
+ let cell = RecommendSubCommentTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ cell.communityPostReplyModel = reply?[indexPath.row]
|
|
|
+ return cell
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
+ pushCommunitySubCommentVC()
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
+ let reply = communityPostCommentModel?.reply?.prefix(2)
|
|
|
+ return reply?[indexPath.row].height ?? 0
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
+ return 0.000001
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
+ return UIView()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
|
|
+ if communityPostCommentModel?.reply?.isEmpty ?? true {
|
|
|
+ return 0.000001
|
|
|
+ }else {
|
|
|
+ if communityPostCommentModel?.replyCount ?? 0 > 2 {
|
|
|
+ return 30
|
|
|
+ }else {
|
|
|
+ return 10
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
|
|
+ if communityPostCommentModel?.replyCount ?? 0 > 2 {
|
|
|
+ let footer = RecommendSubCommentTableViewFooter(frame: CGRect(x: 0, y: 0, width: kScreenWidth-48-14, height: 30))
|
|
|
+ footer.communityPostCommentModel = communityPostCommentModel
|
|
|
+ footer.unfoldClosure = {
|
|
|
+ [weak self] in
|
|
|
+ self?.pushCommunitySubCommentVC()
|
|
|
+ }
|
|
|
+ return footer
|
|
|
+ }else {
|
|
|
+ return UIView()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func pushCommunitySubCommentVC() {
|
|
|
+ let paraDic = ["commmentModel": communityPostCommentModel, "detailModel": communityVideoItemModel]
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("JumpToSubCommentController"), object: paraDic)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|