Commit efa9d3fa69b9fe5c79fba63f5bd73c56bf37e0f0

Authored by liushiyu
1 parent f9f0c0ca

回复相关问题修改

metaCode/Classes/Main/VideoPage/Model/CNLiveShortVideoHomeModel.swift
@@ -26,19 +26,16 @@ class ShortVideoHomeCommentListModel: BaseModel { @@ -26,19 +26,16 @@ class ShortVideoHomeCommentListModel: BaseModel {
26 override func didFinishMapping() { 26 override func didFinishMapping() {
27 super.didFinishMapping() 27 super.didFinishMapping()
28 cell_h += comment.cellH 28 cell_h += comment.cellH
29 - cell_h += 10  
30 29
31 for replyModel in replyData.replys { 30 for replyModel in replyData.replys {
32 tableView_h += replyModel.cellH 31 tableView_h += replyModel.cellH
33 } 32 }
34 if replyData.replyCount ?? 0 > 2 { 33 if replyData.replyCount ?? 0 > 2 {
35 - print("回复数=>\(replyData.replyCount ?? 0)")  
36 tableView_top += 30.0 34 tableView_top += 30.0
37 cell_h += 30 35 cell_h += 30
38 } 36 }
39 cell_h += tableView_h 37 cell_h += tableView_h
40 } 38 }
41 -  
42 } 39 }
43 //评论数据 40 //评论数据
44 class ShortVideoHomeCommentFListModel: BaseModel { 41 class ShortVideoHomeCommentFListModel: BaseModel {
@@ -62,7 +59,8 @@ class ShortVideoHomeCommentFListModel: BaseModel { @@ -62,7 +59,8 @@ class ShortVideoHomeCommentFListModel: BaseModel {
62 59
63 var iconSize: CGSize = CGSize(width: 50, height: 50) 60 var iconSize: CGSize = CGSize(width: 50, height: 50)
64 var textLayout: YYTextLayout! 61 var textLayout: YYTextLayout!
65 - var cellH: CGFloat! = 0 62 + var nickLayout: YYTextLayout!
  63 + var cellH: CGFloat! = 50.0
66 64
67 override func didFinishMapping() { 65 override func didFinishMapping() {
68 super.didFinishMapping() 66 super.didFinishMapping()
@@ -78,7 +76,15 @@ class ShortVideoHomeCommentFListModel: BaseModel { @@ -78,7 +76,15 @@ class ShortVideoHomeCommentFListModel: BaseModel {
78 textContainer.linePositionModifier = modifier; 76 textContainer.linePositionModifier = modifier;
79 let textLayout = YYTextLayout(container: textContainer, text: attributes) 77 let textLayout = YYTextLayout(container: textContainer, text: attributes)
80 self.textLayout = textLayout 78 self.textLayout = textLayout
81 - self.cellH = 70 + (textLayout?.textBoundingRect.size.height ?? 0) 79 + self.cellH += (textLayout?.textBoundingRect.size.height ?? 0)
  80 +
  81 + let textAttributedString = NSMutableAttributedString.init(string: self.nick ?? "")
  82 + textAttributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: HexColor("#AFAFAF")!, range: NSRange(location: 0, length: textAttributedString.length))
  83 + textAttributedString.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 12), range: NSRange(location: 0, length: textAttributedString.length))
  84 + let nickContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80, height: 20))
  85 + nickContainer.linePositionModifier = modifier;
  86 + self.nickLayout = YYTextLayout(container: nickContainer, text: textAttributedString)
  87 + self.cellH += (self.nickLayout?.textBoundingRect.size.height ?? 0)
82 } 88 }
83 } 89 }
84 //回复数据 90 //回复数据
@@ -108,7 +114,8 @@ class ShortVideoHomeCommentRListItemModel: BaseModel { @@ -108,7 +114,8 @@ class ShortVideoHomeCommentRListItemModel: BaseModel {
108 var icon: String? = "" 114 var icon: String? = ""
109 115
110 var textLayout: YYTextLayout! 116 var textLayout: YYTextLayout!
111 - var cellH: CGFloat! = 0 117 + var nickLayout: YYTextLayout!
  118 + var cellH: CGFloat! = 50.0
112 119
113 override func didFinishMapping() { 120 override func didFinishMapping() {
114 super.didFinishMapping() 121 super.didFinishMapping()
@@ -122,9 +129,18 @@ class ShortVideoHomeCommentRListItemModel: BaseModel { @@ -122,9 +129,18 @@ class ShortVideoHomeCommentRListItemModel: BaseModel {
122 attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: temp_string.length)) 129 attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: temp_string.length))
123 let textContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80-40, height: CGFloat(HUGE))) 130 let textContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80-40, height: CGFloat(HUGE)))
124 textContainer.linePositionModifier = modifier; 131 textContainer.linePositionModifier = modifier;
125 - let textLayout = YYTextLayout(container: textContainer, text: attributes)  
126 - self.textLayout = textLayout  
127 - self.cellH = 70 + (textLayout?.textBoundingRect.size.height ?? 0) 132 + self.textLayout = YYTextLayout(container: textContainer, text: attributes)
  133 + self.cellH += (self.textLayout?.textBoundingRect.size.height ?? 0)
  134 +
  135 + let textAttributedString = NSMutableAttributedString.init(string: "\(self.fromNick ?? "") ?? \(self.toNick ?? "")")
  136 + textAttributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: HexColor("#AFAFAF")!, range: NSRange(location: 0, length: textAttributedString.length))
  137 + textAttributedString.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 12), range: NSRange(location: 0, length: textAttributedString.length))
  138 + let attachText = NSAttributedString.yy_attachmentString(withContent: UIImage(named: "short_video_reply_name"), contentMode: .scaleAspectFill, attachmentSize: CGSize(width: adapt_length(length: 8), height: adapt_length(length: 8)), alignTo: medium_adapt_font(pointSize: 12), alignment: .center)
  139 + textAttributedString.replaceCharacters(in: NSRange(location: self.fromNick!.count + 2, length: 2), with: attachText)
  140 + let nickContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80-40, height: 20))
  141 + nickContainer.linePositionModifier = modifier;
  142 + self.nickLayout = YYTextLayout(container: nickContainer, text: textAttributedString)
  143 + self.cellH += (self.nickLayout?.textBoundingRect.size.height ?? 0)
