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.

110 lines
2.5 KiB

5 years ago
5 years ago
5 years ago
  1. //
  2. // LauncherScreenViewController.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 22/07/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class LauncherScreenViewController: UIViewController {
  10. // MARK: Properties
  11. var presenter: LauncherScreenModuleInterface?
  12. private var isShow = false
  13. private var window: UIWindow? {
  14. if let app = UIApplication.shared.delegate as? AppDelegate {
  15. return app.window
  16. } else {
  17. return nil
  18. }
  19. }
  20. // MARK: Computed Properties
  21. // MARK: IBOutlets
  22. @IBOutlet private weak var logoImageView: UIImageView!
  23. // MARK: VC's Life cycle
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. setup()
  27. }
  28. override func viewDidAppear(_ animated: Bool) {
  29. super.viewDidAppear(animated)
  30. #if DEBUG
  31. DebugManager.shared.selectServerAlert(target: self) {
  32. if !self.isShow {
  33. self.setEntryPoint()
  34. self.isShow = true
  35. }
  36. }
  37. #else
  38. if !isShow {
  39. setEntryPoint()
  40. isShow = true
  41. }
  42. #endif
  43. }
  44. }
  45. // MARK: LauncherScreenViewInterface
  46. extension LauncherScreenViewController: LauncherScreenViewInterface {
  47. func setError(with error: Error) {
  48. alertWithOk(
  49. type: .error,
  50. message: error.localizedDescription,
  51. okTitle: "retry_text".localized(),
  52. okAction: {
  53. self.presenter?.goSplashScreen()
  54. }
  55. )
  56. }
  57. }
  58. // MARK: Other Functions
  59. extension LauncherScreenViewController {
  60. private func setup() {
  61. logoImageView?.image = logoImageView?.image?.withRenderingMode(.alwaysTemplate)
  62. logoImageView.tintColor = .themeWhiteRed
  63. setUUID()
  64. setupNavBar()
  65. view.backgroundColor = .themeRed
  66. }
  67. private func setUUID() {
  68. if GMEDB.shared.app.string(.uuid) == nil {
  69. let uuid = UUID().uuidString
  70. GMEDB.shared.app.set(uuid, .uuid)
  71. }
  72. }
  73. private func setupNavBar() {
  74. let appearance = UINavigationBar.appearance()
  75. appearance.backIndicatorImage = #imageLiteral(resourceName: "backIconBlack")
  76. appearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "backIconBlack")
  77. appearance.tintColor = UIColor.black
  78. }
  79. }
  80. // MARK: - Login Logic
  81. extension LauncherScreenViewController {
  82. private func setEntryPoint() {
  83. guard KeyChain.shared.get(key: .id) != nil,
  84. (KeyChain.shared.get(key: .login) ?? "1") == "1" ? true : false else {
  85. presenter?.goSplashScreen()
  86. return
  87. }
  88. presenter?.openAuthenticationScreen()
  89. }
  90. }