LoginViewController.swift 3.67 KB
Newer Older
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
1
2
3
4
5
6
7
8
9
10
11
//
//  LoginViewController.swift
//  App16
//
//  Created by Grigor Aghabalyan on 3/25/20.
//  Copyright © 2020 X-TECH. All rights reserved.
//

import UIKit

class LoginViewController: UIViewController {
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
12
13
14
15
16
17
    
    @IBOutlet weak var firstNameTextField: UITextField!
    @IBOutlet weak var lastNameTextFiled: UITextField!
    @IBOutlet weak var middleNameTextField: UITextField!
    @IBOutlet weak var nextButton: UIButton!
    
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
18
19
20
    // MARK: - LifeCycle
    override func viewDidLoad() {
        super.viewDidLoad()
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
21
22
        
        setRightBarButton()
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
23
        self.title = "App16"
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
24
25
26
27
28
29
30
31
32
33
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        setUI()
    }
    
    private func setUI() {
        
        firstNameTextField.attributedPlaceholder = NSAttributedString(string: "FIRST_NAME".localized(),
34
                                                                      attributes: [NSAttributedString.Key.foregroundColor: UIColor.black.withAlphaComponent(0.2)])
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
35
        lastNameTextFiled.attributedPlaceholder = NSAttributedString(string: "LAST_NAME".localized(),
36
                                                                     attributes: [NSAttributedString.Key.foregroundColor: UIColor.black.withAlphaComponent(0.2)])
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
37
        middleNameTextField.attributedPlaceholder = NSAttributedString(string: "MIDDLE_NAME".localized(),
38
                                                                       attributes: [NSAttributedString.Key.foregroundColor: UIColor.black.withAlphaComponent(0.2)])
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
39
40
        
        nextButton.setTitle("NEXT".localized(), for: .normal)
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
41
42
    }
    
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
43
44
45
46
47
48
49
50
51
52
53
    private func setRightBarButton() {
          
          let editButton = UIBarButtonItem.init(image: UIImage(named: "settings"),
                                                style: .done,
                                                target: self,
                                                action: #selector(settingsActtions))
        editButton.tintColor = .white
          
          self.navigationItem.rightBarButtonItem = editButton
      }
    
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
54
    // MARK: - Navigation
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
55
56
57
58
59
60
    private func openCreateFormViewController() {
        
        let controller = FormCreateViewController()
        let navController = UINavigationController(rootViewController: controller)
        self.present(navController, animated: true, completion: nil)
    }
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
61
62
63
64
65
66
67
    
    private func openWelcomeController() {
        
        let controller = WelcomeViewController()
        changeRoot(UINavigationController(rootViewController: controller))
    }
    
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
68
69
70
71
72
73
74
    private func setDatUserDef() {
        
        UserDefaultsHelper.set(alias: .firstName, value: firstNameTextField.text)
        UserDefaultsHelper.set(alias: .lstName, value: lastNameTextFiled.text)
        UserDefaultsHelper.set(alias: .middleName, value: middleNameTextField.text)
    }
    
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
75
76
77
78
79
80
81
82
83
84
    // MARK: - Actions
    @IBAction func nextButtonAction(_ sender: Any) {
        
        if firstNameTextField.text == ""
            || lastNameTextFiled.text == ""
            || middleNameTextField.text == "" {
            
            let alertController = AlertControllerHelper.showAlert(title: nil, message: "Խնդում ենք լրացրեք բոլոր դաշտերը")
            self.present(alertController, animated: true, completion: nil)
        }else {
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
85
86
            
            setDatUserDef()
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
87
            openWelcomeController()
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
88
            
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
89
90
        }
    }
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
91
92
93
94
95
96
97
98
99
    
    // MARK: - Actions
    @IBAction func settingsActtions() {
        
        let controller = SettingsViewController()
        self.navigationController?.navigationBar.topItem?.title = " "
        self.navigationController?.pushViewController(controller, animated: true)
    }
    
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
100
}