123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- //
- // APMyRingVC.swift
- // AIPlayRingtones
- //
- // Created by 100Years on 2025/5/15.
- //
- import SwipeCellKit
- class APMyRingVC: TSBaseVC {
-
- var listModelArray: [ASActionInfoModel] = []
- var dataChangedBlock:(()->Void)?
-
- lazy var navBarView: TSBaseNavContentBarView = {
- let navBarView = TSBaseNavContentBarView()
- let titleImageView = UIImageView.createImageView(imageName: "nav_title_myRingtones", contentMode: .scaleToFill)
- navBarView.barView.addSubview(titleImageView)
- titleImageView.snp.makeConstraints { make in
- make.center.equalToSuperview()
- }
-
- // let vipBtn = UIButton.createButton(image: .aiRintoneIcon) { [weak self] in
- // guard let self = self else { return }
- //
- // if let model = dbHistory.listModels.first,model.modelType != 1 {
- // ASRMShared.writeThread {
- // model.status = "failed"
- // }
- // }
- //
- // updateListView()
- // }
- // navBarView.barView.addSubview(vipBtn)
- // vipBtn.snp.makeConstraints { make in
- // make.centerY.equalToSuperview()
- // make.trailing.equalTo(-16) // (-60)
- // make.width.height.equalTo(24)
- // }
- return navBarView
- }()
-
- lazy var layout: UICollectionViewFlowLayout = {
- let layout = UICollectionViewFlowLayout()
- layout.scrollDirection = .vertical
- layout.itemSize = CGSize(width: k_ScreenWidth-32, height: 74)
- layout.minimumInteritemSpacing = 10.0
- layout.minimumLineSpacing = 18.0
- return layout
- }()
-
- lazy var collectionView: UICollectionView = {
- let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
- collectionView.delegate = self
- collectionView.dataSource = self
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.backgroundColor = .clear
- collectionView.contentInset = UIEdgeInsets(top: 16, left: 0, bottom: 16, right: 0)
- collectionView.register(ASMyRingCell.self, forCellWithReuseIdentifier: ASMyRingCell.cellID)
- if #available(iOS 11.0, *) {
- collectionView.contentInsetAdjustmentBehavior = .never
- }
- return collectionView
- }()
-
-
- lazy var pageNullView: ASPageNullView = {
- let pageNullView = ASPageNullView()
- pageNullView.isHidden = true
- return pageNullView
- }()
-
-
- override func createView() {
-
- navBarContentView.addSubview(navBarView)
- navBarView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
-
- contentView.addSubview(collectionView)
- collectionView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
-
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- debugPrint("viewWillAppear listModels.count = \(ASRMShared.ringDBHistory.listModels.count)")
- }
-
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- TSBusinessAudioPlayer.shared.stop()
- }
- override func dealThings() {
- updateListView()
-
- NotificationCenter.default.addObserver(self, selector: #selector(operationChanged(_:)), name: .kGenerateRingOperationChanged, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(operationChanged(_:)), name: .kGenerateRTROperationChanged, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(operationChanged(_:)), name: .kGenerateTTROperationChanged, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(updateListView), name: .kRingDataChanged, object: nil)
- }
-
-
- @objc func operationChanged(_ notification: Notification) {
- if let userInfo = notification.userInfo as? [String: Any],let state = userInfo["state"] as? ASProgressState {
- if state.reloadNewData {
- self.updateListView()
- }
- }
- }
-
- @objc func updateListView(){
- dbHistory.getModelList { [weak self] array in
- guard let self = self else { return }
- listModelArray = array
- updateView()
- }
- }
-
- func updateView() {
- collectionView.reloadData()
- pageNullView.isHidden = listModelArray.count > 0
- }
- }
- extension APMyRingVC: UICollectionViewDataSource ,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
-
- public func numberOfSections(in collectionView: UICollectionView) -> Int {
- return 1
- }
-
- public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return listModelArray.count
- }
-
- public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ASMyRingCell.cellID, for: indexPath) as! ASMyRingCell
- if let model = listModelArray.safeObj(At: indexPath.item){
- cell.setTargetVC(targetVC: self, indexPath: indexPath)
- cell.model = model
- }
- return cell
- }
- public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-
- }
-
- }
- extension APMyRingVC{
-
- var dbHistory:ASDBHistory{
- return ASRMShared.ringDBHistory
- }
- }
- extension APMyRingVC: SwipeCollectionViewCellDelegate {
-
- func collectionView(_ collectionView: UICollectionView, editActionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
- guard orientation == .right else { return nil }
-
- if indexPath.section != 0 {
- return nil
- }
-
- if let model = listModelArray.safeObj(At: indexPath.item) {
- switch model.actionStatus {
- case .pending,.running:
- return nil
- default:break
- }
- }
-
- // 删除操作
- let deleteAction = SwipeAction(style: .destructive, title: nil) {[weak self] action, indexPath in
- guard let self = self else { return }
- showCustomAlert(message: "Are you sure to delete".localized, deleteHandler: { [weak self] in
- guard let self = self else { return }
- if let model = listModelArray.safeObj(At: indexPath.item) {
- dbHistory.deleteListModel(id: model.id)
- updateListView()
- TSBusinessAudioPlayer.shared.stop()
- }
- })
- }
-
- deleteAction.backgroundColor = "#E83E3E".uiColor
- deleteAction.image = UIImage(named: "delete_white")
-
- return [deleteAction]
- }
-
- func collectionView(_ collectionView: UICollectionView, editActionsOptionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
- var options = SwipeOptions()
- options.transitionStyle = .border // 滑动动画样式
- return options
- }
-
- }
|