Music_Player3/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultsShowView.swift
2024-07-25 19:44:30 +08:00

217 lines
8.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MPPositive_SearchResultsShowView.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/5/13.
//
import UIKit
class MPPositive_SearchResultsShowView: UIView {
///
var loadModel:MPPositive_SearchResultsLoadViewModel!{
didSet{
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
if loadModel == nil {
emptyImageView.isHidden = false
}else {
if isShowAd == true {
MP_AdMobManager.shared.showSearchInterstitialAdIfAvailable { [weak self] ad in
guard let self = self else {return}
//
if loadModel?.sectionLists?.count != nil {
//
MP_AdMobManager.shared.setInterstitialSwitch(false)
}else {
MP_AdMobManager.shared.isShowingSearchInterstitialAd = true
//
MP_AdMobManager.shared.setInterstitialSwitch(true)
ad.present(fromRootViewController: nil)
}
}
}
//
MP_AnalyticsManager.shared.search_result_pvAction()
loadModel.resultReloadBlock = {
[weak self] in
//
guard let self = self else {return}
MP_HUD.hideNow()
isHidden = false
MP_AnalyticsManager.shared.search_resultsuccess_actionAction()
if let loadModel = loadModel, let titles = loadModel.sectionLists?.compactMap({$0.title ?? ""}) {
dataSource.titles = titles
dataSource.reloadData(selectedIndex: 0)
segmentView.reloadData()
segmentView.selectItemAt(index: 0)
emptyImageView.isHidden = !(titles.count == 0)
}
}
}
}
}
}
///广View
fileprivate lazy var adContainerView:UIView = {
let adContainerView:UIView = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: 300*width))
adContainerView.backgroundColor = .clear
return adContainerView
}()
//MARK: -
//View
lazy var segmentView:JXSegmentedView = {
var jxSegmentView = JXSegmentedView()
jxSegmentView.backgroundColor = .init(hex: "1A1A1A")
return jxSegmentView
}()
//
private lazy var dataSource:JXSegmentedTitleDataSource = {
var dataSource = JXSegmentedTitleDataSource()
dataSource.titles = []
//
dataSource.titleNormalColor = .init(hex: "#666666")
dataSource.titleNormalFont = .systemFont(ofSize: 16*width, weight: .regular)
//
dataSource.titleSelectedColor = .init(hex: "#80F988")
dataSource.titleSelectedFont = .systemFont(ofSize: 16*width, weight: .bold)
//
dataSource.isTitleColorGradientEnabled = true
dataSource.isSelectedAnimable = true
dataSource.isItemTransitionEnabled = true
return dataSource
}()
//
private lazy var indicator:JXSegmentedIndicatorLineView = {
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = 16*width
indicator.indicatorHeight = 3*width
indicator.indicatorCornerRadius = 1.5*width
indicator.indicatorColor = .init(hex: "#80F988")
indicator.indicatorPosition = .bottom
return indicator
}()
//
fileprivate lazy var listContainerView:JXSegmentedListContainerView = {
let listContainerView = JXSegmentedListContainerView(dataSource: self)
listContainerView.backgroundColor = .clear
return listContainerView
}()
//
lazy var emptyImageView:UIImageView = {
let imageView = UIImageView(image: UIImage(named: "empty"))
imageView.contentMode = .scaleAspectFill
return imageView
}()
var scrollBlock:(() -> Void)?
//广
private var isShowAd:Bool = true
init(frame: CGRect, isShowAd:Bool = true) {
super.init(frame: frame)
self.isShowAd = isShowAd
backgroundColor = .init(hex: "1A1A1A")
configure()
MP_AdMobManager.shared.onSearchNativeAdBlock = {
[weak adContainerView] in
guard let adContainerView = adContainerView else {return}
//广
MP_AdMobManager.shared.layoutSearchNativeAd(in: adContainerView)
}
//广
MP_AdMobManager.shared.layoutSearchNativeAd(in: adContainerView)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
//
private func configure() {
addSubview(emptyImageView)
emptyImageView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.equalTo(211*width)
make.height.equalTo(172*width)
}
addSubview(adContainerView)
adContainerView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.height.equalTo(0)
}
segmentView.indicators = [indicator]
segmentView.dataSource = dataSource
//View
addSubview(segmentView)
segmentView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(adContainerView.snp.bottom)
make.height.equalTo(60*width)
}
addSubview(listContainerView)
listContainerView.snp.makeConstraints { (make) in
make.left.right.bottom.equalToSuperview().priority(999)
make.top.equalTo(segmentView.snp.bottom).priority(999)
}
segmentView.contentScrollView = listContainerView.scrollView
segmentView.listContainer = listContainerView
}
}
//MARK: - JXSegmentedTitleDataSource
extension MPPositive_SearchResultsShowView: JXSegmentedListContainerViewDataSource, JXSegmentedViewDelegate {
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
return dataSource.titles.count
}
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
if index == 0 {
//
let showView:MPPositive_SearchResultPreviewShowView = .init(frame: listContainerView.frame, sectionLists: loadModel.sectionLists)
showView.scrollBlock = {
[weak self] in
guard let self = self else {return}
if let block = scrollBlock {
block()
}
}
showView.chooseMoreIndexBlock = {
[weak self] (selectedIndex) in
guard let self = self else {
return
}
if selectedIndex <= (dataSource.titles.count-1) {
//
DispatchQueue.main.async {
self.segmentView.selectItemAt(index: selectedIndex)
}
}else {
//
print("当前越界")
}
}
return showView
}else {
//
if let sectionList = loadModel?.sectionLists?[index] {
let showView:MPPositive_SearchResultTypeShowView = .init(frame: listContainerView.frame, list: sectionList)
showView.scrollBlock = {
[weak self] in
guard let self = self else {return}
if let block = scrollBlock {
block()
}
}
return showView
}else {
let showView:MPPositive_SearchResultTypeShowView = .init(frame: listContainerView.frame, list: nil)
showView.scrollBlock = {
[weak self] in
guard let self = self else {return}
if let block = scrollBlock {
block()
}
}
return showView
}
}
}
}