// // SideMenuViewController.swift // GMERemittance // // Created by Sujal on 2/22/18. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. // import UIKit import SDWebImage import LGSideMenuController struct SideMenuNavigationNotifications { static let aboutGme = "aboutGme" static let support = "support" static let setting = "setting" static let availableBalance = "Available_Balance" } class SideMenuViewController: UIViewController { @IBOutlet weak var imageViewProfileSetting: UIImageView! @IBOutlet weak var labelProfileName: UILabel! @IBOutlet weak var labelPhone: UILabel! @IBOutlet weak var labelEmail: UILabel! @IBOutlet weak var roundedBgView: UIView! @IBOutlet weak var labelBalance: UILabel! @IBOutlet weak var labelWalletNumber: UILabel! @IBOutlet weak var labelBank: UILabel! @IBOutlet weak var labelUserNameInitial: UILabel! @IBOutlet weak var settingButton: UIButton! @IBOutlet weak var aboutGmeButton: UIButton! @IBOutlet weak var logoutButton: UIButton! @IBOutlet weak var aboutIconImageView: UIImageView! @IBOutlet weak var settingIconImageView: UIImageView! @IBOutlet weak var logoutIconImageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() setUpSettingsScreen() setup() // setupBlueBackGroundTheme() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.setUpSettingsScreen() } private func setup() { self.view.backgroundColor = AppConstants.themeRedColor self.roundedBgView.layer.cornerRadius = 20 NotificationCenter.default.addObserver(self, selector: #selector(self.updateBalance(sender:)), name: self.getAvailableBalanceNotificationName(), object: nil) } @objc private func updateBalance(sender: Notification) { let balance = sender.userInfo?[SideMenuNavigationNotifications.availableBalance] as? String self.labelBalance.text = balance } private func setupBlueBackGroundTheme() { self.roundedBgView.backgroundColor = AppConstants.themeBlueColor [ labelPhone, labelEmail, labelBalance, labelWalletNumber, labelBank, labelUserNameInitial].forEach({ $0?.textColor = AppConstants.themWhiteColor }) [aboutGmeButton, settingButton, logoutButton].forEach({ $0?.setTitleColor(AppConstants.themWhiteColor, for: UIControlState.normal) }) aboutIconImageView.tintColor = AppConstants.themWhiteColor } @IBAction func aboutGme(_ sender: UIButton) { self.sideMenuController?.hideLeftView() NotificationCenter.default.post(name: self.getAboutGmeNotificationName(), object: nil, userInfo: nil) } @IBAction func support(_ sender: UIButton) { self.sideMenuController?.hideLeftView() NotificationCenter.default.post(name: self.getSupportNotificationName(), object: nil, userInfo: nil) } @IBAction func setting(_ sender: UIButton) { self.sideMenuController?.hideLeftView() NotificationCenter.default.post(name: self.getSettingNotificationName(), object: nil, userInfo: nil) } @IBAction func withDraw(_ sender: Any) { let storyboard = UIStoryboard.init(name: "Profile", bundle: Bundle.main) // if let withDrawViewController = storyboard.instantiateViewController(withIdentifier: "withdraw") as? WithdrawViewController { // self.navigationController!.pushViewController(withDrawViewController, animated: true) // } } @IBAction func logout(_ sender: Any) { let alert = UIAlertController(title: "Logout?", message: "Are you sure you want to logout?", preferredStyle: .alert) let yesAction = UIAlertAction(title: "Yes", style: .default,handler: { (action : UIAlertAction!) -> Void in // let appDelegate = UIApplication.shared.delegate as! AppDelegate // appDelegate.firstTranscationStatusForHome = true // appDelegate.firstTranscationStatusForProfileForm = true MainWireframe.logout() }) let noAction = UIAlertAction(title: "No", style: .default, handler: nil) noAction.setValue(UIColor.black, forKey: "titleTextColor") yesAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor") alert.addAction(yesAction) alert.addAction(noAction) self.present(alert, animated: true, completion: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func setUpSettingsScreen() { let store = UserDefaults.standard //PHONE labelPhone.text = store.string(forKey: UserKeys.mobileNumber) //EMAIL labelEmail.text = store.string(forKey: UserKeys.email) //NAME labelProfileName.text = store.string(forKey: UserKeys.firstName)?.capitalized //WALLET NUMBER labelWalletNumber.text = store.string(forKey: UserKeys.walletNumber) //BALANCE let balance = store.string(forKey: UserKeys.availableBalance) labelBalance.text = Utility.getCommaSeperatedString(numberString: balance ?? "") //BANK NAME labelBank.text = store.string(forKey: UserKeys.primaryBankName) //IMAGE let userDpString = store.string(forKey: UserKeys.dpUrl) if let userDpUrl = URL(string: userDpString!) { SDImageCache.shared().clearMemory() SDImageCache.shared().clearDisk() self.imageViewProfileSetting.sd_setImage(with: userDpUrl, completed: nil) labelUserNameInitial.isHidden = true imageViewProfileSetting.isHidden = false imageViewProfileSetting.contentMode = .scaleAspectFill } else { labelUserNameInitial.layer.backgroundColor = UIColor(hex: 0x2e3192).cgColor labelUserNameInitial.layer.cornerRadius = labelUserNameInitial.frame.height / 2 labelUserNameInitial.text = labelProfileName.text?.prefix(1).uppercased() labelUserNameInitial.isHidden = false imageViewProfileSetting.isHidden = true } imageViewProfileSetting.layer.cornerRadius = imageViewProfileSetting.frame.height / 2 } // Notification Names func getAboutGmeNotificationName() -> Notification.Name { return Notification.Name.init(SideMenuNavigationNotifications.aboutGme) } func getSupportNotificationName() -> Notification.Name { return Notification.Name.init(SideMenuNavigationNotifications.support) } func getSettingNotificationName() -> Notification.Name { return Notification.Name.init(SideMenuNavigationNotifications.setting) } func getAvailableBalanceNotificationName() -> Notification.Name { return Notification.Name.init(SideMenuNavigationNotifications.availableBalance) } }