Commit 9a6c5c0e23ecd25d1d5e360643867b5f7d861d2d

Authored by Dmitriy Tymofyeyev
1 parent 4cefc57f

add addResidentScreen

  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<Workspace
  3 + version = "1.0">
  4 +</Workspace>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3 +<plist version="1.0">
  4 +<dict>
  5 + <key>IDEDidComputeMac32BitWarning</key>
  6 + <true/>
  7 +</dict>
  8 +</plist>
@@ -5,4 +5,12 @@ @@ -5,4 +5,12 @@
5 // Created by Дмитрий Тимофеев on 18.06.2022. 5 // Created by Дмитрий Тимофеев on 18.06.2022.
6 // 6 //
7 7
8 -import Foundation 8 +import UIKit
  9 +
  10 +struct ResidentModel {
  11 + var name: String
  12 + var mobileNumber: String
  13 + var manager = false
  14 + var hidden = false
  15 + var heart = false
  16 +}
@@ -7,17 +7,31 @@ @@ -7,17 +7,31 @@
7 7
8 import UIKit 8 import UIKit
9 9
  10 +protocol ViewDelegate: AnyObject {
  11 + func viewDidTapImage()
  12 +}
  13 +
10 class AddResidentsView: UIView { 14 class AddResidentsView: UIView {
  15 + var isShow: Bool = false
  16 +
  17 + weak var delegate: ViewDelegate?
  18 +
11 let blurEffect: UIVisualEffectView = { 19 let blurEffect: UIVisualEffectView = {
12 let blur = UIBlurEffect(style: UIBlurEffect.Style.systemMaterialDark) 20 let blur = UIBlurEffect(style: UIBlurEffect.Style.systemMaterialDark)
13 let obj = UIVisualEffectView(effect: blur) 21 let obj = UIVisualEffectView(effect: blur)
14 obj.autoresizingMask = [.flexibleWidth, .flexibleHeight] 22 obj.autoresizingMask = [.flexibleWidth, .flexibleHeight]
15 obj.alpha = 0.9 23 obj.alpha = 0.9
  24 + obj.isUserInteractionEnabled = true
16 return obj 25 return obj
17 }() 26 }()
18 27
19 - var transparentView: UIView = { 28 + lazy var transparentView: UIView = {
20 var obj = UIView() 29 var obj = UIView()
  30 + obj.isUserInteractionEnabled = true
  31 + var tap = UIGestureRecognizer(target: self, action: #selector(imageTapped))
  32 + obj.addGestureRecognizer(tap)
  33 + obj.backgroundColor = .black
  34 + obj.alpha = 0.5
21 return obj 35 return obj
22 }() 36 }()
23 37
@@ -32,7 +46,7 @@ class AddResidentsView: UIView { @@ -32,7 +46,7 @@ class AddResidentsView: UIView {
32 var addResidentLabeL: UILabel = { 46 var addResidentLabeL: UILabel = {
33 var obj = UILabel() 47 var obj = UILabel()
34 obj.text = "Add resident" 48 obj.text = "Add resident"
35 - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1) 49 + obj.textColor = .TextColor.darkBlue
36 obj.font = .skModernist(type: .bold, ofSize: 24) 50 obj.font = .skModernist(type: .bold, ofSize: 24)
37 return obj 51 return obj
38 }() 52 }()
@@ -41,14 +55,14 @@ class AddResidentsView: UIView { @@ -41,14 +55,14 @@ class AddResidentsView: UIView {
41 var obj = UIButton() 55 var obj = UIButton()
42 obj.layer.cornerRadius = 13 56 obj.layer.cornerRadius = 13
43 obj.layer.borderWidth = 1 57 obj.layer.borderWidth = 1
44 - obj.layer.borderColor = UIColor(red: 0.882, green: 0.91, blue: 0.91, alpha: 1).cgColor 58 + obj.layer.borderColor = .ButtonBorderColor.lightGrey
45 obj.setImage(UIImage(named: "Close"), for: .normal) 59 obj.setImage(UIImage(named: "Close"), for: .normal)
46 return obj 60 return obj
47 }() 61 }()
48 62
49 var dividingLineView: UIView = { 63 var dividingLineView: UIView = {
50 var view = UIView() 64 var view = UIView()
51 - view.backgroundColor = UIColor(red: 246/255, green: 246/255, blue: 246/255, alpha: 1) 65 + view.backgroundColor = MyColor.dividingLineBackgroundColor.value
52 return view 66 return view
53 }() 67 }()
54 68
@@ -56,15 +70,18 @@ class AddResidentsView: UIView { @@ -56,15 +70,18 @@ class AddResidentsView: UIView {
56 var obj = UILabel() 70 var obj = UILabel()
57 obj.text = "Resident name" 71 obj.text = "Resident name"
58 obj.font = .skModernist(type: .bold, ofSize: 14) 72 obj.font = .skModernist(type: .bold, ofSize: 14)
59 - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1) 73 + obj.textColor = .TextColor.darkBlue
60 return obj 74 return obj
61 }() 75 }()
62 76
63 - var nameTextField: UITextField = {  
64 - var obj = UITextField()  
65 - obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1) 77 + var nameTextField: TextFieldWithPadding = {
  78 + var obj = TextFieldWithPadding()
  79 + obj.backgroundColor = .TextFieldColor.general
66 obj.textAlignment = .left 80 obj.textAlignment = .left
67 obj.layer.cornerRadius = 15 81 obj.layer.cornerRadius = 15
  82 + obj.placeholder = "Enter resident name"
  83 + obj.font = .skModernist(type: .regular, ofSize: 14)
  84 + obj.textPadding = UIEdgeInsets(top: 0, left: 22, bottom: 0, right: 22)
68 return obj 85 return obj
69 }() 86 }()
70 87
@@ -72,27 +89,36 @@ class AddResidentsView: UIView { @@ -72,27 +89,36 @@ class AddResidentsView: UIView {
72 var obj = UILabel() 89 var obj = UILabel()
73 obj.text = "Mobile number" 90 obj.text = "Mobile number"
74 obj.font = .skModernist(type: .bold, ofSize: 14) 91 obj.font = .skModernist(type: .bold, ofSize: 14)
75 - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1) 92 + obj.textColor = MyColor.darkBlueTextColor.value
76 return obj 93 return obj
77 }() 94 }()
78 95
79 - var mobileNumberTextField: UITextField = {  
80 - var obj = UITextField()  
81 - obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1) 96 + var mobileNumberTextField: TextFieldWithPadding = {
  97 + var obj = TextFieldWithPadding()
  98 + obj.backgroundColor = MyColor.generalTextFieldBackgroundColor.value
82 obj.textAlignment = .left 99 obj.textAlignment = .left
83 obj.layer.cornerRadius = 15 100 obj.layer.cornerRadius = 15
  101 + obj.font = .skModernist(type: .regular, ofSize: 14)
  102 + obj.textPadding = UIEdgeInsets(top: 0, left: 22, bottom: 0, right: 45)
  103 + obj.placeholder = "Enter resident number"
84 return obj 104 return obj
85 }() 105 }()
86 -  
87 - var managerButton: UIButton = {  
88 - var obj = UIButton()  
89 - obj.setImage(UIImage(named: ""), for: .normal)  
90 - obj.setImage(UIImage(named: ""), for: .selected) 106 +
  107 + let contactListButton: UIButton = {
  108 + let obj = UIButton()
  109 + obj.setImage(UIImage(named:"3Users"), for: .normal)
91 return obj 110 return obj
92 }() 111 }()
93 112
94 - var hiddenButton: UIButton = {  
95 - var obj = UIButton() 113 + var managerButton: SquereCheckbox = {
  114 + var obj = SquereCheckbox()
  115 + obj.checkboxTitle = "Manager"
  116 + return obj
  117 + }()
  118 +
  119 + var hiddenButton: SquereCheckbox = {
  120 + var obj = SquereCheckbox()
  121 + obj.checkboxTitle = "Hidden"
96 return obj 122 return obj
97 }() 123 }()
98 124
@@ -118,7 +144,6 @@ class AddResidentsView: UIView { @@ -118,7 +144,6 @@ class AddResidentsView: UIView {
118 obj.setTitle("Add resident", for: .normal) 144 obj.setTitle("Add resident", for: .normal)
119 obj.setTitleColor(UIColor(red: 1, green: 1, blue: 1, alpha: 1), for: .normal) 145 obj.setTitleColor(UIColor(red: 1, green: 1, blue: 1, alpha: 1), for: .normal)
120 obj.titleLabel?.font = .skModernist(type: .bold, ofSize: 16) 146 obj.titleLabel?.font = .skModernist(type: .bold, ofSize: 16)
121 - obj.setTitleColor(.cyan, for: .normal)  
122 obj.clipsToBounds = true 147 obj.clipsToBounds = true
123 obj.layer.masksToBounds = true 148 obj.layer.masksToBounds = true
124 return obj 149 return obj
@@ -135,6 +160,7 @@ class AddResidentsView: UIView { @@ -135,6 +160,7 @@ class AddResidentsView: UIView {
135 } 160 }
136 161
137 func layout() { 162 func layout() {
  163 + isUserInteractionEnabled = true
138 addResidentButton.layer.insertSublayer(gradientBG, at: 0) 164 addResidentButton.layer.insertSublayer(gradientBG, at: 0)
139 165
140 addSubview(transparentView) 166 addSubview(transparentView)
@@ -148,6 +174,8 @@ class AddResidentsView: UIView { @@ -148,6 +174,8 @@ class AddResidentsView: UIView {
148 containerView.addSubview(nameTextField) 174 containerView.addSubview(nameTextField)
149 containerView.addSubview(mobileNumberLabel) 175 containerView.addSubview(mobileNumberLabel)
150 containerView.addSubview(mobileNumberTextField) 176 containerView.addSubview(mobileNumberTextField)
  177 + mobileNumberTextField.addSubview(contactListButton)
  178 +
151 containerView.addSubview(managerButton) 179 containerView.addSubview(managerButton)
152 containerView.addSubview(hiddenButton) 180 containerView.addSubview(hiddenButton)
153 containerView.addSubview(heartButton) 181 containerView.addSubview(heartButton)
@@ -159,9 +187,7 @@ class AddResidentsView: UIView { @@ -159,9 +187,7 @@ class AddResidentsView: UIView {
159 187
160 containerView.snp.makeConstraints { 188 containerView.snp.makeConstraints {
161 $0.leading.trailing.equalToSuperview().inset(25) 189 $0.leading.trailing.equalToSuperview().inset(25)
162 -// $0.top.equalToSuperview().offset(174)  
163 -// $0.bottom.equalToSuperview().offset(-201)  
164 - $0.centerY.equalToSuperview() 190 + $0.centerY.equalTo(transparentView.snp.centerY)
165 } 191 }
166 192
167 addResidentLabeL.snp.makeConstraints { 193 addResidentLabeL.snp.makeConstraints {
@@ -184,7 +210,6 @@ class AddResidentsView: UIView { @@ -184,7 +210,6 @@ class AddResidentsView: UIView {
184 residentNameLabel.snp.makeConstraints { 210 residentNameLabel.snp.makeConstraints {
185 $0.top.equalTo(dividingLineView.snp.bottom).offset(24) 211 $0.top.equalTo(dividingLineView.snp.bottom).offset(24)
186 $0.leading.equalToSuperview().offset(44) 212 $0.leading.equalToSuperview().offset(44)
187 -  
188 } 213 }
189 214
190 nameTextField.snp.makeConstraints { 215 nameTextField.snp.makeConstraints {
@@ -196,7 +221,6 @@ class AddResidentsView: UIView { @@ -196,7 +221,6 @@ class AddResidentsView: UIView {
196 mobileNumberLabel.snp.makeConstraints { 221 mobileNumberLabel.snp.makeConstraints {
197 $0.leading.equalTo(residentNameLabel.snp.leading) 222 $0.leading.equalTo(residentNameLabel.snp.leading)
198 $0.top.equalTo(nameTextField.snp.bottom).offset(15) 223 $0.top.equalTo(nameTextField.snp.bottom).offset(15)
199 -  
200 } 224 }
201 225
202 mobileNumberTextField.snp.makeConstraints { 226 mobileNumberTextField.snp.makeConstraints {
@@ -205,14 +229,22 @@ class AddResidentsView: UIView { @@ -205,14 +229,22 @@ class AddResidentsView: UIView {
205 $0.height.equalTo(47) 229 $0.height.equalTo(47)
206 } 230 }
207 231
  232 + contactListButton.snp.makeConstraints {
  233 + $0.height.width.equalTo(24)
  234 + $0.centerY.equalToSuperview()
  235 + $0.trailing.equalToSuperview().offset(-19)
  236 + }
  237 +
208 managerButton.snp.makeConstraints { 238 managerButton.snp.makeConstraints {
209 $0.leading.equalToSuperview().offset(29) 239 $0.leading.equalToSuperview().offset(29)
210 $0.top.equalTo(mobileNumberTextField.snp.bottom).offset(30) 240 $0.top.equalTo(mobileNumberTextField.snp.bottom).offset(30)
  241 + $0.height.equalTo(20)
211 } 242 }
212 243
213 hiddenButton.snp.makeConstraints { 244 hiddenButton.snp.makeConstraints {
214 $0.top.equalTo(managerButton) 245 $0.top.equalTo(managerButton)
215 $0.leading.equalTo(managerButton.snp.trailing).offset(24) 246 $0.leading.equalTo(managerButton.snp.trailing).offset(24)
  247 + $0.height.equalTo(20)
216 } 248 }
217 249
218 heartButton.snp.makeConstraints { 250 heartButton.snp.makeConstraints {
@@ -223,7 +255,7 @@ class AddResidentsView: UIView { @@ -223,7 +255,7 @@ class AddResidentsView: UIView {
223 addResidentButton.snp.makeConstraints { 255 addResidentButton.snp.makeConstraints {
224 $0.top.equalTo(managerButton.snp.bottom).offset(43) 256 $0.top.equalTo(managerButton.snp.bottom).offset(43)
225 $0.leading.trailing.bottom.equalToSuperview() 257 $0.leading.trailing.bottom.equalToSuperview()
226 - $0.height.equalTo(45) 258 + $0.height.equalTo(64)
227 } 259 }
228 } 260 }
229 261
@@ -232,4 +264,8 @@ class AddResidentsView: UIView { @@ -232,4 +264,8 @@ class AddResidentsView: UIView {
232 gradientBG.frame = addResidentButton.bounds 264 gradientBG.frame = addResidentButton.bounds
233 blurEffect.frame = transparentView.bounds 265 blurEffect.frame = transparentView.bounds
234 } 266 }
  267 +
  268 + @objc func imageTapped() {
  269 + delegate?.viewDidTapImage()
  270 + }
235 } 271 }
@@ -6,8 +6,19 @@ @@ -6,8 +6,19 @@
6 // 6 //
7 7
8 import UIKit 8 import UIKit
  9 +import ContactsUI
9 10
10 -class AddResidentsViewController: UIViewController { 11 +class AddResidentsViewController: UIViewController, ViewDelegate {
  12 + var myData: ResidentModel?
  13 +
  14 + var savedResidents: [ResidentModel] = []
  15 +
  16 + weak var delegate: ResidentSavable?
  17 +
  18 + var contact = ContactPickerViewController()
  19 +
  20 + var isKeyboardAppear = false
  21 +
11 var mainView = AddResidentsView() 22 var mainView = AddResidentsView()
12 23
13 override func loadView() { 24 override func loadView() {
@@ -15,10 +26,136 @@ class AddResidentsViewController: UIViewController { @@ -15,10 +26,136 @@ class AddResidentsViewController: UIViewController {
15 } 26 }
16 27
17 override func viewDidLoad() { 28 override func viewDidLoad() {
  29 + super.viewDidLoad()
  30 + initViewController()
  31 + }
  32 +
  33 + func initViewController() {
18 mainView.closeButton.addTarget(self, action: #selector(didTapCloseButton), for: .touchUpInside) 34 mainView.closeButton.addTarget(self, action: #selector(didTapCloseButton), for: .touchUpInside)
  35 + mainView.managerButton.addTarget(self, action: #selector(didTapOnChangeableButtons(_:)), for: .touchUpInside)
  36 + mainView.hiddenButton.addTarget(self, action: #selector(didTapOnChangeableButtons(_:)), for: .touchUpInside)
  37 + mainView.heartButton.addTarget(self, action: #selector(didTapOnChangeableButtons(_:)), for: .touchUpInside)
  38 + mainView.addResidentButton.addTarget(self, action: #selector(didTapResidentButton), for: .touchUpInside)
  39 + mainView.contactListButton.addTarget(self, action: #selector(didTapContactListButton), for: .touchUpInside)
  40 +
  41 + mainView.delegate = self
  42 + gestureSetup(mainView.transparentView)
  43 +
  44 + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
  45 + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
  46 + }
  47 +
  48 + deinit {
  49 + NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
  50 + NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
19 } 51 }
20 52
21 - @objc func didTapCloseButton() { 53 + @objc func viewDidTapImage() {
  54 + print("🕵️‍♂️")
  55 + }
  56 +
  57 + func gestureSetup(_ view: UIView) {
  58 + let tapGesture = UIGestureRecognizer()
  59 + tapGesture.addTarget(self, action: #selector(gestureFired))
  60 + view.addGestureRecognizer(tapGesture)
  61 + view.isUserInteractionEnabled = true
  62 + }
  63 +
  64 + @objc private func gestureFired() {
  65 + print("❌")
  66 +
  67 + }
  68 +
  69 + func reloadView() {
  70 + mainView.mobileNumberTextField.reloadInputViews()
  71 + }
  72 +
  73 + @objc private func didTapCloseButton() {
22 dismiss(animated: true, completion: nil) 74 dismiss(animated: true, completion: nil)
23 } 75 }
  76 +
  77 + @objc private func didTapResidentButton() {
  78 + print("✅")
  79 + didReceiveData()
  80 + dismiss(animated: true, completion: nil)
  81 + }
  82 +
  83 + func didReceiveData() {
  84 + mainView.nameTextField.text = myData?.name
  85 + mainView.mobileNumberTextField.text = myData?.mobileNumber
  86 + mainView.managerButton.isSelected = ((myData?.manager) != nil)
  87 + mainView.hiddenButton.isSelected = ((myData?.hidden) != nil)
  88 + mainView.heartButton.isSelected = ((myData?.hidden) != nil)
  89 +
  90 + delegate?.save(myData!)
  91 + }
  92 +
  93 + @objc private func didTapOnChangeableButtons(_ sender: SquereCheckbox) {
  94 + switch sender {
  95 + case mainView.managerButton :
  96 + if mainView.managerButton.isSelected == true {
  97 + mainView.managerButton.isSelected = false
  98 + } else {
  99 + mainView.managerButton.isSelected = true
  100 + }
  101 + case mainView.hiddenButton :
  102 + if mainView.hiddenButton.isSelected == true {
  103 + mainView.hiddenButton.isSelected = false
  104 + } else {
  105 + mainView.hiddenButton.isSelected = true
  106 + }
  107 + case mainView.heartButton :
  108 + if mainView.heartButton.isSelected == true {
  109 + mainView.heartButton.isSelected = false
  110 + } else {
  111 + mainView.heartButton.isSelected = true
  112 + }
  113 + default:
  114 + return
  115 + }
  116 + }
  117 +
  118 + @objc func didTapContactListButton() {
  119 + presentContactPickerVC()
  120 + }
  121 +
  122 + func presentContactPickerVC() {
  123 + let viewController = ContactPickerViewController()
  124 + present(viewController, animated: true)
  125 + }
  126 +}
  127 +
  128 +//MARK: - Keyboard observer
  129 +extension AddResidentsViewController {
  130 + @objc private func keyboardWillShow(notification: NSNotification) {
  131 + let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
  132 +
  133 + if !isKeyboardAppear {
  134 +
  135 + UIView.animate(withDuration: duration ?? 0) {
  136 + self.mainView.containerView.snp.updateConstraints { make in
  137 + make.centerY.equalTo(self.mainView.transparentView.snp.centerY).offset(-150)
  138 + }
  139 + self.mainView.layoutIfNeeded()
  140 + }
  141 + isKeyboardAppear = true
  142 + }
  143 + }
  144 +
  145 + @objc private func keyboardWillHide(notification: NSNotification) {
  146 + let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
  147 +
  148 + if isKeyboardAppear {
  149 +
  150 + UIView.animate(withDuration: duration ?? 0) {
  151 + self.mainView.containerView.snp.updateConstraints { make in
  152 + make.centerY.equalTo(self.mainView.transparentView.snp.centerY)
  153 + }
  154 + self.mainView.layoutIfNeeded()
  155 + }
  156 + isKeyboardAppear = false
  157 + }
  158 + }
24 } 159 }
  160 +
  161 +
Please register or login to post a comment