128 } 144 }
129 } 145 }
130 146
metaCode/Classes/Main/VideoPage/View/CNLiveShortVideoCommentListView.swift
@@ -218,7 +218,7 @@ class CNLiveShortVideoCommentListView: UIView, UITableViewDelegate, UITableViewD @@ -218,7 +218,7 @@ class CNLiveShortVideoCommentListView: UIView, UITableViewDelegate, UITableViewD
218 contentView.addSubview(tableView) 218 contentView.addSubview(tableView)
219 tableView.snp.makeConstraints { make in 219 tableView.snp.makeConstraints { make in
220 make.left.right.equalToSuperview() 220 make.left.right.equalToSuperview()
221 - make.top.equalTo(lineLabel.snp.bottom).offset(10) 221 + make.top.equalTo(lineLabel.snp.bottom)
222 make.bottom.equalTo(sendButton.snp.top).offset(-5) 222 make.bottom.equalTo(sendButton.snp.top).offset(-5)
223 } 223 }
224 } 224 }
@@ -356,12 +356,19 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -356,12 +356,19 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
356 return imageView 356 return imageView
357 }() 357 }()
358 358
359 - lazy var titleLabel: UILabel = {  
360 - let titleLabel = UILabel.init() 359 + lazy var titleLabel: YYLabel = {
  360 + let titleLabel = YYLabel()
361 titleLabel.textColor = HexColor("#AFAFAF") 361 titleLabel.textColor = HexColor("#AFAFAF")
362 titleLabel.lineBreakMode = .byTruncatingTail 362 titleLabel.lineBreakMode = .byTruncatingTail
363 titleLabel.numberOfLines = 2 363 titleLabel.numberOfLines = 2
364 titleLabel.font = medium_adapt_font(pointSize: 12) 364 titleLabel.font = medium_adapt_font(pointSize: 12)
  365 + titleLabel.displaysAsynchronously = true
  366 + titleLabel.clearContentsBeforeAsynchronouslyDisplay = false
  367 + titleLabel.fadeOnAsynchronouslyDisplay = false
  368 + titleLabel.textAlignment = .left
  369 + titleLabel.textVerticalAlignment = .center
  370 + titleLabel.textContainerInset = UIEdgeInsets.zero
  371 + titleLabel.isUserInteractionEnabled = true
365 return titleLabel 372 return titleLabel
366 }() 373 }()
367 374
@@ -483,7 +490,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -483,7 +490,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
483 make.left.equalTo(iconView.snp.right).offset(10) 490 make.left.equalTo(iconView.snp.right).offset(10)
484 make.top.equalToSuperview().offset(10) 491 make.top.equalToSuperview().offset(10)
485 make.right.equalToSuperview().offset(-10) 492 make.right.equalToSuperview().offset(-10)
486 - make.height.equalTo(20) 493 + make.height.equalTo(1)
487 } 494 }
488 contentView.addSubview(owerView) 495 contentView.addSubview(owerView)
489 owerView.snp.makeConstraints { make in 496 owerView.snp.makeConstraints { make in
@@ -495,7 +502,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -495,7 +502,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
495 make.top.equalTo(titleLabel.snp.bottom).offset(10) 502 make.top.equalTo(titleLabel.snp.bottom).offset(10)
496 make.left.equalTo(titleLabel.snp.left) 503 make.left.equalTo(titleLabel.snp.left)
497 make.right.equalToSuperview().offset(-10) 504 make.right.equalToSuperview().offset(-10)
498 - make.height.equalTo(20) 505 + make.height.equalTo(1)
499 } 506 }
500 contentView.addSubview(likeButton) 507 contentView.addSubview(likeButton)
501 likeButton.snp.makeConstraints { make in 508 likeButton.snp.makeConstraints { make in
@@ -519,9 +526,9 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -519,9 +526,9 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
519 } 526 }
520 contentView.addSubview(replyUnfoldButton) 527 contentView.addSubview(replyUnfoldButton)
521 replyUnfoldButton.snp.makeConstraints { make in 528 replyUnfoldButton.snp.makeConstraints { make in
522 - make.top.equalTo(timeLabel.snp.bottom).offset(5) 529 + make.top.equalTo(timeLabel.snp.bottom)
523 make.left.equalTo(titleLabel.snp.left) 530 make.left.equalTo(titleLabel.snp.left)
524 - make.height.equalTo(20) 531 + make.height.equalTo(30)
525 } 532 }
526 contentView.addSubview(tableView) 533 contentView.addSubview(tableView)
527 } 534 }
@@ -535,8 +542,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -535,8 +542,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
535 indexPath_current = indexPath 542 indexPath_current = indexPath
536 commentModel = commentData 543 commentModel = commentData
537 iconView.kf.indicatorType = .activity 544 iconView.kf.indicatorType = .activity
538 - iconView.kf.setImage(with: URL(string: commentData.icon!), placeholder: UIImage(named: "short_video_default"))  
539 - titleLabel.text = commentData.nick 545 + iconView.kf.setImage(with: URL(string: commentData.facepath!), placeholder: UIImage(named: "short_video_default"))
540 likeButton.isSelected = commentData.isPraised! 546 likeButton.isSelected = commentData.isPraised!
541 likeButton.setTitle("\(commentData.praiseCount ?? 0)", for: .normal) 547 likeButton.setTitle("\(commentData.praiseCount ?? 0)", for: .normal)
542 timeLabel.text = commentData.created_at 548 timeLabel.text = commentData.created_at
@@ -561,13 +567,20 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -561,13 +567,20 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
561 make.right.equalToSuperview().offset(-10) 567 make.right.equalToSuperview().offset(-10)
562 make.height.equalTo(commentData.textLayout.textBoundingRect.size.height) 568 make.height.equalTo(commentData.textLayout.textBoundingRect.size.height)
563 } 569 }
  570 + self.titleLabel.textLayout = commentData.nickLayout
  571 + self.titleLabel.snp.remakeConstraints { make in
  572 + make.left.equalTo(self.iconView.snp.right).offset(10)
  573 + make.top.equalToSuperview().offset(10)
  574 + make.right.equalToSuperview().offset(-10)
  575 + make.height.equalTo(commentData.nickLayout.textBoundingRect.size.height)
  576 + }
