|
|
@@ -16,6 +16,7 @@ class LNGameMateListCell: UITableViewCell {
|
|
|
|
|
|
private let playButton = UIButton()
|
|
|
private let voiceLabel = UILabel()
|
|
|
+ private let voiceWaveView = LNVoiceWaveView()
|
|
|
|
|
|
private let priceLabel = UILabel()
|
|
|
private let unitLabel = UILabel()
|
|
|
@@ -44,6 +45,8 @@ class LNGameMateListCell: UITableViewCell {
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
|
|
setupViews()
|
|
|
+
|
|
|
+ LNEventDeliver.addObserver(self)
|
|
|
}
|
|
|
|
|
|
func update(_ item: LNGameMateListItemVO) {
|
|
|
@@ -66,11 +69,19 @@ class LNGameMateListCell: UITableViewCell {
|
|
|
|
|
|
updatePhotos(item.images)
|
|
|
|
|
|
- curItem = item
|
|
|
-
|
|
|
if let curItem {
|
|
|
LNVoiceResourceManager.shared.cancelLoadingAsset(urlStr: curItem.voiceBar)
|
|
|
}
|
|
|
+
|
|
|
+ curItem = item
|
|
|
+
|
|
|
+ if LNVoicePlayer.shared.playingUrl == curItem?.voiceBar {
|
|
|
+ voiceWaveView.startAnimate()
|
|
|
+ } else {
|
|
|
+ voiceWaveView.stopAnimate()
|
|
|
+ }
|
|
|
+
|
|
|
+ playButton.isHidden = true
|
|
|
if !item.voiceBar.isEmpty {
|
|
|
LNVoiceResourceManager.shared.getRemoteAudioDuration(urlStr: item.voiceBar)
|
|
|
{ [weak self] duration, error in
|
|
|
@@ -80,8 +91,6 @@ class LNGameMateListCell: UITableViewCell {
|
|
|
voiceLabel.text = "\(Int(duration.rounded()))\""
|
|
|
playButton.isHidden = false
|
|
|
}
|
|
|
- } else {
|
|
|
- playButton.isHidden = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -90,6 +99,31 @@ class LNGameMateListCell: UITableViewCell {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+extension LNGameMateListCell: LNVoicePlayerNotify {
|
|
|
+ func onAudioStartPlay(path: String) {
|
|
|
+ guard path == curItem?.voiceBar else { return }
|
|
|
+ voiceWaveView.startAnimate()
|
|
|
+ }
|
|
|
+
|
|
|
+ func onAudioStopPlay(path: String) {
|
|
|
+ guard path == curItem?.voiceBar else { return }
|
|
|
+ voiceWaveView.stopAnimate()
|
|
|
+ let url = curItem?.voiceBar
|
|
|
+ LNVoiceResourceManager.shared.getRemoteAudioDuration(urlStr: curItem?.voiceBar)
|
|
|
+ { [weak self] duration, err in
|
|
|
+ guard let self else { return }
|
|
|
+ guard let duration, err == nil else { return }
|
|
|
+ guard curItem?.voiceBar == url else { return }
|
|
|
+ voiceLabel.text = "\(Int(duration.rounded()))\""
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func onAudioUpdateDuration(path: String, cur: TimeInterval, total: TimeInterval) {
|
|
|
+ guard path == curItem?.voiceBar else { return }
|
|
|
+ voiceLabel.text = "\(Int((total - cur).rounded()))\""
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
extension LNGameMateListCell {
|
|
|
private func updatePhotos(_ photos: [String]) {
|
|
|
var old = photoStackView.arrangedSubviews
|
|
|
@@ -205,8 +239,11 @@ extension LNGameMateListCell {
|
|
|
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)
|
|
|
+ if LNVoicePlayer.shared.playingUrl == curItem.voiceBar {
|
|
|
+ LNVoicePlayer.shared.stop()
|
|
|
+ } else {
|
|
|
+ LNVoicePlayer.shared.play(curItem.voiceBar)
|
|
|
+ }
|
|
|
}), for: .touchUpInside)
|
|
|
container.addSubview(playButton)
|
|
|
playButton.snp.makeConstraints { make in
|
|
|
@@ -223,11 +260,12 @@ extension LNGameMateListCell {
|
|
|
make.center.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
- let ic = UIImageView()
|
|
|
- ic.image = .init(named: "ic_voice")
|
|
|
- voice.addSubview(ic)
|
|
|
- ic.snp.makeConstraints { make in
|
|
|
+ voiceWaveView.build()
|
|
|
+ voice.addSubview(voiceWaveView)
|
|
|
+ voiceWaveView.snp.makeConstraints { make in
|
|
|
make.leading.centerY.equalToSuperview()
|
|
|
+ make.width.equalTo(19)
|
|
|
+ make.height.equalTo(11)
|
|
|
}
|
|
|
|
|
|
voiceLabel.font = .heading_h5
|
|
|
@@ -236,7 +274,7 @@ extension LNGameMateListCell {
|
|
|
voiceLabel.snp.makeConstraints { make in
|
|
|
make.verticalEdges.equalToSuperview()
|
|
|
make.trailing.equalToSuperview()
|
|
|
- make.leading.equalTo(ic.snp.trailing).offset(4)
|
|
|
+ make.leading.equalTo(voiceWaveView.snp.trailing).offset(4)
|
|
|
}
|
|
|
|
|
|
let price = UIView()
|