Sfoglia il codice sorgente

音乐列表 -- to be continued

Chris 5 anni fa
parent
commit
9f25546f1e

+ 4 - 4
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -647,8 +647,8 @@
 		BDD54A2822C31D60005BBE19 /* LocalFilter.json in Resources */ = {isa = PBXBuildFile; fileRef = BDD54A2322C31D5F005BBE19 /* LocalFilter.json */; };
 		BDD54A2922C31D60005BBE19 /* LocalMV.json in Resources */ = {isa = PBXBuildFile; fileRef = BDD54A2422C31D5F005BBE19 /* LocalMV.json */; };
 		BDD54A2B22C31D78005BBE19 /* filter in Resources */ = {isa = PBXBuildFile; fileRef = BDD54A2A22C31D78005BBE19 /* filter */; };
-		BDD9377322DEF2E8002D11B3 /* PublishMusicListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD9377222DEF2E8002D11B3 /* PublishMusicListView.swift */; };
 		BDD9377522DEF371002D11B3 /* PublishMusicListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD9377422DEF371002D11B3 /* PublishMusicListCell.swift */; };
+		BDD9377722DF3B47002D11B3 /* PublishMusicListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD9377622DF3B47002D11B3 /* PublishMusicListController.swift */; };
 		BDDF3B28228EBB72003A7D16 /* ProductRefundReasonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDF3B27228EBB72003A7D16 /* ProductRefundReasonModel.swift */; };
 		BDE3045D22851E4F001D050F /* ProductCartListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE3045C22851E4F001D050F /* ProductCartListModel.swift */; };
 		BDE3045F228554CA001D050F /* ProductCartAmountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE3045E228554CA001D050F /* ProductCartAmountModel.swift */; };
@@ -1431,8 +1431,8 @@
 		BDD54A2322C31D5F005BBE19 /* LocalFilter.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = LocalFilter.json; sourceTree = "<group>"; };
 		BDD54A2422C31D5F005BBE19 /* LocalMV.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = LocalMV.json; sourceTree = "<group>"; };
 		BDD54A2A22C31D78005BBE19 /* filter */ = {isa = PBXFileReference; lastKnownFileType = folder; path = filter; sourceTree = "<group>"; };
-		BDD9377222DEF2E8002D11B3 /* PublishMusicListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishMusicListView.swift; sourceTree = "<group>"; };
 		BDD9377422DEF371002D11B3 /* PublishMusicListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishMusicListCell.swift; sourceTree = "<group>"; };
+		BDD9377622DF3B47002D11B3 /* PublishMusicListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishMusicListController.swift; sourceTree = "<group>"; };
 		BDDF3B27228EBB72003A7D16 /* ProductRefundReasonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductRefundReasonModel.swift; sourceTree = "<group>"; };
 		BDE3045C22851E4F001D050F /* ProductCartListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCartListModel.swift; sourceTree = "<group>"; };
 		BDE3045E228554CA001D050F /* ProductCartAmountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCartAmountModel.swift; sourceTree = "<group>"; };
@@ -5092,7 +5092,7 @@
 			isa = PBXGroup;
 			children = (
 				BDBC0AF122DDD7E800CA788E /* PublishMusicChooseView.swift */,
-				BDD9377222DEF2E8002D11B3 /* PublishMusicListView.swift */,
+				BDD9377622DF3B47002D11B3 /* PublishMusicListController.swift */,
 				BDD9377422DEF371002D11B3 /* PublishMusicListCell.swift */,
 				BD5CA89122DD73A500364A67 /* PublishMusicVolumnView.swift */,
 				BDBC0AF522DDEA4E00CA788E /* PublishRecommendMusicController.swift */,
@@ -6200,7 +6200,6 @@
 				A7BF203122B47CC000396DB3 /* CardContentCommnetTableViewCell.swift in Sources */,
 				A7D07CDA22B7DFAE00186014 /* OtherPersonalCenterHeaderView.swift in Sources */,
 				A72A72AF22321DE000B21995 /* AppInfo.swift in Sources */,
-				BDD9377322DEF2E8002D11B3 /* PublishMusicListView.swift in Sources */,
 				BD6122D122C364E400D3F513 /* AliyunMusicPickTopView.m in Sources */,
 				A70B843422911AF600882BC5 /* ProductDetailView.swift in Sources */,
 				A72623D722C26A2A00AEF875 /* MessageListModel.swift in Sources */,
