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.

278 lines
11 KiB

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