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.

154 lines
4.3 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // LoginViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 07/09/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class LoginViewController: UIViewController {
  10. // MARK: IBOutlets
  11. @IBOutlet weak var userNameTextField: UITextField!
  12. @IBOutlet weak var passwordTextField: UITextField!
  13. // views
  14. @IBOutlet weak var backgroundTextfieldsView: UIView!
  15. @IBOutlet weak var userIdBackgroundView: UIView!
  16. @IBOutlet weak var passwordBackgroundView: UIView!
  17. @IBOutlet weak var headerTitle: UILabel!
  18. @IBOutlet weak var subtitle: UILabel!
  19. @IBOutlet weak var forgotPasswordView: UIView!
  20. @IBOutlet weak var logoImageView: UIImageView!
  21. @IBOutlet weak var loginButton: UIButton!
  22. // MARK: Properties
  23. var presenter: LoginModuleInterface?
  24. // MARK: VC's Life cycle
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. self.setup()
  28. }
  29. override func viewWillDisappear(_ animated: Bool) {
  30. super.viewWillDisappear(animated)
  31. self.navigationItem.title = ""
  32. }
  33. // MARK: IBActions
  34. @IBAction func forgotPassword(_ sender: UIButton) {
  35. self.presenter?.forgotPassword()
  36. }
  37. @IBAction func register(_ sender: UIButton) {
  38. self.presenter?.register()
  39. }
  40. @IBAction func login(_ sender: UIButton) {
  41. let username = self.userNameTextField.text!
  42. let password = self.passwordTextField.text!
  43. self.presenter?.login(userName: username, password: password)
  44. }
  45. // MARK: Other Functions
  46. private func setup() {
  47. // all setup should be done here
  48. setupNavBar()
  49. setupColor()
  50. // showAnimation()
  51. }
  52. func setupColor() {
  53. self.loginButton.backgroundColor = AppConstants.themeRedColor
  54. self.headerTitle.textColor = AppConstants.themeRedColor
  55. }
  56. func showAnimation() {
  57. setupInitialPositionsOfviews()
  58. animateViews()
  59. }
  60. private func setupInitialPositionsOfviews() {
  61. self.userIdBackgroundView.center.x -= self.view.bounds.width
  62. self.passwordBackgroundView.center.x -= self.view.bounds.width
  63. self.loginButton.transform = CGAffineTransform.init(scaleX: 0, y: 1)
  64. self.headerTitle.alpha = 0
  65. self.headerTitle.center.y -= 200
  66. self.subtitle.alpha = 0
  67. self.forgotPasswordView.alpha = 0
  68. self.logoImageView.center.y += (self.logoImageView.bounds.height + 20)
  69. self.loginButton.setTitle("", for: UIControlState.normal)
  70. }
  71. private func animateViews() {
  72. // user id
  73. UIView.animate(withDuration: 0.5, animations: {
  74. self.userIdBackgroundView.center.x += self.view.bounds.width
  75. })
  76. // password
  77. UIView.animate(withDuration: 0.5, delay: 0.3, options: [], animations: {
  78. self.passwordBackgroundView.center.x += self.view.bounds.width
  79. }, completion: nil)
  80. // login button
  81. UIView.animate(withDuration: 0.5, delay: 0.4, options: [], animations: {
  82. self.loginButton.transform = CGAffineTransform.identity
  83. }, completion: { (_) in
  84. self.loginButton.setTitle("Login", for: UIControlState.normal)
  85. })
  86. // subtitle
  87. UIView.animate(withDuration: 0.5, delay: 0.7, options: [], animations: {
  88. self.subtitle.alpha = 1
  89. }, completion: nil)
  90. // forgot password
  91. UIView.animate(withDuration: 0.5, delay: 0.9, options: [], animations: {
  92. self.forgotPasswordView.alpha = 1
  93. })
  94. // header title
  95. // logoimageview
  96. UIView.animate(withDuration: 0.7, delay: 0, options: [], animations: {
  97. // todo
  98. self.headerTitle.alpha = 1
  99. self.headerTitle.center.y += 200
  100. self.logoImageView.center.y -= (self.logoImageView.bounds.height + 20)
  101. }, completion: nil)
  102. }
  103. private func setupNavBar() {
  104. self.setupPicturedNavBar()
  105. }
  106. }
  107. // MARK: LoginViewInterface
  108. extension LoginViewController: LoginViewInterface {
  109. func show(error: String) {
  110. self.alert(message: error)
  111. }
  112. func showLoading() {
  113. self.showProgressHud()
  114. }
  115. func hideLoading() {
  116. self.hideProgressHud()
  117. }
  118. }