|
@@ -0,0 +1,262 @@
|
|
|
+//
|
|
|
+// PublishEditNewMusicView.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by 南鑫林 on 2019/10/24.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import JXSegmentedView
|
|
|
+
|
|
|
+class PublishEditNewMusicView: BaseView {
|
|
|
+
|
|
|
+ deinit {
|
|
|
+ NXLLog("deinit")
|
|
|
+ }
|
|
|
+
|
|
|
+ var index : Int = 0
|
|
|
+ var musicCategoryNames = Array<String>()
|
|
|
+ var musicCategorys : Array<MusicCategoryItemModel> = [] {
|
|
|
+ didSet {
|
|
|
+ guard !(musicCategorys.isEmpty) else { return }
|
|
|
+ for categoryMdl in musicCategorys {
|
|
|
+ musicCategoryNames.append(categoryMdl.name!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ typealias UserMusicClosure = () -> Void
|
|
|
+ var userMusicClosure : UserMusicClosure?
|
|
|
+
|
|
|
+ override func setupViews() {
|
|
|
+ configRectCorner(corner: [.topLeft,.topRight], radii: CGSize(width: 8, height: 8))
|
|
|
+ clipsToBounds = true
|
|
|
+ addSubview(vibrancyView)
|
|
|
+ addSubview(closeButton)
|
|
|
+ addSubview(noUseMusicButton)
|
|
|
+ addSubview(lineLabel)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupLayouts() {
|
|
|
+
|
|
|
+ vibrancyView.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.equalTo(kSafeTabBarHeight+48)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(kScreenHeight - kSafeStatusBarHeight)
|
|
|
+ }
|
|
|
+
|
|
|
+ closeButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(9)
|
|
|
+ make.left.equalTo(12)
|
|
|
+ make.size.equalTo(26)
|
|
|
+ }
|
|
|
+
|
|
|
+ noUseMusicButton.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalTo(closeButton)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ }
|
|
|
+
|
|
|
+ lineLabel.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.equalTo(-(kSafeTabBarHeight + 48))
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(0.5)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupData() {
|
|
|
+ /// 获取音乐分类
|
|
|
+ communityGetMusicCategoryApi()
|
|
|
+
|
|
|
+ recommendMusicLabel.addClickText("点击推荐", attributeds: [NSAttributedString.Key.font:kMediumFont14!,NSAttributedString.Key.foregroundColor:kffffffColor], transmitBody: nil) {
|
|
|
+ (data) in
|
|
|
+ let vc = PublishRecommendMusicNewController()
|
|
|
+ AliPlayerManager.shared.audioPlayer?.pause()
|
|
|
+ vc.backClosure = {
|
|
|
+ AliPlayerManager.shared.audioPlayer?.start()
|
|
|
+ }
|
|
|
+ UIViewController.topMost?.navigationController?.pushViewController(vc, animated: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 毛玻璃效果
|
|
|
+ lazy var vibrancyView: UIVisualEffectView = {
|
|
|
+ let vibrancyView = UIVisualEffectView(frame: self.frame)
|
|
|
+ vibrancyView.effect = UIBlurEffect(style: .dark)
|
|
|
+ return vibrancyView
|
|
|
+ }()
|
|
|
+
|
|
|
+ /// 关闭按钮
|
|
|
+ lazy var closeButton: UIButton = {
|
|
|
+ let closeButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ closeButton.setImage(kImage(name: "video_btn_close_white"), for: UIControl.State.normal)
|
|
|
+ return closeButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ //1.初始化JXSegmentedViewx
|
|
|
+ private lazy var segmentedView: JXSegmentedView = {
|
|
|
+ let segmentedView = JXSegmentedView()
|
|
|
+ segmentedView.backgroundColor = .clear
|
|
|
+ segmentedView.delegate = self
|
|
|
+ segmentedView.dataSource = segmentedDataSourceMusic
|
|
|
+ segmentedView.indicators = [indicator]
|
|
|
+ segmentedView.listContainer = listContainerView
|
|
|
+ segmentedView.contentEdgeInsetLeft = 14
|
|
|
+ segmentedView.contentEdgeInsetRight = 14
|
|
|
+ return segmentedView
|
|
|
+ }()
|
|
|
+
|
|
|
+ //2.初始化dataSource
|
|
|
+ private lazy var segmentedDataSourceMusic: JXSegmentedTitleDataSource = {
|
|
|
+ let segmentedDataSource = JXSegmentedTitleDataSource()
|
|
|
+ segmentedDataSource.isTitleColorGradientEnabled = true
|
|
|
+ segmentedDataSource.isItemSpacingAverageEnabled = false
|
|
|
+ segmentedDataSource.isTitleZoomEnabled = true
|
|
|
+ segmentedDataSource.titleNormalColor = k999999Color
|
|
|
+ segmentedDataSource.titleSelectedColor = kffffffColor
|
|
|
+ segmentedDataSource.titleNormalFont = kRegularFont14!
|
|
|
+ segmentedDataSource.titleSelectedFont = kBoldFont22
|
|
|
+ segmentedDataSource.isTitleStrokeWidthEnabled = true
|
|
|
+ //reloadData(selectedIndex:)方法一定要调用,方法内部会刷新数据源数组
|
|
|
+ segmentedDataSource.itemSpacing = 34
|
|
|
+ return segmentedDataSource
|
|
|
+ }()
|
|
|
+
|
|
|
+ //3.初始化指示器indicator
|
|
|
+ private lazy var indicator: JXSegmentedIndicatorLineView = {
|
|
|
+ let indicator = JXSegmentedIndicatorLineView()
|
|
|
+ indicator.indicatorColor = .white
|
|
|
+ indicator.indicatorHeight = 3
|
|
|
+ indicator.indicatorWidth = 20
|
|
|
+ return indicator
|
|
|
+ }()
|
|
|
+
|
|
|
+ //4.初始化JXSegmentedListContainerView
|
|
|
+ lazy var listContainerView: JXSegmentedListContainerView = {
|
|
|
+ let listContainerView = JXSegmentedListContainerView(dataSource: self)
|
|
|
+ return listContainerView
|
|
|
+ }()
|
|
|
+
|
|
|
+ /// 不使用音乐
|
|
|
+ lazy var noUseMusicButton: UIButton = {
|
|
|
+ let noUseMusicButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ noUseMusicButton.setTitle("不使用音乐", for: UIControl.State.normal)
|
|
|
+ noUseMusicButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
+ noUseMusicButton.titleLabel?.font = kRegularFont15
|
|
|
+ return noUseMusicButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 推荐音乐
|
|
|
+ private lazy var recommendMusicLabel: FMLinkLabel = {
|
|
|
+ let recommendMusicLabel = FMLinkLabel()
|
|
|
+ recommendMusicLabel.text = "没有找到想要的音乐?点击推荐"
|
|
|
+ recommendMusicLabel.numberOfLines = 0
|
|
|
+ recommendMusicLabel.textColor = k999999Color
|
|
|
+ recommendMusicLabel.font = kRegularFont14
|
|
|
+ return recommendMusicLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var lineLabel: UILabel = {
|
|
|
+ let lineLabel = UILabel()
|
|
|
+ lineLabel.backgroundColor = kffffffColor.withAlphaComponent(0.2)
|
|
|
+ return lineLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ /// 获取音乐分类
|
|
|
+ func communityGetMusicCategoryApi() {
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityGetMusicCategoryApi() {
|
|
|
+ [weak self] (musicCategoryListModel) -> (Void) in
|
|
|
+ guard let strongSelf = self else { return }
|
|
|
+ let musicCategoryListModel = musicCategoryListModel as? CommunityMusicCategoryListModel
|
|
|
+
|
|
|
+ guard !(musicCategoryListModel?.data?.isEmpty ?? true) else { return }
|
|
|
+
|
|
|
+ strongSelf.musicCategorys = (musicCategoryListModel?.data)!
|
|
|
+ strongSelf.segmentedDataSourceMusic.titles = strongSelf.musicCategoryNames
|
|
|
+ strongSelf.segmentedView.selectItemAt(index: strongSelf.index)
|
|
|
+ strongSelf.segmentedView.defaultSelectedIndex = strongSelf.index
|
|
|
+ strongSelf.segmentedDataSourceMusic.reloadData(selectedIndex: strongSelf.index)
|
|
|
+ strongSelf.segmentedView.reloadData()
|
|
|
+ strongSelf.listContainerView.defaultSelectedIndex = (self?.index)!
|
|
|
+ strongSelf.listContainerView.reloadData()
|
|
|
+
|
|
|
+ strongSelf.addSubview(strongSelf.recommendMusicLabel)
|
|
|
+ strongSelf.addSubview(strongSelf.segmentedView)
|
|
|
+ strongSelf.addSubview(strongSelf.listContainerView)
|
|
|
+ strongSelf.segmentedView.snp.makeConstraints { (make) in
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ make.top.equalTo(48)
|
|
|
+ make.height.equalTo(44)
|
|
|
+ }
|
|
|
+ strongSelf.recommendMusicLabel.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.equalTo(strongSelf.lineLabel.snp.top).offset(-15)
|
|
|
+ make.height.equalTo(20)
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ strongSelf.listContainerView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(strongSelf.segmentedView.snp.bottom)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ make.bottom.equalTo(strongSelf.recommendMusicLabel.snp.top).offset(-20)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension PublishEditNewMusicView : JXSegmentedViewDelegate {
|
|
|
+
|
|
|
+ //点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,而不关心具体是点击还是滚动选中的情况。
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
|
|
|
+ listContainerView.didClickSelectedItem(at: index)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 点击选中的情况才会调用该方法
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {
|
|
|
+ //传递didClickSelectedItemAt事件给listContainerView,必须调用!!!
|
|
|
+ }
|
|
|
+
|
|
|
+ // 滚动选中的情况才会调用该方法(未支持滚动选中)
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 正在滚动中的回调
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {
|
|
|
+ self.segmentedView.backgroundColor = .clear
|
|
|
+ //传递scrolling事件给listContainerView,必须调用!!!
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 是否允许点击选中目标index的item
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, canClickItemAt index: Int) -> Bool {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension PublishEditNewMusicView : 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 musicListView = PublishNewMusicListView()
|
|
|
+ musicListView.categoryId = musicCategorys[index].id ?? 0
|
|
|
+ musicListView.index = index
|
|
|
+ musicListView.userMusicClosure = {
|
|
|
+ [weak self] in
|
|
|
+ if let userMusicClosure = self?.userMusicClosure {
|
|
|
+ userMusicClosure()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return musicListView
|
|
|
+ }
|
|
|
+}
|
|
|
+
|