|
|
@@ -12,7 +12,10 @@ import SnapKit
|
|
|
|
|
|
class LNGameMateListCell: UITableViewCell {
|
|
|
private let avatar = UIImageView()
|
|
|
+
|
|
|
+ private let playButton = UIButton()
|
|
|
private let voiceLabel = UILabel()
|
|
|
+
|
|
|
private let priceLabel = UILabel()
|
|
|
private let unitLabel = UILabel()
|
|
|
|
|
|
@@ -34,6 +37,8 @@ class LNGameMateListCell: UITableViewCell {
|
|
|
private let photoSize = 72
|
|
|
private let photoStackView = UIStackView()
|
|
|
|
|
|
+ private var curItem: LNGameMateListItemVO?
|
|
|
+
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
|
|
@@ -44,7 +49,6 @@ class LNGameMateListCell: UITableViewCell {
|
|
|
avatar.sd_setImage(with: URL(string: item.avatar))
|
|
|
priceLabel.text = item.price.toDisplay
|
|
|
unitLabel.text = "/\(item.unit)"
|
|
|
- voiceLabel.isHidden = item.voiceBar.isEmpty
|
|
|
|
|
|
nameLabel.text = item.nickname
|
|
|
genderView.update(item.gender, item.age)
|
|
|
@@ -59,6 +63,24 @@ class LNGameMateListCell: UITableViewCell {
|
|
|
bioLabel.text = item.summary
|
|
|
|
|
|
updatePhotos(item.images)
|
|
|
+
|
|
|
+ curItem = item
|
|
|
+
|
|
|
+ if let curItem {
|
|
|
+ LNVoicePlayer.shared.cancelLoadingAsset(urlStr: curItem.voiceBar)
|
|
|
+ }
|
|
|
+ if !item.voiceBar.isEmpty {
|
|
|
+ LNVoicePlayer.shared.getRemoteAudioDuration(urlStr: item.voiceBar)
|
|
|
+ { [weak self] duration, error in
|
|
|
+ guard let self else { return }
|
|
|
+ guard let duration, error == nil else { return }
|
|
|
+ guard curItem?.id == item.id else { return }
|
|
|
+ voiceLabel.text = "\(Int(duration.rounded()))\""
|
|
|
+ playButton.isHidden = false
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ playButton.isHidden = true
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
@@ -165,10 +187,15 @@ extension LNGameMateListCell {
|
|
|
make.bottom.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
- let playButton = UIButton()
|
|
|
playButton.setBackgroundImage(.primary_7, for: .normal)
|
|
|
playButton.layer.cornerRadius = 11
|
|
|
playButton.clipsToBounds = true
|
|
|
+ playButton.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ guard let curItem, !curItem.voiceBar.isEmpty else { return }
|
|
|
+
|
|
|
+ LNVoicePlayer.shared.play(curItem.voiceBar)
|
|
|
+ }), for: .touchUpInside)
|
|
|
container.addSubview(playButton)
|
|
|
playButton.snp.makeConstraints { make in
|
|
|
make.centerX.equalToSuperview()
|
|
|
@@ -178,6 +205,7 @@ extension LNGameMateListCell {
|
|
|
}
|
|
|
|
|
|
let voice = UIView()
|
|
|
+ voice.isUserInteractionEnabled = false
|
|
|
playButton.addSubview(voice)
|
|
|
voice.snp.makeConstraints { make in
|
|
|
make.center.equalToSuperview()
|
|
|
@@ -189,7 +217,7 @@ extension LNGameMateListCell {
|
|
|
ic.snp.makeConstraints { make in
|
|
|
make.leading.centerY.equalToSuperview()
|
|
|
}
|
|
|
- voiceLabel.text = .init(key: "15“")
|
|
|
+
|
|
|
voiceLabel.font = .heading_h5
|
|
|
voiceLabel.textColor = .text_1
|
|
|
voice.addSubview(voiceLabel)
|