123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // MusicContainerViewController.swift
- // DiaryWallPaper
- //
- // Created by 倪锴伦 on 2025/1/20.
- //
- import ADManager
- import BetterSegmentedControl
- import Foundation
- import TSVideoKit
- class MusicPlaylistContainerViewController: LWBGViewController {
- lazy var navBar: LWRightNavigationBar = {
- let bar = LWRightNavigationBar()
- bar.iconView.image = .init(named: "ic_nav_playlist")
- return bar
- }()
-
- lazy var searchBar: MusicSearchBar = MusicSearchBar()
- weak var importMenuView: BubbleMenuView?
- lazy var importButton: UIButton = {
- let bt = UIButton(frame: CGRect(x: 0, y: 0, width: 42, height: 42))
- bt.setImage(.icNavImport, for: .normal)
- return bt
- }()
- lazy var playlistVc: PlaylistViewController = PlaylistViewController()
-
- var viewModel: MusicContainerViewModel = MusicContainerViewModel()
-
- lazy var guideBubble: GuideBubbleView = {
- let guide = GuideBubbleView()
- guide.addTarget(self, action: #selector(dismissGuideBubble), for: .touchUpInside)
- guide.tapArea.addTarget(self, action: #selector(bubbleClick), for: .touchUpInside)
- return guide
- }()
- override func viewDidLoad() {
- super.viewDidLoad()
- bgImageView.image = .viewMainBg
- addTargets()
- }
- override func addNotifaction() {
- super.addNotifaction()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- PlayerManager.shared.rootVc?.moveUpMiniBar()
- }
- override func viewDidLayoutSubviews() {
- super.viewDidLayoutSubviews()
- print("TSConfiguration.isYs ===", TSConfiguration.isYs)
- if UserDefaults.standard.string(forKey: "GuideKey") == nil, TSConfiguration.isYs {
- view.addSubview(guideBubble)
- view.bringSubviewToFront(guideBubble)
- guideBubble.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
- }
- }
- func addTargets() {
- searchBar.addTarget(self, action: #selector(showSearchViewController), for: .touchUpInside)
- importButton.addTarget(self, action: #selector(showImportMenuView), for: .touchUpInside)
- }
- @objc func showImportMenuView() {
- let menuView = BubbleMenuView()
- menuView.position = FitManager.isAr ? .topLeft : .topRight
- menuView.actionHanlder = { type in
- self.menuClick(type: type)
- }
- view.addSubview(menuView)
- menuView.snp.makeConstraints { make in
- make.trailing.equalToSuperview().offset(-16)
- make.top.equalTo(self.importButton.snp.bottom).offset(0)
- }
- importMenuView = menuView
- }
- func menuClick(type: ImportSource) {
- importMenuView?.removeFromSuperview()
- if type == .library {
- ImportFilesManager.shared.openPhotoLibrary(parent: self)
- } else if type == .file {
- ImportFilesManager.shared.openFileDocument(parent: self, completion: nil)
- }
- }
- @objc func bubbleClick() {
- showSearchViewController()
- dismissGuideBubble()
- }
- @objc func dismissGuideBubble() {
- guideBubble.isHidden = true
- UserDefaults.standard.setValue("Guide", forKey: "GuideKey")
- }
- @objc func showSearchViewController() {
- if PurchaseManager.default.isVip {
- if TSConfiguration.isYs {
- let vc = SearchOnlineViewController()
- vc.hidesBottomBarWhenPushed = true
- navigationController?.pushViewController(vc, animated: true)
- } else {
- let vc = LocalSearchViewController()
- vc.hidesBottomBarWhenPushed = true
- navigationController?.pushViewController(vc, animated: true)
- }
- } else {
- ADManager.shared.showAd(scene: ADScene.searchInsert, from: self) { state in
- if state == .finished || state == .fail {
- if TSConfiguration.isYs {
- let vc = SearchOnlineViewController()
- vc.hidesBottomBarWhenPushed = true
- self.navigationController?.pushViewController(vc, animated: true)
- } else {
- let vc = LocalSearchViewController()
- vc.hidesBottomBarWhenPushed = true
- self.navigationController?.pushViewController(vc, animated: true)
- }
- }
- }
- }
- }
- override func addChildren() {
- super.addChildren()
- view.addSubview(navBar)
- navBar.appendRightItem(item: importButton)
- view.addSubview(searchBar)
- view.addSubview(playlistVc.view)
- addChild(playlistVc)
- playlistVc.didMove(toParent: self)
- }
- override func makeConstarints() {
- super.makeConstarints()
- navBar.snp.makeConstraints { make in
- make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
- make.horizontalEdges.equalToSuperview()
- make.height.equalTo(k_Height_NavBar)
- }
- searchBar.snp.makeConstraints { make in
- make.top.equalTo(navBar.snp.bottom)
- make.horizontalEdges.equalToSuperview().inset(16)
- make.height.equalTo(44)
- }
- playlistVc.view.snp.makeConstraints { make in
- make.top.equalTo(searchBar.snp.bottom).offset(8)
- make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
- make.left.right.equalToSuperview()
- }
- }
- }
|