2024-05-02 13:20:40 +05:30
|
|
|
//
|
|
|
|
|
// UserIntrestVM.swift
|
|
|
|
|
// WOKA
|
|
|
|
|
//
|
|
|
|
|
// Created by MacBook Pro on 30/04/24.
|
|
|
|
|
//
|
|
|
|
|
|
2024-05-02 19:30:09 +05:30
|
|
|
import UIKit
|
2024-05-07 19:33:29 +05:30
|
|
|
import Alamofire
|
2024-05-02 13:20:40 +05:30
|
|
|
|
|
|
|
|
class UserIntrestVM{
|
|
|
|
|
|
|
|
|
|
weak var vc : UserIntrestVC!
|
2024-05-08 19:36:20 +05:30
|
|
|
// var gender = GenderEnum.none
|
2024-05-07 19:33:29 +05:30
|
|
|
var intrestTopics = [IntrestTopicDM.Result]()
|
2024-05-02 13:20:40 +05:30
|
|
|
|
|
|
|
|
func initView(){
|
2024-05-02 19:30:09 +05:30
|
|
|
setupCell()
|
2024-05-02 13:20:40 +05:30
|
|
|
|
2024-05-08 19:36:20 +05:30
|
|
|
/*
|
|
|
|
|
Setting the minimum and maximum date as per user type
|
|
|
|
|
*/
|
|
|
|
|
if AuthFunc.shareInstance.userType == .adult{
|
|
|
|
|
vc.datePicker.minimumDate = Calendar.current.date(byAdding: .year, value: -150, to: Date())
|
|
|
|
|
vc.datePicker.maximumDate = Calendar.current.date(byAdding: .year, value: -16, to: Date())
|
|
|
|
|
}else{
|
|
|
|
|
vc.datePicker.minimumDate = Calendar.current.date(byAdding: .year, value: -16, to: Date())
|
|
|
|
|
vc.datePicker.maximumDate = Calendar.current.date(byAdding: .year, value: -3, to: Date())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vc.fullName.text = (AuthFunc.shareInstance.regData.full_name != nil && AuthFunc.shareInstance.regData.full_name != "") ? AuthFunc.shareInstance.regData.full_name : "Guardian"
|
2024-05-02 19:30:09 +05:30
|
|
|
|
2024-05-08 19:36:20 +05:30
|
|
|
let bottomPadding: CGFloat = 60 // Adjust this value as needed
|
2024-05-02 19:30:09 +05:30
|
|
|
// 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()
|
2024-05-07 19:33:29 +05:30
|
|
|
getIntrests()
|
2024-05-02 19:30:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setGender(){
|
|
|
|
|
let alphaComp = 0.6
|
2024-05-08 19:36:20 +05:30
|
|
|
switch AuthFunc.shareInstance.regData.gender{
|
|
|
|
|
case 2:
|
2024-05-02 19:30:09 +05:30
|
|
|
vc.boyView.backgroundColor = UIColor.white
|
|
|
|
|
vc.girlView.backgroundColor = UIColor.white.withAlphaComponent(alphaComp)
|
2024-05-08 19:36:20 +05:30
|
|
|
case 1:
|
2024-05-02 19:30:09 +05:30
|
|
|
vc.girlView.backgroundColor = UIColor.white
|
|
|
|
|
vc.boyView.backgroundColor = UIColor.white.withAlphaComponent(alphaComp)
|
2024-05-08 19:36:20 +05:30
|
|
|
default:
|
2024-05-02 19:30:09 +05:30
|
|
|
vc.girlView.backgroundColor = UIColor.white.withAlphaComponent(alphaComp)
|
|
|
|
|
vc.boyView.backgroundColor = UIColor.white.withAlphaComponent(alphaComp)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func boyBtnTapped() {
|
|
|
|
|
// Apply click effect animation
|
2024-05-08 19:36:20 +05:30
|
|
|
AuthFunc.shareInstance.regData.gender = 2
|
2024-05-02 19:30:09 +05:30
|
|
|
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() {
|
2024-05-08 19:36:20 +05:30
|
|
|
AuthFunc.shareInstance.regData.gender = 1
|
|
|
|
|
|
2024-05-02 19:30:09 +05:30
|
|
|
// 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
|
2024-05-02 13:20:40 +05:30
|
|
|
}
|
2024-05-07 19:33:29 +05:30
|
|
|
|
|
|
|
|
// MARK: - Get Intrests
|
|
|
|
|
|
|
|
|
|
func getIntrests(){
|
|
|
|
|
Utilities.startProgressHUD()
|
|
|
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Auth.interest_topic_listing, method: .post) {(result : Result<BaseResponseModel<IntrestTopicDM>, 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()
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 19:36:20 +05:30
|
|
|
// self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
2024-05-07 19:33:29 +05:30
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
case .failure(let error):
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
self.vc.toast(msg: error.localizedDescription, time: 2)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-02 13:20:40 +05:30
|
|
|
}
|