CommunityReplyCommentCell.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //
  2. // CommunityReplyCommentCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/12.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 二级评论--评论回复のCell
  8. import UIKit
  9. import RxSwift
  10. import Kingfisher
  11. class CommunityReplyCommentCell: UITableViewCell {
  12. let disposeBag = DisposeBag()
  13. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> CommunityReplyCommentCell {
  14. let ID = "CommunityReplyCommentCell"
  15. tableView.register(CommunityReplyCommentCell.self, forCellReuseIdentifier: ID)
  16. let cell : CommunityReplyCommentCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! CommunityReplyCommentCell
  17. cell.indexPath = indexPath
  18. return cell
  19. }
  20. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  21. super.init(style: style, reuseIdentifier: reuseIdentifier)
  22. setupViews()
  23. setupLayouts()
  24. }
  25. required init?(coder aDecoder: NSCoder) {
  26. fatalError("init(coder:) has not been implemented")
  27. }
  28. var indexPath: IndexPath? {
  29. didSet {
  30. }
  31. }
  32. //MRAK: - 设置View
  33. private func setupViews() {
  34. backgroundColor = kf7f8faColor
  35. addSubview(iconButton)
  36. addSubview(titleLabel)
  37. addSubview(contentLabel)
  38. addSubview(timeLabel)
  39. addSubview(likeButton)
  40. addSubview(likeCountLabel)
  41. }
  42. private func setupLayouts() {
  43. iconButton.snp.makeConstraints { (make) in
  44. make.top.equalTo(0)
  45. make.left.equalTo(14)
  46. make.size.equalTo(38)
  47. }
  48. titleLabel.snp.makeConstraints { (make) in
  49. make.left.equalTo(iconButton.snp.right).offset(10)
  50. make.right.equalToSuperview().offset(-26)
  51. make.top.equalTo(iconButton)
  52. make.height.equalTo(17)
  53. }
  54. contentLabel.snp.makeConstraints { (make) in
  55. make.top.equalTo(titleLabel.snp.bottom).offset(8)
  56. make.left.equalTo(titleLabel)
  57. make.right.equalToSuperview().offset(-14)
  58. }
  59. timeLabel.snp.makeConstraints { (make) in
  60. make.top.equalTo(contentLabel.snp.bottom).offset(8)
  61. make.left.equalTo(titleLabel.snp.left)
  62. make.right.equalTo(contentLabel.snp.right)
  63. make.height.equalTo(15)
  64. }
  65. likeCountLabel.snp.makeConstraints { (make) in
  66. make.centerY.equalTo(timeLabel)
  67. make.right.equalTo(-14)
  68. }
  69. likeButton.snp.makeConstraints { (make) in
  70. make.right.equalTo(likeCountLabel.snp.left).offset(-5)
  71. make.centerY.equalTo(timeLabel)
  72. make.size.equalTo(20)
  73. }
  74. }
  75. private lazy var iconButton : UIButton = {
  76. let iconButton = UIButton(type: UIButton.ButtonType.custom)
  77. iconButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal)
  78. iconButton.cornerRadius = 12
  79. iconButton.masksToBounds = true
  80. iconButton.isUserInteractionEnabled = false
  81. iconButton.rx.tap.subscribe(onNext: { [weak self] (data) in
  82. }).disposed(by: disposeBag)
  83. return iconButton
  84. }()
  85. private lazy var titleLabel: UILabel = {
  86. let titleLabel = UILabel()
  87. titleLabel.textColor = k999999Color
  88. titleLabel.font = kRegularFont14
  89. titleLabel.textAlignment = .left
  90. return titleLabel
  91. }()
  92. private lazy var contentLabel: FMLinkLabel = {
  93. let contentLabel = FMLinkLabel()
  94. contentLabel.textColor = k333333Color
  95. contentLabel.font = kRegularFont14
  96. contentLabel.textAlignment = .left
  97. contentLabel.numberOfLines = 0
  98. contentLabel.isUserInteractionEnabled = false
  99. return contentLabel
  100. }()
  101. lazy var timeLabel: UILabel = {
  102. let timeLabel = UILabel()
  103. timeLabel.textColor = kbbbbbbColor
  104. timeLabel.font = kRegularFont12
  105. timeLabel.textAlignment = .left
  106. return timeLabel
  107. }()
  108. lazy var likeButton: UIButton = {
  109. let likeButton = UIButton(type: UIButton.ButtonType.custom)
  110. likeButton.setImage(kImage(name: "btn_praise"), for: UIControl.State.normal)
  111. likeButton.setImage(kImage(name: "btn_praise_pre_36px"), for: UIControl.State.selected)
  112. likeButton.addTarget(self, action: #selector(likeAction), for: UIControl.Event.touchUpInside)
  113. return likeButton
  114. }()
  115. lazy var likeCountLabel: UILabel = {
  116. let likeCountLabel = UILabel()
  117. likeCountLabel.textColor = k313334Color
  118. likeCountLabel.font = kRegularFont14
  119. likeCountLabel.addTapGesture(1, target: self, action: #selector(likeAction))
  120. return likeCountLabel
  121. }()
  122. @objc func likeAction() {
  123. if communityPostDetailModel != nil {
  124. VirusViewModel.shared.commentlikeVirueRecordApi(button: likeButton,
  125. label: likeCountLabel,
  126. isCommentLike: communityPostReplyModel?.isLike,
  127. postId: communityPostDetailModel?.id,
  128. postAuthorUid: "\(communityPostDetailModel?.uid ?? 0)",
  129. title: communityPostDetailModel?.title,
  130. content: communityPostDetailModel?.content,
  131. postCover: communityPostDetailModel?.img,
  132. actionId: "\(communityPostDetailModel?.id ?? 0)",
  133. postType: communityPostDetailModel?.type,
  134. commentContent: communityPostReplyModel?.content,
  135. commentId: communityPostReplyModel?.id,
  136. commentUId: communityPostReplyModel?.uid,
  137. commentLikeCount: communityPostReplyModel?.likeCount) {
  138. [weak self] (isCommentLike) in
  139. self?.communityPostReplyModel?.isLike = isCommentLike
  140. if isCommentLike == 1 {
  141. self?.communityPostReplyModel?.likeCount = (self?.communityPostReplyModel?.likeCount ?? 0) + 1
  142. }
  143. if isCommentLike == 0 {
  144. self?.communityPostReplyModel?.likeCount = (self?.communityPostReplyModel?.likeCount ?? 0) - 1
  145. }
  146. }
  147. }
  148. if communityVideoItemModel != nil {
  149. VirusViewModel.shared.commentlikeVirueRecordApi(button: likeButton,
  150. label: likeCountLabel,
  151. isCommentLike: communityPostReplyModel?.isLike,
  152. postId: communityVideoItemModel?.id,
  153. postAuthorUid: "\(communityVideoItemModel?.uid ?? 0)",
  154. title: communityVideoItemModel?.title,
  155. content: communityVideoItemModel?.content,
  156. postCover: communityVideoItemModel?.img,
  157. actionId: "\(communityVideoItemModel?.id ?? 0)",
  158. postType: communityVideoItemModel?.type,
  159. commentContent: communityPostReplyModel?.content,
  160. commentId: communityPostReplyModel?.id,
  161. commentUId: communityPostReplyModel?.uid,
  162. commentLikeCount: communityPostReplyModel?.likeCount) {
  163. [weak self] (isCommentLike) in
  164. self?.communityPostReplyModel?.isLike = isCommentLike
  165. if isCommentLike == 1 {
  166. self?.communityPostReplyModel?.likeCount = (self?.communityPostReplyModel?.likeCount ?? 0) + 1
  167. }
  168. if isCommentLike == 0 {
  169. self?.communityPostReplyModel?.likeCount = (self?.communityPostReplyModel?.likeCount ?? 0) - 1
  170. }
  171. }
  172. }
  173. }
  174. /// 帖子Id
  175. var communityPostDetailModel : CommunityPostDetailModel?
  176. /// 视频id
  177. var communityVideoItemModel : CommunityVideoItemModel?
  178. var communityPostReplyModel: CommunityPostReplyModel? {
  179. didSet {
  180. iconButton.kf.setImage(with: kURLImage(name: communityPostReplyModel?.avatar ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
  181. titleLabel.text = communityPostReplyModel?.username
  182. let replyUsername = "回复 @\(communityPostReplyModel?.replyUsername ?? ""):"
  183. let content = "\(communityPostReplyModel?.content ?? "")"
  184. if communityPostReplyModel?.replyUsername != "" && communityPostReplyModel?.replyUsername != nil {
  185. contentLabel.text = replyUsername + content
  186. contentLabel.addClickText("@\(communityPostReplyModel?.replyUsername ?? "")", attributeds: [NSAttributedString.Key.font:kMediumFont14 as Any], transmitBody: nil) {
  187. (data) in
  188. }
  189. }else {
  190. contentLabel.text = content
  191. }
  192. timeLabel.text = communityPostReplyModel?.createdAt
  193. let likeCount = "\(communityPostReplyModel?.likeCount ?? 0)"
  194. likeCountLabel.text = likeCount
  195. if communityPostReplyModel?.isLike == 1 {
  196. likeButton.isSelected = true
  197. }else {
  198. likeButton.isSelected = false
  199. }
  200. if communityPostReplyModel?.isDelete == 1 {
  201. likeCountLabel.isHidden = true
  202. likeButton.isHidden = true
  203. }else {
  204. likeCountLabel.isHidden = false
  205. likeButton.isHidden = false
  206. }
  207. let contentLabelHeight = contentLabel.text?.heightForComment(font: kRegularFont14!, width: kScreenWidth - 58 - 14)
  208. let subViewHeight = 17.0 + (contentLabelHeight ?? 0) + 15.0
  209. let spacHeight = 10.0 + 8.0 + 8.0
  210. communityPostReplyModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
  211. }
  212. }
  213. }