|
@@ -10,6 +10,7 @@ import UIKit
|
|
import FWPopupView
|
|
import FWPopupView
|
|
import RxSwift
|
|
import RxSwift
|
|
import SwiftyMediator
|
|
import SwiftyMediator
|
|
|
|
+import JXSegmentedView
|
|
|
|
|
|
class PublishMusicChooseView: FWPopupView {
|
|
class PublishMusicChooseView: FWPopupView {
|
|
|
|
|
|
@@ -22,15 +23,51 @@ class PublishMusicChooseView: FWPopupView {
|
|
super.init(frame: frame)
|
|
super.init(frame: frame)
|
|
setupViews()
|
|
setupViews()
|
|
setupLayouts()
|
|
setupLayouts()
|
|
|
|
+
|
|
|
|
+ // 获取分类列表
|
|
|
|
+ self.communityGetMusicCategoryApi()
|
|
}
|
|
}
|
|
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ var JXheightForHeaderInSection: Int = 44
|
|
|
|
+ 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!)
|
|
|
|
+ }
|
|
|
|
+ addHeader()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ addHeader()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// 添加View
|
|
|
|
+ func addHeader() {
|
|
|
|
+ setupSegmentedView()
|
|
|
|
+ isShowEmpty()
|
|
|
|
+ }
|
|
|
|
+
|
|
func setupViews() {
|
|
func setupViews() {
|
|
frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight - kSafeTabBarHeight - kSafeStatusBarHeight - 22)
|
|
frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight - kSafeTabBarHeight - kSafeStatusBarHeight - 22)
|
|
- backgroundColor = UIColor(hexString: "000000", alpha: 0.5)
|
|
|
|
|
|
+
|
|
|
|
+ // 添加毛玻璃效果,需使用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))
|
|
configRectCorner(corner: [.topLeft,.topRight], radii: CGSize(width: 8, height: 8))
|
|
|
|
|
|
addSubview(cancelButton)
|
|
addSubview(cancelButton)
|
|
@@ -55,7 +92,7 @@ class PublishMusicChooseView: FWPopupView {
|
|
// 底部分割线
|
|
// 底部分割线
|
|
sepLineView.snp.makeConstraints { (make) in
|
|
sepLineView.snp.makeConstraints { (make) in
|
|
make.left.right.equalToSuperview()
|
|
make.left.right.equalToSuperview()
|
|
- make.bottom.equalTo(-48-kSafeStatusBarHeight)
|
|
|
|
|
|
+ make.bottom.equalTo(-48-kSafeTabBarHeight)
|
|
make.height.equalTo(0.5)
|
|
make.height.equalTo(0.5)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -73,13 +110,13 @@ class PublishMusicChooseView: FWPopupView {
|
|
|
|
|
|
musicButton.snp.makeConstraints { (make) in
|
|
musicButton.snp.makeConstraints { (make) in
|
|
make.centerX.equalTo(kScreenWidth*0.25)
|
|
make.centerX.equalTo(kScreenWidth*0.25)
|
|
- make.bottom.equalTo(-17-kSafeStatusBarHeight)
|
|
|
|
|
|
+ make.bottom.equalTo(-17-kSafeTabBarHeight)
|
|
make.width.equalTo(40)
|
|
make.width.equalTo(40)
|
|
make.height.equalTo(21)
|
|
make.height.equalTo(21)
|
|
}
|
|
}
|
|
volumnButton.snp.makeConstraints { (make) in
|
|
volumnButton.snp.makeConstraints { (make) in
|
|
make.centerX.equalTo(kScreenWidth*0.75)
|
|
make.centerX.equalTo(kScreenWidth*0.75)
|
|
- make.bottom.equalTo(-17-kSafeStatusBarHeight)
|
|
|
|
|
|
+ make.bottom.equalTo(-17-kSafeTabBarHeight)
|
|
make.width.equalTo(40)
|
|
make.width.equalTo(40)
|
|
make.height.equalTo(21)
|
|
make.height.equalTo(21)
|
|
}
|
|
}
|
|
@@ -87,11 +124,40 @@ class PublishMusicChooseView: FWPopupView {
|
|
make.centerX.equalTo(volumnButton.snp_centerX)
|
|
make.centerX.equalTo(volumnButton.snp_centerX)
|
|
make.width.equalTo(20)
|
|
make.width.equalTo(20)
|
|
make.height.equalTo(3)
|
|
make.height.equalTo(3)
|
|
- make.bottom.equalTo(-11-kSafeStatusBarHeight)
|
|
|
|
|
|
+ make.bottom.equalTo(-11-kSafeTabBarHeight)
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func setupSegmentedView() {
|
|
|
|
+ addSubview(listContainerView)
|
|
|
|
+ addSubview(segmentedView)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// 缺省页面
|
|
|
|
+ private func isShowEmpty() {
|
|
|
|
+ segmentedView.contentScrollView!.ly_emptyView = emptyView
|
|
|
|
+ if categoryTitleArr.isEmpty {
|
|
|
|
+ segmentedView.contentScrollView!.ly_showEmpty()
|
|
|
|
+ }else {
|
|
|
|
+ segmentedView.contentScrollView!.ly_hideEmpty()
|
|
|
|
+ self.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// 刷新页面
|
|
|
|
+ func reloadData() {
|
|
|
|
+ segmentedDataSource.titles = categoryTitleArr
|
|
|
|
+ segmentedView.indicators = [indicator]
|
|
|
|
+ JXheightForHeaderInSection = 44
|
|
|
|
+
|
|
|
|
+ // self.segmentedDataSource.reloadData(selectedIndex: shoppingMallListVCType)
|
|
|
|
+ // self.segmentedView.defaultSelectedIndex = shoppingMallListVCType
|
|
|
|
+ self.segmentedView.reloadData()
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // MARK: - 视图创建
|
|
lazy var cancelButton: UIButton = {
|
|
lazy var cancelButton: UIButton = {
|
|
let cancelButton = UIButton(type: UIButton.ButtonType.custom)
|
|
let cancelButton = UIButton(type: UIButton.ButtonType.custom)
|
|
cancelButton.setImage(kImage(name: "video_btn_close_white"), for: .normal)
|
|
cancelButton.setImage(kImage(name: "video_btn_close_white"), for: .normal)
|
|
@@ -143,6 +209,62 @@ class PublishMusicChooseView: FWPopupView {
|
|
return v_lineLabel
|
|
return v_lineLabel
|
|
}()
|
|
}()
|
|
|
|
|
|
|
|
+ //MARK: -
|
|
|
|
+ //1.初始化JXSegmentedView
|
|
|
|
+ lazy var segmentedView: JXSegmentedView = {
|
|
|
|
+ let segmentedView = JXSegmentedView(frame: CGRect(x: 0, y: 48, width: kScreenWidth, height: CGFloat(JXheightForHeaderInSection)))
|
|
|
|
+ segmentedView.delegate = self
|
|
|
|
+ segmentedView.dataSource = segmentedDataSource
|
|
|
|
+ segmentedView.indicators = [indicator]
|
|
|
|
+ segmentedView.contentScrollView = listContainerView.scrollView
|
|
|
|
+ segmentedView.selectItemAt(index: 0)
|
|
|
|
+ segmentedView.defaultSelectedIndex = 0
|
|
|
|
+ segmentedView.backgroundColor = UIColor.yellow
|
|
|
|
+ return segmentedView
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ //2.初始化dataSource
|
|
|
|
+ lazy var segmentedDataSource: JXSegmentedTitleDataSource = {
|
|
|
|
+ let segmentedDataSource = JXSegmentedTitleDataSource()
|
|
|
|
+ segmentedDataSource.isTitleColorGradientEnabled = true
|
|
|
|
+ segmentedDataSource.isItemSpacingAverageEnabled = true
|
|
|
|
+ segmentedDataSource.titleNormalColor = kffffffColor
|
|
|
|
+ segmentedDataSource.titleSelectedColor = kbbbbbbColor
|
|
|
|
+ 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 = kFFA42FColor
|
|
|
|
+ indicator.indicatorHeight = 4
|
|
|
|
+ indicator.indicatorWidth = 34
|
|
|
|
+ return indicator
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ //4.初始化JXSegmentedListContainerView
|
|
|
|
+ private lazy var listContainerView: JXSegmentedListContainerView = {
|
|
|
|
+ let listContainerView = JXSegmentedListContainerView(dataSource: self)
|
|
|
|
+ listContainerView.didAppearPercent = 0.01
|
|
|
|
+ listContainerView.defaultSelectedIndex = 0
|
|
|
|
+ listContainerView.scrollView.isScrollEnabled = false
|
|
|
|
+ listContainerView.frame = CGRect(x: 0, y: 48+44, width: kScreenWidth, height: kScreenHeight - kSafeTabBarHeight - kSafeStatusBarHeight - 103 - 114)
|
|
|
|
+ return listContainerView
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /// 7.加载空白图
|
|
|
|
+ lazy var emptyView: LYEmptyView = {
|
|
|
|
+ let emptyView = DIYEmptyView.empty(with: kImage(name: "default_page_data"), titleStr: nil, detailStr: "当前暂无数据,请下拉刷新")
|
|
|
|
+ emptyView!.contentViewY = kScaleValue(value: 182)
|
|
|
|
+ return emptyView!
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
|
|
/// 初始化View
|
|
/// 初始化View
|
|
@objc class func publishMusicChooseView(attachedView:UIView) -> PublishMusicChooseView {
|
|
@objc class func publishMusicChooseView(attachedView:UIView) -> PublishMusicChooseView {
|
|
@@ -185,15 +307,26 @@ class PublishMusicChooseView: FWPopupView {
|
|
|
|
|
|
// MARK: - 网络请求
|
|
// MARK: - 网络请求
|
|
extension PublishMusicChooseView {
|
|
extension PublishMusicChooseView {
|
|
|
|
+ /// 获取音乐分类
|
|
|
|
+ func communityGetMusicCategoryApi() {
|
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityGetMusicCategoryApi() {
|
|
|
|
+ [weak self] (musicCategoryListModel) -> (Void) in
|
|
|
|
+ let musicCategoryListModel = musicCategoryListModel as? CommunityMusicCategoryListModel
|
|
|
|
+ self?.categoryListMdlArr = musicCategoryListModel?.data
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/// 热门推荐音乐列表
|
|
/// 热门推荐音乐列表
|
|
func communityRecMusicListApi(page:Int) {
|
|
func communityRecMusicListApi(page:Int) {
|
|
SwiftMoyaNetWorkServiceCommunity.shared().communityRecMusicListApi(page: page) { (recommendMusicListModel) -> (Void) in
|
|
SwiftMoyaNetWorkServiceCommunity.shared().communityRecMusicListApi(page: page) { (recommendMusicListModel) -> (Void) in
|
|
let recommendMusicListModel = recommendMusicListModel as? CommunityRecommendMusicListModel
|
|
let recommendMusicListModel = recommendMusicListModel as? CommunityRecommendMusicListModel
|
|
if recommendMusicListModel?.pagination?.currentPage ?? 1 <= recommendMusicListModel?.pagination?.totalPages ?? 1 {
|
|
if recommendMusicListModel?.pagination?.currentPage ?? 1 <= recommendMusicListModel?.pagination?.totalPages ?? 1 {
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
+ print("----endWithNoMoreData")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
// if communityRecommendFeedModel?.pagination?.currentPage ?? 1 <= communityRecommendFeedModel?.pagination?.totalPages ?? 1 {
|
|
// if communityRecommendFeedModel?.pagination?.currentPage ?? 1 <= communityRecommendFeedModel?.pagination?.totalPages ?? 1 {
|
|
// if communityRecommendFeedModel?.pagination?.currentPage == 1{
|
|
// if communityRecommendFeedModel?.pagination?.currentPage == 1{
|
|
@@ -211,21 +344,6 @@ extension PublishMusicChooseView {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- /// 获取音乐分类
|
|
|
|
- func communityGetMusicCategoryApi(page:Int) {
|
|
|
|
- SwiftMoyaNetWorkServiceCommunity.shared().communityGetMusicCategoryApi(page: page) { (musicCategoryListModel) -> (Void) in
|
|
|
|
- let musicCategoryListModel = musicCategoryListModel as? CommunityMusicCategoryListModel
|
|
|
|
- if musicCategoryListModel?.pagination?.currentPage ?? 1 <= musicCategoryListModel?.pagination?.totalPages ?? 1 {
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- self.communityCateMusicListApi(page: 1, categoryId: 1)
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// 获取分类下所有音乐
|
|
/// 获取分类下所有音乐
|
|
func communityCateMusicListApi(page:Int, categoryId:Int) {
|
|
func communityCateMusicListApi(page:Int, categoryId:Int) {
|
|
SwiftMoyaNetWorkServiceCommunity.shared().communityCateMusicListApi(categoryID: categoryId, page: page) { (categoryMusicListModel) -> (Void) in
|
|
SwiftMoyaNetWorkServiceCommunity.shared().communityCateMusicListApi(categoryID: categoryId, page: page) { (categoryMusicListModel) -> (Void) in
|
|
@@ -240,3 +358,41 @@ extension PublishMusicChooseView {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// MARK: - JXSegmentedViewDelegate
|
|
|
|
+extension PublishMusicChooseView : JXSegmentedViewDelegate {
|
|
|
|
+ //点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,而不关心具体是点击还是滚动选中的情况。
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
|
|
|
|
+// self.shoppingMallListVCType = index
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 点击选中的情况才会调用该方法
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 滚动选中的情况才会调用该方法
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 正在滚动中的回调
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// 是否允许点击选中目标index的item
|
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, canClickItemAt index: Int) -> Bool {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: - JXSegmentedListContainerViewDataSource
|
|
|
|
+extension PublishMusicChooseView :JXSegmentedListContainerViewDataSource {
|
|
|
|
+
|
|
|
|
+ func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
|
|
|
|
+ return categoryTitleArr.count
|
|
|
|
+ }
|
|
|
|
+ func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
|
|
|
|
+ let listVc = PublishMusicListController()
|
|
|
|
+
|
|
|
|
+ return listVc
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|