123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- //
- // CommunityReplyCommentCell.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/6/12.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 二级评论--评论回复のCell
- import UIKit
- import RxSwift
- import Kingfisher
- class CommunityReplyCommentCell: UITableViewCell {
-
- let disposeBag = DisposeBag()
-
- class func cellWith(tableView:UITableView,indexPath:IndexPath) -> CommunityReplyCommentCell {
- let ID = "CommunityReplyCommentCell"
- tableView.register(CommunityReplyCommentCell.self, forCellReuseIdentifier: ID)
- let cell : CommunityReplyCommentCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! CommunityReplyCommentCell
- 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() {
-
- backgroundColor = kf7f8faColor
-
- addSubview(iconButton)
- 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(14)
- make.size.equalTo(38)
- }
- titleLabel.snp.makeConstraints { (make) in
- make.left.equalTo(iconButton.snp.right).offset(10)
- 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(8)
- make.left.equalTo(titleLabel)
- 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)
- }
- 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)
- make.size.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.isUserInteractionEnabled = false
- 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: FMLinkLabel = {
- let contentLabel = FMLinkLabel()
- contentLabel.textColor = k333333Color
- contentLabel.font = kRegularFont14
- contentLabel.textAlignment = .left
- contentLabel.numberOfLines = 0
- contentLabel.isUserInteractionEnabled = false
- return contentLabel
- }()
-
- lazy var timeLabel: UILabel = {
- let timeLabel = UILabel()
- timeLabel.textColor = kbbbbbbColor
- timeLabel.font = kRegularFont12
- timeLabel.textAlignment = .left
- 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"))
-
-
- titleLabel.text = communityPostReplyModel?.username
-
- let replyUsername = "回复 @\(communityPostReplyModel?.replyUsername ?? ""):"
- let content = "\(communityPostReplyModel?.content ?? "")"
- if communityPostReplyModel?.replyUsername != "" && communityPostReplyModel?.replyUsername != nil {
- contentLabel.text = replyUsername + content
- contentLabel.addClickText("@\(communityPostReplyModel?.replyUsername ?? "")", attributeds: [NSAttributedString.Key.font:kMediumFont14 as Any], transmitBody: nil) {
- (data) in
-
- }
- }else {
- contentLabel.text = content
- }
-
- 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 = 17.0 + (contentLabelHeight ?? 0) + 15.0
- let spacHeight = 10.0 + 8.0 + 8.0
- communityPostReplyModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
- }
- }
-
- }
|