CNLiveShortVideoHomeModel.swift
6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// CNLiveShortVideoHomeModel.swift
// metaCode
//
// Created by open on 2024/1/8.
//
import Foundation
import YYText
import CNLiveBusinessTools
//!!!: 评论相关 model
class ShortVideoHomeCommentModel: BaseModel {
var total_hd: Int? = 0 //总数
var hasNext: Bool? = false
var comments = [ShortVideoHomeCommentListModel]()
}
class ShortVideoHomeCommentListModel: BaseModel {
var comment = ShortVideoHomeCommentFListModel()
var replyData = ShortVideoHomeCommentRListModel()
var cell_h: CGFloat! = 0.0
var tableView_h: CGFloat! = 0.0
override func didFinishMapping() {
super.didFinishMapping()
cell_h += comment.cellH
cell_h += 10
for replyModel in replyData.replys {
tableView_h += replyModel.cellH
}
cell_h += tableView_h
}
}
//评论数据
class ShortVideoHomeCommentFListModel: BaseModel {
var commentId: String? = ""
var pid: String? = ""
var uid: String? = ""
var nick: String? = ""
var facepath: String? = ""
var content: String? = ""
var created_at: String? = ""
var praise: String? = ""
var plat: String? = ""
var isOffical: Bool? = false
var model: String? = ""
var spId: String? = ""
var seqId: Int? = 0
var topicId: String? = ""
var praiseCount: Int? = 0
var isPraised: Bool? = false
var icon: String? = ""
var iconSize: CGSize = CGSize(width: 50, height: 50)
var textLayout: YYTextLayout!
var cellH: CGFloat! = 0
override func didFinishMapping() {
super.didFinishMapping()
let modifier = CNLiveShortVideoMateCodeLinePositionModifier(font: medium_adapt_font(pointSize: 16), paddingTop: 5, paddingBottom: 5, lineHeightMultiple: 2)
let comment = CNLiveBusinessTools.replaceQQemoji(withCustomText: self.content ?? "")
let attributes = NSMutableAttributedString(attributedString: comment)
attributes.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.white, range: NSRange(location: 0, length: comment.length))
attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: comment.length))
let textContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80, height: CGFloat(HUGE)))
textContainer.linePositionModifier = modifier;
let textLayout = YYTextLayout(container: textContainer, text: attributes)
self.textLayout = textLayout
self.cellH = 70 + (textLayout?.textBoundingRect.size.height ?? 0)
}
}
//回复数据
class ShortVideoHomeCommentRListModel: BaseModel {
var total_hd: Int? = 0 //总数
var replys = [ShortVideoHomeCommentRListItemModel]()
}
class ShortVideoHomeCommentRListItemModel: BaseModel {
var praiseCount: Int? = 0
var isPraised: Bool? = false
var commentId: String? = ""
var replyId: String? = ""
var topicId: String? = ""
var created_at: String? = ""
var plat: String? = ""
var fromFace: String? = ""
var fromSid: String? = ""
var fromNick: String? = ""
var toSid: String? = ""
var toNick: String? = ""
var toFace: String? = ""
var seqId: Int? = 0
var content: String? = ""
var level: Int? = 0
var icon: String? = ""
var textLayout: YYTextLayout!
var cellH: CGFloat! = 0
override func didFinishMapping() {
super.didFinishMapping()
let modifier = CNLiveShortVideoMateCodeLinePositionModifier(font: semibold_adapt_font(pointSize: 14), paddingTop: 0, paddingBottom: 0, lineHeightMultiple: 1.5)
let comment = CNLiveBusinessTools.replaceQQemoji(withCustomText: content ?? "")
let attributes = NSMutableAttributedString(attributedString: comment)
attributes.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.white, range: NSRange(location: 0, length: comment.length))
attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: comment.length))
let textContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80-40, height: CGFloat(HUGE)))
textContainer.linePositionModifier = modifier;
let textLayout = YYTextLayout(container: textContainer, text: attributes)
self.textLayout = textLayout
self.cellH = 70 + (textLayout?.textBoundingRect.size.height ?? 0)
}
}
class CNLiveShortVideoMateCodeLinePositionModifier: NSObject, YYTextLinePositionModifier {
var font: UIFont // 基准字体 (例如 Heiti SC/PingFang SC)
var paddingTop: CGFloat // 文本顶部留白
var paddingBottom: CGFloat // 文本底部留白
var lineHeightMultiple: CGFloat // 行距倍数
init(font: UIFont, paddingTop: CGFloat, paddingBottom: CGFloat, lineHeightMultiple: CGFloat) {
self.font = font
self.paddingTop = paddingTop
self.paddingBottom = paddingBottom
self.lineHeightMultiple = lineHeightMultiple
super.init()
if #available(iOS 9.0, *) {
self.lineHeightMultiple = 1.34 // for PingFang SC
} else {
self.lineHeightMultiple = 1.3125 // for Heiti SC
}
}
func modifyLines(_ lines: [YYTextLine], fromText text: NSAttributedString, in container: YYTextContainer) {
let ascent = font.pointSize * 0.86
let lineHeight = font.pointSize * lineHeightMultiple
for item in lines {
let line = item as YYTextLine
var position = line.position
position.y = paddingTop + ascent + CGFloat(line.row) * lineHeight
line.position = position
}
}
func copy(with zone: NSZone? = nil) -> Any {
let one = CNLiveShortVideoMateCodeLinePositionModifier(
font: font,
paddingTop: paddingTop,
paddingBottom: paddingBottom,
lineHeightMultiple: lineHeightMultiple
)
return one
}
func heightForLineCount(_ lineCount: UInt) -> CGFloat {
if lineCount == 0 {
return 0
}
let ascent = font.pointSize * 0.86
let descent = font.pointSize * 0.14
let lineHeight = font.pointSize * lineHeightMultiple
return paddingTop + paddingBottom + ascent + descent + CGFloat(lineCount - 1) * lineHeight
}
}