You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
8.0 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // SideMenuViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 2/22/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. import SDWebImage
  10. import LGSideMenuController
  11. struct SideMenuNavigationNotifications {
  12. static let aboutGme = "aboutGme"
  13. static let support = "support"
  14. static let setting = "setting"
  15. static let availableBalance = "Available_Balance"
  16. static let withdraw = "withdraw"
  17. static let KftcAccountList = "KftcAccountList"
  18. }
  19. class SideMenuViewController: UIViewController {
  20. @IBOutlet weak var imageViewProfileSetting: UIImageView!
  21. @IBOutlet weak var labelProfileName: UILabel!
  22. @IBOutlet weak var labelPhone: UILabel!
  23. @IBOutlet weak var labelEmail: UILabel!
  24. @IBOutlet weak var roundedBgView: UIView!
  25. @IBOutlet weak var labelBalance: UILabel!
  26. @IBOutlet weak var labelWalletNumber: UILabel!
  27. @IBOutlet weak var labelBank: UILabel!
  28. @IBOutlet weak var labelUserNameInitial: UILabel!
  29. @IBOutlet weak var settingButton: UIButton!
  30. @IBOutlet weak var aboutGmeButton: UIButton!
  31. @IBOutlet weak var logoutButton: UIButton!
  32. @IBOutlet weak var aboutIconImageView: UIImageView!
  33. @IBOutlet weak var settingIconImageView: UIImageView!
  34. @IBOutlet weak var logoutIconImageView: UIImageView!
  35. @IBOutlet weak var withdrawButton: UIButton!
  36. override func viewDidLoad() {
  37. super.viewDidLoad()
  38. setUpSettingsScreen()
  39. setup()
  40. }
  41. override func viewWillAppear(_ animated: Bool) {
  42. super.viewWillAppear(animated)
  43. self.setUpSettingsScreen()
  44. }
  45. private func addShadow(view: UIView) {
  46. view.layer.shadowColor = UIColor.darkGray.cgColor
  47. view.layer.shadowOpacity = 0.5
  48. view.layer.shadowRadius = 2
  49. let offset = CGSize(width: 1, height: 1)
  50. view.layer.shadowOffset = offset
  51. }
  52. private func setup() {
  53. let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
  54. self.withdrawButton.isHidden = !shouldShowWithdrawButton
  55. self.view.backgroundColor = AppConstants.themeRedColor
  56. self.roundedBgView.layer.cornerRadius = 20
  57. self.labelBalance.text = "0"
  58. NotificationCenter.default.addObserver(self, selector: #selector(self.updateBalance(sender:)), name: self.getAvailableBalanceNotificationName(), object: nil)
  59. self.addShadow(view: withdrawButton)
  60. }
  61. @objc private func updateBalance(sender: Notification) {
  62. let balance = sender.userInfo?[SideMenuNavigationNotifications.availableBalance] as? String
  63. self.labelBalance.text = balance
  64. let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
  65. self.withdrawButton.isHidden = !shouldShowWithdrawButton
  66. }
  67. private func setupBlueBackGroundTheme() {
  68. self.roundedBgView.backgroundColor = AppConstants.themeBlueColor
  69. [ labelPhone, labelEmail, labelBalance, labelWalletNumber, labelBank, labelUserNameInitial].forEach({
  70. $0?.textColor = AppConstants.themWhiteColor
  71. })
  72. [aboutGmeButton, settingButton, logoutButton].forEach({
  73. $0?.setTitleColor(AppConstants.themWhiteColor, for: UIControlState.normal)
  74. })
  75. aboutIconImageView.tintColor = AppConstants.themWhiteColor
  76. }
  77. @IBAction func withdraw(_ sender: UIButton) {
  78. self.sideMenuController?.hideLeftView()
  79. NotificationCenter.default.post(name: self.getWithdrawNotificationName(), object: nil, userInfo: nil)
  80. }
  81. @IBAction func openKftcAccountList(_ sender: UIButton) {
  82. self.sideMenuController?.hideLeftView()
  83. NotificationCenter.default.post(name: self.getKftcAccountListNotificationName(), object: nil, userInfo: nil)
  84. }
  85. @IBAction func aboutGme(_ sender: UIButton) {
  86. self.sideMenuController?.hideLeftView()
  87. NotificationCenter.default.post(name: self.getAboutGmeNotificationName(), object: nil, userInfo: nil)
  88. }
  89. @IBAction func support(_ sender: UIButton) {
  90. self.sideMenuController?.hideLeftView()
  91. NotificationCenter.default.post(name: self.getSupportNotificationName(), object: nil, userInfo: nil)
  92. }
  93. @IBAction func setting(_ sender: UIButton) {
  94. self.sideMenuController?.hideLeftView()
  95. NotificationCenter.default.post(name: self.getSettingNotificationName(), object: nil, userInfo: nil)
  96. }
  97. @IBAction func logout(_ sender: Any) {
  98. let alert = UIAlertController(title: "Logout?", message: "Are you sure you want to logout?", preferredStyle: .alert)
  99. let yesAction = UIAlertAction(title: "Yes", style: .default,handler: {
  100. (action : UIAlertAction!) -> Void in
  101. MainWireframe.logout()
  102. })
  103. let noAction = UIAlertAction(title: "No", style: .default, handler: nil)
  104. noAction.setValue(UIColor.black, forKey: "titleTextColor")
  105. yesAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
  106. alert.addAction(yesAction)
  107. alert.addAction(noAction)
  108. self.present(alert, animated: true, completion: nil)
  109. }
  110. override func didReceiveMemoryWarning() {
  111. super.didReceiveMemoryWarning()
  112. // Dispose of any resources that can be recreated.
  113. }
  114. func setUpSettingsScreen() {
  115. let store = UserDefaults.standard
  116. //PHONE
  117. labelPhone.text = store.string(forKey: UserKeys.mobileNumber)
  118. //EMAIL
  119. labelEmail.text = store.string(forKey: UserKeys.email)
  120. //NAME
  121. labelProfileName.text = store.string(forKey: UserKeys.firstName)?.capitalized
  122. //WALLET NUMBER
  123. labelWalletNumber.text = store.string(forKey: UserKeys.walletNumber)
  124. //BALANCE
  125. let balance = store.string(forKey: UserKeys.availableBalance)
  126. labelBalance.text = Utility.getCommaSeperatedString(numberString: balance ?? "")
  127. //BANK NAME
  128. labelBank.text = store.string(forKey: UserKeys.primaryBankName)
  129. //IMAGE
  130. let userDpString = store.string(forKey: UserKeys.dpUrl)
  131. if let userDpUrl = URL(string: userDpString!) {
  132. SDImageCache.shared().clearMemory()
  133. SDImageCache.shared().clearDisk()
  134. self.imageViewProfileSetting.sd_setImage(with: userDpUrl, completed: nil)
  135. labelUserNameInitial.isHidden = true
  136. imageViewProfileSetting.isHidden = false
  137. imageViewProfileSetting.contentMode = .scaleAspectFill
  138. } else {
  139. labelUserNameInitial.layer.backgroundColor = UIColor(hex: 0x2e3192).cgColor
  140. labelUserNameInitial.layer.cornerRadius = labelUserNameInitial.frame.height / 2
  141. labelUserNameInitial.text = labelProfileName.text?.prefix(1).uppercased()
  142. labelUserNameInitial.isHidden = false
  143. imageViewProfileSetting.isHidden = true
  144. }
  145. imageViewProfileSetting.layer.cornerRadius = imageViewProfileSetting.frame.height / 2
  146. }
  147. // Notification Names
  148. func getAboutGmeNotificationName() -> Notification.Name {
  149. return Notification.Name.init(SideMenuNavigationNotifications.aboutGme)
  150. }
  151. func getSupportNotificationName() -> Notification.Name {
  152. return Notification.Name.init(SideMenuNavigationNotifications.support)
  153. }
  154. func getSettingNotificationName() -> Notification.Name {
  155. return Notification.Name.init(SideMenuNavigationNotifications.setting)
  156. }
  157. func getAvailableBalanceNotificationName() -> Notification.Name {
  158. return Notification.Name.init(SideMenuNavigationNotifications.availableBalance)
  159. }
  160. func getWithdrawNotificationName() -> Notification.Name {
  161. return Notification.Name.init(SideMenuNavigationNotifications.withdraw)
  162. }
  163. func getKftcAccountListNotificationName() -> Notification.Name {
  164. return Notification.Name.init(SideMenuNavigationNotifications.KftcAccountList)
  165. }
  166. }