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.2 KiB

  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 {
  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. 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. }
  57. @objc func tapGesture(_ sender: UITapGestureRecognizer) {
  58. touchCancel(UIButton())
  59. }
  60. override func viewWillAppear(_ animated: Bool) {
  61. super.viewWillAppear(animated)
  62. mainView.bottomToOrigin()
  63. }
  64. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  65. super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  66. self.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
  67. self.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
  68. }
  69. required init?(coder aDecoder: NSCoder) {
  70. super.init(coder: aDecoder)
  71. self.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
  72. self.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
  73. }
  74. func setConfigure(with configure: ConfirmViewControllerConfiguration){
  75. self.configure = configure
  76. }
  77. private func roundView(){
  78. mainView.layer.cornerRadius = 5
  79. confirmButton.layer.cornerRadius = 5
  80. cancelButton.layer.cornerRadius = 5
  81. }
  82. private func setMultiLanguage(){
  83. receiverTitleLabel.text = "receiver_text".localized()
  84. mobileNumberTitleLabel.text = "mobile_number_text".localized()
  85. branchTitleLabel.text = "branch_text".localized()
  86. cancelButton.setTitle("cancel_text".localized(), for: .normal)
  87. confirmButton.setTitle("confirm_text".localized(), for: .normal)
  88. }
  89. private func cancel(){
  90. mainView.originToBottom(){
  91. self.dismiss(animated: true){
  92. self.delegate?.cancel(self)
  93. }
  94. }
  95. }
  96. private func confirm(){
  97. mainView.originToBottom(){
  98. self.dismiss(animated: true){
  99. print("Touched Confirm!")
  100. self.delegate?.confirm(self)
  101. }
  102. }
  103. }
  104. }
  105. extension ConfirmViewController: UIGestureRecognizerDelegate {
  106. func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
  107. return touch.view == gestureRecognizer.view
  108. }
  109. }