564 self.tableView.removeFromSuperview() 577 self.tableView.removeFromSuperview()
565 if replyData.replyCount ?? 0 > 2 { 578 if replyData.replyCount ?? 0 > 2 {
566 self.contentView.addSubview(self.tableView) 579 self.contentView.addSubview(self.tableView)
567 self.tableView.snp.makeConstraints { make in 580 self.tableView.snp.makeConstraints { make in
568 make.left.equalToSuperview().offset(60) 581 make.left.equalToSuperview().offset(60)
569 make.right.equalToSuperview().offset(-10) 582 make.right.equalToSuperview().offset(-10)
570 - make.top.equalTo(self.timeLabel.snp.bottom).offset(10+tableView_top) 583 + make.top.equalTo(self.timeLabel.snp.bottom).offset(tableView_top)
571 make.height.equalTo(self.tableView_height) 584 make.height.equalTo(self.tableView_height)
572 } 585 }
573 self.tableView.reloadData() 586 self.tableView.reloadData()
@@ -580,7 +593,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -580,7 +593,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
580 commentModel = commentData 593 commentModel = commentData
581 iconView.kf.indicatorType = .activity 594 iconView.kf.indicatorType = .activity
582 iconView.kf.setImage(with: URL(string: replyModel.fromFace!), placeholder: UIImage(named: "short_video_default")) 595 iconView.kf.setImage(with: URL(string: replyModel.fromFace!), placeholder: UIImage(named: "short_video_default"))
583 - titleLabel.text = replyModel.fromNick 596 + titleLabel.textLayout = replyModel.nickLayout
584 likeButton.isSelected = replyModel.isPraised! 597 likeButton.isSelected = replyModel.isPraised!
585 likeButton.setTitle("\(replyModel.praiseCount ?? 0)", for: .normal) 598 likeButton.setTitle("\(replyModel.praiseCount ?? 0)", for: .normal)
586 timeLabel.text = replyModel.created_at 599 timeLabel.text = replyModel.created_at
@@ -598,6 +611,13 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -598,6 +611,13 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
598 make.right.equalToSuperview().offset(-10) 611 make.right.equalToSuperview().offset(-10)
599 make.height.equalTo(replyModel.textLayout.textBoundingRect.size.height) 612 make.height.equalTo(replyModel.textLayout.textBoundingRect.size.height)
600 } 613 }
  614 + self.titleLabel.textLayout = replyModel.nickLayout
  615 + self.titleLabel.snp.remakeConstraints { make in
  616 + make.left.equalTo(self.iconView.snp.right).offset(10)
  617 + make.top.equalToSuperview().offset(10)
  618 + make.right.equalToSuperview().offset(-10)
  619 + make.height.equalTo(replyModel.nickLayout.textBoundingRect.size.height)
  620 + }
