ASMyRingVC.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //
  2. // APMyRingVC.swift
  3. // AIPlayRingtones
  4. //
  5. // Created by 100Years on 2025/5/15.
  6. //
  7. import SwipeCellKit
  8. class APMyRingVC: TSBaseVC {
  9. var listModelArray: [ASActionInfoModel] = []
  10. var dataChangedBlock:(()->Void)?
  11. lazy var navBarView: TSBaseNavContentBarView = {
  12. let navBarView = TSBaseNavContentBarView()
  13. let titleImageView = UIImageView.createImageView(imageName: "nav_title_myRingtones", contentMode: .scaleToFill)
  14. navBarView.barView.addSubview(titleImageView)
  15. titleImageView.snp.makeConstraints { make in
  16. make.center.equalToSuperview()
  17. }
  18. // let vipBtn = UIButton.createButton(image: .aiRintoneIcon) { [weak self] in
  19. // guard let self = self else { return }
  20. //
  21. // if let model = dbHistory.listModels.first,model.modelType != 1 {
  22. // ASRMShared.writeThread {
  23. // model.status = "failed"
  24. // }
  25. // }
  26. //
  27. // updateListView()
  28. // }
  29. // navBarView.barView.addSubview(vipBtn)
  30. // vipBtn.snp.makeConstraints { make in
  31. // make.centerY.equalToSuperview()
  32. // make.trailing.equalTo(-16) // (-60)
  33. // make.width.height.equalTo(24)
  34. // }
  35. return navBarView
  36. }()
  37. lazy var layout: UICollectionViewFlowLayout = {
  38. let layout = UICollectionViewFlowLayout()
  39. layout.scrollDirection = .vertical
  40. layout.itemSize = CGSize(width: k_ScreenWidth-32, height: 74)
  41. layout.minimumInteritemSpacing = 10.0
  42. layout.minimumLineSpacing = 18.0
  43. return layout
  44. }()
  45. lazy var collectionView: UICollectionView = {
  46. let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
  47. collectionView.delegate = self
  48. collectionView.dataSource = self
  49. collectionView.showsVerticalScrollIndicator = false
  50. collectionView.showsHorizontalScrollIndicator = false
  51. collectionView.backgroundColor = .clear
  52. collectionView.contentInset = UIEdgeInsets(top: 16, left: 0, bottom: 16, right: 0)
  53. collectionView.register(ASMyRingCell.self, forCellWithReuseIdentifier: ASMyRingCell.cellID)
  54. if #available(iOS 11.0, *) {
  55. collectionView.contentInsetAdjustmentBehavior = .never
  56. }
  57. return collectionView
  58. }()
  59. lazy var pageNullView: ASPageNullView = {
  60. let pageNullView = ASPageNullView()
  61. pageNullView.isHidden = true
  62. return pageNullView
  63. }()
  64. override func createView() {
  65. navBarContentView.addSubview(navBarView)
  66. navBarView.snp.makeConstraints { make in
  67. make.edges.equalToSuperview()
  68. }
  69. contentView.addSubview(collectionView)
  70. collectionView.snp.makeConstraints { make in
  71. make.edges.equalToSuperview()
  72. }
  73. }
  74. override func viewWillAppear(_ animated: Bool) {
  75. super.viewWillAppear(animated)
  76. debugPrint("viewWillAppear listModels.count = \(ASRMShared.ringDBHistory.listModels.count)")
  77. }
  78. override func viewWillDisappear(_ animated: Bool) {
  79. super.viewWillDisappear(animated)
  80. TSBusinessAudioPlayer.shared.stop()
  81. }
  82. override func dealThings() {
  83. updateListView()
  84. NotificationCenter.default.addObserver(self, selector: #selector(operationChanged(_:)), name: .kGenerateRingOperationChanged, object: nil)
  85. NotificationCenter.default.addObserver(self, selector: #selector(operationChanged(_:)), name: .kGenerateRTROperationChanged, object: nil)
  86. NotificationCenter.default.addObserver(self, selector: #selector(operationChanged(_:)), name: .kGenerateTTROperationChanged, object: nil)
  87. NotificationCenter.default.addObserver(self, selector: #selector(updateListView), name: .kRingDataChanged, object: nil)
  88. }
  89. @objc func operationChanged(_ notification: Notification) {
  90. if let userInfo = notification.userInfo as? [String: Any],let state = userInfo["state"] as? ASProgressState {
  91. if state.reloadNewData {
  92. self.updateListView()
  93. }
  94. }
  95. }
  96. @objc func updateListView(){
  97. dbHistory.getModelList { [weak self] array in
  98. guard let self = self else { return }
  99. listModelArray = array
  100. updateView()
  101. }
  102. }
  103. func updateView() {
  104. collectionView.reloadData()
  105. pageNullView.isHidden = listModelArray.count > 0
  106. }
  107. }
  108. extension APMyRingVC: UICollectionViewDataSource ,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
  109. public func numberOfSections(in collectionView: UICollectionView) -> Int {
  110. return 1
  111. }
  112. public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  113. return listModelArray.count
  114. }
  115. public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  116. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ASMyRingCell.cellID, for: indexPath) as! ASMyRingCell
  117. if let model = listModelArray.safeObj(At: indexPath.item){
  118. cell.setTargetVC(targetVC: self, indexPath: indexPath)
  119. cell.model = model
  120. }
  121. return cell
  122. }
  123. public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  124. }
  125. }
  126. extension APMyRingVC{
  127. var dbHistory:ASDBHistory{
  128. return ASRMShared.ringDBHistory
  129. }
  130. }
  131. extension APMyRingVC: SwipeCollectionViewCellDelegate {
  132. func collectionView(_ collectionView: UICollectionView, editActionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
  133. guard orientation == .right else { return nil }
  134. if indexPath.section != 0 {
  135. return nil
  136. }
  137. if let model = listModelArray.safeObj(At: indexPath.item) {
  138. switch model.actionStatus {
  139. case .pending,.running:
  140. return nil
  141. default:break
  142. }
  143. }
  144. // 删除操作
  145. let deleteAction = SwipeAction(style: .destructive, title: nil) {[weak self] action, indexPath in
  146. guard let self = self else { return }
  147. showCustomAlert(message: "Are you sure to delete".localized, deleteHandler: { [weak self] in
  148. guard let self = self else { return }
  149. if let model = listModelArray.safeObj(At: indexPath.item) {
  150. dbHistory.deleteListModel(id: model.id)
  151. updateListView()
  152. TSBusinessAudioPlayer.shared.stop()
  153. }
  154. })
  155. }
  156. deleteAction.backgroundColor = "#E83E3E".uiColor
  157. deleteAction.image = UIImage(named: "delete_white")
  158. return [deleteAction]
  159. }
  160. func collectionView(_ collectionView: UICollectionView, editActionsOptionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
  161. var options = SwipeOptions()
  162. options.transitionStyle = .border // 滑动动画样式
  163. return options
  164. }
  165. }