123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- //
- // PersonViewUserAndOtherListView.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/6/17.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import SwiftyMediator
- class PersonViewUserAndOtherListView: BaseView {
-
- deinit {
- listViewDidScrollCallback = nil
- if observe != nil {
- NotificationCenter.default.removeObserver(observe!)
- }
- }
- weak var observe : NSObjectProtocol?
- var listViewDidScrollCallback: ((UIScrollView) -> ())?
-
- var jumpModeType : JumpModeType? {
- didSet {
- collectionView.snp_makeConstraints { (make) in
- make.top.right.left.equalToSuperview()
- if jumpModeType == JumpModeType.none {
- make.height.equalTo(kScreenHeight-kNavBarTotalHeight-kTabBarTotalHeight-44)
- }else {
- make.height.equalTo(kScreenHeight-kNavBarTotalHeight-kSafeTabBarHeight-44)
- }
- }
- }
- }
- /// 用户Id
- var uid:Int?
- /// 发布,收藏,分享类型
- var personalCenterVCType : Int?
- /// 模型数组
- var postMyModels = Array<PostMyModel>()
- override func setupViews() {
- addSubview(collectionView)
- }
-
- override func setupData() {
- collectionView.addHeader(withBeginRefresh: true, animation: false, refreshBlock: { [weak self] (page) in
- self?.communityPostMyApi(page: page)
- })
- collectionView.addAutoNormalFooter(withAutomaticallyRefresh: true, loadMoreBlock: {
- [weak self] (page) in
- self?.communityPostMyApi(page: page)
- })
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("communityDeletePostApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let postId = notification.object as? Int
- if !(self?.postMyModels.isEmpty ?? true) {
- for (index,postMyModel) in (self?.postMyModels)!.enumerated() {
- if postMyModel.id == postId {
- self?.postMyModels.remove(at: index)
- }
- }
- self?.collectionView.reloadData()
- }
- }
- }
- lazy var collectionView: UICollectionView = {
- let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
- collectionView.backgroundColor = kf7f8faColor
- collectionView.delegate = self;
- collectionView.dataSource = self;
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- return collectionView
- }()
-
- private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
- let collectionViewLayout = UICollectionViewFlowLayout.init()
- collectionViewLayout.minimumLineSpacing = 1
- collectionViewLayout.minimumInteritemSpacing = 1
- return collectionViewLayout
- }()
-
- }
- extension PersonViewUserAndOtherListView {
- func communityPostMyApi(page:Int) {
- var type : CommunityPostMyType!
- if personalCenterVCType == 0 {
- type = .create
- }
- if personalCenterVCType == 1 {
- type = .collect
- }
- if personalCenterVCType == 2 {
- type = .share
- }
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostMyApi(type: type,uid:uid ?? 0,page:page, completion: {
- [weak self] (communityPostMyModel) -> (Void) in
- DIYEmptyView.emptyNoDataCollectionView(collectionView: self?.collectionView, detailStr: .one)
-
- let communityPostMyModel = communityPostMyModel as? CommunityPostMyModel
- if communityPostMyModel?.pagination?.currentPage == 1{
- self?.postMyModels.removeAll()
- self?.collectionView.resetNoMoreData()
- }
- self?.postMyModels = (self?.postMyModels)! + (communityPostMyModel?.data!)!
- self?.collectionView.reloadData()
- MJRefreshManager.hiddenHeaderWithFooter(collectionView: self?.collectionView, pagination: communityPostMyModel?.pagination)
- }) {
- [weak self] _ in
- MJRefreshManager.hiddenHeaderWithFooterNONetWork(collectionView: self?.collectionView)
- }
- }
- }
- extension PersonViewUserAndOtherListView: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return 1
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return postMyModels.isEmpty ? 0 : postMyModels.count
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = PersonViewUserAndOtherListCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
- cell.uid = self.uid
- cell.type = self.personalCenterVCType
- cell.postMyModel = postMyModels[indexPath.row]
- return cell
-
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- let postMyModel = postMyModels[indexPath.row]
- if PostType(rawValue: postMyModel.type ?? "video") == .video {
- Mediator.push(CommunityRouterModuleType.pushPostDetailVoide(postId: "\(postMyModel.id ?? 0)", departType: .personal))
-
- }else {
- let vc = CommunityRecommendController()
- vc.id = postMyModel.id ?? 0
- findViewController().navigationController?.pushViewController(vc, animated: true)
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width:(kScreenWidth-4)/3, height:(kScreenWidth-4)/3)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- return UIEdgeInsets(top:1, left: 1, bottom: 10, right: 1)
- }
-
- public func scrollViewDidScroll(_ scrollView: UIScrollView) {
- self.listViewDidScrollCallback?(scrollView)
- }
-
- }
- extension PersonViewUserAndOtherListView: JXPagingViewListViewDelegate {
- public func listView() -> UIView {
- return self
- }
-
- public func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
- self.listViewDidScrollCallback = callback
- }
-
- public func listScrollView() -> UIScrollView {
- return self.collectionView
- }
- }
|