|
@@ -0,0 +1,284 @@
|
|
|
|
+//
|
|
|
|
+// PublishRecordMusicView.swift
|
|
|
|
+// RainbowPlanet
|
|
|
|
+//
|
|
|
|
+// Created by Christopher on 2019/7/19.
|
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
|
+// 录制视频--选择音乐のView
|
|
|
|
+
|
|
|
|
+import UIKit
|
|
|
|
+import FWPopupView
|
|
|
|
+import RxSwift
|
|
|
|
+import SwiftyMediator
|
|
|
|
+import JXSegmentedView
|
|
|
|
+
|
|
|
|
+class PublishRecordMusicView: FWPopupView {
|
|
|
|
+
|
|
|
|
+ let disposeBag = DisposeBag()
|
|
|
|
+
|
|
|
|
+ typealias RecommendClosure = () -> Void
|
|
|
|
+ var recommendClosure : RecommendClosure?
|
|
|
|
+
|
|
|
|
+ override init(frame: CGRect) {
|
|
|
|
+ super.init(frame: frame)
|
|
|
|
+ setupViews()
|
|
|
|
+ setupLayouts()
|
|
|
|
+
|
|
|
|
+ // 获取分类列表
|
|
|
|
+ self.communityGetMusicCategoryApi()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var categoryTitleArr = Array<String>()
|
|
|
|
+
|
|
|
|
+ var categoryListMdlArr : Array<MusicCategoryItemModel>? {
|
|
|
|
+ didSet {
|
|
|
|
+ guard categoryListMdlArr?.isEmpty ?? true else {
|
|
|
|
+ categoryTitleArr.removeAll()
|
|
|
|
+ categoryTitleArr.append("推荐")
|
|
|
|
+ for categoryMdl in categoryListMdlArr! {
|
|
|
|
+ categoryTitleArr.append(categoryMdl.name!)
|
|
|
|
+ }
|
|
|
|
+ setupSegmentedView()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ setupSegmentedView()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func setupViews() {
|
|
|
|
+ frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight - kSafeTabBarHeight - kSafeStatusBarHeight - 22)
|
|
|
|
+
|
|
|
|
+ // 添加毛玻璃效果,需使用frame设置位置
|
|
|
|
+ let blurEffect = UIBlurEffect(style: .dark)
|
|
|
|
+ let blurEffectView = UIVisualEffectView(effect: blurEffect)
|
|
|
|
+ blurEffectView.frame = CGRect(x: CGFloat(0), y: 0, width: kScreenWidth, height: kScreenHeight - kSafeTabBarHeight - kSafeStatusBarHeight - 22)
|
|
|
|
+ addSubview(blurEffectView)
|
|
|
|
+
|
|
|
|
+ self.backgroundColor = UIColor.clear
|
|
|
|
+
|
|
|
|
+ configRectCorner(corner: [.topLeft,.topRight], radii: CGSize(width: 8, height: 8))
|
|
|
|
+
|
|
|
|
+ addSubview(cancelButton)
|
|
|
|
+
|
|
|
|
+ addSubview(recommendLabel)
|
|
|
|
+ addSubview(recommendButton)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func setupLayouts() {
|
|
|
|
+
|
|
|
|
+ cancelButton.snp.makeConstraints { (make) in
|
|
|
|
+ make.top.equalTo(2)
|
|
|
|
+ make.left.equalTo(3)
|
|
|
|
+ make.size.equalTo(44)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ recommendLabel.snp.makeConstraints { (make) in
|
|
|
|
+ make.centerX.equalTo(kScreenWidth*0.5-20)
|
|
|
|
+ make.bottom.equalTo(-(kSafeTabBarHeight+20))
|
|
|
|
+ make.height.equalTo(20)
|
|
|
|
+ }
|
|
|
|
+ recommendButton.snp.makeConstraints { (make) in
|
|
|
|
+ make.left.equalTo(recommendLabel.snp_right)
|
|
|
|
+ make.height.equalTo(30)
|
|
|
|
+ make.centerY.equalTo(recommendLabel.snp_centerY)
|
|
|
|
+ make.width.equalTo(60)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func setupSegmentedView() {
|
|
|
|
+ addSubview(segmentedView)
|
|
|
|
+ addSubview(listContainerView)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // MARK: - 视图创建
|
|
|
|
+ lazy var cancelButton: UIButton = {
|
|
|
|
+ let cancelButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
|
+ cancelButton.setImage(kImage(name: "video_btn_close_white"), for: .normal)
|
|
|
|
+ return cancelButton
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ lazy var recommendLabel: UILabel = {
|
|
|
|
+ let recommendLabel = UILabel()
|
|
|
|
+ recommendLabel.text = "没有找到想要的音乐?"
|
|
|
|
+ recommendLabel.textColor = k999999Color
|
|
|
|
+ recommendLabel.font = kRegularFont14
|
|
|
|
+ return recommendLabel
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ lazy var recommendButton: UIButton = {
|
|
|
|
+ let recommendButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
|
+ recommendButton.setTitle("点击推荐", for: UIControl.State.normal)
|
|
|
|
+ recommendButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
|
+ recommendButton.titleLabel?.font = kMediumFont14
|
|
|
|
+ return recommendButton
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ //MARK: -
|
|
|
|
+ //1.初始化JXSegmentedView
|
|
|
|
+ lazy var segmentedView: JXSegmentedView = {
|
|
|
|
+ let segmentedView = JXSegmentedView(frame: CGRect(x: 0, y: 48, width: kScreenWidth, height: 44))
|
|
|
|
+ segmentedView.delegate = self
|
|
|
|
+ segmentedView.dataSource = segmentedDataSource
|
|
|
|
+ segmentedView.indicators = [indicator]
|
|
|
|
+ segmentedView.contentScrollView = listContainerView.scrollView
|
|
|
|
+ segmentedView.defaultSelectedIndex = 0
|
|
|
|
+
|
|
|
|
+ let lineWidth: CGFloat = 0.5
|
|
|
|
+ let lineLayer = CALayer()
|
|
|
|
+ lineLayer.backgroundColor = k999999Color.cgColor
|
|
|
|
+ lineLayer.frame = CGRect(x: 0, y: segmentedView.bounds.height - lineWidth, width: segmentedView.bounds.width, height: lineWidth)
|
|
|
|
+ segmentedView.layer.addSublayer(lineLayer)
|
|
|
|
+ return segmentedView
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ //2.初始化dataSource
|
|
|
|
+ lazy var segmentedDataSource: JXSegmentedTitleDataSource = {
|
|
|
|
+ let segmentedDataSource = JXSegmentedTitleDataSource()
|
|
|
|
+ segmentedDataSource.titles = categoryTitleArr
|
|
|
|
+ segmentedDataSource.isTitleColorGradientEnabled = true
|
|
|
|
+ segmentedDataSource.isItemSpacingAverageEnabled = true
|
|
|
|
+ segmentedDataSource.isTitleZoomEnabled = true
|
|
|
|
+ segmentedDataSource.titleNormalColor = kbbbbbbColor
|
|
|
|
+ segmentedDataSource.titleSelectedColor = kffffffColor
|
|
|
|
+ segmentedDataSource.titleNormalFont = kRegularFont14!
|
|
|
|
+ segmentedDataSource.titleSelectedFont = kMediumFont14
|
|
|
|
+
|
|
|
|
+ //reloadData(selectedIndex:)方法一定要调用,方法内部会刷新数据源数组
|
|
|
|
+ segmentedDataSource.reloadData(selectedIndex: 0)
|
|
|
|
+ return segmentedDataSource
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ //3.初始化指示器indicator
|
|
|
|
+ lazy var indicator: JXSegmentedIndicatorLineView = {
|
|
|
|
+ let indicator = JXSegmentedIndicatorLineView()
|
|
|
|
+ indicator.indicatorColor = kffffffColor
|
|
|
|
+ indicator.indicatorHeight = 3
|
|
|
|
+ indicator.indicatorWidth = 20
|
|
|
|
+ indicator.cornerRadius = 1.5
|
|
|
|
+ indicator.masksToBounds = true
|
|
|
|
+ return indicator
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ //4.初始化JXSegmentedListContainerView
|
|
|
|
+ private lazy var listContainerView: JXSegmentedListContainerView = {
|
|
|
|
+ let listContainerView = JXSegmentedListContainerView(dataSource: self)
|
|
|
|
+ listContainerView.didAppearPercent = 0.01
|
|
|
|
+ listContainerView.defaultSelectedIndex = 0
|
|
|
|
+ listContainerView.frame = CGRect(x: 0, y: 48+44, width: kScreenWidth, height: kScreenHeight - kSafeTabBarHeight - kSafeStatusBarHeight - 55 - 114)
|
|
|
|
+ return listContainerView
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ /// 初始化View
|
|
|
|
+ @objc class func publishRecordMusicView(attachedView:UIView) -> PublishRecordMusicView {
|
|
|
|
+ let view = PublishRecordMusicView()
|
|
|
|
+ view.attachedView = attachedView
|
|
|
|
+ let vProperty = FWPopupViewProperty()
|
|
|
|
+ vProperty.popupCustomAlignment = .bottomCenter
|
|
|
|
+ vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
|
|
|
|
+ vProperty.popupAnimationType = .frame
|
|
|
|
+ vProperty.maskViewColor = UIColor(white: 0, alpha: 0.2)
|
|
|
|
+ // 用户点击外部遮罩层页面是否可以消失
|
|
|
|
+ vProperty.touchWildToHide = "0"
|
|
|
|
+ view.vProperty = vProperty
|
|
|
|
+ view.show()
|
|
|
|
+
|
|
|
|
+ view.cancelButton.rx.tap.subscribe(onNext: { (data) in
|
|
|
|
+ view.hide()
|
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RecordCloseMusicChooseViewNoti"), object: nil)
|
|
|
|
+
|
|
|
|
+ MusicPlayManager.shared().destroyPlayer()
|
|
|
|
+ MusicPlayManager.shared().curPlayingId = -1
|
|
|
|
+
|
|
|
|
+ }).disposed(by: view.disposeBag)
|
|
|
|
+
|
|
|
|
+ view.recommendButton.rx.tap.subscribe(onNext: { (data) in
|
|
|
|
+ Mediator.push(PublishRouterModuleType.push)
|
|
|
|
+
|
|
|
|
+ }).disposed(by: view.disposeBag)
|
|
|
|
+
|
|
|
|
+ return view
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: - JXSegmentedViewDelegate
|
|
|
|
+extension PublishRecordMusicView : JXSegmentedViewDelegate {
|
|
|
|
+ //点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,而不关心具体是点击还是滚动选中的情况。
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
|
|
|
|
+ //传递didClickSelectedItemAt事件给listContainerView,必须调用!!!
|
|
|
|
+ listContainerView.didClickSelectedItem(at: index)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 点击选中的情况才会调用该方法
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {
|
|
|
|
+ listContainerView.didClickSelectedItem(at: index)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 滚动选中的情况才会调用该方法
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 正在滚动中的回调
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {
|
|
|
|
+ //传递scrolling事件给listContainerView,必须调用!!!
|
|
|
|
+ listContainerView.segmentedViewScrolling(from: leftIndex, to: rightIndex, percent: percent, selectedIndex: segmentedView.selectedIndex)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// 是否允许点击选中目标index的item
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, canClickItemAt index: Int) -> Bool {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: - JXSegmentedListContainerViewDataSource
|
|
|
|
+extension PublishRecordMusicView :JXSegmentedListContainerViewDataSource {
|
|
|
|
+
|
|
|
|
+ func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
|
|
|
|
+ if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
|
|
|
|
+ return titleDataSource.dataSource.count
|
|
|
|
+ }
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+ func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
|
|
|
|
+ let listVc = PublishMusicListController()
|
|
|
|
+ if index == 0 {
|
|
|
|
+ listVc.isReccomendList = true
|
|
|
|
+ } else {
|
|
|
|
+ listVc.categoryItemMdl = categoryListMdlArr![index-1]
|
|
|
|
+ }
|
|
|
|
+ listVc.playMusicClosure = {
|
|
|
|
+ (musicUrl) in
|
|
|
|
+ MusicPlayManager.shared().initPlay()
|
|
|
|
+ MusicPlayManager.shared().audioUrl = musicUrl
|
|
|
|
+ MusicPlayManager.shared().playAudio()
|
|
|
|
+ }
|
|
|
|
+ listVc.chooseMusicClosure = {
|
|
|
|
+ [weak self] (musicUrl) in
|
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RecordDownloadMusicAndCombineNoti"), object: musicUrl)
|
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RecordCloseMusicChooseViewNoti"), object: nil)
|
|
|
|
+
|
|
|
|
+ MusicPlayManager.shared().destroyPlayer()
|
|
|
|
+ MusicPlayManager.shared().curPlayingId = -1
|
|
|
|
+ self?.hide()
|
|
|
|
+ }
|
|
|
|
+ return listVc
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: - 网络请求
|
|
|
|
+extension PublishRecordMusicView {
|
|
|
|
+ /// 获取音乐分类
|
|
|
|
+ func communityGetMusicCategoryApi() {
|
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityGetMusicCategoryApi() {
|
|
|
|
+ [weak self] (musicCategoryListModel) -> (Void) in
|
|
|
|
+ let musicCategoryListModel = musicCategoryListModel as? CommunityMusicCategoryListModel
|
|
|
|
+ self?.categoryListMdlArr = musicCategoryListModel?.data
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|