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.

257 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.manageAccountStackView.isHidden = true
  79. self.view.backgroundColor = AppConstants.themeRedColor
  80. self.roundedBgView.layer.cornerRadius = 20
  81. self.labelBalance.text = "0"
  82. NotificationCenter.default.addObserver(self, selector: #selector(self.updateBalance(sender:)), name: self.getAvailableBalanceNotificationName(), object: nil)
  83. self.addShadow(view: withdrawButton)
  84. }
  85. @objc private func configureText() {
  86. autoDebitAccountButton.setTitle(StringConstants().autoDebitMenuText, for: UIControlState.normal)
  87. aboutGmeButton.setTitle(StringConstants().aboutGmeMenuText, for: UIControlState.normal)
  88. settingButton.setTitle(StringConstants().settingMenuText, for: UIControlState.normal)
  89. logoutButton.setTitle(StringConstants().logoutTitleText, for: UIControlState.normal)
  90. self.availableBalanceTitleLabel.text = StringConstants().availableBalanceTitleLabelText
  91. self.gmeWalletNoTitleLabel.text = StringConstants().gmeWalletNoTitleText
  92. self.withdrawButton.setTitle(StringConstants().withdrawButtonText, for: UIControlState.normal)
  93. }
  94. @objc private func updateBalance(sender: Notification) {
  95. let balance = sender.userInfo?[SideMenuNavigationNotifications.availableBalance] as? String
  96. self.labelBalance.text = balance
  97. let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
  98. self.withdrawButton.isHidden = !shouldShowWithdrawButton
  99. // self.manageAccountStackView.isHidden = !shouldShowWithdrawButton
  100. self.manageAccountStackView.isHidden = true
  101. }
  102. private func setupBlueBackGroundTheme() {
  103. self.roundedBgView.backgroundColor = AppConstants.themeBlueColor
  104. [ labelPhone, labelEmail, labelBalance, labelWalletNumber, labelBank, labelUserNameInitial].forEach({
  105. $0?.textColor = AppConstants.themWhiteColor
  106. })
  107. [aboutGmeButton, settingButton, logoutButton].forEach({
  108. $0?.setTitleColor(AppConstants.themWhiteColor, for: UIControlState.normal)
  109. })
  110. aboutIconImageView.tintColor = AppConstants.themWhiteColor
  111. }
  112. @IBAction func withdraw(_ sender: UIButton) {
  113. self.sideMenuController?.hideLeftView()
  114. NotificationCenter.default.post(name: self.getWithdrawNotificationName(), object: nil, userInfo: nil)
  115. }
  116. @IBAction func openKftcAccountList(_ sender: UIButton) {
  117. self.sideMenuController?.hideLeftView()
  118. NotificationCenter.default.post(name: self.getKftcAccountListNotificationName(), object: nil, userInfo: nil)
  119. }
  120. @IBAction func aboutGme(_ sender: UIButton) {
  121. self.sideMenuController?.hideLeftView()
  122. NotificationCenter.default.post(name: self.getAboutGmeNotificationName(), object: nil, userInfo: nil)
  123. }
  124. @IBAction func support(_ sender: UIButton) {
  125. self.sideMenuController?.hideLeftView()
  126. NotificationCenter.default.post(name: self.getSupportNotificationName(), object: nil, userInfo: nil)
  127. }
  128. @IBAction func setting(_ sender: UIButton) {
  129. self.sideMenuController?.hideLeftView()
  130. NotificationCenter.default.post(name: self.getSettingNotificationName(), object: nil, userInfo: nil)
  131. }
  132. @IBAction func logout(_ sender: Any) {
  133. let alert = UIAlertController(title: StringConstants().logoutTitleText, message: StringConstants().logoutConfirmationText, preferredStyle: .alert)
  134. let yesAction = UIAlertAction(title: StringConstants().yesText, style: .default,handler: {
  135. (action : UIAlertAction!) -> Void in
  136. MainWireframe.logout()
  137. })
  138. let noAction = UIAlertAction(title: StringConstants().noText, style: .default, handler: nil)
  139. noAction.setValue(UIColor.black, forKey: "titleTextColor")
  140. yesAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
  141. alert.addAction(yesAction)
  142. alert.addAction(noAction)
  143. self.present(alert, animated: true, completion: nil)
  144. }
  145. override func didReceiveMemoryWarning() {
  146. super.didReceiveMemoryWarning()
  147. // Dispose of any resources that can be recreated.
  148. }
  149. func setUpSettingsScreen() {
  150. let store = UserDefaults.standard
  151. //PHONE
  152. labelPhone.text = store.string(forKey: UserKeys.mobileNumber)
  153. //EMAIL
  154. labelEmail.text = store.string(forKey: UserKeys.email)
  155. //NAME
  156. labelProfileName.text = store.string(forKey: UserKeys.firstName)?.capitalized
  157. //WALLET NUMBER
  158. labelWalletNumber.text = store.string(forKey: UserKeys.walletNumber)
  159. //BALANCE
  160. let balance = store.string(forKey: UserKeys.availableBalance)
  161. labelBalance.text = Utility.getCommaSeperatedString(numberString: balance ?? "")
  162. //BANK NAME
  163. labelBank.text = store.string(forKey: UserKeys.primaryBankName)
  164. //IMAGE
  165. let userDpString = store.string(forKey: UserKeys.dpUrl)
  166. if let userDpUrl = URL(string: userDpString!) {
  167. SDImageCache.shared().clearMemory()
  168. SDImageCache.shared().clearDisk()
  169. self.imageViewProfileSetting.sd_setImage(with: userDpUrl, completed: nil)
  170. labelUserNameInitial.isHidden = true
  171. imageViewProfileSetting.isHidden = false
  172. imageViewProfileSetting.contentMode = .scaleAspectFill
  173. } else {
  174. labelUserNameInitial.layer.backgroundColor = UIColor(hex: 0x2e3192).cgColor
  175. labelUserNameInitial.layer.cornerRadius = labelUserNameInitial.frame.height / 2
  176. labelUserNameInitial.text = labelProfileName.text?.prefix(1).uppercased()
  177. labelUserNameInitial.isHidden = false
  178. imageViewProfileSetting.isHidden = true
  179. }
  180. imageViewProfileSetting.layer.cornerRadius = imageViewProfileSetting.frame.height / 2
  181. }
  182. // Notification Names
  183. func getAboutGmeNotificationName() -> Notification.Name {
  184. return Notification.Name.init(SideMenuNavigationNotifications.aboutGme)
  185. }
  186. func getSupportNotificationName() -> Notification.Name {
  187. return Notification.Name.init(SideMenuNavigationNotifications.support)
  188. }
  189. func getSettingNotificationName() -> Notification.Name {
  190. return Notification.Name.init(SideMenuNavigationNotifications.setting)
  191. }
  192. func getAvailableBalanceNotificationName() -> Notification.Name {
  193. return Notification.Name.init(SideMenuNavigationNotifications.availableBalance)
  194. }
  195. func getWithdrawNotificationName() -> Notification.Name {
  196. return Notification.Name.init(SideMenuNavigationNotifications.withdraw)
  197. }
  198. func getKftcAccountListNotificationName() -> Notification.Name {
  199. return Notification.Name.init(SideMenuNavigationNotifications.KftcAccountList)
  200. }
  201. }