123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- //
- // CommunityVideoListController.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/7/3.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 推荐--视频内容详情
- import UIKit
- import RxSwift
- class CommunityVideoListController: BaseViewController {
-
- // 内容Id
- var contentId: Int? {
- didSet {
- setupData()
- }
- }
-
- var videoItemList: Array<CommunityVideoItemModel>?
-
- private var prePlayCell: CommunityVideoCoverCollectionCell?
-
- deinit {
- if observe != nil {
- NotificationCenter.default.removeObserver(observe!)
- }
- }
- weak var observe : NSObjectProtocol?
-
- override var prefersStatusBarHidden: Bool {
- return true
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setupViews()
- setUpAppStatusNotification()
- }
-
- override func viewDidAppear(_ animated: Bool) {
- playFirstVideoWhenViewDidAppeared()
- }
-
- override func viewWillDisappear(_ animated: Bool) {
- pauseCurrentVideo()
- }
-
- func setUpAppStatusNotification() {
- observe = NotificationCenter.default.addObserver(forName: UIApplication.willResignActiveNotification, object: nil, queue: OperationQueue.main, using: {
- [weak self] (notification) in
- self?.pauseCurrentVideo()
- })
-
- observe = NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: OperationQueue.main, using: {
- [weak self] (notification) in
- self?.startPlay(self?.prePlayCell)
- })
-
- observe = NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: OperationQueue.main, using: {
- [weak self] (notification) in
- self?.startPlay(self?.prePlayCell)
- })
- }
-
- override func setupViews() {
-
- self.view.addSubview(collectionView)
- let emptyView = DIYEmptyView.empty(with: kImage(name: "default_page_data"), titleStr: nil, detailStr: "当前暂无数据")
- emptyView!.contentViewY = kScaleValue(value: 182)
- collectionView.ly_emptyView = emptyView
- collectionView.ly_startLoading()
- collectionView.snp.makeConstraints { (make) in
- make.top.equalTo(0)
- make.left.right.bottom.equalToSuperview()
- }
-
- }
-
- override func setupData() {
- collectionView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
- self?.communityVideoListApi()
- }
- }
-
- /// 视频列表
- func communityVideoListApi() {
- SwiftMoyaNetWorkServiceCommunity.shared().communityVideoListApi(id: contentId ?? 0) {
- [weak self] (communityVideoListModel) -> (Void) in
- let videoListMdl = communityVideoListModel as? CommunityVideoListModel
- self?.videoItemList = videoListMdl?.data
- self?.collectionView.reloadData()
- }
- }
-
- private lazy var collectionView: UICollectionView = {
- let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
- collectionView.backgroundColor = kf7f8faColor
- collectionView.delegate = self;
- collectionView.dataSource = self;
- collectionView.isPagingEnabled = true
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- return collectionView
- }()
-
- private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
- let collectionViewLayout = UICollectionViewFlowLayout.init()
- collectionViewLayout.minimumLineSpacing = 0
- collectionViewLayout.minimumInteritemSpacing = 0
- return collectionViewLayout
- }()
-
- }
- // MARK: - collectionView dataSource && delegate
- extension CommunityVideoListController: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return 1
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return videoItemList?.count ?? 0
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = CommunityVideoCoverCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
- cell.videoItemMdl = videoItemList?[indexPath.row]
- cell.backClosure = {
- [weak self] in
- self?.navigationController?.popViewController(animated: true)
- }
- cell.shareClosure = {
- [weak self] in
- print("------点击了[分享]")
- }
- cell.followClosure = { (videoItemMdl, followButton) in
- CommunityFollowUserViewModel.shared.follow(communityVideoItemModel: videoItemMdl, button: followButton)
- }
- cell.buttonClickClosure = {
- [weak self] (clickType, uid, postId) in
- switch clickType {
- case videoBtnClickType.typeComment:
- self?.showCommentView(postId: postId)
-
- case videoBtnClickType.typeLike:
- VirusViewModel.shared.praise(communityVideoItemModel: (self?.videoItemList?[indexPath.row])!)
-
- case videoBtnClickType.typeCollect: VirusViewModel.shared.collection(communityVideoItemModel: (self?.videoItemList?[indexPath.row])!)
-
- case videoBtnClickType.typePerson:
- let vc = OtherPersonalCenterViewController()
- vc.uid = uid
- self?.navigationController?.pushViewController(vc, animated: true)
-
- default:
- break
- }
- }
- return cell
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- print("----collectionClicked -- \(indexPath.row)")
- }
-
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width:kScreenWidth, height:kScreenHeight)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- return UIEdgeInsets(top:0, left: 0, bottom: 0, right: 0)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
- return CGSize(width: kScreenWidth, height: 10)
- }
-
- func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
- prePlayCell = cell as? CommunityVideoCoverCollectionCell
- self.pauseCurrentVideo()
- }
-
- func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
- let index = Int(collectionView.contentOffset.y / CGFloat(kScreenHeight))
- let indexPath = IndexPath(item: index, section: 0)
- let cell = collectionView.cellForItem(at: indexPath) as? CommunityVideoCoverCollectionCell
-
- if(cell != nil) {
- self.startPlay(cell)
- }
- }
-
- }
- // MARK: -
- extension CommunityVideoListController {
-
- func startPlay(_ cell: CommunityVideoCoverCollectionCell?) {
- cell?.play()
- }
-
- func pauseCurrentVideo() {
- if prePlayCell != nil {
- prePlayCell?.pause()
- }
- }
-
- func playFirstVideoWhenViewDidAppeared() {
- let showCells = collectionView.visibleCells
- for tmpCell in showCells {
- let videoCell = tmpCell as? CommunityVideoCoverCollectionCell
- startPlay(videoCell)
- prePlayCell = videoCell
- break
- }
- }
-
- func showCommentView(postId: Int) {
-
- AlertSheetView.commentAlertSheetView(postId: postId, cancelClosure: {
- [weak self] in
-
- }) {
- [weak self] (payType) in
- print("----\(payType)")
- }
- }
-
- }
|