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.

340 lines
12 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
  1. //
  2. // SendMoneyParentViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 28/08/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. import Localize_Swift
  10. protocol HUDStatusDelegate {
  11. func showLoading()
  12. func hideLoading()
  13. }
  14. protocol SendMoneyPaymentModeActionDelegate {
  15. func selected(bank: SendMoneyBank?)
  16. func selected(branch: SendMoneyBankBranch?)
  17. func selected(payoutMethod: SendMoneyPayoutMode?)
  18. func added(acountNumber: String)
  19. func continueToExchangeAction()
  20. }
  21. protocol SendMoneyExchangeRateActionDelegate {
  22. func continueToVerificationAction()
  23. func calculated(model: SendMoneyExchangeRateModel?)
  24. }
  25. class SendMoneyRequestModel {
  26. var paymemtMode: SendMoneyPayoutMode?
  27. var bank: SendMoneyBank?
  28. var branch: SendMoneyBankBranch?
  29. var accountNumber: String?
  30. var payingAmount: String?
  31. var exchangeRateDetail: SendMoneyExchangeRateModel?
  32. var transactionPassword: String?
  33. var autoDebitAccount: Account?
  34. }
  35. class SendMoneyParentViewController: UIViewController {
  36. enum StateButtons: Int {
  37. case paymentMode = 1
  38. case exchange = 2
  39. case verification = 3
  40. }
  41. struct Constants {
  42. static let stateRedColor = UIColor.init(hex: "#EC1C24")
  43. static let stateGreenColor = AppConstants.themeBlueColor
  44. static let stateLabelGreyColor = UIColor.init(hex: "4a4a4a")
  45. }
  46. struct StringConstants {
  47. let payoutModeText = "payout_mode_text".localized()
  48. let amountDetailText = "amount_detail_text".localized()
  49. let verificationDetailText = "verification_detail_text".localized()
  50. }
  51. // MARK: IBOutlets
  52. @IBOutlet weak var containerView: UIView!
  53. @IBOutlet weak var paymentModeButton: UIButton!
  54. @IBOutlet weak var exchangeRateButton: UIButton!
  55. @IBOutlet weak var verificationButton: UIButton!
  56. @IBOutlet weak var paymentModeLabel: UILabel!
  57. @IBOutlet weak var exchangeRateLabel: UILabel!
  58. @IBOutlet weak var verificationLabel: UILabel!
  59. // MARK: Properties
  60. var paymentModeViewController: UIViewController?
  61. var exchangeViewController: UIViewController?
  62. var verificationViewController: UIViewController?
  63. var requestModel: SendMoneyRequestModel?
  64. var presenter: SendMoneyParentModuleInterface?
  65. var stateButtons: [UIButton] = []
  66. var state: StateButtons = .paymentMode {
  67. didSet {
  68. self.updateState(state: state)
  69. }
  70. }
  71. var receipient: Recipient? {
  72. didSet {
  73. print( self.receipient?.firstName)
  74. }
  75. }
  76. var account: Account? {
  77. didSet {
  78. self.requestModel?.autoDebitAccount = account
  79. }
  80. }
  81. // MARK: VC's Life cycle
  82. override func viewDidLoad() {
  83. super.viewDidLoad()
  84. self.setup()
  85. self.presenter?.viewIsReady()
  86. self.setupViewControllers()
  87. self.addPaymentModeViewController()
  88. }
  89. override func viewWillAppear(_ animated: Bool) {
  90. super.viewWillAppear(animated)
  91. setTitle(title: "send_money_text".localized())
  92. }
  93. override func viewWillDisappear(_ animated: Bool) {
  94. super.viewWillDisappear(animated)
  95. self.navigationItem.title = ""
  96. }
  97. // MARK: IBActions
  98. @IBAction func paymentMode(_ sender: UIButton) {
  99. self.addPaymentModeViewController()
  100. self.state = StateButtons.paymentMode
  101. }
  102. @IBAction func exchangeRate(_ sender: UIButton) {
  103. self.addExchangeViewController()
  104. self.state = StateButtons.exchange
  105. }
  106. @IBAction func verification(_ sender: UIButton) {
  107. self.addVerificationViewController()
  108. self.state = StateButtons.verification
  109. }
  110. // MARK: Other Functions
  111. private func setup() {
  112. // all setup should be done here
  113. self.setTitle(title: "send_money_text".localized())
  114. self.state = StateButtons.paymentMode
  115. self.configureViews()
  116. self.requestModel = SendMoneyRequestModel()
  117. configureLanguage()
  118. }
  119. private func configureLanguage() {
  120. self.paymentModeLabel.text = StringConstants().payoutModeText
  121. self.exchangeRateLabel.text = StringConstants().amountDetailText
  122. self.verificationLabel.text = StringConstants().verificationDetailText
  123. }
  124. private func setupNavigationBar() {
  125. }
  126. private func setTitle(title: String) {
  127. self.navigationItem.title = title
  128. }
  129. private func setupViewControllers() {
  130. let paymentModelWireframe = SendMoneyPaymentModeWireframe()
  131. let pvc = paymentModelWireframe.getMainView() as! SendMoneyPaymentModeViewController
  132. pvc.recipient = self.receipient
  133. pvc.hudDelegate = self
  134. pvc.actionDelegate = self
  135. self.paymentModeViewController = pvc
  136. let exchangeViewWireframe = SendMoneyExchangeRateWireframe()
  137. let evc = exchangeViewWireframe.getMainView() as! SendMoneyExchangeRateViewController
  138. evc.reciepient = self.receipient
  139. evc.actionDelegate = self
  140. evc.hudDelegate = self
  141. self.exchangeViewController = evc
  142. let verificationWireframe = SendMoneyVerificationWireframe()
  143. let vvc = verificationWireframe.getMainView() as! SendMoneyVerificationViewController
  144. vvc.reciepient = self.receipient
  145. vvc.requestModel = self.requestModel
  146. vvc.hudDelegate = self
  147. self.verificationViewController = vvc
  148. }
  149. private func configureViews() {
  150. self.paymentModeButton.tag = 1
  151. self.exchangeRateButton.tag = 2
  152. self.verificationButton.tag = 3
  153. self.stateButtons = [paymentModeButton,exchangeRateButton, verificationButton ]
  154. [paymentModeButton, exchangeRateButton, verificationButton].forEach({
  155. $0?.rounded()
  156. })
  157. }
  158. func updateState(state: StateButtons) {
  159. switch state {
  160. case .paymentMode:
  161. // buttons
  162. self.paymentModeButton.backgroundColor = Constants.stateGreenColor
  163. self.exchangeRateButton.backgroundColor = Constants.stateRedColor
  164. self.verificationButton.backgroundColor = Constants.stateRedColor
  165. self.exchangeRateButton.isUserInteractionEnabled = false
  166. self.verificationButton.isUserInteractionEnabled = false
  167. // labels
  168. self.paymentModeLabel.textColor = Constants.stateGreenColor
  169. self.exchangeRateLabel.textColor = Constants.stateLabelGreyColor
  170. self.verificationLabel.textColor = Constants.stateLabelGreyColor
  171. self.requestModel?.bank = nil
  172. self.requestModel?.branch = nil
  173. case .exchange:
  174. // buttons
  175. self.paymentModeButton.backgroundColor = Constants.stateGreenColor
  176. self.exchangeRateButton.backgroundColor = Constants.stateGreenColor
  177. self.verificationButton.backgroundColor = Constants.stateRedColor
  178. self.exchangeRateButton.isUserInteractionEnabled = true
  179. self.verificationButton.isUserInteractionEnabled = false
  180. // labels
  181. self.paymentModeLabel.textColor = Constants.stateLabelGreyColor
  182. self.exchangeRateLabel.textColor = Constants.stateGreenColor
  183. self.verificationLabel.textColor = Constants.stateLabelGreyColor
  184. case .verification:
  185. // button
  186. self.paymentModeButton.backgroundColor = Constants.stateGreenColor
  187. self.exchangeRateButton.backgroundColor = Constants.stateGreenColor
  188. self.verificationButton.backgroundColor = Constants.stateGreenColor
  189. self.exchangeRateButton.isUserInteractionEnabled = true
  190. // labels
  191. self.paymentModeLabel.textColor = Constants.stateLabelGreyColor
  192. self.exchangeRateLabel.textColor = Constants.stateLabelGreyColor
  193. self.verificationLabel.textColor = Constants.stateLabelGreyColor
  194. }
  195. }
  196. func addPaymentModeViewController() {
  197. guard let paymentModeViewController = self.paymentModeViewController else {return}
  198. self.addChildViewController(paymentModeViewController)
  199. UIView.transition(with: self.containerView, duration: 0.33, options: .transitionCrossDissolve, animations: {
  200. self.containerView.addSubview(paymentModeViewController.view)
  201. }, completion: nil)
  202. paymentModeViewController.view.frame = containerView.bounds
  203. paymentModeViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  204. paymentModeViewController.didMove(toParentViewController: self)
  205. }
  206. func addExchangeViewController() {
  207. guard let exchangeViewController = self.exchangeViewController as? SendMoneyExchangeRateViewController else {return}
  208. exchangeViewController.requestModel = self.requestModel
  209. exchangeViewController.actionDelegate = self
  210. self.addChildViewController(exchangeViewController)
  211. UIView.transition(with: self.containerView, duration: 0.33, options: .transitionCrossDissolve, animations: {
  212. self.containerView.addSubview(exchangeViewController.view)
  213. }, completion: nil)
  214. exchangeViewController.view.frame = containerView.bounds
  215. exchangeViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  216. exchangeViewController.didMove(toParentViewController: self)
  217. }
  218. func addVerificationViewController() {
  219. guard let verificationViewController = self.verificationViewController as? SendMoneyVerificationViewController else {return}
  220. verificationViewController.reciepient = self.receipient
  221. verificationViewController.requestModel = self.requestModel
  222. self.addChildViewController(verificationViewController)
  223. UIView.transition(with: self.containerView, duration: 0.33, options: .transitionCrossDissolve, animations: {
  224. self.containerView.addSubview(verificationViewController.view)
  225. }, completion: nil)
  226. verificationViewController.view.frame = containerView.bounds
  227. verificationViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  228. verificationViewController.didMove(toParentViewController: self)
  229. }
  230. }
  231. // MARK: SendMoneyParentViewInterface
  232. extension SendMoneyParentViewController: SendMoneyParentViewInterface {
  233. func show(model: Recipient) {
  234. self.receipient = model
  235. }
  236. func show(model: Account) {
  237. self.account = model
  238. }
  239. }
  240. extension SendMoneyParentViewController: HUDStatusDelegate {
  241. func showLoading() {
  242. self.showProgressHud()
  243. }
  244. func hideLoading() {
  245. self.hideProgressHud()
  246. }
  247. }
  248. extension SendMoneyParentViewController: SendMoneyPaymentModeActionDelegate {
  249. func selected(bank: SendMoneyBank?) {
  250. self.requestModel?.bank = bank
  251. }
  252. func selected(branch: SendMoneyBankBranch?) {
  253. self.requestModel?.branch = branch
  254. }
  255. func selected(payoutMethod: SendMoneyPayoutMode?) {
  256. self.requestModel?.paymemtMode = payoutMethod
  257. }
  258. func continueToExchangeAction() {
  259. self.addExchangeViewController()
  260. self.state = StateButtons.exchange
  261. }
  262. func added(acountNumber: String) {
  263. self.requestModel?.accountNumber = acountNumber
  264. }
  265. }
  266. extension SendMoneyParentViewController: SendMoneyExchangeRateActionDelegate {
  267. func continueToVerificationAction() {
  268. self.addVerificationViewController()
  269. self.state = StateButtons.verification
  270. }
  271. func calculated(model: SendMoneyExchangeRateModel?) {
  272. self.requestModel?.exchangeRateDetail = model
  273. }
  274. }