|
@@ -47,25 +47,27 @@ class CommunityReplyCommentCell: UITableViewCell {
|
|
|
addSubview(titleLabel)
|
|
|
addSubview(contentLabel)
|
|
|
addSubview(timeLabel)
|
|
|
+ addSubview(likeButton)
|
|
|
+ addSubview(likeCountLabel)
|
|
|
}
|
|
|
|
|
|
private func setupLayouts() {
|
|
|
iconButton.snp.makeConstraints { (make) in
|
|
|
make.top.equalTo(0)
|
|
|
- make.left.equalTo(24)
|
|
|
- make.size.equalTo(24)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.size.equalTo(38)
|
|
|
}
|
|
|
titleLabel.snp.makeConstraints { (make) in
|
|
|
make.left.equalTo(iconButton.snp_right).offset(10)
|
|
|
- make.right.equalToSuperview().offset(-10)
|
|
|
- make.centerY.equalTo(iconButton)
|
|
|
+ make.right.equalToSuperview().offset(-26)
|
|
|
+ make.top.equalTo(iconButton)
|
|
|
make.height.equalTo(17)
|
|
|
}
|
|
|
+
|
|
|
contentLabel.snp.makeConstraints { (make) in
|
|
|
- make.top.equalTo(titleLabel.snp_bottom).offset(12)
|
|
|
- make.left.equalTo(titleLabel.snp_left)
|
|
|
- make.right.equalToSuperview().offset(-10)
|
|
|
- make.width.equalTo(kScreenWidth-62-54)
|
|
|
+ make.top.equalTo(titleLabel.snp_bottom).offset(8)
|
|
|
+ make.left.equalTo(titleLabel)
|
|
|
+ make.right.equalToSuperview().offset(-14)
|
|
|
}
|
|
|
timeLabel.snp.makeConstraints { (make) in
|
|
|
make.top.equalTo(contentLabel.snp_bottom).offset(8)
|
|
@@ -73,6 +75,15 @@ class CommunityReplyCommentCell: UITableViewCell {
|
|
|
make.right.equalTo(contentLabel.snp_right)
|
|
|
make.height.equalTo(15)
|
|
|
}
|
|
|
+ likeCountLabel.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalTo(timeLabel)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ }
|
|
|
+ likeButton.snp.makeConstraints { (make) in
|
|
|
+ make.right.equalTo(likeCountLabel.snp.left).offset(-5)
|
|
|
+ make.centerY.equalTo(timeLabel)
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private lazy var iconButton : UIButton = {
|
|
@@ -115,6 +126,86 @@ class CommunityReplyCommentCell: UITableViewCell {
|
|
|
return timeLabel
|
|
|
}()
|
|
|
|
|
|
+ lazy var likeButton: UIButton = {
|
|
|
+ let likeButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ likeButton.setImage(kImage(name: "btn_praise"), for: UIControl.State.normal)
|
|
|
+ likeButton.setImage(kImage(name: "btn_praise_pre_36px"), for: UIControl.State.selected)
|
|
|
+ likeButton.addTarget(self, action: #selector(likeAction), for: UIControl.Event.touchUpInside)
|
|
|
+
|
|
|
+ return likeButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var likeCountLabel: UILabel = {
|
|
|
+ let likeCountLabel = UILabel()
|
|
|
+ likeCountLabel.textColor = k313334Color
|
|
|
+ likeCountLabel.font = kRegularFont14
|
|
|
+ likeCountLabel.addTapGesture(1, target: self, action: #selector(likeAction))
|
|
|
+
|
|
|
+ return likeCountLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ @objc func likeAction() {
|
|
|
+ if communityPostDetailModel != nil {
|
|
|
+ VirusViewModel.shared.commentlikeVirueRecordApi(button: likeButton,
|
|
|
+ label: likeCountLabel,
|
|
|
+ isCommentLike: communityPostReplyModel?.isLike,
|
|
|
+ postId: communityPostDetailModel?.id,
|
|
|
+ postAuthorUid: "\(communityPostDetailModel?.uid ?? 0)",
|
|
|
+ title: communityPostDetailModel?.title,
|
|
|
+ content: communityPostDetailModel?.content,
|
|
|
+ postCover: communityPostDetailModel?.img,
|
|
|
+ actionId: "\(communityPostDetailModel?.id ?? 0)",
|
|
|
+ postType: communityPostDetailModel?.type,
|
|
|
+ commentContent: communityPostReplyModel?.content,
|
|
|
+ commentId: communityPostReplyModel?.id,
|
|
|
+ commentUId: communityPostReplyModel?.uid,
|
|
|
+ commentLikeCount: communityPostReplyModel?.likeCount) {
|
|
|
+ [weak self] (isCommentLike) in
|
|
|
+ self?.communityPostReplyModel?.isLike = isCommentLike
|
|
|
+ if isCommentLike == 1 {
|
|
|
+ self?.communityPostReplyModel?.likeCount = (self?.communityPostReplyModel?.likeCount ?? 0) + 1
|
|
|
+ }
|
|
|
+ if isCommentLike == 0 {
|
|
|
+ self?.communityPostReplyModel?.likeCount = (self?.communityPostReplyModel?.likeCount ?? 0) - 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if communityVideoItemModel != nil {
|
|
|
+ VirusViewModel.shared.commentlikeVirueRecordApi(button: likeButton,
|
|
|
+ label: likeCountLabel,
|
|
|
+ isCommentLike: communityPostReplyModel?.isLike,
|
|
|
+ postId: communityVideoItemModel?.id,
|
|
|
+ postAuthorUid: "\(communityVideoItemModel?.uid ?? 0)",
|
|
|
+ title: communityVideoItemModel?.title,
|
|
|
+ content: communityVideoItemModel?.content,
|
|
|
+ postCover: communityVideoItemModel?.img,
|
|
|
+ actionId: "\(communityVideoItemModel?.id ?? 0)",
|
|
|
+ postType: communityVideoItemModel?.type,
|
|
|
+ commentContent: communityPostReplyModel?.content,
|
|
|
+ commentId: communityPostReplyModel?.id,
|
|
|
+ commentUId: communityPostReplyModel?.uid,
|
|
|
+ commentLikeCount: communityPostReplyModel?.likeCount) {
|
|
|
+ [weak self] (isCommentLike) in
|
|
|
+ self?.communityPostReplyModel?.isLike = isCommentLike
|
|
|
+ if isCommentLike == 1 {
|
|
|
+ self?.communityPostReplyModel?.likeCount = (self?.communityPostReplyModel?.likeCount ?? 0) + 1
|
|
|
+ }
|
|
|
+ if isCommentLike == 0 {
|
|
|
+ self?.communityPostReplyModel?.likeCount = (self?.communityPostReplyModel?.likeCount ?? 0) - 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 帖子Id
|
|
|
+ var communityPostDetailModel : CommunityPostDetailModel?
|
|
|
+ /// 视频id
|
|
|
+ var communityVideoItemModel : CommunityVideoItemModel?
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
var communityPostReplyModel: CommunityPostReplyModel? {
|
|
|
didSet {
|
|
|
iconButton.kf.setImage(with: kURLImage(name: communityPostReplyModel?.avatar ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
|
|
@@ -135,8 +226,23 @@ class CommunityReplyCommentCell: UITableViewCell {
|
|
|
}
|
|
|
|
|
|
timeLabel.text = communityPostReplyModel?.createdAt
|
|
|
+ let likeCount = "\(communityPostReplyModel?.likeCount ?? 0)"
|
|
|
+ likeCountLabel.text = likeCount
|
|
|
+ if communityPostReplyModel?.isLike == 1 {
|
|
|
+ likeButton.isSelected = true
|
|
|
+ }else {
|
|
|
+ likeButton.isSelected = false
|
|
|
+ }
|
|
|
+ if communityPostReplyModel?.isDelete == 1 {
|
|
|
+ likeCountLabel.isHidden = true
|
|
|
+ likeButton.isHidden = true
|
|
|
+ }else {
|
|
|
+ likeCountLabel.isHidden = false
|
|
|
+ likeButton.isHidden = false
|
|
|
+ }
|
|
|
+
|
|
|
let contentLabelHeight = contentLabel.text?.heightForComment(font: kRegularFont14!, width: kScreenWidth - 58 - 14)
|
|
|
- let subViewHeight = 24.0 + (contentLabelHeight ?? 0) + 15.0
|
|
|
+ let subViewHeight = 17.0 + (contentLabelHeight ?? 0) + 15.0
|
|
|
let spacHeight = 10.0 + 8.0 + 8.0
|
|
|
communityPostReplyModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
|
|
|
}
|