Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // VenueVC.swift
- // SelectSociety
- //
- // Created by Kseniya on 6/12/19.
- // Copyright © 2019 maddevs. All rights reserved.
- //
- import UIKit
- import SnapKit
- import SafariServices
- class VenueVC: BaseVC {
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- let viewModel = VenueVM()
- var idVenue = ""
- var selectedTabIndex: Int = 0
- var newTabForReload:Int = 0
- private var isBlurNavBarActive = false
- private var heightForInterestsCells: CGFloat = 0.0
- static func newInstance(idVenue:String) -> VenueVC {
- let vc = VenueVC()
- vc.hidesBottomBarWhenPushed = true
- vc.idVenue = idVenue
- return vc
- }
- var trendingEventVC = TrendingEventVC()
- lazy var visualBLurffectView: UIVisualEffectView = {
- let bounds = CGRect(x: 0, y: -50, width: view.frame.width, height: (self.navigationController?.navigationBar.bounds.height ?? 22) + 50)
- let visualBLurffectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
- visualBLurffectView.frame = bounds
- visualBLurffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
- return visualBLurffectView
- }()
- lazy var collectionView: UICollectionView = {
- let layout = UICollectionViewFlowLayout()
- let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
- collectionView.delegate = self
- collectionView.dataSource = self
- collectionView.register(VenueHeaderCell.self, forCellWithReuseIdentifier: VenueHeaderCell.identity)
- collectionView.register(ProfileInterestCell.self, forCellWithReuseIdentifier: ProfileInterestCell.identity)
- collectionView.register(PromotersCell.self, forCellWithReuseIdentifier: PromotersCell.identity)
- collectionView.register(TabsCell.self, forCellWithReuseIdentifier: TabsCell.identity)
- collectionView.register(ImageUserPostCell.self, forCellWithReuseIdentifier: ImageUserPostCell.identity)
- collectionView.register(TrendingEventCell.self, forCellWithReuseIdentifier: TrendingEventCell.identity)
- collectionView.register(UserEventsCell.self, forCellWithReuseIdentifier: UserEventsCell.identity)
- collectionView.register(UserPhotosCell.self, forCellWithReuseIdentifier: UserPhotosCell.identity)
- collectionView.register(RatingViewCell.self, forCellWithReuseIdentifier: RatingViewCell.identity)
- collectionView.register(VenueLabelInfoCell.self, forCellWithReuseIdentifier: VenueLabelInfoCell.identity)
- collectionView.register(LessButtonCell.self, forCellWithReuseIdentifier: LessButtonCell.identity)
- collectionView.register(CommentViewCell.self, forCellWithReuseIdentifier: CommentViewCell.identity)
- collectionView.register(SocialMediaLinksCell.self, forCellWithReuseIdentifier: SocialMediaLinksCell.identity)
- collectionView.register(HeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerView")
- collectionView.register(RatingHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "ratingHeaderView")
- return collectionView
- }()
- lazy var heightEventCell: CGFloat = {
- // let heightTrendingVenuesCell = collectionView.frame.size.height / 3
- let heightTrendingVenuesCell = Const.HeightCell.heightTrendingVenues
- return heightTrendingVenuesCell
- }()
- lazy var widthEventCell: CGFloat = {
- let widthTrendingVenuesCell = collectionView.frame.size.width / 2 - 25
- return widthTrendingVenuesCell
- }()
- override func viewDidLoad() {
- super.viewDidLoad()
- viewModel.bind(self)
- viewModel.getVenueProfile(idVenue: idVenue)
- viewModel.getVenuePost()
- add(trendingEventVC)
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- setUpUI()
- }
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- navigationController?.navigationBar.backgroundColor = DefaultPresentationPalette.backgroundColorItems
- navigationController?.navigationBar.barTintColor = DefaultPresentationPalette.backgroundColorItems
- navigationController?.navigationBar.isTranslucent = false
- if #available(iOS 11.0, *) {
- if isBlurNavBarActive {
- visualBLurffectView.removeFromSuperview()
- }
- }
- }
- func setUpUI(){
- self.view.backgroundColor = DefaultPresentationPalette.backgroundColor
- self.navigationController?.navigationBar.topItem?.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)
- DispatchQueue.main.async {
- UIApplication.shared.statusBarView?.backgroundColor = .clear
- self.navigationController?.navigationBar.isTranslucent = true
- self.navigationController?.navigationBar.backgroundColor = .clear
- self.navigationController?.navigationBar.tintColor = .white
- self.navigationController?.navigationBar.barStyle = UIBarStyle.blackTranslucent
- self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
- }
- navigationItem.rightBarButtonItems = [UIBarButtonItem(image: UIImage(named: "menu_option_round"),
- style: .plain,
- target: self,
- action: nil)]
- if isBlurNavBarActive {
- let bounds = CGRect(x: 0, y: -50, width: view.frame.width, height: (self.navigationController?.navigationBar.bounds.height ?? 22) + 50)
- visualBLurffectView.frame = bounds
- self.navigationController?.navigationBar.insertSubview(visualBLurffectView, at: 0)
- }
- }
- override func setupConstraint() {
- view.addSubview(collectionView)
- collectionView.snp.makeConstraints { make in
- make.top.left.right.equalToSuperview()
- make.bottom.equalToSuperview()
- make.width.equalToSuperview()
- make.centerX.equalToSuperview()
- }
- }
- override func setupUI() {
- super.setupUI()
- view.backgroundColor = DefaultPresentationPalette.backgroundColor
- collectionView.backgroundColor = DefaultPresentationPalette.backgroundColor
- }
- @objc func updateVenuePost(_ notification: Notification) {
- collectionView.reloadData()
- }
- @objc func showMenuOption(idVenue:String) {
- let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
- let deletePost = UIAlertAction(title: "Some Option", style: .default) { (alerAction) in
- }
- let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
- cancel.setValue(UIColor.red, forKey: "titleTextColor")
- alert.addAction(deletePost)
- alert.addAction(cancel)
- present(alert, animated: true, completion: nil)
- }
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- print(scrollView.contentOffset.y)
- let heightNavBar = 0.0 - ( (self.navigationController?.navigationBar.bounds.height ?? 22))
- if scrollView.contentOffset.y > heightNavBar && !isBlurNavBarActive {
- isBlurNavBarActive = true
- self.navigationController?.navigationBar.insertSubview(visualBLurffectView, at: 0)
- }
- if scrollView.contentOffset.y <= heightNavBar {
- visualBLurffectView.removeFromSuperview()
- isBlurNavBarActive = false
- }
- }
- }
- extension VenueVC: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return viewModel.getSectionCount(viewModel.stateVC)
- }
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- switch viewModel.getVenueSection(viewModel.stateVC)[section] {
- case .socialLinks:
- return 4
- case .selectedTab:
- switch selectedTabIndex {
- case 0:
- return viewModel.venuePostList.count
- case 1:
- return 1
- case 2:
- return 10
- case 3:
- return 10
- default : return 0
- }
- case .eventsCell:
- return viewModel.venueEvents.count
- default:
- return 1
- }
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
- indexPath: IndexPath) -> CGSize {
- switch viewModel.getVenueSection(viewModel.stateVC)[indexPath.section] {
- case .venueHeaderCell:
- return getTotalHeightOfVenueHeaderCell()
- case .socialLinks:
- return CGSize(width: 44, height: 44)
- case .interestCell:
- switch viewModel.stateVC {
- case .defaultState:
- return CGSize(width:collectionView.frame.width - 20, height: Const.HeightCell.minHeightInterests)
- case .expandedState:
- return CGSize(width: collectionView.frame.width - 20, height: heightForInterestsCells)
- }
- case .venueInfoCell:
- return CGSize(width:collectionView.frame.width , height: 44)
- case .tabsCell:
- return CGSize(width: collectionView.frame.width, height: 44)
- case .selectedTab:
- switch selectedTabIndex {
- case 0:
- return getTotalHeightOfPostCell(indexPath: indexPath)
- case 1:
- return CGSize(width: collectionView.frame.width, height: Const.HeightCell.trendingEvent)
- case 2:
- return CGSize(width: collectionView.frame.width / 3, height: Const.HeightCell.photos)
- case 3:
- return getTotalHeightOfRatingCell()
- default :
- return CGSize(width: UIScreen.main.bounds.size.width, height: 100)
- }
- case .lessButton:
- return CGSize(width: collectionView.frame.width, height: Const.HeightCell.minHeightInterests)
- case .promotersCell:
- return getTotalHeightOfPromotersCell()
- case .eventsCell:
- switch selectedTabIndex {
- case 1:
- return CGSize(width: widthEventCell,height: heightEventCell)
- default:
- return CGSize.zero
- }
- case .commentCell:
- switch selectedTabIndex {
- case 0:
- return CGSize(width: collectionView.frame.width ,height: Const.HeightSectionHeader.venueCommentView)
- default:
- return CGSize.zero
- }
- }
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
- switch viewModel.getVenueSection(viewModel.stateVC)[section] {
- case .promotersCell:
- return CGSize(width: collectionView.frame.width, height: Const.HeightSectionHeader.venuePromoter)
- case .selectedTab:
- switch selectedTabIndex {
- case 1: return CGSize(width: collectionView.frame.width, height: Const.HeightSectionHeader.discover)
- case 3: return CGSize(width: collectionView.frame.width, height: Const.HeightSectionHeader.venueRatingView)
- default:return CGSize.zero
- }
- case .eventsCell:
- switch selectedTabIndex {
- case 1: return CGSize(width: collectionView.frame.width, height: Const.HeightSectionHeader.discover)
- default:return CGSize.zero
- }
- default: return CGSize.zero
- }
- }
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
- switch viewModel.getVenueSection(viewModel.stateVC)[indexPath.section] {
- case .promotersCell:
- let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerView", for: indexPath) as! HeaderView
- headerView.setTopPromotersHeader()
- return headerView
- case .selectedTab:
- switch selectedTabIndex {
- case 1:
- let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerView", for: indexPath) as! HeaderView
- headerView.setVenueFeaturedEventsHeader()
- return headerView
- case 3:
- let ratingView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "ratingHeaderView", for: indexPath) as! RatingHeaderView
- return ratingView
- default : return UICollectionReusableView()
- }
- case .eventsCell:
- let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerView", for: indexPath) as! HeaderView
- headerView.setVenueThisWeekEventsHeader()
- return headerView
- default : return UICollectionReusableView()
- }
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- switch viewModel.getVenueSection(viewModel.stateVC)[indexPath.section] {
- case .venueHeaderCell:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: VenueHeaderCell.identity, for:indexPath ) as! VenueHeaderCell
- self.navigationItem.title = "@\(viewModel.venueProfileResponse?.username ?? "")"
- cell.setUserData(venue: viewModel.venueProfileResponse ?? Venue_GetVenueProfileResponse() )
- return cell
- case .socialLinks:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SocialMediaLinksCell.identity, for: indexPath) as! SocialMediaLinksCell
- cell.setupSocialLink(index: indexPath.row)
- cell.delegate = self
- return cell
- case .interestCell:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ProfileInterestCell.identity, for:indexPath ) as! ProfileInterestCell
- cell.setupConstrainVenue(state: viewModel.stateVC)
- cell.setInterrestProfile(interest: viewModel.venueProfileResponse?.interestOptions ?? [])
- cell.backgroundColor = .clear
- cell.delegate = self
- if cell.getContentSize() > 0 && heightForInterestsCells == 0.0 {
- heightForInterestsCells = cell.getContentSize()
- }
- return cell
- case .venueInfoCell:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: VenueLabelInfoCell.identity, for: indexPath) as! VenueLabelInfoCell
- cell.setVenueData(venue: viewModel.venueProfileResponse, index: indexPath.section)
- return cell
- case .tabsCell:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TabsCell.identity, for: indexPath) as! TabsCell
- self.reloadTabsSection(cell: cell,collectionView: collectionView)
- return cell
- case .promotersCell:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PromotersCell.identity, for: indexPath) as! PromotersCell
- cell.fillPromoters(promoters:viewModel.venueProfileResponse?.promoters ?? [])
- return cell
- case .lessButton:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LessButtonCell.identity, for: indexPath) as! LessButtonCell
- cell.delegate = self
- return cell
- case .eventsCell:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: UserEventsCell.identity, for: indexPath) as! UserEventsCell
- cell.eventView.fillEvent(event: viewModel.venueEvents[indexPath.row])
- return cell
- case .commentCell:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CommentViewCell.identity, for: indexPath) as! CommentViewCell
- return cell
- case .selectedTab:
- switch selectedTabIndex {
- case 1:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TrendingEventCell.identity, for: indexPath) as! TrendingEventCell
- cell.configure(trendingEventVC.view)
- return cell
- case 2:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: UserPhotosCell.identity, for: indexPath) as! UserPhotosCell
- return cell
- case 3:
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: RatingViewCell.identity, for: indexPath) as! RatingViewCell
- return cell
- default : let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageUserPostCell.identity, for: indexPath) as! ImageUserPostCell
- cell.imagePostView.fillPost(post: viewModel.venuePostList[indexPath.row])
- return cell
- }
- }
- }
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- // open Event Page
- // print("user event \(viewModel.venueEvents[indexPath.row])")
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- switch viewModel.getVenueSection(viewModel.stateVC)[section] {
- case .tabsCell:
- return UIEdgeInsets (top: 15, left: 0, bottom: 0, right: 0)
- case .interestCell:
- switch viewModel.stateVC {
- case .defaultState:
- return UIEdgeInsets (top: 5, left: 0, bottom: 0, right: 0)
- case .expandedState:
- return UIEdgeInsets.zero
- }
- case .socialLinks:
- let totalCellWidth = 44 * collectionView.numberOfItems(inSection: 1)
- let totalSpacingWidth = 10 * (collectionView.numberOfItems(inSection: 1))
- let leftInset = (collectionView.layer.frame.size.width - CGFloat(totalCellWidth + totalSpacingWidth)) / 2
- let rightInset = leftInset
- return UIEdgeInsets(top: 5, left: leftInset, bottom: 0, right: rightInset)
- case .promotersCell:
- return UIEdgeInsets (top: 10, left: 0, bottom: 10, right: 0)
- case .eventsCell:
- switch selectedTabIndex {
- case 1 :
- return UIEdgeInsets (top: 0, left: 20, bottom: 40, right: 20)
- default:
- return UIEdgeInsets.zero
- }
- case .commentCell:
- switch selectedTabIndex {
- case 0 :
- return UIEdgeInsets (top: 10, left: 0, bottom: 10, right: 0)
- default:
- return UIEdgeInsets.zero
- }
- default:
- return UIEdgeInsets.zero
- }
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
- switch selectedTabIndex {
- case 2 :
- return 0.0
- default:
- return 10.0
- }
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
- switch selectedTabIndex {
- case 2 :
- return 0.0
- default:
- return 10.0
- }
- }
- func reloadTabsSection(cell : TabsCell, collectionView: UICollectionView) {
- cell.tabs = Const.Tabs.venueTabs
- cell.selectedTabIndex = selectedTabIndex
- cell.tabChangeEvent = { [weak self] tab in
- guard let `self` = self else { return }
- if let newIndex = tab {
- self.selectedTabIndex = newIndex
- if self.newTabForReload != self.selectedTabIndex {
- let sectionForReload = IndexSet(integer: self.viewModel.getVenueSection(self.viewModel.stateVC).firstIndex(of: .selectedTab) ?? 0 )
- UIView.performWithoutAnimation {
- collectionView.performBatchUpdates({
- collectionView.reloadSections(sectionForReload)
- }, completion: nil)
- }
- self.newTabForReload = newIndex
- }
- }
- }
- }
- func getTotalHeightOfVenueHeaderCell() -> CGSize {
- return CGSize(width: UIScreen.main.bounds.size.width , height: Const.VenueHeaderView.aboutVenueTextHeight
- + Const.VenueHeaderView.venueImageHeight
- + Const.VenueHeaderView.venueNameHeight
- + Const.VenueHeaderView.venueWriteReviewButtonHeight
- + Const.VenueHeaderView.topOfset * 9)
- }
- func getTotalHeightOfPromotersCell() -> CGSize {
- return CGSize(width: collectionView.frame.width , height: Const.VenuePromotersView.promoterProfileImageHeight
- + Const.VenuePromotersView.fullNameHeight
- + Const.VenuePromotersView.userNameHeight)
- }
- func getTotalHeightOfPostCell(indexPath: IndexPath) -> CGSize {
- return CGSize(width: collectionView.frame.width, height:Const.ImagePostView.postTextHeight[indexPath.row]
- + Const.ImagePostView.postImageHeight
- + Const.ImagePostView.profileImageHeight
- + Const.ImagePostView.timeViewHeight + (Const.ImagePostView.topOfset * 5))
- }
- func getTotalHeightOfRatingCell() -> CGSize {
- return CGSize(width: collectionView.frame.width, height: 150)
- }
- }
- extension VenueVC: VenueDelegate {
- func checkConnectedToNetwork() {
- appDelegate.checkForNetwork()
- }
- func showAlertView(title: String, message: String) {
- showAlert(title: title, message: message)
- }
- func showHud(_ message:String) {
- showHudView(message)
- }
- func reloadData() {
- DispatchQueue.main.async {
- self.collectionView.reloadData()
- }
- }
- func hideHud() {
- hideHudView()
- }
- func showTokenAlert() {
- }
- }
- extension VenueVC: MoreAndLessButtonDelegate {
- func moreOrLessButtonPressed() {
- viewModel.stateVC.changeState()
- collectionView.reloadData()
- }
- }
- extension VenueVC: OpenSocialMediaLinkDelegate {
- func openURL(_ link: URL) {
- let vc = SFSafariViewController(url: link, entersReaderIfAvailable: false)
- vc.preferredBarTintColor = DefaultPresentationPalette.backgroundColor
- present(vc, animated: true)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement