You are on page 1of 8

//

// MenuTableVC.swift
// matrimonyy
//
// Created by iOS Developer on 07/04/21.
// Copyright © 2021 iOS Developer. All rights reserved.
//

import UIKit

class MenuTableVC: UITableViewController {


@IBOutlet var menuTableView: UITableView!
var isMyAccountOpen = false
var isHelpOpen = true
var isSupportOpen = true
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.setNavigationBarHidden(true, animated: true)
cellIntialisation()

override func viewWillAppear(_ animated: Bool) {


menuTableView.reloadData()
}

func cellIntialisation(){
menuTableView.register(UINib(nibName: CellIdentifier.HelpMenuTableViewCell,
bundle: nil), forCellReuseIdentifier: CellIdentifier.HelpMenuTableViewCell)
menuTableView.register(UINib(nibName:
CellIdentifier.MenuHeaderTableViewCell, bundle: nil), forCellReuseIdentifier:
CellIdentifier.MenuHeaderTableViewCell)
menuTableView.register(UINib(nibName:
CellIdentifier.MenuOptionTableViewCell, bundle: nil), forCellReuseIdentifier:
CellIdentifier.MenuOptionTableViewCell)
menuTableView.register(UINib(nibName:
CellIdentifier.MyAccountMenuTableViewCell, bundle: nil), forCellReuseIdentifier:
CellIdentifier.MyAccountMenuTableViewCell)
}

extension MenuTableVC{

override func tableView(_ tableView: UITableView, heightForRowAt indexPath:


IndexPath) -> CGFloat {
if indexPath.row == 0{
return 130
}else{
return UITableView.automaticDimension
}
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection


section: Int) -> Int {
if Util.userDefault.bool(forKey: UserDefaultIdentifier.userStatusActive){
return 4
}else{
return 2
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath:


IndexPath) -> UITableViewCell {
if Util.userDefault.bool(forKey: UserDefaultIdentifier.userStatusActive){
switch indexPath.row{
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.MenuHeaderTableViewCell, for: indexPath) as! MenuHeaderTableViewCell
cell.doInit()
return cell

case 1:
let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.MyAccountMenuTableViewCell, for: indexPath) as!
MyAccountMenuTableViewCell

cell.bcgButton.addTarget(self,action:#selector(didTapMyAccountButton), for:
.touchUpInside)

cell.photoButton.addTarget(self,action:#selector(didTapMyAccountButton), for:
.touchUpInside)

cell.profileButton.addTarget(self,action:#selector(didTapMyAccountButton), for:
.touchUpInside)

cell.accountButton.addTarget(self,action:#selector(didTapMyAccountButton), for:
.touchUpInside)

cell.privecyButton.addTarget(self,action:#selector(didTapMyAccountButton), for:
.touchUpInside)

cell.membershipButton.addTarget(self,action:#selector(didTapMyAccountButton),
for: .touchUpInside)

cell.shareProfileButton.addTarget(self,action:#selector(didTapMyAccountButton),
for: .touchUpInside)

cell.partnerPreferenceButton.addTarget(self,action:#selector(didTapMyAccountButton)
, for: .touchUpInside)
cell.updateUI(isMyAccountOpen)
return cell

// case 2:
// let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.MenuOptionTableViewCell, for: indexPath) as! MenuOptionTableViewCell
// cell.titleLabel.text = "Refer & Earn"
// cell.iconImage.image = #imageLiteral(resourceName: "referral")
// return cell

case 2:
let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.HelpMenuTableViewCell, for: indexPath) as! HelpMenuTableViewCell
cell.updateUI(isHelpOpen, isSupportOpen: isSupportOpen)

cell.faqButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)
cell.helpButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.supportButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.aboutUsButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.termsOfUseButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.privecyPolicyButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.repoartAnIssueButton.addTarget(self,action:#selector(didTapHelpRowButton),
for: .touchUpInside)

cell.viewReportedIssueButton.addTarget(self,action:#selector(didTapHelpRowButton),
for: .touchUpInside)

cell.ApplicationVersionButton.addTarget(self,action:#selector(didTapHelpRowButton),
for: .touchUpInside)
return cell

case 3:
let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.MenuOptionTableViewCell, for: indexPath) as! MenuOptionTableViewCell
cell.titleLabel.text = "Suggestions"
cell.iconImage.image = #imageLiteral(resourceName: "good")
return cell

// case 4:
// let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.MenuOptionTableViewCell, for: indexPath) as! MenuOptionTableViewCell
// cell.titleLabel.text = "Rate Us On App Store"
// cell.iconImage.image = #imageLiteral(resourceName: "account")
// return cell

default:
return UITableViewCell()
}
}else{
switch indexPath.row {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.MenuHeaderTableViewCell, for: indexPath) as! MenuHeaderTableViewCell
return cell

case 1:
let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.HelpMenuTableViewCell, for: indexPath) as! HelpMenuTableViewCell
cell.updateUI(isHelpOpen, isSupportOpen: isSupportOpen)

cell.faqButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.helpButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)
cell.supportButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.aboutUsButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.termsOfUseButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.privecyPolicyButton.addTarget(self,action:#selector(didTapHelpRowButton), for:
.touchUpInside)

cell.repoartAnIssueButton.addTarget(self,action:#selector(didTapHelpRowButton),
for: .touchUpInside)

cell.viewReportedIssueButton.addTarget(self,action:#selector(didTapHelpRowButton),
for: .touchUpInside)

cell.ApplicationVersionButton.addTarget(self,action:#selector(didTapHelpRowButton),
for: .touchUpInside)
return cell

// case 2:
// let cell = tableView.dequeueReusableCell(withIdentifier:
CellIdentifier.MenuOptionTableViewCell, for: indexPath) as! MenuOptionTableViewCell
// cell.titleLabel.text = "Rate Us On App Store"
// cell.iconImage.image = #imageLiteral(resourceName: "account")
// return cell

default:
return UITableViewCell()
}
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath:


IndexPath) {
if Util.userDefault.bool(forKey: UserDefaultIdentifier.userStatusActive){
switch indexPath.row {
case 0:
if !Util.userDefault.bool(forKey: UserDefaultIdentifier.isPaid){
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.SubscriptionPlanVC) as? SubscriptionPlanVC
self.navigationController?.pushViewController(vc!, animated:
true)
}

// case 2:
// let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.ReferEarnVC) as? ReferEarnVC
// self.navigationController?.pushViewController(vc!, animated:
true)
// break

case 3:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.SuggestionListVC) as? SuggestionListVC
self.navigationController?.pushViewController(vc!, animated: true)
break

// case 4:
// openAppStrore()
// break

default:
break
}
}else{
if indexPath.row == 2{ openAppStrore() }
}
}

func openAppStrore() {
if let url = URL(string: "itms-apps://apple.com/app/id839686104"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler:nil)
} else {
print("Error in opening dial pad")
}
}

//MARK:- Menu Button Actions


extension MenuTableVC{

func reloadRow(_ indexPath:IndexPath){


// menuTableView.reloadRows(at: [indexPath], with: .fade)
menuTableView.reloadData()
// menuTableView.beginUpdates()
// menuTableView.endUpdates()
}

@objc func didTapMyAccountButton(_ sender: UIButton){


switch sender.tag {
case 0:
let indexPath = IndexPath(row: 1, section: 0)
isMyAccountOpen = !isMyAccountOpen
reloadRow(indexPath)
break

case 1:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.PhotosVC) as? PhotosVC
self.navigationController?.pushViewController(vc!, animated: true)
break

case 2:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.ProfileMainVc) as? ProfileMainVc
self.navigationController?.pushViewController(vc!, animated: true)
break

case 3:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.PrivacySettingVC) as? PrivacySettingVC
vc?.isFromMenu = true
self.navigationController?.pushViewController(vc!, animated: true)
break

case 4:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.PartnerPreferenceDetailVC) as? PartnerPreferenceDetailVC
vc?.isFromMenu = true
self.navigationController?.pushViewController(vc!, animated: true)
break

case 5:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.MembershipListVC) as? MembershipListVC
navigationController?.pushViewController(vc!, animated: true)
break

case 6:
let vc = UIStoryboard.init(name: "BCG", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.BCGMainListVC) as? BCGMainListVC
vc?.memberID = Util.userDefault.integer(forKey:
UserDefaultIdentifier.memberid)
vc?.isFromMenu = true
navigationController?.pushViewController(vc!, animated: true)
break

case 7:
let FirstName:String =
DatabaseManager.getDBInstance().getUserDetail("c_FirstName")
let memberID = Util.userDefault.integer(forKey:
UserDefaultIdentifier.memberid)
shareProfile(FirstName, memberID: memberID, toMemberID: memberID)
break

default:
break
}
}

@objc func didTapHelpRowButton(_ sender: UIButton){


let row = Util.userDefault.bool(forKey:
UserDefaultIdentifier.userStatusActive) ? 2 : 1
let indexPath = IndexPath(row: row, section: 0)

switch sender.tag {
case 0:
isHelpOpen = !isHelpOpen
reloadRow(indexPath)
break
case 1:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.FaqListVC) as? FaqListVC
self.navigationController?.pushViewController(vc!, animated: true)
break

case 2:
isSupportOpen = !isSupportOpen
reloadRow(indexPath)
break

case 3:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.ReportAnIssueVC) as? ReportAnIssueVC
self.navigationController?.pushViewController(vc!, animated: true)
break

case 4:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.ReportedIssueListVC) as? ReportedIssueListVC
self.navigationController?.pushViewController(vc!, animated: true)
break

case 5:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.TermsAndPrivecyVC) as? TermsAndPrivecyVC
vc?.url = "https://matrimonyy.com/Terms-of-Use.html"
self.navigationController?.pushViewController(vc!, animated: true)
break

case 6:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.TermsAndPrivecyVC) as? TermsAndPrivecyVC
vc?.url = "https://matrimonyy.com/Privacy-Policy.html"
self.navigationController?.pushViewController(vc!, animated: true)
break

case 7:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.AboutUsVC) as? AboutUsVC
self.navigationController?.pushViewController(vc!, animated: true)
break

case 8:
let vc = UIStoryboard.init(name: "Main", bundle:
Bundle.main).instantiateViewController(withIdentifier:
StoryboardIdentifier.ApplicationVersionVC) as? ApplicationVersionVC
self.navigationController?.pushViewController(vc!, animated: true)
break

default:
break
}
}

You might also like