@@ -6492,6 +6491,7 @@
 				A72A72B522321DE000B21995 /* Extension+UITextView.swift in Sources */,
 				A770E61922D6780600CBD0A4 /* ShareCommunityVideoView.swift in Sources */,
 				A7DAB33922DC2B83005B964E /* ShareRouterModuleType.swift in Sources */,
+				BDD9377722DF3B47002D11B3 /* PublishMusicListController.swift in Sources */,
 				BD6122FD22C36B0F00D3F513 /* AlivcBaseViewController.m in Sources */,
 				BD0FAA6522C4C35E00DDFB37 /* AliyunCycleProgressView.m in Sources */,
 				A7AA9F6322C62B270086498B /* CommunityRecommnendViewController.swift in Sources */,

+ 178 - 22
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishMusicAbout/PublishMusicChooseView.swift

@@ -10,6 +10,7 @@ import UIKit
 import FWPopupView
 import RxSwift
 import SwiftyMediator
+import JXSegmentedView
 
 class PublishMusicChooseView: FWPopupView {
     
@@ -22,15 +23,51 @@ class PublishMusicChooseView: FWPopupView {
         super.init(frame: frame)
         setupViews()
         setupLayouts()
+        
+        // 获取分类列表
+        self.communityGetMusicCategoryApi()
     }
     
     required init?(coder aDecoder: NSCoder) {
         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() {
         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))
         
         addSubview(cancelButton)
@@ -55,7 +92,7 @@ class PublishMusicChooseView: FWPopupView {
         // 底部分割线
         sepLineView.snp.makeConstraints { (make) in
             make.left.right.equalToSuperview()
-            make.bottom.equalTo(-48-kSafeStatusBarHeight)
+            make.bottom.equalTo(-48-kSafeTabBarHeight)
             make.height.equalTo(0.5)
         }
         
@@ -73,13 +110,13 @@ class PublishMusicChooseView: FWPopupView {
         
         musicButton.snp.makeConstraints { (make) in
             make.centerX.equalTo(kScreenWidth*0.25)
-            make.bottom.equalTo(-17-kSafeStatusBarHeight)
+            make.bottom.equalTo(-17-kSafeTabBarHeight)
             make.width.equalTo(40)
             make.height.equalTo(21)
         }
         volumnButton.snp.makeConstraints { (make) in
             make.centerX.equalTo(kScreenWidth*0.75)
-            make.bottom.equalTo(-17-kSafeStatusBarHeight)
+            make.bottom.equalTo(-17-kSafeTabBarHeight)
             make.width.equalTo(40)
             make.height.equalTo(21)
         }
@@ -87,11 +124,40 @@ class PublishMusicChooseView: FWPopupView {
             make.centerX.equalTo(volumnButton.snp_centerX)
             make.width.equalTo(20)
             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 = {
         let cancelButton = UIButton(type: UIButton.ButtonType.custom)
         cancelButton.setImage(kImage(name: "video_btn_close_white"), for: .normal)
@@ -143,6 +209,62 @@ class PublishMusicChooseView: FWPopupView {
         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
     @objc class func publishMusicChooseView(attachedView:UIView) -> PublishMusicChooseView {
@@ -185,15 +307,26 @@ class PublishMusicChooseView: FWPopupView {
 
 // MARK: - 网络请求
 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) {
         SwiftMoyaNetWorkServiceCommunity.shared().communityRecMusicListApi(page: page) { (recommendMusicListModel) -> (Void) in
             let recommendMusicListModel = recommendMusicListModel as? CommunityRecommendMusicListModel
             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{
@@ -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) {
         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
+    }
+}
+

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishMusicAbout/PublishMusicListCell.swift

@@ -50,7 +50,7 @@ class PublishMusicListCell: UITableViewCell {
     //MRAK: - 设置View
     private func setupViews() {
         self.selectionStyle = .none
-        backgroundColor = kffffffColor
+        backgroundColor = UIColor.clear
         
         addSubview(iconImageView)
         addSubview(titleLabel)

+ 24 - 30
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishMusicAbout/PublishMusicListView.swift

@@ -1,5 +1,5 @@
 //
-//  PublishMusicListView.swift
+//  PublishMusicListController.swift
 //  RainbowPlanet
 //
 //  Created by Christopher on 2019/7/17.
@@ -7,8 +7,10 @@
 //
 
 import UIKit
+import RxSwift
+import JXSegmentedView
 
-class PublishMusicListView: BaseView {
+class PublishMusicListController: BaseViewController {
     
     var listViewDidScrollCallback: ((UIScrollView) -> ())?
     deinit {
@@ -20,28 +22,22 @@ class PublishMusicListView: BaseView {
             
         }
     }
-            
-    var musicItemMdlArr : Array<CommunityMusicItemModel>?
-    
-//    /// 获取首页数据
-//    func cmsTemplateSetPreviewApi() {
-//        SwiftMoyaNetWorkServiceCMS.shared().cmsTemplateSetPreviewApi(type: shoppingMallListVCType) {
-//            [weak self] (cmsModel) -> (Void) in
-//            let cmsModel = cmsModel as! CMSModel
-//            self?.cmsSectionModels = cmsModel.content
-//            self?.tableView.reloadData()
-//
-//        }
-//    }
     
+    var musicItemMdlArr : Array<CommunityMusicItemModel>?
     
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        setupViews()
+        setupLayouts()
+    }
     
     override func setupViews() {
-        addSubview(tableView)
+        view.addSubview(tableView)
         let emptyView = DIYEmptyView.empty(with: kImage(name: "default_page_data"), titleStr: nil, detailStr: "当前暂无数据")
         emptyView!.contentViewY = kScaleValue(value: 182)
         tableView.ly_emptyView = emptyView
         tableView.ly_startLoading()
+        
     }
     
     override func setupLayouts() {
@@ -53,7 +49,7 @@ class PublishMusicListView: BaseView {
     lazy var tableView: UITableView = {
         let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
         tableView.separatorStyle = .none
-        tableView.backgroundColor = UIColor.black
+        tableView.backgroundColor = kRGBColor(r: 255, g: 192, b: 203)
         tableView.dataSource = self
         tableView.delegate = self
         tableView.estimatedRowHeight = 0.000001
@@ -64,22 +60,22 @@ class PublishMusicListView: BaseView {
     
 }
 
-extension PublishMusicListView : UITableViewDelegate, UITableViewDataSource {
+extension PublishMusicListController : UITableViewDelegate, UITableViewDataSource {
     func numberOfSections(in tableView: UITableView) -> Int {
         return 1
     }
     
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-//        return cmsSectionModels?.isEmpty ?? true ? 0 : (cmsSectionModels?.count)!
+        //        return cmsSectionModels?.isEmpty ?? true ? 0 : (cmsSectionModels?.count)!
         return 5
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         
-//        let cmsSectionModel = cmsSectionModels?[indexPath.section]
+        //        let cmsSectionModel = cmsSectionModels?[indexPath.section]
         
         let cell = PublishMusicListCell.cellWith(tableView: tableView, indexPath: indexPath)
-//        cell.musicItemMdl =
+        //        cell.musicItemMdl =
         return cell
     }
     
@@ -108,16 +104,14 @@ extension PublishMusicListView : UITableViewDelegate, UITableViewDataSource {
     
 }
 
-extension PublishMusicListView: JXPagingViewListViewDelegate {
-    public func listView() -> UIView {
-        return self
+extension PublishMusicListController : JXSegmentedListContainerViewListDelegate {
+    func listView() -> UIView {
+        return view
     }
-    
-    public func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
-        self.listViewDidScrollCallback = callback
+    func listDidAppear() {
+        
     }
-    
-    public func listScrollView() -> UIScrollView {
-        return self.tableView
+    func listDidDisappear() {
+        
     }
 }

+ 2 - 3
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceCommunity/SwiftMoyaNetWorkServiceCommunity.swift

@@ -227,9 +227,8 @@ public class SwiftMoyaNetWorkServiceCommunity: NSObject {
     /// - Parameters:
     ///   - page: 分页
     ///   - completion: 回调
-    func communityGetMusicCategoryApi(page:Int = 1,completion: @escaping apiCallBack) {
-        var parameters = Dictionary<String,Any>()
-        parameters.updateValue(page, forKey: "page")
+    func communityGetMusicCategoryApi(completion: @escaping apiCallBack) {
+        let parameters = Dictionary<String,Any>()
         
         SwiftMoyaNetWorkManager.shared.requestObject(CommunityMusicCategoryListModel.self, target: MultiTarget(SwiftMoyaServiceCommunityApi.communityGetMusicCategory(parameters: parameters))) { (communityMusicCategoryListModel) in
             SwiftProgressHUD.shared().hide()