601 } 621 }
602 } 622 }
603 623
@@ -695,11 +715,15 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel @@ -695,11 +715,15 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
695 715
696 @objc func replyUnfoldMethod(button: UIButton) { 716 @objc func replyUnfoldMethod(button: UIButton) {
697 showLoading(message: "") 717 showLoading(message: "")
  718 + print("这里点击的时候走了多少次")
698 let replyModel: ShortVideoHomeCommentRListItemModel = self.dataSource.lastObject as! ShortVideoHomeCommentRListItemModel 719 let replyModel: ShortVideoHomeCommentRListItemModel = self.dataSource.lastObject as! ShortVideoHomeCommentRListItemModel
699 CNLiveShortVideoViewModel.requestcommentWithReplyList(commentId: commentModel.commentId!, seqId: replyModel.seqId!) {[weak self] result, respStatue in 720 CNLiveShortVideoViewModel.requestcommentWithReplyList(commentId: commentModel.commentId!, seqId: replyModel.seqId!) {[weak self] result, respStatue in
700 guard let self = self else { return } 721 guard let self = self else { return }
701 if respStatue == .success { 722 if respStatue == .success {
702 let tempArray = result as! [ShortVideoHomeCommentRListItemModel] 723 let tempArray = result as! [ShortVideoHomeCommentRListItemModel]
  724 + if tempArray.count == 0 {
  725 + return
  726 + }
703 let dataArray_temp = NSMutableArray(array: self.dataSource) 727 let dataArray_temp = NSMutableArray(array: self.dataSource)
704 self.dataSource.removeAllObjects() 728 self.dataSource.removeAllObjects()
705 var cell_h: CGFloat = 0.0 729 var cell_h: CGFloat = 0.0
metaCode/Classes/Main/VideoPage/ViewModel/CNLiveShortVideoViewModel.swift
@@ -407,8 +407,9 @@ class CNLiveShortVideoViewModel: NSObject { @@ -407,8 +407,9 @@ class CNLiveShortVideoViewModel: NSObject {
407 tempArray.add(listModel) 407 tempArray.add(listModel)
408 } 408 }
409 reultShortVideoBlock(tempArray, .success) 409 reultShortVideoBlock(tempArray, .success)
  410 + } else {
  411 + reultShortVideoBlock(Array<Any>(), .success)
410 } 412 }
411 - reultShortVideoBlock(Array<Any>(), .success)  
412 } 413 }
413 } else { 414 } else {
414 showMessage(message: resp["errorMessage"] as! String) 415 showMessage(message: resp["errorMessage"] as! String)