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.

146 lines
4.4 KiB

5 years ago
5 years ago
  1. //
  2. // ConfirmViewController.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon Devik Kim on 07/05/2019.
  6. // Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. protocol ConfirmViewControllerDelegate: class {
  10. func confirm(_ viewController: ConfirmViewController)
  11. func cancel(_ viewController: ConfirmViewController)
  12. }
  13. struct ConfirmViewControllerConfiguration {
  14. var title: String? = "confirm_viewconroller_default_title_text".localized()
  15. var content1: String? = ""
  16. var content2: String? = ""
  17. var multiLineContent: String? = ""
  18. var confirmButtonTitle: String? = "Confirm"
  19. var cancelButtonTitle: String? = "Cancel"
  20. }
  21. class ConfirmViewController: UIViewController {
  22. weak var delegate: ConfirmViewControllerDelegate?
  23. private var configure: ConfirmViewControllerConfiguration?
  24. @IBOutlet private weak var titleLabel: UILabel!
  25. @IBOutlet private weak var content1Label: UILabel!
  26. @IBOutlet private weak var content2Label: UILabel!
  27. @IBOutlet private weak var multiLineContentLabel: UILabel!
  28. @IBOutlet private weak var mainView: UIView!
  29. @IBOutlet private weak var confirmButton: UIButton!
  30. @IBOutlet private weak var cancelButton: UIButton!
  31. @IBOutlet weak var receiverTitleLabel: UILabel!
  32. @IBOutlet weak var mobileNumberTitleLabel: UILabel!
  33. @IBOutlet weak var branchTitleLabel: UILabel!
  34. @IBOutlet weak var transparentView: UIView!
  35. @IBAction private func touchCancel(_ sender: UIButton) {
  36. cancel()
  37. }
  38. @IBAction private func touchConfirm(_ sender: UIButton) {
  39. confirm()
  40. }
  41. override func viewDidLoad() {
  42. super.viewDidLoad()
  43. self.roundView()
  44. self.titleLabel.text = self.configure?.title
  45. self.content1Label.text = self.configure?.content1
  46. self.content2Label.text = self.configure?.content2
  47. self.multiLineContentLabel.text = self.configure?.multiLineContent
  48. self.confirmButton.setTitle(self.configure?.confirmButtonTitle, for: .normal)
  49. // self.cancelButton.setTitle(self.configure?.cancelButtonTitle, for: .normal)
  50. setMultiLanguage()
  51. self.mainView.invalidateIntrinsicContentSize()
  52. let tapGestureRecognizer = UITapGestureRecognizer()
  53. transparentView.addGestureRecognizer(tapGestureRecognizer)
  54. tapGestureRecognizer.addTarget(self, action: #selector(tapGesture(_:)))
  55. tapGestureRecognizer.delegate = self
  56. confirmButton.backgroundColor = .themeRed
  57. cancelButton.setTitleColor(.themeRed, for: .normal)
  58. transparentView.backgroundColor = .themeBackgroundGray
  59. }
  60. @objc func tapGesture(_ sender: UITapGestureRecognizer) {
  61. touchCancel(UIButton())
  62. }
  63. override func viewWillAppear(_ animated: Bool) {
  64. super.viewWillAppear(animated)
  65. mainView.bottomToOrigin()
  66. }
  67. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  68. super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  69. self.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
  70. self.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
  71. }
  72. required init?(coder aDecoder: NSCoder) {
  73. super.init(coder: aDecoder)
  74. self.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
  75. self.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
  76. }
  77. func setConfigure(with configure: ConfirmViewControllerConfiguration) {
  78. self.configure = configure
  79. }
  80. private func roundView() {
  81. // mainView.layer.cornerRadius = 5
  82. // confirmButton.layer.cornerRadius = 5
  83. // cancelButton.layer.cornerRadius = 5
  84. }
  85. private func setMultiLanguage() {
  86. receiverTitleLabel.text = "receiver_text".localized()
  87. mobileNumberTitleLabel.text = "mobile_number_text".localized()
  88. branchTitleLabel.text = "branch_text".localized()
  89. // cancelButton.setTitle("cancel_text".localized(), for: .normal)
  90. //
  91. confirmButton.setTitle("confirm_text".localized(), for: .normal)
  92. }
  93. private func cancel() {
  94. mainView.originToBottom {
  95. self.dismiss(animated: true) {
  96. self.delegate?.cancel(self)
  97. }
  98. }
  99. }
  100. private func confirm() {
  101. mainView.originToBottom {
  102. self.dismiss(animated: true) {
  103. print("Touched Confirm!")
  104. self.delegate?.confirm(self)
  105. }
  106. }
  107. }
  108. }
  109. extension ConfirmViewController: UIGestureRecognizerDelegate {
  110. func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
  111. return touch.view == gestureRecognizer.view
  112. }
  113. }