// // UserIntrestVM.swift // WOKA // // Created by MacBook Pro on 30/04/24. // import UIKit import Alamofire class UserIntrestVM{ weak var vc : UserIntrestVC! var gender = GenderEnum.none var intrestTopics = [IntrestTopicDM.Result]() func initView(){ setupCell() let bottomPadding: CGFloat = 60 // Adjust this value as needed // Get the current content inset var contentInset = vc.scrollView.contentInset // Add bottom padding contentInset.bottom = bottomPadding // Set the updated content inset vc.scrollView.contentInset = contentInset let color1 = #colorLiteral(red: 0.144693464, green: 0.1426281333, blue: 0.6686832905, alpha: 1) let color2 = #colorLiteral(red: 0.6901960784, green: 0.2745098039, blue: 0.7568627451, alpha: 1) vc.nextBtn.applyGradient(colors: [color1, color2], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0.8, y: 0)) vc.nextBtn.roundCorner() // Add tap gesture recognizer to the view let tapGesture = UITapGestureRecognizer(target: self, action: #selector(boyBtnTapped)) vc.boyView.addGestureRecognizer(tapGesture) // Add tap gesture recognizer to the view let tapGesture2 = UITapGestureRecognizer(target: self, action: #selector(girlBtnTapped)) vc.girlView.addGestureRecognizer(tapGesture2) setGender() getIntrests() } func setGender(){ let alphaComp = 0.6 switch gender{ case .boy: vc.boyView.backgroundColor = UIColor.white vc.girlView.backgroundColor = UIColor.white.withAlphaComponent(alphaComp) case .girl: vc.girlView.backgroundColor = UIColor.white vc.boyView.backgroundColor = UIColor.white.withAlphaComponent(alphaComp) case .none: vc.girlView.backgroundColor = UIColor.white.withAlphaComponent(alphaComp) vc.boyView.backgroundColor = UIColor.white.withAlphaComponent(alphaComp) } } @objc func boyBtnTapped() { // Apply click effect animation gender = .boy UIView.animate(withDuration: 0.1, animations: { self.vc.boyView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) }) { _ in UIView.animate(withDuration: 0.1) { self.vc.boyView.transform = .identity self.setGender() } } } @objc func girlBtnTapped() { gender = .girl // Apply click effect animation UIView.animate(withDuration: 0.1, animations: { self.vc.girlView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) }) { _ in UIView.animate(withDuration: 0.1) { self.vc.girlView.transform = .identity self.setGender() } } } func setupCell(){ vc.collectionView.register(UINib(nibName: K.CellIdentifier.Authentication.yourIntrestCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Authentication.yourIntrestCell) vc.collectionView.delegate = self.vc vc.collectionView.dataSource = self.vc } // MARK: - Get Intrests func getIntrests(){ Utilities.startProgressHUD() NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Auth.interest_topic_listing, method: .post) {(result : Result, NetworkManager.APIError>) in switch result{ case .success(let data): switch data.success{ case 0: Utilities.dismissProgressHUD() self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2) case 1: Utilities.dismissProgressHUD() if let intrests = data.data?.result{ self.intrestTopics = intrests self.vc.collectionView.reloadData() /* Set the collectionview height */ let height = self.vc.collectionView.collectionViewLayout.collectionViewContentSize.height self.vc.contentHeight.constant = height self.vc.view.layoutIfNeeded() } self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2) default: break } case .failure(let error): Utilities.dismissProgressHUD() self.vc.toast(msg: error.localizedDescription, time: 2) } } } }