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.

253 lines
9.8 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
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. struct StringConstants {
  21. static let logoutTitleText = "Logout"
  22. static let logoutConfirmationText = "Are you sure you want to logout?"
  23. static let noText = "No"
  24. static let yesText = "Yes"
  25. static let autoDebitMenuText = "Auto Debit Account"
  26. static let aboutGmeMenuText = "About GMEs"
  27. static let settingMenuText = "Settings"
  28. static let availableBalanceTitleLabelText = "Your Available Balance"
  29. static let withdrawButtonText = "Withdraw"
  30. static let gmeWalletNoTitleText = "GME Wallet No."
  31. }
  32. // @IBOutlets
  33. @IBOutlet weak var imageViewProfileSetting: UIImageView!
  34. @IBOutlet weak var labelProfileName: UILabel!
  35. @IBOutlet weak var labelPhone: UILabel!
  36. @IBOutlet weak var labelEmail: UILabel!
  37. @IBOutlet weak var roundedBgView: UIView!
  38. @IBOutlet weak var labelBalance: UILabel!
  39. @IBOutlet weak var labelWalletNumber: UILabel!
  40. @IBOutlet weak var labelBank: UILabel!
  41. @IBOutlet weak var labelUserNameInitial: UILabel!
  42. @IBOutlet weak var settingButton: UIButton!
  43. @IBOutlet weak var aboutGmeButton: UIButton!
  44. @IBOutlet weak var autoDebitAccountButton: UIButton!
  45. @IBOutlet weak var logoutButton: UIButton!
  46. @IBOutlet weak var aboutIconImageView: UIImageView!
  47. @IBOutlet weak var settingIconImageView: UIImageView!
  48. @IBOutlet weak var logoutIconImageView: UIImageView!
  49. @IBOutlet weak var withdrawButton: UIButton!
  50. @IBOutlet weak var manageAccountStackView: UIStackView!
  51. @IBOutlet weak var availableBalanceTitleLabel: UILabel!
  52. @IBOutlet weak var gmeWalletNoTitleLabel: UILabel!
  53. // Life Cycle
  54. override func viewDidLoad() {
  55. super.viewDidLoad()
  56. setUpSettingsScreen()
  57. setup()
  58. }
  59. override func viewWillAppear(_ animated: Bool) {
  60. super.viewWillAppear(animated)
  61. self.setUpSettingsScreen()
  62. }
  63. // Other Functions
  64. private func addShadow(view: UIView) {
  65. view.layer.shadowColor = UIColor.darkGray.cgColor
  66. view.layer.shadowOpacity = 0.5
  67. view.layer.shadowRadius = 2
  68. let offset = CGSize(width: 1, height: 1)
  69. view.layer.shadowOffset = offset
  70. }
  71. private func setup() {
  72. configureText()
  73. let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
  74. self.withdrawButton.isHidden = !shouldShowWithdrawButton
  75. self.manageAccountStackView.isHidden = !shouldShowWithdrawButton
  76. self.view.backgroundColor = AppConstants.themeRedColor
  77. self.roundedBgView.layer.cornerRadius = 20
  78. self.labelBalance.text = "0"
  79. NotificationCenter.default.addObserver(self, selector: #selector(self.updateBalance(sender:)), name: self.getAvailableBalanceNotificationName(), object: nil)
  80. self.addShadow(view: withdrawButton)
  81. }
  82. private func configureText() {
  83. autoDebitAccountButton.setTitle(StringConstants.autoDebitMenuText, for: UIControlState.normal)
  84. aboutGmeButton.setTitle(StringConstants.aboutGmeMenuText, for: UIControlState.normal)
  85. settingButton.setTitle(StringConstants.settingMenuText, for: UIControlState.normal)
  86. logoutButton.setTitle(StringConstants.logoutTitleText, for: UIControlState.normal)
  87. self.availableBalanceTitleLabel.text = StringConstants.availableBalanceTitleLabelText
  88. self.gmeWalletNoTitleLabel.text = StringConstants.gmeWalletNoTitleText
  89. self.withdrawButton.setTitle(StringConstants.withdrawButtonText, for: UIControlState.normal)
  90. }
  91. @objc private func updateBalance(sender: Notification) {
  92. let balance = sender.userInfo?[SideMenuNavigationNotifications.availableBalance] as? String
  93. self.labelBalance.text = balance
  94. let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
  95. self.withdrawButton.isHidden = !shouldShowWithdrawButton
  96. self.manageAccountStackView.isHidden = !shouldShowWithdrawButton
  97. }
  98. private func setupBlueBackGroundTheme() {
  99. self.roundedBgView.backgroundColor = AppConstants.themeBlueColor
  100. [ labelPhone, labelEmail, labelBalance, labelWalletNumber, labelBank, labelUserNameInitial].forEach({
  101. $0?.textColor = AppConstants.themWhiteColor
  102. })
  103. [aboutGmeButton, settingButton, logoutButton].forEach({
  104. $0?.setTitleColor(AppConstants.themWhiteColor, for: UIControlState.normal)
  105. })
  106. aboutIconImageView.tintColor = AppConstants.themWhiteColor
  107. }
  108. @IBAction func withdraw(_ sender: UIButton) {
  109. self.sideMenuController?.hideLeftView()
  110. NotificationCenter.default.post(name: self.getWithdrawNotificationName(), object: nil, userInfo: nil)
  111. }
  112. @IBAction func openKftcAccountList(_ sender: UIButton) {
  113. self.sideMenuController?.hideLeftView()
  114. NotificationCenter.default.post(name: self.getKftcAccountListNotificationName(), object: nil, userInfo: nil)
  115. }
  116. @IBAction func aboutGme(_ sender: UIButton) {
  117. self.sideMenuController?.hideLeftView()
  118. NotificationCenter.default.post(name: self.getAboutGmeNotificationName(), object: nil, userInfo: nil)
  119. }
  120. @IBAction func support(_ sender: UIButton) {
  121. self.sideMenuController?.hideLeftView()
  122. NotificationCenter.default.post(name: self.getSupportNotificationName(), object: nil, userInfo: nil)
  123. }
  124. @IBAction func setting(_ sender: UIButton) {
  125. self.sideMenuController?.hideLeftView()
  126. NotificationCenter.default.post(name: self.getSettingNotificationName(), object: nil, userInfo: nil)
  127. }
  128. @IBAction func logout(_ sender: Any) {
  129. let alert = UIAlertController(title: StringConstants.logoutTitleText, message: StringConstants.logoutConfirmationText, preferredStyle: .alert)
  130. let yesAction = UIAlertAction(title: StringConstants.yesText, style: .default,handler: {
  131. (action : UIAlertAction!) -> Void in
  132. MainWireframe.logout()
  133. })
  134. let noAction = UIAlertAction(title: StringConstants.noText, style: .default, handler: nil)
  135. noAction.setValue(UIColor.black, forKey: "titleTextColor")
  136. yesAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
  137. alert.addAction(yesAction)
  138. alert.addAction(noAction)
  139. self.present(alert, animated: true, completion: nil)
  140. }
  141. override func didReceiveMemoryWarning() {
  142. super.didReceiveMemoryWarning()
  143. // Dispose of any resources that can be recreated.
  144. }
  145. func setUpSettingsScreen() {
  146. let store = UserDefaults.standard
  147. //PHONE
  148. labelPhone.text = store.string(forKey: UserKeys.mobileNumber)
  149. //EMAIL
  150. labelEmail.text = store.string(forKey: UserKeys.email)
  151. //NAME
  152. labelProfileName.text = store.string(forKey: UserKeys.firstName)?.capitalized
  153. //WALLET NUMBER
  154. labelWalletNumber.text = store.string(forKey: UserKeys.walletNumber)
  155. //BALANCE
  156. let balance = store.string(forKey: UserKeys.availableBalance)
  157. labelBalance.text = Utility.getCommaSeperatedString(numberString: balance ?? "")
  158. //BANK NAME
  159. labelBank.text = store.string(forKey: UserKeys.primaryBankName)
  160. //IMAGE
  161. let userDpString = store.string(forKey: UserKeys.dpUrl)
  162. if let userDpUrl = URL(string: userDpString!) {
  163. SDImageCache.shared().clearMemory()
  164. SDImageCache.shared().clearDisk()
  165. self.imageViewProfileSetting.sd_setImage(with: userDpUrl, completed: nil)
  166. labelUserNameInitial.isHidden = true
  167. imageViewProfileSetting.isHidden = false
  168. imageViewProfileSetting.contentMode = .scaleAspectFill
  169. } else {
  170. labelUserNameInitial.layer.backgroundColor = UIColor(hex: 0x2e3192).cgColor
  171. labelUserNameInitial.layer.cornerRadius = labelUserNameInitial.frame.height / 2
  172. labelUserNameInitial.text = labelProfileName.text?.prefix(1).uppercased()
  173. labelUserNameInitial.isHidden = false
  174. imageViewProfileSetting.isHidden = true
  175. }
  176. imageViewProfileSetting.layer.cornerRadius = imageViewProfileSetting.frame.height / 2
  177. }
  178. // Notification Names
  179. func getAboutGmeNotificationName() -> Notification.Name {
  180. return Notification.Name.init(SideMenuNavigationNotifications.aboutGme)
  181. }
  182. func getSupportNotificationName() -> Notification.Name {
  183. return Notification.Name.init(SideMenuNavigationNotifications.support)
  184. }
  185. func getSettingNotificationName() -> Notification.Name {
  186. return Notification.Name.init(SideMenuNavigationNotifications.setting)
  187. }
  188. func getAvailableBalanceNotificationName() -> Notification.Name {
  189. return Notification.Name.init(SideMenuNavigationNotifications.availableBalance)
  190. }
  191. func getWithdrawNotificationName() -> Notification.Name {
  192. return Notification.Name.init(SideMenuNavigationNotifications.withdraw)
  193. }
  194. func getKftcAccountListNotificationName() -> Notification.Name {
  195. return Notification.Name.init(SideMenuNavigationNotifications.KftcAccountList)
  196. }
  197. }