|
@@ -26,32 +26,17 @@ class TSAIRintoneHistoryCell: SwipeCollectionViewCell {
|
|
|
|
|
|
lazy var setRingBtn: TSUIExpandedTouchButton = {
|
|
lazy var setRingBtn: TSUIExpandedTouchButton = {
|
|
let setRingBtn = TSUIExpandedTouchButton()
|
|
let setRingBtn = TSUIExpandedTouchButton()
|
|
- setRingBtn.setUpButton(image: UIImage(named: "ai_setRing_icon")){[weak self] in
|
|
|
|
- guard let self = self else { return }
|
|
|
|
- actionHandler(any: "SetNow")
|
|
|
|
- }
|
|
|
|
|
|
+ setRingBtn.setUpButton(image: UIImage(named: "ai_setRing_icon"))
|
|
setRingBtn.setImage(UIImage(named: "ai_setRing_icon"), for: .normal)
|
|
setRingBtn.setImage(UIImage(named: "ai_setRing_icon"), for: .normal)
|
|
return setRingBtn
|
|
return setRingBtn
|
|
}()
|
|
}()
|
|
|
|
|
|
lazy var ringView: TSRingToneCellView = {
|
|
lazy var ringView: TSRingToneCellView = {
|
|
let ringToneView = TSRingToneCellView()
|
|
let ringToneView = TSRingToneCellView()
|
|
|
|
+ ringToneView.cornerRadius = 0.0
|
|
ringToneView.clickPlayHandel = { [weak self] isplay in
|
|
ringToneView.clickPlayHandel = { [weak self] isplay in
|
|
guard let self = self else { return }
|
|
guard let self = self else { return }
|
|
-
|
|
|
|
- if playSelf{
|
|
|
|
- if TSBusinessAudioPlayer.shared.isLoading{
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- if TSBusinessAudioPlayer.shared.isPlaying{
|
|
|
|
- TSBusinessAudioPlayer.shared.stop()
|
|
|
|
- }else{
|
|
|
|
- TSBusinessAudioPlayer.shared.playUrlString(modelUrlString,indexPath: indexPath)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }else{
|
|
|
|
- TSBusinessAudioPlayer.shared.playUrlString(modelUrlString,indexPath: indexPath)
|
|
|
|
- }
|
|
|
|
|
|
+ clickPlay()
|
|
}
|
|
}
|
|
return ringToneView
|
|
return ringToneView
|
|
}()
|
|
}()
|
|
@@ -69,7 +54,6 @@ class TSAIRintoneHistoryCell: SwipeCollectionViewCell {
|
|
}()
|
|
}()
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
lazy var exampleView: UIView = {
|
|
lazy var exampleView: UIView = {
|
|
let exampleView = UIView()
|
|
let exampleView = UIView()
|
|
exampleView.backgroundColor = "#7E57F4".uiColor
|
|
exampleView.backgroundColor = "#7E57F4".uiColor
|
|
@@ -100,87 +84,20 @@ class TSAIRintoneHistoryCell: SwipeCollectionViewCell {
|
|
|
|
|
|
var model:TSActionInfoModel?{
|
|
var model:TSActionInfoModel?{
|
|
didSet{
|
|
didSet{
|
|
- guard let model = model else { return }
|
|
|
|
- if let rintoneOperation = TSGenerateRintoneOperationQueue.shared.findOperation(uuid: model.uuid) as? TSGenerateRintoneOperation {
|
|
|
|
- rintoneOperation.currentActionInfoModelChanged = { [weak self] actionInfoModel in
|
|
|
|
- guard let self = self else { return }
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- self.updataActionInfoModelView(model: actionInfoModel)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- updataActionInfoModelView(model: model)
|
|
|
|
- dePrint("model actionStatus 收到=\(model.actionStatus)")
|
|
|
|
|
|
+ modelDidSet()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- func updataActionInfoModelView(model:TSActionInfoModel){
|
|
|
|
-
|
|
|
|
- if model.modelType == .example {
|
|
|
|
- model.actionStatus = .success
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- switch model.actionStatus {
|
|
|
|
- case .pending,.running:
|
|
|
|
- generateView.isHidden = false
|
|
|
|
- generateView.setProgress(progress: model.percent)
|
|
|
|
- case .success:
|
|
|
|
- generateView.isHidden = true
|
|
|
|
-
|
|
|
|
- ringView.timeLab.text = Float(model.request.duration).floatToMinuteSecond()
|
|
|
|
- ringView.nameLab.text = model.response.title
|
|
|
|
- ringView.setCoverImageView(urlString: model.response.coverUrl)
|
|
|
|
- exampleView.isHidden = model.modelType != .example
|
|
|
|
- vipView.isHidden = true
|
|
|
|
-
|
|
|
|
- self.changePlayerState(state: TSBusinessAudioPlayer.shared.currentPlayerState)
|
|
|
|
-
|
|
|
|
- case .failed:
|
|
|
|
- generateView.isHidden = false
|
|
|
|
- generateView.setFail()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
var ringModel:TSRingModel?{
|
|
var ringModel:TSRingModel?{
|
|
didSet{
|
|
didSet{
|
|
- guard let ringModel = ringModel else { return }
|
|
|
|
-
|
|
|
|
- ringView.timeLab.text = Float(ringModel.duration).floatToMinuteSecond()
|
|
|
|
- ringView.nameLab.text = ringModel.title
|
|
|
|
- ringView.setCoverImageView(urlString: "")
|
|
|
|
- exampleView.isHidden = true
|
|
|
|
- generateView.isHidden = true
|
|
|
|
- vipView.isHidden = !ringModel.vip
|
|
|
|
- self.changePlayerState(state: TSBusinessAudioPlayer.shared.currentPlayerState)
|
|
|
|
|
|
+ ringModelDidSet()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var playSelf:Bool{
|
|
|
|
- return TSBusinessAudioPlayer.shared.isPlayURLString(string: modelUrlString,indexPath: indexPath)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var modelUrlString:String{
|
|
|
|
- var urlString:String = ""
|
|
|
|
- if let model = model{
|
|
|
|
- urlString = model.response.musicUrl
|
|
|
|
- }else if let ringModel = ringModel{
|
|
|
|
- urlString = ringModel.audioUrl
|
|
|
|
- }
|
|
|
|
- return urlString
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
func creatUI() {
|
|
func creatUI() {
|
|
cornerRadius = 16.0
|
|
cornerRadius = 16.0
|
|
backgroundColor = .cardColor
|
|
backgroundColor = .cardColor
|
|
-
|
|
|
|
- contentView.addSubview(exampleView)
|
|
|
|
- exampleView.snp.makeConstraints { make in
|
|
|
|
- make.trailing.equalToSuperview()
|
|
|
|
- make.top.equalTo(0)
|
|
|
|
- make.height.equalTo(20)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
contentView.addSubview(ringView)
|
|
contentView.addSubview(ringView)
|
|
ringView.snp.makeConstraints { make in
|
|
ringView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
make.edges.equalToSuperview()
|
|
@@ -199,7 +116,13 @@ class TSAIRintoneHistoryCell: SwipeCollectionViewCell {
|
|
make.width.height.equalTo(24)
|
|
make.width.height.equalTo(24)
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ contentView.addSubview(exampleView)
|
|
|
|
+ exampleView.snp.makeConstraints { make in
|
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
|
+ make.top.equalTo(0)
|
|
|
|
+ make.height.equalTo(20)
|
|
|
|
+ }
|
|
|
|
+
|
|
contentView.addSubview(generateView)
|
|
contentView.addSubview(generateView)
|
|
generateView.snp.makeConstraints { make in
|
|
generateView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
make.edges.equalToSuperview()
|
|
@@ -222,49 +145,120 @@ class TSAIRintoneHistoryCell: SwipeCollectionViewCell {
|
|
// cancellable.removeAll()
|
|
// cancellable.removeAll()
|
|
}
|
|
}
|
|
|
|
|
|
- func changePlayerState(state:TSBusinessAudioPlayer.PlayerState){
|
|
|
|
- dePrint("changePlayerState = \(state)")
|
|
|
|
- if playSelf == false {
|
|
|
|
- ringView.handelAudioPlayerStateChange(state: .stop)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- ringView.handelAudioPlayerStateChange(state: state)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
deinit {
|
|
deinit {
|
|
NotificationCenter.default.removeObserver(self)
|
|
NotificationCenter.default.removeObserver(self)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+extension TSAIRintoneHistoryCell {
|
|
|
|
|
|
- var indexPath:IndexPath? {
|
|
|
|
- return setRingBtn.indexPath
|
|
|
|
|
|
+ func modelDidSet(){
|
|
|
|
+ guard let model = model else { return }
|
|
|
|
+ if let rintoneOperation = TSGenerateRintoneOperationQueue.shared.findOperation(uuid: model.uuid) as? TSGenerateRintoneOperation {
|
|
|
|
+ rintoneOperation.currentActionInfoModelChanged = { [weak self] actionInfoModel in
|
|
|
|
+ guard let self = self else { return }
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.updataActionInfoModelView(model: actionInfoModel)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ updataActionInfoModelView(model: model)
|
|
|
|
+ dePrint("model actionStatus 收到=\(model.actionStatus)")
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ func ringModelDidSet(){
|
|
|
|
+ guard let ringModel = ringModel else { return }
|
|
|
|
+
|
|
|
|
+ ringView.timeLab.text = Float(ringModel.duration).floatToMinuteSecond()
|
|
|
|
+ ringView.nameLab.text = ringModel.title
|
|
|
|
+ ringView.setCoverImageView(urlString: "")
|
|
|
|
+ exampleView.isHidden = true
|
|
|
|
+ generateView.isHidden = true
|
|
|
|
+ vipView.isHidden = !ringModel.vip
|
|
|
|
+ self.changePlayerState(state: TSBusinessAudioPlayer.shared.currentPlayerState)
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
-extension TSAIRintoneHistoryCell : TSComponentView {
|
|
|
|
|
|
+
|
|
|
|
+extension TSAIRintoneHistoryCell {
|
|
|
|
+ func clickPlay() {
|
|
|
|
+ if playSelf{
|
|
|
|
+ if TSBusinessAudioPlayer.shared.isLoading{
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if TSBusinessAudioPlayer.shared.isPlaying{
|
|
|
|
+ TSBusinessAudioPlayer.shared.stop()
|
|
|
|
+ }else{
|
|
|
|
+ TSBusinessAudioPlayer.shared.playUrlString(modelUrlString,indexPath: indexPath)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ TSBusinessAudioPlayer.shared.playUrlString(modelUrlString,indexPath: indexPath)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- func renderView(with object: Any?, component: TSCollectionViewComponent, attributes: [String : Any]?) {
|
|
|
|
- self.colComponent = component
|
|
|
|
- self.colAttributes = attributes
|
|
|
|
|
|
+
|
|
|
|
+ func changePlayerState(state:TSBusinessAudioPlayer.PlayerState){
|
|
|
|
+ if playSelf == false {
|
|
|
|
+ if ringView.isPlay == true ||
|
|
|
|
+ ringView.isloading == true
|
|
|
|
+ {
|
|
|
|
+ ringView.handelAudioPlayerStateChange(state: .stop)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+// dePrint("changePlayerState = \(state)")
|
|
|
|
+ ringView.handelAudioPlayerStateChange(state: state)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ func updataActionInfoModelView(model:TSActionInfoModel){
|
|
|
|
|
|
|
|
+ if model.modelType == .example {
|
|
|
|
+ model.actionStatus = .success
|
|
|
|
+ }
|
|
|
|
|
|
- if let itemModel = object as? TSColVVMItemModel{
|
|
|
|
- if let dataModel = itemModel.dataModel as? TSRingModel{
|
|
|
|
- ringModel = dataModel
|
|
|
|
- }
|
|
|
|
|
|
+ switch model.actionStatus {
|
|
|
|
+ case .pending,.running:
|
|
|
|
+ generateView.isHidden = false
|
|
|
|
+ generateView.setProgress(progress: model.percent)
|
|
|
|
+ case .success:
|
|
|
|
+ generateView.isHidden = true
|
|
|
|
+
|
|
|
|
+ ringView.timeLab.text = Float(model.request.duration).floatToMinuteSecond()
|
|
|
|
+ ringView.nameLab.text = model.response.title
|
|
|
|
+ ringView.setCoverImageView(urlString: model.response.coverUrl)
|
|
|
|
+ exampleView.isHidden = model.modelType != .example
|
|
|
|
+ vipView.isHidden = true
|
|
|
|
+
|
|
|
|
+ self.changePlayerState(state: TSBusinessAudioPlayer.shared.currentPlayerState)
|
|
|
|
+
|
|
|
|
+ case .failed:
|
|
|
|
+ generateView.isHidden = false
|
|
|
|
+ generateView.setFail()
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ var playSelf:Bool{
|
|
|
|
+ return TSBusinessAudioPlayer.shared.isPlayURLString(string: modelUrlString,indexPath: indexPath)
|
|
}
|
|
}
|
|
-
|
|
|
|
- public var itemActionHandler: ((Any?, IndexPath) -> Void)?{
|
|
|
|
- if let colComponent = colComponent,let itemActionHandler = colComponent.itemActionHandler {
|
|
|
|
- return itemActionHandler
|
|
|
|
|
|
+
|
|
|
|
+ var modelUrlString:String{
|
|
|
|
+ var urlString:String = ""
|
|
|
|
+ if let model = model{
|
|
|
|
+ urlString = model.response.musicUrl
|
|
|
|
+ }else if let ringModel = ringModel{
|
|
|
|
+ urlString = ringModel.audioUrl
|
|
}
|
|
}
|
|
- return nil
|
|
|
|
|
|
+ return urlString
|
|
}
|
|
}
|
|
|
|
|
|
- public func actionHandler(any:Any?){
|
|
|
|
- if let sectionActionHandler = itemActionHandler ,let indexPath = indexPath{
|
|
|
|
- sectionActionHandler(any,indexPath)
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ var indexPath:IndexPath? {
|
|
|
|
+ return setRingBtn.indexPath
|
|
}
|
|
}
|
|
}
|
|
}
|