MusicPlaylistContainerViewController.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // MusicContainerViewController.swift
  3. // DiaryWallPaper
  4. //
  5. // Created by 倪锴伦 on 2025/1/20.
  6. //
  7. import ADManager
  8. import BetterSegmentedControl
  9. import Foundation
  10. import TSVideoKit
  11. class MusicPlaylistContainerViewController: LWBGViewController {
  12. lazy var navBar: LWRightNavigationBar = {
  13. let bar = LWRightNavigationBar()
  14. bar.iconView.image = .init(named: "ic_nav_playlist")
  15. return bar
  16. }()
  17. lazy var searchBar: MusicSearchBar = MusicSearchBar()
  18. weak var importMenuView: BubbleMenuView?
  19. lazy var importButton: UIButton = {
  20. let bt = UIButton(frame: CGRect(x: 0, y: 0, width: 42, height: 42))
  21. bt.setImage(.icNavImport, for: .normal)
  22. return bt
  23. }()
  24. lazy var playlistVc: PlaylistViewController = PlaylistViewController()
  25. var viewModel: MusicContainerViewModel = MusicContainerViewModel()
  26. lazy var guideBubble: GuideBubbleView = {
  27. let guide = GuideBubbleView()
  28. guide.addTarget(self, action: #selector(dismissGuideBubble), for: .touchUpInside)
  29. guide.tapArea.addTarget(self, action: #selector(bubbleClick), for: .touchUpInside)
  30. return guide
  31. }()
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. bgImageView.image = .viewMainBg
  35. addTargets()
  36. }
  37. override func addNotifaction() {
  38. super.addNotifaction()
  39. }
  40. override func viewWillAppear(_ animated: Bool) {
  41. super.viewWillAppear(animated)
  42. PlayerManager.shared.rootVc?.moveUpMiniBar()
  43. }
  44. override func viewDidLayoutSubviews() {
  45. super.viewDidLayoutSubviews()
  46. print("TSConfiguration.isYs ===", TSConfiguration.isYs)
  47. if UserDefaults.standard.string(forKey: "GuideKey") == nil, TSConfiguration.isYs {
  48. view.addSubview(guideBubble)
  49. view.bringSubviewToFront(guideBubble)
  50. guideBubble.snp.makeConstraints { make in
  51. make.edges.equalToSuperview()
  52. }
  53. }
  54. }
  55. func addTargets() {
  56. searchBar.addTarget(self, action: #selector(showSearchViewController), for: .touchUpInside)
  57. importButton.addTarget(self, action: #selector(showImportMenuView), for: .touchUpInside)
  58. }
  59. @objc func showImportMenuView() {
  60. let menuView = BubbleMenuView()
  61. menuView.position = FitManager.isAr ? .topLeft : .topRight
  62. menuView.actionHanlder = { type in
  63. self.menuClick(type: type)
  64. }
  65. view.addSubview(menuView)
  66. menuView.snp.makeConstraints { make in
  67. make.trailing.equalToSuperview().offset(-16)
  68. make.top.equalTo(self.importButton.snp.bottom).offset(0)
  69. }
  70. importMenuView = menuView
  71. }
  72. func menuClick(type: ImportSource) {
  73. importMenuView?.removeFromSuperview()
  74. if type == .library {
  75. ImportFilesManager.shared.openPhotoLibrary(parent: self)
  76. } else if type == .file {
  77. ImportFilesManager.shared.openFileDocument(parent: self, completion: nil)
  78. }
  79. }
  80. @objc func bubbleClick() {
  81. showSearchViewController()
  82. dismissGuideBubble()
  83. }
  84. @objc func dismissGuideBubble() {
  85. guideBubble.isHidden = true
  86. UserDefaults.standard.setValue("Guide", forKey: "GuideKey")
  87. }
  88. @objc func showSearchViewController() {
  89. if PurchaseManager.default.isVip {
  90. if TSConfiguration.isYs {
  91. let vc = SearchOnlineViewController()
  92. vc.hidesBottomBarWhenPushed = true
  93. navigationController?.pushViewController(vc, animated: true)
  94. } else {
  95. let vc = LocalSearchViewController()
  96. vc.hidesBottomBarWhenPushed = true
  97. navigationController?.pushViewController(vc, animated: true)
  98. }
  99. } else {
  100. ADManager.shared.showAd(scene: ADScene.searchInsert, from: self) { state in
  101. if state == .finished || state == .fail {
  102. if TSConfiguration.isYs {
  103. let vc = SearchOnlineViewController()
  104. vc.hidesBottomBarWhenPushed = true
  105. self.navigationController?.pushViewController(vc, animated: true)
  106. } else {
  107. let vc = LocalSearchViewController()
  108. vc.hidesBottomBarWhenPushed = true
  109. self.navigationController?.pushViewController(vc, animated: true)
  110. }
  111. }
  112. }
  113. }
  114. }
  115. override func addChildren() {
  116. super.addChildren()
  117. view.addSubview(navBar)
  118. navBar.appendRightItem(item: importButton)
  119. view.addSubview(searchBar)
  120. view.addSubview(playlistVc.view)
  121. addChild(playlistVc)
  122. playlistVc.didMove(toParent: self)
  123. }
  124. override func makeConstarints() {
  125. super.makeConstarints()
  126. navBar.snp.makeConstraints { make in
  127. make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
  128. make.horizontalEdges.equalToSuperview()
  129. make.height.equalTo(k_Height_NavBar)
  130. }
  131. searchBar.snp.makeConstraints { make in
  132. make.top.equalTo(navBar.snp.bottom)
  133. make.horizontalEdges.equalToSuperview().inset(16)
  134. make.height.equalTo(44)
  135. }
  136. playlistVc.view.snp.makeConstraints { make in
  137. make.top.equalTo(searchBar.snp.bottom).offset(8)
  138. make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
  139. make.left.right.equalToSuperview()
  140. }
  141. }
  142. }