diff --git a/MoviaBox/Base/Extension/UIView+SPAdd.swift b/MoviaBox/Base/Extension/UIView+SPAdd.swift index bb6ce03..02bc159 100644 --- a/MoviaBox/Base/Extension/UIView+SPAdd.swift +++ b/MoviaBox/Base/Extension/UIView+SPAdd.swift @@ -109,3 +109,30 @@ extension UIView { } } + +//MARK: -------------- 添加点击事件 -------------- +extension UIView { + + private var sp_tapGestureBlock: ((_ view: UIView) -> Void)? { + get { + return objc_getAssociatedObject(self,&AssociatedKeys.sp_tapGesture) as? ((_ view: UIView) -> Void) + } + set { + objc_setAssociatedObject(self,&AssociatedKeys.sp_tapGesture, newValue, .OBJC_ASSOCIATION_COPY) + } + } + + func sp_addTapGestureRecognizer(_ block: ((_ view: UIView) -> Void)?) { + if sp_tapGestureBlock == nil { + let tap = UITapGestureRecognizer(target: self, action: #selector(handleTapGestureRecognizer(tap:))) + self.addGestureRecognizer(tap) + } + self.sp_tapGestureBlock = block + } + + @objc private func handleTapGestureRecognizer(tap: UITapGestureRecognizer) { + if tap.state == .recognized { + self.sp_tapGestureBlock?(self) + } + } +} diff --git a/MoviaBox/Class/Login/Controller/SPLoginViewController.swift b/MoviaBox/Class/Login/Controller/SPLoginViewController.swift index 1b99bac..9174ca6 100644 --- a/MoviaBox/Class/Login/Controller/SPLoginViewController.swift +++ b/MoviaBox/Class/Login/Controller/SPLoginViewController.swift @@ -24,7 +24,7 @@ class SPLoginViewController: SPViewController { private lazy var stackView: UIStackView = { let stackView = UIStackView(arrangedSubviews: [faceBookButton, appleButton]) stackView.axis = .vertical - stackView.spacing = 18 + stackView.spacing = 20 return stackView }() @@ -146,6 +146,7 @@ extension SPLoginViewController { logoImageView.snp.makeConstraints { make in make.centerX.equalToSuperview() make.top.equalToSuperview().offset(kSPStatusbarHeight + kSPMainW(120)) + make.width.height.equalTo(120) } // nameImageView.snp.makeConstraints { make in @@ -156,7 +157,7 @@ extension SPLoginViewController { stackView.snp.makeConstraints { make in make.left.equalToSuperview().offset(37) make.centerX.equalToSuperview() - make.top.equalTo(logoImageView.snp.bottom).offset(40) + make.top.equalTo(logoImageView.snp.bottom).offset(80) } let size = agreementLabel.textLayout?.textBoundingSize ?? .zero diff --git a/MoviaBox/Class/Mine/Controller/SPMineViewController.swift b/MoviaBox/Class/Mine/Controller/SPMineViewController.swift index 1941e12..15336ab 100644 --- a/MoviaBox/Class/Mine/Controller/SPMineViewController.swift +++ b/MoviaBox/Class/Mine/Controller/SPMineViewController.swift @@ -152,7 +152,7 @@ extension SPMineViewController { } ///获取播放记录 private func requestPlayHistoryList() { - SPVideoAPI.requestPlayHistoryList(page: 1, pageSize: 3) { [weak self] listModel in + SPVideoAPI.requestPlayHistoryList(page: 1, pageSize: 10) { [weak self] listModel in guard let self = self else { return } if let list = listModel?.list { self.headerView.playHistoryArr = list diff --git a/MoviaBox/Class/Mine/View/SPAboutUsHeaderView.swift b/MoviaBox/Class/Mine/View/SPAboutUsHeaderView.swift index d148884..186a020 100644 --- a/MoviaBox/Class/Mine/View/SPAboutUsHeaderView.swift +++ b/MoviaBox/Class/Mine/View/SPAboutUsHeaderView.swift @@ -15,6 +15,11 @@ class SPAboutUsHeaderView: UIView { imageView.layer.cornerRadius = 8 imageView.layer.masksToBounds = true imageView.backgroundColor = .red + imageView.isUserInteractionEnabled = true + imageView.sp_addTapGestureRecognizer { _ in + guard let url = URL(string: SPWebBaseURL) else { return } + UIApplication.shared.open(url) + } return imageView }() diff --git a/MoviaBox/Class/Mine/View/SPMinePlayHistoryView.swift b/MoviaBox/Class/Mine/View/SPMinePlayHistoryView.swift index 6cebff6..9ebad3b 100644 --- a/MoviaBox/Class/Mine/View/SPMinePlayHistoryView.swift +++ b/MoviaBox/Class/Mine/View/SPMinePlayHistoryView.swift @@ -53,6 +53,7 @@ class SPMinePlayHistoryView: UIView { layout.minimumLineSpacing = 8 layout.minimumInteritemSpacing = 8 layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16) + layout.scrollDirection = .horizontal return layout }() @@ -60,7 +61,7 @@ class SPMinePlayHistoryView: UIView { let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout) collectionView.delegate = self collectionView.dataSource = self - collectionView.isScrollEnabled = false + collectionView.showsHorizontalScrollIndicator = false SPMinePlayHistoryCell.registerCell(collectionView: collectionView) return collectionView }() diff --git a/MoviaBox/Class/Mine/View/SPMineWalletView.swift b/MoviaBox/Class/Mine/View/SPMineWalletView.swift index 1ea1107..667af43 100644 --- a/MoviaBox/Class/Mine/View/SPMineWalletView.swift +++ b/MoviaBox/Class/Mine/View/SPMineWalletView.swift @@ -10,7 +10,11 @@ import UIKit class SPMineWalletView: UIView { override var intrinsicContentSize: CGSize { - return .init(width: kSPScreenWidth, height: 119) + if isShowMore { + return .init(width: kSPScreenWidth, height: 119) + } else { + return .init(width: kSPScreenWidth, height: 82) + } } var userInfo: SPUserInfo? { @@ -20,6 +24,16 @@ class SPMineWalletView: UIView { } } + ///是否展示更多按钮 + var isShowMore: Bool = true { + didSet { + moreButton.isHidden = !isShowMore + lineView.isHidden = !isShowMore + + invalidateIntrinsicContentSize() + } + } + //MARK: UI属性 private lazy var bgView: UIView = { let view = UIView() diff --git a/MoviaBox/Class/Player/Controller/SPPlayerDetailViewController.swift b/MoviaBox/Class/Player/Controller/SPPlayerDetailViewController.swift index 6aa1c4f..4aabe8b 100644 --- a/MoviaBox/Class/Player/Controller/SPPlayerDetailViewController.swift +++ b/MoviaBox/Class/Player/Controller/SPPlayerDetailViewController.swift @@ -85,7 +85,12 @@ class SPPlayerDetailViewController: SPPlayerListViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.navigationController?.setNavigationBarHidden(true, animated: true) + } + + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + self.uploadPlayTime() } override func play() { @@ -110,28 +115,27 @@ class SPPlayerDetailViewController: SPPlayerListViewController { } override func currentPlayFinish() { - if let videoInfo = self.viewModel.currentPlayer?.videoInfo, let activityId = self.activityId { + if let videoInfo = self.viewModel.currentPlayer?.videoInfo, let activityId = self.activityId, let shortPlayId = videoInfo.short_play_id, let videoId = videoInfo.short_play_video_id { //播放完成统计 - SPVideoAPI.requestViewingFinish(shortPlayId: videoInfo.short_play_id ?? "", videoId: videoInfo.short_play_video_id ?? "", activityId: activityId) + SPVideoAPI.requestViewingFinish(shortPlayId: shortPlayId, videoId: videoId, activityId: activityId) + //播放完成上报进度为0 + SPVideoAPI.requestUploadPlayTime(shortPlayId: shortPlayId, videoId: videoId, seconds: 0) } super.currentPlayFinish() } override func currentPlayTimeDidChange(time: Int) { super.currentPlayTimeDidChange(time: time) - let videoInfo = self.viewModel.currentPlayer?.videoInfo //每播放5秒上报一次 播放时长小于上次上报时间也需要上报 - if (time >= lastUploadTime + 5 || time < lastUploadTime) && time >= 5 { - lastUploadTime = time - - guard let shortPlayId = videoInfo?.short_play_id, let videoId = videoInfo?.short_play_video_id else { return } - //上报播放时长 - SPVideoAPI.requestUploadPlayTime(shortPlayId: shortPlayId, videoId: videoId, seconds: time) - } - +// if (time >= lastUploadTime + 5 || time < lastUploadTime) && time >= 5 { +// lastUploadTime = time +// +// uploadPlayTime() +// } } + } @@ -237,6 +241,23 @@ extension SPPlayerDetailViewController { } } + ///上报播放进度 + private func uploadPlayTime() { + let videoInfo = self.viewModel.currentPlayer?.videoInfo + let currentTime = self.viewModel.currentPlayer?.currentPosition ?? 0 + let duration = self.viewModel.currentPlayer?.duration ?? 0 + + var time = currentTime + if currentTime >= duration { + time = 0 + } + + guard let shortPlayId = videoInfo?.short_play_id, let videoId = videoInfo?.short_play_video_id else { return } + //上报播放时长 + SPVideoAPI.requestUploadPlayTime(shortPlayId: shortPlayId, videoId: videoId, seconds: time * 1000) + + } + @objc private func buyVipFinishNotification() { guard SPLoginManager.manager.userInfo?.is_vip == true else { return } @@ -254,6 +275,7 @@ extension SPPlayerDetailViewController { self.requestDetailData() } } + } //MARK: -------------- SPPlayerListViewControllerDataSource -------------- @@ -289,12 +311,20 @@ extension SPPlayerDetailViewController: SPPlayerListViewControllerDataSource, SP self.episodeView?.currentIndex = indexPath.row let videoInfo = detailModel?.episodeList?[indexPath.row] -// titleLabel.text = String(format: "kPlayerDetailTitleString".localized, "\(videoInfo?.episode ?? "0")", self.detailModel?.shortPlayInfo?.name ?? "") titleLabel.text = detailModel?.shortPlayInfo?.name episodeLabel.text = "\(videoInfo?.episode ?? "0")/\(detailModel?.shortPlayInfo?.episode_total ?? 0)" } } +//MARK: -------------- APP生命周期 -------------- +extension SPPlayerDetailViewController { + + @objc override func willResignActiveNotification() { + super.willResignActiveNotification() + uploadPlayTime() + } +} + extension SPPlayerDetailViewController { @@ -316,7 +346,11 @@ extension SPPlayerDetailViewController { } }) if let row = row { - self.scrollToItem(indexPath: IndexPath(row: row, section: 0), animated: false) + self.scrollToItem(indexPath: IndexPath(row: row, section: 0), animated: false) { [weak self] in + guard let self = self else { return } + //跳转到指定进度 + self.viewModel.currentPlayer?.seekToTime(toTime: (videoInfo.play_seconds ?? 0) / 1000) + } } else { self.play() } @@ -324,23 +358,6 @@ extension SPPlayerDetailViewController { } else { self.play() } - - /* - if let playHistoryModel = self.playHistoryModel { - var row: Int? - self.detailModel?.episodeList?.enumerated().forEach({ - if $1.episode == playHistoryModel.current_episode { - row = $0 - } - }) - if let row = row { - self.scrollToItem(indexPath: IndexPath(row: row, section: 0), animated: false) - } - self.playHistoryModel = nil - } else { - self.play() - } - */ } } diff --git a/MoviaBox/Class/Player/Controller/SPPlayerListViewController.swift b/MoviaBox/Class/Player/Controller/SPPlayerListViewController.swift index 3e2ebf0..2d37fde 100644 --- a/MoviaBox/Class/Player/Controller/SPPlayerListViewController.swift +++ b/MoviaBox/Class/Player/Controller/SPPlayerListViewController.swift @@ -202,7 +202,7 @@ class SPPlayerListViewController: SPViewController { return self.collectionView(self.collectionView, numberOfItemsInSection: 0) } - func scrollToItem(indexPath: IndexPath, animated: Bool = true) { + func scrollToItem(indexPath: IndexPath, animated: Bool = true, completer: (() -> Void)? = nil) { CATransaction.setCompletionBlock { [weak self] in guard let self = self else { return } if !animated { @@ -212,6 +212,7 @@ class SPPlayerListViewController: SPViewController { self.play() } } + completer?() } CATransaction.begin() self.collectionView.scrollToItem(at: indexPath, at: .top, animated: animated); diff --git a/MoviaBox/Class/Player/Model/SPVideoInfoModel.swift b/MoviaBox/Class/Player/Model/SPVideoInfoModel.swift index 5f56992..f365ba1 100644 --- a/MoviaBox/Class/Player/Model/SPVideoInfoModel.swift +++ b/MoviaBox/Class/Player/Model/SPVideoInfoModel.swift @@ -25,5 +25,7 @@ class SPVideoInfoModel: SPModel, SmartCodable { var short_play_id: String? var short_play_video_id: String? var video_url: String? + ///播放进度,毫秒 + var play_seconds: Int? } diff --git a/MoviaBox/Class/Wallet/Controller/SPWalletViewController.swift b/MoviaBox/Class/Wallet/Controller/SPWalletViewController.swift index c51654d..f691902 100644 --- a/MoviaBox/Class/Wallet/Controller/SPWalletViewController.swift +++ b/MoviaBox/Class/Wallet/Controller/SPWalletViewController.swift @@ -31,7 +31,7 @@ class SPWalletViewController: SPViewController { }() private lazy var headerView: SPWalletHeaderView = { - let view = SPWalletHeaderView(frame: .init(x: 0, y: 0, width: kSPScreenWidth, height: 152)) + let view = SPWalletHeaderView(frame: .init(x: 0, y: 0, width: kSPScreenWidth, height: 115)) view.userInfo = SPLoginManager.manager.userInfo return view }() diff --git a/MoviaBox/Class/Wallet/View/SPWalletHeaderView.swift b/MoviaBox/Class/Wallet/View/SPWalletHeaderView.swift index 8aafa4c..a97ec0d 100644 --- a/MoviaBox/Class/Wallet/View/SPWalletHeaderView.swift +++ b/MoviaBox/Class/Wallet/View/SPWalletHeaderView.swift @@ -18,6 +18,7 @@ class SPWalletHeaderView: UIView { //MARK: UI属性 private lazy var contentView: SPMineWalletView = { let view = SPMineWalletView() + view.isShowMore = false return view }() diff --git a/MoviaBox/Source/Assets.xcassets/icon/login_logo_icon_01.imageset/LOGO(MoviaBox).jpg b/MoviaBox/Source/Assets.xcassets/icon/login_logo_icon_01.imageset/LOGO(MoviaBox).jpg index 20c1b8d..99582a1 100644 Binary files a/MoviaBox/Source/Assets.xcassets/icon/login_logo_icon_01.imageset/LOGO(MoviaBox).jpg and b/MoviaBox/Source/Assets.xcassets/icon/login_logo_icon_01.imageset/LOGO(MoviaBox).jpg differ