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.

143 lines
4.4 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. // PennyTestViewController.swift
  3. // GME Remit
  4. //
  5. // Created by Mac on 11/27/18.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class PennyTestViewController: UIViewController {
  10. struct StringConstants {
  11. let proceedText = "proceed_text".localized()
  12. let notNowText = "not_now_text".localized()
  13. }
  14. // MARK: Properties
  15. var presenter: PennyTestModuleInterface?
  16. var model: KYCResponse?
  17. var backGroundView: UIView?
  18. // MARK: IBOutlets
  19. @IBOutlet weak var dismissButton: UIButton!
  20. @IBOutlet weak var iconImageView: UIImageView!
  21. @IBOutlet weak var infoLabel: UILabel!
  22. @IBOutlet weak var proceedButton: UIButton!
  23. // MARK: VC's Life cycle
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. NotificationCenter.default.addObserver(self, selector: #selector(self.closePennyTest(sender:)), name: NSNotification.Name.init("closePennyTest"), object: nil)
  27. self.setup()
  28. }
  29. @objc private func closePennyTest(sender: Notification) {
  30. self.dismiss(animated: true, completion: nil)
  31. }
  32. override func viewWillAppear(_ animated: Bool) {
  33. super.viewWillAppear(animated)
  34. UserDefaults.standard.set(true, forKey: AppConstants.pennyTestPresentedOnce)
  35. self.navigationItem.title = "penny_test_title_text".localized()
  36. self.setupNormalNavigation()
  37. self.navigationItem.hidesBackButton = true
  38. }
  39. override func viewWillDisappear(_ animated: Bool) {
  40. super.viewWillDisappear(animated)
  41. self.navigationItem.title = ""
  42. UserDefaults.standard.set(true, forKey: AppConstants.pennyTestPresentedOnce)
  43. }
  44. // MARK: IBActions
  45. // MARK: Other Functions
  46. private func setup() {
  47. // all setup should be done here
  48. self.setupNormalNavigation()
  49. self.proceedButton.rounded()
  50. iconImageView.rounded()
  51. iconImageView.layer.borderColor = AppConstants.themeRedColor.cgColor
  52. iconImageView.layer.borderWidth = 2
  53. iconImageView.layer.contentsScale = UIScreen.main.scale
  54. if let _view = self.backGroundView {
  55. _view.frame = self.view.frame
  56. self.view.addSubview(_view)
  57. }
  58. UserDefaults.standard.set(true, forKey: AppConstants.pennyTestPresentedOnce)
  59. configureText()
  60. }
  61. private func configureText() {
  62. self.proceedButton.setTitle(StringConstants().proceedText, for: UIControlState.normal)
  63. self.dismissButton.setTitle(StringConstants().notNowText, for: UIControlState.normal)
  64. // penny_test_promt_description_text
  65. infoLabel.text = "penny_test_promt_description_text".localized()
  66. }
  67. @IBAction func proceed(_ sender: UIButton) {
  68. self.proceed()
  69. }
  70. @IBAction func dismiss(_ sender: UIButton) {
  71. self.updatePennyTestCancelledStatus()
  72. self.dismiss(animated: true, completion: nil)
  73. }
  74. private func proceed() {
  75. let userId = Utility.getMyUserName()
  76. self.showLoading()
  77. self.initiate(userId: userId, isResendRequest: "N", success: { result in
  78. self.hideLoading()
  79. UserDefaults.standard.set(result.message, forKey: AppConstants.pennyTestServerMessage)
  80. self.updatePennyTestRequestStatus()
  81. let wireframe = PennyTestSubmitWireframe()
  82. if let navigation = self.navigationController {
  83. wireframe.parentViewController = self
  84. wireframe.pushMainView(in: navigation)
  85. }
  86. }) { (error) in
  87. self.hideLoading()
  88. self.alert(message: error.localizedDescription)
  89. }
  90. }
  91. private func updatePennyTestRequestStatus() {
  92. let _default = UserDefaults.standard
  93. _default.set(PennyTestStatusCode.requested.rawValue, forKey: AppConstants.pennyTestStatusCode)
  94. }
  95. private func updatePennyTestCancelledStatus() {
  96. let _default = UserDefaults.standard
  97. _default.set(PennyTestStatusCode.cancelled.rawValue, forKey: AppConstants.pennyTestStatusCode)
  98. }
  99. func showLoading() {
  100. self.showProgressHud()
  101. }
  102. func hideLoading() {
  103. self.hideProgressHud()
  104. }
  105. }
  106. // MARK: PennyTestViewInterface
  107. extension PennyTestViewController: PennyTestViewInterface {
  108. }
  109. extension PennyTestViewController: InitiatePennyTestService {
  110. }