Showing
8 changed files
with
108 additions
and
62 deletions
... | ... | @@ -58,9 +58,20 @@ class AddResidentsViewController: UIViewController { |
58 | 58 | } |
59 | 59 | |
60 | 60 | @objc private func didTapResidentButton() { |
61 | - print("✅") | |
62 | - didReceiveData() | |
63 | - dismiss(animated: true, completion: nil) | |
61 | + if mainView.nameTextField.text == "" { | |
62 | + let alert = UIAlertController(title: "Enter name field", message: "", preferredStyle: .alert) | |
63 | + alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil)) | |
64 | + present(alert, animated: true, completion: nil) | |
65 | + } else { | |
66 | + if mainView.mobileNumberTextField.text == "" { | |
67 | + let alert = UIAlertController(title: "Enter phone number field", message: "", preferredStyle: .alert) | |
68 | + alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil)) | |
69 | + present(alert, animated: true, completion: nil) | |
70 | + } else { | |
71 | + didReceiveData() | |
72 | + dismiss(animated: true, completion: nil) | |
73 | + } | |
74 | + } | |
64 | 75 | } |
65 | 76 | |
66 | 77 | func didReceiveData() { | ... | ... |
InterQR-Internship/Modules/OneTimePasswordScreen/ViewController/CodeVerificationViewController.swift
... | ... | @@ -37,9 +37,8 @@ class CodeVerificationViewController: UIViewController { |
37 | 37 | } |
38 | 38 | |
39 | 39 | func networkingVerify() { |
40 | - guard let verifyUrl = URL(string: APIRoutes.verifyURL.urlString) else { return } | |
41 | - let verifyModel = verifyModelFilling() | |
42 | - AuthService.share.verifyRequest(verifyUrl, model: verifyModel!) { response in | |
40 | + guard let verifyModel = verifyModelFilling() else { return } | |
41 | + AuthService.share.verifyRequest(model: verifyModel) { response in | |
43 | 42 | print("3️⃣✅\(response.data)") |
44 | 43 | print("\(response.message)✅") |
45 | 44 | self.networkingLogin() |
... | ... | @@ -50,12 +49,9 @@ class CodeVerificationViewController: UIViewController { |
50 | 49 | } |
51 | 50 | |
52 | 51 | func networkingLogin() { |
53 | - guard let loginUrl = URL(string: APIRoutes.loginURL.urlString) else { return } | |
54 | 52 | guard let loginModel = loginModelFilling() else { return } |
55 | - | |
56 | - self.networkManager.loginRequest(loginUrl, model: loginModel) { response in | |
57 | - guard let message = response.message else { return } | |
58 | - print("4️⃣✅\(message)✅") | |
53 | + AuthService.share.loginRequest(model: loginModel) { response in | |
54 | + print("4️⃣\(response.message)4️⃣") | |
59 | 55 | self.errorProcessing() |
60 | 56 | } fail: { error in |
61 | 57 | print("4️⃣⛔️\(error)⛔️") | ... | ... |
... | ... | @@ -183,9 +183,9 @@ class ResidentTableViewCell: UITableViewCell { |
183 | 183 | } |
184 | 184 | |
185 | 185 | removeCellButton.addTarget(self, action: #selector(didRemoveButtonTapped(_:)), for: .touchUpInside) |
186 | - managerButton.addTarget(self, action: #selector(didButtonsTapped(_:)), for: .touchUpInside) | |
187 | - hiddenButton.addTarget(self, action: #selector(didButtonsTapped(_:)), for: .touchUpInside) | |
188 | - heartButton.addTarget(self, action: #selector(didButtonsTapped(_:)), for: .touchUpInside) | |
186 | + managerButton.addTarget(self, action: #selector(didManagerButtonTapped(_:)), for: .touchUpInside) | |
187 | + hiddenButton.addTarget(self, action: #selector(didHiddenButtonTapped(_:)), for: .touchUpInside) | |
188 | + heartButton.addTarget(self, action: #selector(didHeartButtonTapped(_:)), for: .touchUpInside) | |
189 | 189 | } |
190 | 190 | |
191 | 191 | override func layoutSubviews() { |
... | ... | @@ -201,9 +201,16 @@ extension ResidentTableViewCell { |
201 | 201 | delegate?.didRemoveButtonTapped(cell: self) |
202 | 202 | } |
203 | 203 | |
204 | - @objc private func didButtonsTapped(_ sender: UIButton) { | |
204 | + @objc private func didManagerButtonTapped(_ sender: UIButton) { | |
205 | 205 | delegate?.didManagerButtonTapped(cell: self) |
206 | + } | |
207 | + | |
208 | + @objc private func didHiddenButtonTapped(_ sender: UIButton) { | |
206 | 209 | delegate?.didHiddenButtonTapped(cell: self) |
210 | + } | |
211 | + | |
212 | + @objc private func didHeartButtonTapped(_ sender: UIButton) { | |
207 | 213 | delegate?.didHeardButtonTapped(cell: self) |
208 | 214 | } |
215 | + | |
209 | 216 | } | ... | ... |
... | ... | @@ -50,7 +50,7 @@ class ResidentsViewController: UIViewController { |
50 | 50 | guard let model = modelFilling() else { |
51 | 51 | return |
52 | 52 | } |
53 | - AuthService.share.initRequest(model) { result in | |
53 | + AuthService.share.initRequest(model: model) { result in | |
54 | 54 | print("1️⃣✅\(result.message)✅") |
55 | 55 | } fail: { error in |
56 | 56 | print("1️⃣\(error)") |
... | ... | @@ -84,20 +84,6 @@ extension ResidentsViewController: UITableViewDelegate, UITableViewDataSource { |
84 | 84 | cell.delegate = self |
85 | 85 | return cell |
86 | 86 | } |
87 | - | |
88 | -// @objc private func removeCell(_ sender: UIButton) { | |
89 | -// myData.remove(at: sender.tag) | |
90 | -// mainView.tableView.deleteRows(at: [IndexPath(row: sender.tag, section: 0)], with: .fade) | |
91 | -// mainView.tableView.reloadData() | |
92 | -// } | |
93 | - | |
94 | -// @objc private func didTapManagerButton(_ sender: UIButton) { | |
95 | -// if !sender.isSelected { | |
96 | -// sender.isSelected = true | |
97 | -// } else { | |
98 | -// sender.isSelected = false | |
99 | -// } | |
100 | -// } | |
101 | 87 | } |
102 | 88 | //MARK: - ResidentSavable delegate |
103 | 89 | extension ResidentsViewController: ResidentSavable { |
... | ... | @@ -109,6 +95,14 @@ extension ResidentsViewController: ResidentSavable { |
109 | 95 | |
110 | 96 | //MARK: residentcell delegate |
111 | 97 | extension ResidentsViewController: ResidentTableViewCellDelegate { |
98 | + func didButtonsTapped(cell: ResidentTableViewCell) { | |
99 | + if !cell.managerButton.isSelected { | |
100 | + cell.managerButton.isSelected = true | |
101 | + } else { | |
102 | + cell.managerButton.isSelected = false | |
103 | + } | |
104 | + } | |
105 | + | |
112 | 106 | func didRemoveButtonTapped(cell: ResidentTableViewCell) { |
113 | 107 | guard let model = cell.model else { |
114 | 108 | return |
... | ... | @@ -117,9 +111,13 @@ extension ResidentsViewController: ResidentTableViewCellDelegate { |
117 | 111 | mainView.tableView.reloadData() |
118 | 112 | } |
119 | 113 | |
120 | - func didButtonsTapped(_ sender: UIButton) { | |
121 | - | |
122 | - } | |
114 | +// func didButtonsTapped(_ button: UIButton) { | |
115 | +// if !button.isSelected { | |
116 | +// button.isSelected = true | |
117 | +// } else { | |
118 | +// button.isSelected = false | |
119 | +// } | |
120 | +// } | |
123 | 121 | |
124 | 122 | func didManagerButtonTapped(cell: ResidentTableViewCell) { |
125 | 123 | if !cell.managerButton.isSelected { |
... | ... | @@ -136,7 +134,7 @@ extension ResidentsViewController: ResidentTableViewCellDelegate { |
136 | 134 | cell.hiddenButton.isSelected = false |
137 | 135 | } |
138 | 136 | } |
139 | - | |
137 | + | |
140 | 138 | func didHeardButtonTapped(cell: ResidentTableViewCell) { |
141 | 139 | if !cell.heartButton.isSelected { |
142 | 140 | cell.heartButton.isSelected = true | ... | ... |
... | ... | @@ -40,15 +40,15 @@ extension SettingsViewController { |
40 | 40 | } |
41 | 41 | |
42 | 42 | @objc private func didLogoutAndShowVerificationVC() { |
43 | + networking() | |
43 | 44 | let vc = VerificationViewController() |
44 | 45 | navigationController?.pushViewController(vc, animated: true) |
45 | - networking() | |
46 | + | |
46 | 47 | } |
47 | 48 | |
48 | 49 | func networking() { |
49 | - guard let logoutUrl = URL(string: APIRoutes.logoutURL.urlString) else { return } | |
50 | 50 | guard let logoutModel = logoutModelFilling() else { return } |
51 | - networkManager.logoutRequest(logoutUrl, model: logoutModel) { response in | |
51 | + AuthService.share.logoutRequest(model: logoutModel) { response in | |
52 | 52 | print("5️⃣❇️\(response.message ?? "Data not received!")❇️") |
53 | 53 | } fail: { error in |
54 | 54 | print("5️⃣❗️\(error)❗️") | ... | ... |
... | ... | @@ -95,7 +95,7 @@ class VerificationView: UIView { |
95 | 95 | textField.backgroundColor = .TextFieldColor.general |
96 | 96 | textField.textAlignment = .left |
97 | 97 | textField.layer.cornerRadius = 15 |
98 | - textField.keyboardType = .numberPad | |
98 | + textField.keyboardType = .phonePad | |
99 | 99 | textField.text = .Text.plusOne |
100 | 100 | textField.font = .skModernist(type: .regular, ofSize: 15) |
101 | 101 | textField.layer.masksToBounds = true | ... | ... |
... | ... | @@ -11,6 +11,7 @@ class VerificationViewController: UIViewController { |
11 | 11 | var networkManager = AuthService() |
12 | 12 | var isKeyboardAppear = false |
13 | 13 | private let mainView = VerificationView() |
14 | + var closeTap: UITapGestureRecognizer? | |
14 | 15 | |
15 | 16 | lazy var phonePickerModels: [PhonePickerModel] = { |
16 | 17 | var models: [PhonePickerModel] = [] |
... | ... | @@ -37,6 +38,11 @@ class VerificationViewController: UIViewController { |
37 | 38 | } |
38 | 39 | |
39 | 40 | private func initViewController() { |
41 | + addDoneButtonOnKeyboard() | |
42 | + | |
43 | + mainView.emailTextField.delegate = self | |
44 | + mainView.phoneTextField.delegate = self | |
45 | + | |
40 | 46 | mainView.phonePickerView.phoneNumberPicker.delegate = self |
41 | 47 | mainView.phonePickerView.phoneNumberPicker.dataSource = self |
42 | 48 | |
... | ... | @@ -45,16 +51,15 @@ class VerificationViewController: UIViewController { |
45 | 51 | mainView.showPickerButton.addTarget(self, action: #selector(didshowPickerButtonTapped(_:)), for: .touchUpInside) |
46 | 52 | mainView.phonePickerView.selectButton.addTarget(self, action: #selector(didshowPickerButtonTapped(_:)), for: .touchUpInside) |
47 | 53 | mainView.phonePickerView.titleButton.addTarget(self, action: #selector(didshowPickerButtonTapped(_:)), for: .touchDragInside) |
48 | - | |
49 | 54 | mainView.continueButton.addTarget(self, action: #selector(didTapContinueButton), for: .touchUpInside) |
55 | + | |
50 | 56 | NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil) |
51 | 57 | NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil) |
52 | 58 | } |
53 | 59 | |
54 | 60 | func networking() { |
55 | - guard let startUrl = URL(string: APIRoutes.startURL.urlString) else { return } | |
56 | 61 | guard let startModel = startModelFilling() else { return } |
57 | - networkManager.startRequest(startUrl, model: startModel) { response in | |
62 | + AuthService.share.startRequest(model: startModel) { response in | |
58 | 63 | print("2️⃣✅\(response.message)✅") |
59 | 64 | } fail: { error in |
60 | 65 | print("2️⃣❌\(error)❌") |
... | ... | @@ -70,6 +75,25 @@ class VerificationViewController: UIViewController { |
70 | 75 | return StartRequestModel(emailOrNumber: (String(describing: number))) |
71 | 76 | } |
72 | 77 | } |
78 | + | |
79 | + func addDoneButtonOnKeyboard() { | |
80 | + let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50)) | |
81 | + doneToolbar.barStyle = .default | |
82 | + | |
83 | + let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) | |
84 | + let done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(self.doneButtonAction)) | |
85 | + | |
86 | + let items = [flexSpace, done] | |
87 | + doneToolbar.items = items | |
88 | + doneToolbar.sizeToFit() | |
89 | + | |
90 | + mainView.phoneTextField.inputAccessoryView = doneToolbar | |
91 | + } | |
92 | + | |
93 | + @objc func doneButtonAction(){ | |
94 | + mainView.phoneTextField.resignFirstResponder() | |
95 | + didShowCodeVerificationVC() | |
96 | + } | |
73 | 97 | } |
74 | 98 | |
75 | 99 | //MARK: helpers and handlers |
... | ... | @@ -92,7 +116,6 @@ extension VerificationViewController { |
92 | 116 | default: |
93 | 117 | return |
94 | 118 | } |
95 | -// mainView.handleUI(mainView.emailButton.isSelected) | |
96 | 119 | } |
97 | 120 | |
98 | 121 | @objc private func didshowPickerButtonTapped(_ sender: UIButton) { |
... | ... | @@ -166,7 +189,7 @@ extension VerificationViewController { |
166 | 189 | } |
167 | 190 | } |
168 | 191 | } |
169 | - | |
192 | +//MARK: - PickerView Delegate | |
170 | 193 | extension VerificationViewController: UIPickerViewDataSource, UIPickerViewDelegate { |
171 | 194 | func numberOfComponents(in pickerView: UIPickerView) -> Int { |
172 | 195 | return 1 |
... | ... | @@ -193,4 +216,12 @@ extension VerificationViewController: UIPickerViewDataSource, UIPickerViewDelega |
193 | 216 | mainView.flagPickerView.image = model.icon |
194 | 217 | } |
195 | 218 | } |
219 | +//MARK: - TextField delegate | |
220 | +extension VerificationViewController: UITextFieldDelegate { | |
221 | + func textFieldShouldReturn(_ textField: UITextField) -> Bool { | |
222 | + mainView.emailTextField.resignFirstResponder() | |
223 | + return true | |
224 | + } | |
225 | +} | |
226 | + | |
196 | 227 | ... | ... |
... | ... | @@ -9,7 +9,6 @@ import Foundation |
9 | 9 | import Alamofire |
10 | 10 | |
11 | 11 | class AuthService { |
12 | - | |
13 | 12 | static let share = AuthService() |
14 | 13 | |
15 | 14 | var networkToken: String? { |
... | ... | @@ -28,9 +27,10 @@ class AuthService { |
28 | 27 | typealias VerifyWebServiceResponse = (VerifyResponseModel) -> Void |
29 | 28 | typealias LoginWebServiceResponse = (LoginResponseModel) -> Void |
30 | 29 | typealias LogoutWebServiceResponse = (LogoutResponseModel) -> Void |
30 | + | |
31 | 31 | typealias FailedHandler = (Error) -> Void |
32 | 32 | |
33 | - func initRequest(_ model: InitRequestModel, success: @escaping InitWebServiceResponse, fail: @escaping FailedHandler) { | |
33 | + func initRequest(model: InitRequestModel, completion: @escaping InitWebServiceResponse, fail: @escaping FailedHandler) { | |
34 | 34 | |
35 | 35 | let params = ["device_uuid": model.deviceUUID, |
36 | 36 | "manufacturer": model.manufacturer, |
... | ... | @@ -40,20 +40,22 @@ class AuthService { |
40 | 40 | "app_version": model.appVersion] as [String: Any] |
41 | 41 | |
42 | 42 | AF.request(Constants.baseURL + APIRoutes.initURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: InitResponseModel.self ) { response in |
43 | - switch response.result { | |
44 | - case .failure(let error) : | |
43 | + | |
44 | + if let error = response.error { | |
45 | 45 | fail(error) |
46 | - case .success(let res) : | |
47 | - success(res) | |
46 | + } else { | |
47 | + if let res = response.value { | |
48 | + completion(res) | |
49 | + } | |
48 | 50 | } |
49 | 51 | } |
50 | 52 | } |
51 | 53 | |
52 | - func startRequest(_ url: URL, model: StartRequestModel, completion: @escaping StartWebServiceResponse, fail: @escaping FailedHandler) { | |
54 | + func startRequest(model: StartRequestModel, completion: @escaping StartWebServiceResponse, fail: @escaping FailedHandler) { | |
53 | 55 | |
54 | 56 | let params = ["email_or_number": model.emailOrNumber] as [String: Any] |
55 | 57 | |
56 | - AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: StartResponseModel.self ) { response in | |
58 | + AF.request(Constants.baseURL + APIRoutes.startURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: StartResponseModel.self ) { response in | |
57 | 59 | |
58 | 60 | if let error = response.error { |
59 | 61 | fail(error) |
... | ... | @@ -65,13 +67,13 @@ class AuthService { |
65 | 67 | } |
66 | 68 | } |
67 | 69 | |
68 | - func verifyRequest(_ url: URL, model: VerifyRequestModel, completion: @escaping VerifyWebServiceResponse, fail: @escaping FailedHandler) { | |
70 | + func verifyRequest(model: VerifyRequestModel, completion: @escaping VerifyWebServiceResponse, fail: @escaping FailedHandler) { | |
69 | 71 | |
70 | 72 | let params = ["email_or_number": model.emailOrNumber, |
71 | 73 | "code": model.code, |
72 | 74 | "second_auth_token": model.secondAuthToken] as [String: Any] |
73 | 75 | |
74 | - AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: VerifyResponseModel.self ) { response in | |
76 | + AF.request(Constants.baseURL + APIRoutes.verifyURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: VerifyResponseModel.self ) { response in | |
75 | 77 | |
76 | 78 | if let error = response.error { |
77 | 79 | fail(error) |
... | ... | @@ -84,25 +86,26 @@ class AuthService { |
84 | 86 | } |
85 | 87 | } |
86 | 88 | |
87 | - func loginRequest(_ url: URL, model: LoginRequestModel, completion: @escaping LoginWebServiceResponse, fail: @escaping FailedHandler) { | |
89 | + func loginRequest(model: LoginRequestModel, success: @escaping LoginWebServiceResponse, fail: @escaping FailedHandler) { | |
88 | 90 | let headers = ["Authorization": "Bearer \(self.networkToken ?? "")"] |
89 | 91 | let params = ["device_uuid": model.deviceUUID] as [String: Any] |
90 | - AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: HTTPHeaders(headers), interceptor: nil).responseDecodable(of: LoginResponseModel.self ) { response in | |
91 | - if let error = response.error { | |
92 | + | |
93 | + AF.request(Constants.baseURL + APIRoutes.loginURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default, headers: HTTPHeaders(headers), interceptor: nil).responseDecodable(of: LoginResponseModel.self ) { response in | |
94 | + | |
95 | + switch response.result { | |
96 | + case .failure(let error) : | |
92 | 97 | fail(error) |
93 | - } else { | |
94 | - if let res = response.value { | |
95 | - completion(res) | |
96 | - } | |
98 | + case .success(let res) : | |
99 | + success(res) | |
97 | 100 | } |
98 | 101 | } |
99 | 102 | } |
100 | 103 | |
101 | - func logoutRequest(_ url: URL, model: LogoutRequestModel, completion: @escaping LogoutWebServiceResponse, fail: @escaping FailedHandler) { | |
104 | + func logoutRequest(model: LogoutRequestModel, completion: @escaping LogoutWebServiceResponse, fail: @escaping FailedHandler) { | |
102 | 105 | let headers = ["Authorization": "Bearer \(self.networkToken ?? "")"] |
103 | 106 | let params = ["device_uuid": model.deviceUUID] as [String: Any] |
104 | 107 | |
105 | - AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: HTTPHeaders(headers), interceptor: nil).responseDecodable(of: LogoutResponseModel.self ) { response in | |
108 | + AF.request(Constants.baseURL + APIRoutes.logoutURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default, headers: HTTPHeaders(headers), interceptor: nil).responseDecodable(of: LogoutResponseModel.self ) { response in | |
106 | 109 | |
107 | 110 | if let error = response.error { |
108 | 111 | fail(error) | ... | ... |
Please
register
or
login
to post a comment