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.

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