Commit 60397c80a0edf947ac8257c8e0adfb8dea31558d

Authored by Dmitriy Tymofyeyev
1 parent 74d86ccf

Code refactoring

Showing 40 changed files with 1048 additions and 577 deletions
... ... @@ -20,6 +20,8 @@
20 20 00A48B7B285F8F6600EF0A08 /* ProtocolDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A48B79285F8F6600EF0A08 /* ProtocolDelegate.swift */; };
21 21 00A48B7F285F8F9200EF0A08 /* ContactPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A48B7E285F8F9200EF0A08 /* ContactPickerViewController.swift */; };
22 22 00E581BB284F71CD00E779FB /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00E581BA284F71CD00E779FB /* Checkbox.swift */; };
  23 + 1721AEF028704E3100EC4FDB /* Strings + Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1721AEEF28704E3100EC4FDB /* Strings + Extension.swift */; };
  24 + 1721AEF228705FD600EC4FDB /* OTPView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1721AEF128705FD600EC4FDB /* OTPView.swift */; };
23 25 17287C602848AD8D00AA7113 /* Fonts + Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17287C5F2848AD8D00AA7113 /* Fonts + Extension.swift */; };
24 26 17287C692848C69600AA7113 /* Sk-Modernist-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 17287C642848C69600AA7113 /* Sk-Modernist-Bold.otf */; };
25 27 17287C6A2848C69600AA7113 /* Sk-Modernist-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 17287C652848C69600AA7113 /* Sk-Modernist-Regular.otf */; };
... ... @@ -32,8 +34,8 @@
32 34 1738F7DA2850F5F1003F1806 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1738F7D92850F5F1003F1806 /* SettingsView.swift */; };
33 35 175DA474285241C90075F0A9 /* SettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 175DA473285241C90075F0A9 /* SettingsModel.swift */; };
34 36 1763F7FC2861FFFD005D988C /* ResidentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1763F7FB2861FFFD005D988C /* ResidentTableViewCell.swift */; };
35   - 1764A05C28670B9F00847A30 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1764A05B28670B9F00847A30 /* NetworkManager.swift */; };
36   - 1764A05E28673C7F00847A30 /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1764A05D28673C7F00847A30 /* Constant.swift */; };
  37 + 1764A05C28670B9F00847A30 /* AuthNetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1764A05B28670B9F00847A30 /* AuthNetworkManager.swift */; };
  38 + 1764A05E28673C7F00847A30 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1764A05D28673C7F00847A30 /* Constants.swift */; };
37 39 1774213D2866EE13002730EE /* AuthModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1774213C2866EE13002730EE /* AuthModel.swift */; };
38 40 17ABE070285B80DC0006E7EC /* DisplayNameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17ABE06F285B80DC0006E7EC /* DisplayNameCell.swift */; };
39 41 17ABE072285B810F0006E7EC /* SettingsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17ABE071285B810F0006E7EC /* SettingsTableViewCell.swift */; };
... ... @@ -68,6 +70,8 @@
68 70 00A48B79285F8F6600EF0A08 /* ProtocolDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProtocolDelegate.swift; sourceTree = "<group>"; };
69 71 00A48B7E285F8F9200EF0A08 /* ContactPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactPickerViewController.swift; sourceTree = "<group>"; };
70 72 00E581BA284F71CD00E779FB /* Checkbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Checkbox.swift; sourceTree = "<group>"; };
  73 + 1721AEEF28704E3100EC4FDB /* Strings + Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Strings + Extension.swift"; sourceTree = "<group>"; };
  74 + 1721AEF128705FD600EC4FDB /* OTPView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OTPView.swift; sourceTree = "<group>"; };
71 75 17287C5F2848AD8D00AA7113 /* Fonts + Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Fonts + Extension.swift"; sourceTree = "<group>"; };
72 76 17287C642848C69600AA7113 /* Sk-Modernist-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Sk-Modernist-Bold.otf"; sourceTree = "<group>"; };
73 77 17287C652848C69600AA7113 /* Sk-Modernist-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Sk-Modernist-Regular.otf"; sourceTree = "<group>"; };
... ... @@ -80,8 +84,8 @@
80 84 1738F7D92850F5F1003F1806 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
81 85 175DA473285241C90075F0A9 /* SettingsModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = "<group>"; };
82 86 1763F7FB2861FFFD005D988C /* ResidentTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResidentTableViewCell.swift; sourceTree = "<group>"; };
83   - 1764A05B28670B9F00847A30 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
84   - 1764A05D28673C7F00847A30 /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; };
  87 + 1764A05B28670B9F00847A30 /* AuthNetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthNetworkManager.swift; sourceTree = "<group>"; };
  88 + 1764A05D28673C7F00847A30 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
85 89 1774213C2866EE13002730EE /* AuthModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthModel.swift; sourceTree = "<group>"; };
86 90 17ABE06F285B80DC0006E7EC /* DisplayNameCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayNameCell.swift; sourceTree = "<group>"; };
87 91 17ABE071285B810F0006E7EC /* SettingsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTableViewCell.swift; sourceTree = "<group>"; };
... ... @@ -121,8 +125,8 @@
121 125 00A48B5D285F8CDD00EF0A08 /* OneTimePasswordScreen */ = {
122 126 isa = PBXGroup;
123 127 children = (
124   - 00A48B5E285F8CDD00EF0A08 /* View */,
125 128 00A48B60285F8CDD00EF0A08 /* ViewController */,
  129 + 00A48B5E285F8CDD00EF0A08 /* View */,
126 130 );
127 131 path = OneTimePasswordScreen;
128 132 sourceTree = "<group>";
... ... @@ -130,6 +134,7 @@
130 134 00A48B5E285F8CDD00EF0A08 /* View */ = {
131 135 isa = PBXGroup;
132 136 children = (
  137 + 1721AEF128705FD600EC4FDB /* OTPView.swift */,
133 138 00A48B5F285F8CDD00EF0A08 /* CodeVerificationView.swift */,
134 139 );
135 140 path = View;
... ... @@ -146,9 +151,9 @@
146 151 00A48B64285F8CEA00EF0A08 /* AddResidentsScreen */ = {
147 152 isa = PBXGroup;
148 153 children = (
  154 + 00A48B68285F8CEA00EF0A08 /* ViewController */,
149 155 00A48B65285F8CEA00EF0A08 /* View */,
150 156 00A48B67285F8CEA00EF0A08 /* ResidentModel.swift */,
151   - 00A48B68285F8CEA00EF0A08 /* ViewController */,
152 157 );
153 158 path = AddResidentsScreen;
154 159 sourceTree = "<group>";
... ... @@ -182,7 +187,8 @@
182 187 children = (
183 188 00A48B75285F8EE800EF0A08 /* Colors + Extension.swift */,
184 189 );
185   - path = "Colors + Extension";
  190 + name = "Colors + Extension";
  191 + path = "InterQR-Internship/Extensions/Colors + Extension";
186 192 sourceTree = SOURCE_ROOT;
187 193 };
188 194 00A48B77285F8F6600EF0A08 /* Protocols */ = {
... ... @@ -278,6 +284,31 @@
278 284 path = Checkbox;
279 285 sourceTree = "<group>";
280 286 };
  287 + 1721AEEB28704D6500EC4FDB /* PhonePickerModel */ = {
  288 + isa = PBXGroup;
  289 + children = (
  290 + 1729E22028465DA9006C7C29 /* PhonePickerModel.swift */,
  291 + );
  292 + path = PhonePickerModel;
  293 + sourceTree = "<group>";
  294 + };
  295 + 1721AEEC28704DBF00EC4FDB /* Extensions */ = {
  296 + isa = PBXGroup;
  297 + children = (
  298 + 1721AEED28704DCD00EC4FDB /* String + Extension */,
  299 + 00A48B74285F8EE800EF0A08 /* Colors + Extension */,
  300 + );
  301 + path = Extensions;
  302 + sourceTree = "<group>";
  303 + };
  304 + 1721AEED28704DCD00EC4FDB /* String + Extension */ = {
  305 + isa = PBXGroup;
  306 + children = (
  307 + 1721AEEF28704E3100EC4FDB /* Strings + Extension.swift */,
  308 + );
  309 + path = "String + Extension";
  310 + sourceTree = "<group>";
  311 + };
281 312 17287C5E2848AC8800AA7113 /* Fonts + Extension */ = {
282 313 isa = PBXGroup;
283 314 children = (
... ... @@ -334,7 +365,7 @@
334 365 1764A05A28670B7200847A30 /* NetworkManager */ = {
335 366 isa = PBXGroup;
336 367 children = (
337   - 1764A05B28670B9F00847A30 /* NetworkManager.swift */,
  368 + 1764A05B28670B9F00847A30 /* AuthNetworkManager.swift */,
338 369 );
339 370 path = NetworkManager;
340 371 sourceTree = "<group>";
... ... @@ -342,6 +373,7 @@
342 373 1774213A2866EDF4002730EE /* Models */ = {
343 374 isa = PBXGroup;
344 375 children = (
  376 + 1721AEEB28704D6500EC4FDB /* PhonePickerModel */,
345 377 1774213B2866EDFD002730EE /* Auth Model */,
346 378 );
347 379 path = Models;
... ... @@ -464,10 +496,10 @@
464 496 17CF9EDF2844ED8F000D8077 /* InterQR-Internship */ = {
465 497 isa = PBXGroup;
466 498 children = (
  499 + 1721AEEC28704DBF00EC4FDB /* Extensions */,
467 500 1764A05A28670B7200847A30 /* NetworkManager */,
468 501 1774213A2866EDF4002730EE /* Models */,
469 502 00A48B77285F8F6600EF0A08 /* Protocols */,
470   - 00A48B74285F8EE800EF0A08 /* Colors + Extension */,
471 503 00E581B7284F71A700E779FB /* Common */,
472 504 00E581B0284F666000E779FB /* Modules */,
473 505 17CF9EE02844ED8F000D8077 /* AppDelegate.swift */,
... ... @@ -476,8 +508,7 @@
476 508 17CF9EEB2844ED90000D8077 /* LaunchScreen.storyboard */,
477 509 17CF9EEE2844ED90000D8077 /* Info.plist */,
478 510 1729E21C28465162006C7C29 /* PhoneService.swift */,
479   - 1729E22028465DA9006C7C29 /* PhonePickerModel.swift */,
480   - 1764A05D28673C7F00847A30 /* Constant.swift */,
  511 + 1764A05D28673C7F00847A30 /* Constants.swift */,
481 512 );
482 513 path = "InterQR-Internship";
483 514 sourceTree = "<group>";
... ... @@ -634,7 +665,7 @@
634 665 isa = PBXSourcesBuildPhase;
635 666 buildActionMask = 2147483647;
636 667 files = (
637   - 1764A05C28670B9F00847A30 /* NetworkManager.swift in Sources */,
  668 + 1764A05C28670B9F00847A30 /* AuthNetworkManager.swift in Sources */,
638 669 17ABE070285B80DC0006E7EC /* DisplayNameCell.swift in Sources */,
639 670 00A48B73285F8EB000EF0A08 /* SquereCheckBox.swift in Sources */,
640 671 1729E22128465DA9006C7C29 /* PhonePickerModel.swift in Sources */,
... ... @@ -646,8 +677,10 @@
646 677 17ABE072285B810F0006E7EC /* SettingsTableViewCell.swift in Sources */,
647 678 17CD09AC2858F9B0008483E2 /* ResidentsView.swift in Sources */,
648 679 00A48B7A285F8F6600EF0A08 /* Reusable + Cell.swift in Sources */,
  680 + 1721AEF228705FD600EC4FDB /* OTPView.swift in Sources */,
649 681 00A48B71285F8E8200EF0A08 /* HomeTableViewCell.swift in Sources */,
650 682 00A48B6E285F8E5700EF0A08 /* TextFieldWithPadding.swift in Sources */,
  683 + 1721AEF028704E3100EC4FDB /* Strings + Extension.swift in Sources */,
651 684 17B0254628587716004225AE /* ChooseApartmentsViewController.swift in Sources */,
652 685 17ABFE58284FD20C003B6959 /* HomeViewController.swift in Sources */,
653 686 17CF9EE52844ED8F000D8077 /* VerificationViewController.swift in Sources */,
... ... @@ -669,7 +702,7 @@
669 702 17287C602848AD8D00AA7113 /* Fonts + Extension.swift in Sources */,
670 703 00A48B6A285F8CEA00EF0A08 /* AddResidentsView.swift in Sources */,
671 704 00A48B63285F8CDD00EF0A08 /* CodeVerificationViewController.swift in Sources */,
672   - 1764A05E28673C7F00847A30 /* Constant.swift in Sources */,
  705 + 1764A05E28673C7F00847A30 /* Constants.swift in Sources */,
673 706 17ABE074285B81390006E7EC /* SettingsSwitchCell.swift in Sources */,
674 707 17CF9EF72844EF8B000D8077 /* VerificationView.swift in Sources */,
675 708 17B0254828587726004225AE /* ChooseApartmentsView.swift in Sources */,
... ...
... ... @@ -20,5 +20,21 @@
20 20 landmarkType = "7">
21 21 </BreakpointContent>
22 22 </BreakpointProxy>
  23 + <BreakpointProxy
  24 + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
  25 + <BreakpointContent
  26 + uuid = "352946CD-61D5-4838-888E-86E2F3E773EF"
  27 + shouldBeEnabled = "Yes"
  28 + ignoreCount = "0"
  29 + continueAfterRunningActions = "No"
  30 + filePath = "InterQR-Internship/Common/CustomUI/OTPView.swift"
  31 + startingColumnNumber = "9223372036854775807"
  32 + endingColumnNumber = "9223372036854775807"
  33 + startingLineNumber = "112"
  34 + endingLineNumber = "112"
  35 + landmarkName = "handleErrorUI(_:)"
  36 + landmarkType = "7">
  37 + </BreakpointContent>
  38 + </BreakpointProxy>
23 39 </Breakpoints>
24 40 </Bucket>
... ...
  1 +{
  2 + "colors" : [
  3 + {
  4 + "color" : {
  5 + "color-space" : "srgb",
  6 + "components" : {
  7 + "alpha" : "1.000",
  8 + "blue" : "0.180",
  9 + "green" : "0.000",
  10 + "red" : "1.000"
  11 + }
  12 + },
  13 + "idiom" : "universal"
  14 + },
  15 + {
  16 + "appearances" : [
  17 + {
  18 + "appearance" : "luminosity",
  19 + "value" : "dark"
  20 + }
  21 + ],
  22 + "color" : {
  23 + "color-space" : "srgb",
  24 + "components" : {
  25 + "alpha" : "1.000",
  26 + "blue" : "1.000",
  27 + "green" : "1.000",
  28 + "red" : "1.000"
  29 + }
  30 + },
  31 + "idiom" : "universal"
  32 + }
  33 + ],
  34 + "info" : {
  35 + "author" : "xcode",
  36 + "version" : 1
  37 + }
  38 +}
... ...
... ... @@ -7,8 +7,7 @@
7 7
8 8 import Foundation
9 9 import UIKit
10   -class Checkbox: UIButton {
11   -
  10 +class Checkbox: UIButton {
12 11 private let checkboxImageView: UIImageView = {
13 12 let obj = UIImageView()
14 13 return obj
... ... @@ -26,8 +25,8 @@ class Checkbox: UIButton {
26 25 .TextColor.darkBlue :
27 26 .TextColor.lightGrey
28 27 checkboxImageView.image = isSelected ?
29   - UIImage(named: "OnIndicator") :
30   - UIImage(named: "OffIndicator")
  28 + UIImage(named: .Image.onIndicator) :
  29 + UIImage(named: .Image.offIndicator)
31 30 }
32 31 }
33 32
... ...
... ... @@ -24,8 +24,8 @@ class SquereCheckbox: UIButton {
24 24 .TextColor.darkBlue :
25 25 .TextColor.lightGrey
26 26 checkboxImageView.image = isSelected ?
27   - UIImage(named: "FullSquere") :
28   - UIImage(named: "EmptySquere")
  27 + UIImage(named: .Image.fullSquere) :
  28 + UIImage(named: .Image.emptySquere)
29 29 }
30 30 }
31 31
... ...
... ... @@ -18,7 +18,7 @@ class TextFieldWithPadding: UITextField {
18 18 let rect = super.textRect(forBounds: bounds)
19 19 return rect.inset(by: textPadding)
20 20 }
21   -
  21 +
22 22 override func editingRect(forBounds bounds: CGRect) -> CGRect {
23 23 let rect = super.editingRect(forBounds: bounds)
24 24 return rect.inset(by: textPadding)
... ...
1   -//
2   -// Constant.swift
3   -// InterQR-Internship
4   -//
5   -// Created by Дмитрий Тимофеев on 25.06.2022.
6   -//
7   -
8   -import Foundation
9   -
10   -enum Constant: String {
11   - case URL = "https://www.interqr.com/api/init"
12   -}
  1 +//
  2 +// Constant.swift
  3 +// InterQR-Internship
  4 +//
  5 +// Created by Дмитрий Тимофеев on 25.06.2022.
  6 +//
  7 +
  8 +import Foundation
  9 +
  10 +struct Constants {
  11 + enum APIRoutes {
  12 + case initURL
  13 + case startURL
  14 + case verifyURL
  15 + case loginURL
  16 + case logoutURL
  17 +
  18 + var urlString: String {
  19 + switch self {
  20 + case .initURL:
  21 + return "https://www.interqr.com/api/init"
  22 + case .startURL:
  23 + return "https://www.interqr.com/api/twofa/start"
  24 + case .verifyURL:
  25 + return "https://www.interqr.com/api/twofa/verify"
  26 + case .loginURL:
  27 + return "https://www.interqr.com/api/login"
  28 + case .logoutURL:
  29 + return "https://www.interqr.com/api/logout"
  30 + }
  31 + }
  32 + }
  33 +}
  34 +
... ...
... ... @@ -22,6 +22,12 @@ extension UIColor {
22 22
23 23 enum Background {
24 24 static let lightGrey = UIColor(named: "LightGreyBackground")
  25 + static let lightRed = UIColor(named: "LightRedBackgroud")
  26 + }
  27 +
  28 + enum GradientBlue {
  29 + static let left = UIColor(named: "Left")?.cgColor
  30 + static let right = UIColor(named: "Right")?.cgColor
25 31 }
26 32
27 33 }
... ... @@ -36,3 +42,10 @@ extension CGColor {
36 42 static let right = UIColor(named: "Right")?.cgColor
37 43 }
38 44 }
  45 +
  46 +extension CAGradientLayer {
  47 + enum GradientBlue {
  48 + static let left = UIColor(named: "Left")?.cgColor
  49 + static let right = UIColor(named: "Right")?.cgColor
  50 + }
  51 +}
... ...
  1 +//
  2 +// Strings + Extension.swift
  3 +// InterQR-Internship
  4 +//
  5 +// Created by Дмитрий Тимофеев on 02.07.2022.
  6 +//
  7 +
  8 +import Foundation
  9 +import UIKit
  10 +
  11 +extension String {
  12 + enum Text {
  13 + static let addResident = "Add resident"
  14 + static let residentName = "Resident name"
  15 + static let enterResidentName = "Enter resident name"
  16 + static let mobileNumber = "Mobile number"
  17 + static let enterResidentNumber = "Enter resident number"
  18 + static let manager = "Manager"
  19 + static let hidden = "Hidden"
  20 + static let enterYourVerificationCode = "Enter your\nverification code"
  21 + static let pleaseEnterValidCode = "Please, enter valid verification code"
  22 + static let verify = "Verify"
  23 + static let myApartName = "My apart name"
  24 + static let residents = "Residents"
  25 + static let chooseApartment = "Choose\napartman"
  26 + static let settings = "Settings"
  27 + static let logout = "Logout"
  28 + static let yourDisplayName = "Your display name"
  29 + static let nameWillBeDisplay = "This name will be displayed everywhere"
  30 + static let editResidents = "Edit residents"
  31 + static let editResidentsAndInfo = "Edit the residents and their information"
  32 + static let doNotDisturb = "Do not disturb"
  33 + static let youWillNotBeNotified = "You will not be notified of any calls for one day. Auto reset at midnight"
  34 + static let welcome = "Welcome"
  35 + static let myDoors = "My doors"
  36 + static let locked = "Locked"
  37 + static let home = "Home"
  38 + static let frontDoor = "Front Door"
  39 + static let selectYourCountry = "Select your country"
  40 + static let select = "Select"
  41 + static let hello = "Hello"
  42 + static let letsVerifyYourAccount = "Lets verify your \naccount"
  43 + static let chooseWhatToStartWith = "Choose what to start with"
  44 + static let email = "Email"
  45 + static let phoneNumber = "Phone Number"
  46 + static let enterYourEmailAddress = "Enter your email address"
  47 + static let exampleEmail = "Example: john.doe@gmail.com"
  48 + static let plusOne = "+1"
  49 + static let verificationCodeWillBeSentToYourEmail = "Verification code will be sent to your e-mail"
  50 + static let continueText = "Continue"
  51 + static let johnDoe = "John Doe"
  52 + static let userCode = "503331651"
  53 + static let enterYourPhoneNumber = "Enter your phone number"
  54 + static let verificationCodeWillBeSentToYourNumber = "Verification code will be sent to\nyour phone number"
  55 + static let apple = "Apple"
  56 + }
  57 +
  58 + enum Image {
  59 + static let close = "Close"
  60 + static let threeUsers = "3Users"
  61 + static let heart = "Heart"
  62 + static let heartRed = "HeartRed"
  63 + static let backPointer = "BackPointer"
  64 + static let interQR = "InterQR"
  65 + static let lock = "Lock"
  66 + static let RectangleWithShadow = "RectangleWithShadow"
  67 + static let tick = "Tick"
  68 + static let edit = "Edit"
  69 + static let bin = "Bin"
  70 + static let mask = "Mask"
  71 + static let apartman = "Apartman"
  72 + static let nextPointer = "NextPointer"
  73 + static let gear = "Gear"
  74 + static let profile = "Profile"
  75 + static let notification = "Notification"
  76 + static let setting = "Setting"
  77 + static let home = "Home"
  78 + static let gradient = "Gradient"
  79 + static let password = "Password"
  80 + static let rightStatus = "RightBlue"
  81 + static let leftBlue = "LeftBlue"
  82 + static let shield = "Shield"
  83 + static let USA = "USA"
  84 + static let flagPointer = "FlagPointer"
  85 + static let fullSquere = "FullSquere"
  86 + static let emptySquere = "EmptySquere"
  87 + static let pointer = "Pointer"
  88 + static let onIndicator = "OnIndicator"
  89 + static let offIndicator = "OffIndicator"
  90 + }
  91 +}
... ...
... ... @@ -6,49 +6,23 @@
6 6 //
7 7
8 8 import Foundation
9   -struct InterQR: Decodable {
10   - var Auth: Auth
11   -}
12   -
13   -struct Auth: Decodable {
14   - var initialize: Init
15   - var start: Start
16   - var verify: Verify
17   - var login: Login
18   -
19   - enum CodingKeys: String, CodingKey {
20   - case initialize = "init"
21   - case start = "start 2fa"
22   - case verify = "verify 2fa"
23   - case login
24   - }
25   -}
26   -
27   -struct Initialize : Decodable {
28   - var message: Init
29   -
30   - enum CodingKeys: String, CodingKey {
31   - case message = "message"
32   - }
33   -}
34 9
35   -struct Init: Decodable {
36   - var deviceID: String
  10 +//MARK: - Init collection
  11 +struct InitRequestModel: Codable {
  12 + var deviceUUID: String
37 13 var manufacturer: String
38 14 var model: String
39 15 var platform: String
40 16 var osVersion: String
41 17 var appVersion: String
42   -
43   - enum CodingKeys: String, CodingKey {
44   - case deviceID = "device_uuid"
45   - case manufacturer, model, platform
46   - case osVersion = "os_version"
47   - case appVersion = "app_version"
48   - }
49 18 }
50 19
51   -struct Start: Decodable {
  20 +struct InitResponseModel: Decodable {
  21 + var message: String
  22 +}
  23 +
  24 +//MARK: - Start2fa collection
  25 +struct StartRequestModel: Codable {
52 26 var emailOrNumber: String
53 27
54 28 enum CodingKeys: String, CodingKey {
... ... @@ -56,7 +30,12 @@ struct Start: Decodable {
56 30 }
57 31 }
58 32
59   -struct Verify: Decodable {
  33 +struct StartResponseModel: Decodable {
  34 + var message: String
  35 +}
  36 +
  37 +//MARK: - Verify2fa collection
  38 +struct VerifyRequestModel: Codable {
60 39 var emailOrNumber: String
61 40 var code: String
62 41 var secondAuthToken: String
... ... @@ -68,10 +47,39 @@ struct Verify: Decodable {
68 47 }
69 48 }
70 49
71   -struct Login: Decodable {
72   - var deviceID: String
  50 +struct VerifyResponseModel: Decodable {
  51 + var data: VerifyData
  52 + var message: String
  53 +}
  54 +
  55 +struct VerifyData: Decodable {
  56 + var token: String
  57 + var uuid: String
  58 +}
  59 +
  60 +//MARK: - Login collection
  61 +struct LoginRequestModel: Codable {
  62 + var deviceUUID: String
  63 +
  64 + enum CodingKeys: String, CodingKey {
  65 + case deviceUUID = "device_uuid"
  66 + }
  67 +}
  68 +
  69 +struct LoginResponseModel: Decodable {
  70 + var message: String?
  71 +}
  72 +
  73 +//MARK: - Logout collection
  74 +
  75 +struct LogoutRequestModel: Codable {
  76 + var deviceUUID: String
73 77
74 78 enum CodingKeys: String, CodingKey {
75   - case deviceID = "device_uuid"
  79 + case deviceUUID = "device_uuid"
76 80 }
77 81 }
  82 +
  83 +struct LogoutResponseModel: Decodable {
  84 + var message: String?
  85 +}
... ...
... ... @@ -9,7 +9,6 @@ import Foundation
9 9 import UIKit
10 10
11 11 struct PhonePickerModel {
12   -
13 12 let code: String
14 13 let countryCode: String
15 14 let title: String
... ...
... ... @@ -37,7 +37,7 @@ class AddResidentsView: UIView {
37 37
38 38 var addResidentLabeL: UILabel = {
39 39 var obj = UILabel()
40   - obj.text = "Add resident"
  40 + obj.text = .Text.addResident
41 41 obj.textColor = .TextColor.darkBlue
42 42 obj.font = .skModernist(type: .bold, ofSize: 24)
43 43 return obj
... ... @@ -48,7 +48,7 @@ class AddResidentsView: UIView {
48 48 obj.layer.cornerRadius = 13
49 49 obj.layer.borderWidth = 1
50 50 obj.layer.borderColor = .BorderColor.lightGrey
51   - obj.setImage(UIImage(named: "Close"), for: .normal)
  51 + obj.setImage(UIImage(named: .Image.close), for: .normal)
52 52 return obj
53 53 }()
54 54
... ... @@ -60,7 +60,7 @@ class AddResidentsView: UIView {
60 60
61 61 var residentNameLabel: UILabel = {
62 62 var obj = UILabel()
63   - obj.text = "Resident name"
  63 + obj.text = .Text.residentName
64 64 obj.font = .skModernist(type: .bold, ofSize: 14)
65 65 obj.textColor = .TextColor.darkBlue
66 66 return obj
... ... @@ -71,7 +71,7 @@ class AddResidentsView: UIView {
71 71 obj.backgroundColor = .TextFieldColor.general
72 72 obj.textAlignment = .left
73 73 obj.layer.cornerRadius = 15
74   - obj.placeholder = "Enter resident name"
  74 + obj.placeholder = .Text.enterResidentName
75 75 obj.font = .skModernist(type: .regular, ofSize: 14)
76 76 obj.textPadding = UIEdgeInsets(top: 0, left: 22, bottom: 0, right: 22)
77 77 return obj
... ... @@ -79,9 +79,9 @@ class AddResidentsView: UIView {
79 79
80 80 var mobileNumberLabel: UILabel = {
81 81 var obj = UILabel()
82   - obj.text = "Mobile number"
  82 + obj.text = .Text.mobileNumber
83 83 obj.font = .skModernist(type: .bold, ofSize: 14)
84   - obj.textColor = .TextColor.lightGrey
  84 + obj.textColor = .TextColor.darkBlue
85 85 return obj
86 86 }()
87 87
... ... @@ -92,39 +92,38 @@ class AddResidentsView: UIView {
92 92 obj.layer.cornerRadius = 15
93 93 obj.font = .skModernist(type: .regular, ofSize: 14)
94 94 obj.textPadding = UIEdgeInsets(top: 0, left: 22, bottom: 0, right: 45)
95   - obj.placeholder = "Enter resident number"
  95 + obj.placeholder = .Text.enterResidentNumber
96 96 return obj
97 97 }()
98 98
99 99 let contactListButton: UIButton = {
100 100 let obj = UIButton()
101   - obj.setImage(UIImage(named:"3Users"), for: .normal)
  101 + obj.setImage(UIImage(named: .Image.threeUsers), for: .normal)
102 102 return obj
103 103 }()
104 104
105 105 var managerButton: SquereCheckbox = {
106 106 var obj = SquereCheckbox()
107   - obj.checkboxTitle = "Manager"
  107 + obj.checkboxTitle = .Text.manager
108 108 return obj
109 109 }()
110 110
111 111 var hiddenButton: SquereCheckbox = {
112 112 var obj = SquereCheckbox()
113   - obj.checkboxTitle = "Hidden"
  113 + obj.checkboxTitle = .Text.hidden
114 114 return obj
115 115 }()
116 116
117 117 var heartButton: UIButton = {
118 118 var obj = UIButton()
119   - obj.setImage(UIImage(named: "Heart"), for: .normal)
120   - obj.setImage(UIImage(named: "HeartRed"), for: .selected)
  119 + obj.setImage(UIImage(named: .Image.heart), for: .normal)
  120 + obj.setImage(UIImage(named: .Image.heartRed), for: .selected)
121 121 return obj
122 122 }()
123 123
124 124 var gradientBG: CAGradientLayer = {
125 125 let obj = CAGradientLayer()
126 126 var leftColor = CGColor.GradientBlue.left
127   -
128 127 var rightColor = CGColor.GradientBlue.right
129 128 obj.colors = [leftColor, rightColor]
130 129 obj.startPoint = CGPoint(x: 0, y: 0.5)
... ... @@ -134,7 +133,7 @@ class AddResidentsView: UIView {
134 133
135 134 var addResidentButton: UIButton = {
136 135 var obj = UIButton()
137   - obj.setTitle("Add resident", for: .normal)
  136 + obj.setTitle(.Text.addResident, for: .normal)
138 137 obj.setTitleColor(.white, for: .normal)
139 138 obj.titleLabel?.font = .skModernist(type: .bold, ofSize: 16)
140 139 obj.clipsToBounds = true
... ...
... ... @@ -9,14 +9,12 @@ import UIKit
9 9 import ContactsUI
10 10
11 11 class AddResidentsViewController: UIViewController {
12   - var savedResidents: [ResidentModel] = []
  12 + var isKeyboardAppear = false
13 13
  14 + var savedResidents: [ResidentModel] = []
14 15 weak var delegate: ResidentSavable?
15 16
16 17 var contact = ContactPickerViewController()
17   -
18   - var isKeyboardAppear = false
19   -
20 18 var mainView = AddResidentsView()
21 19
22 20 var closeTap: UITapGestureRecognizer?
... ... @@ -56,7 +54,6 @@ class AddResidentsViewController: UIViewController {
56 54 mainView.mobileNumberTextField.reloadInputViews()
57 55 }
58 56
59   -
60 57 @objc private func didTapCloseButton() {
61 58 dismiss(animated: true, completion: nil)
62 59 }
... ... @@ -80,13 +77,13 @@ class AddResidentsViewController: UIViewController {
80 77 heart: mainView.heartButton.isSelected)]
81 78 savedResidents.append(contentsOf: model)
82 79 delegate?.save(savedResidents)
83   -// ???????????????????????????????
  80 + // ???????????????????????????????
84 81 mainView.nameTextField.text = "" //???
85 82 mainView.mobileNumberTextField.text = "" //???
86 83 mainView.managerButton.isSelected = false //???
87 84 mainView.hiddenButton.isSelected = false //???
88 85 mainView.heartButton.isSelected = false //???
89   -// ???????????????????????????????
  86 + // ???????????????????????????????
90 87 }
91 88
92 89 @objc private func didTapOnChangeableButtons(_ sender: SquereCheckbox) {
... ... @@ -114,7 +111,7 @@ class AddResidentsViewController: UIViewController {
114 111 }
115 112 }
116 113
117   - @objc func didTapContactListButton() {
  114 + @objc private func didTapContactListButton() {
118 115 presentContactPickerVC()
119 116 }
120 117
... ...
... ... @@ -12,14 +12,14 @@ class ChooseApartmentsTableViewCell: UITableViewCell {
12 12
13 13 var apartmanImage: UIImageView = {
14 14 var obj = UIImageView()
15   - obj.image = UIImage(named: "Apartman")
  15 + obj.image = UIImage(named: .Image.apartman)
16 16 return obj
17 17 }()
18 18
19 19 var clientNameLabel: UILabel = {
20 20 var obj = UILabel()
21 21 obj.text = "Bares Family"
22   - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1)
  22 + obj.textColor = .TextColor.darkBlue
23 23 obj.font = .skModernist(type: .bold, ofSize: 16)
24 24 return obj
25 25 }()
... ... @@ -27,27 +27,27 @@ class ChooseApartmentsTableViewCell: UITableViewCell {
27 27 var adressLabel: UILabel = {
28 28 var obj = UILabel()
29 29 obj.text = "200 5th Ave"
30   - obj.textColor = UIColor(red: 0.725, green: 0.725, blue: 0.725, alpha: 1)
  30 + obj.textColor = .TextColor.lightGrey
31 31 obj.font = .skModernist(type: .regular, ofSize: 14)
32 32 return obj
33 33 }()
34 34
35 35 var nextPointerImage: UIImageView = {
36 36 var obj = UIImageView()
37   - obj.image = UIImage(named: "NextPointer")
  37 + obj.image = UIImage(named: .Image.nextPointer)
38 38 return obj
39 39 }()
40 40
41 41 override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
42 42 super.init(style: style, reuseIdentifier: reuseIdentifier)
43   - layout()
  43 + setup()
44 44 }
45 45
46 46 required init?(coder: NSCoder) {
47 47 fatalError("init(coder:) has not been implemented")
48 48 }
49 49
50   - func layout() {
  50 + func setup() {
51 51 selectionStyle = .none
52 52 contentView.addSubview(apartmanImage)
53 53 contentView.addSubview(clientNameLabel)
... ...
... ... @@ -11,9 +11,9 @@ class ChooseApartmentView: UIView {
11 11
12 12 var backButton: UIButton = {
13 13 var obj = UIButton()
14   - obj.setImage(UIImage(named: "BackPointer"), for: .normal)
  14 + obj.setImage(UIImage(named: .Image.backPointer), for: .normal)
15 15 obj.backgroundColor = .white
16   - obj.layer.borderColor = UIColor(red: 224/255, green: 231/255, blue: 232/255, alpha: 1).cgColor
  16 + obj.layer.borderColor = .BorderColor.lightGrey
17 17 obj.layer.cornerRadius = 13
18 18 obj.layer.borderWidth = 1
19 19 return obj
... ... @@ -21,20 +21,20 @@ class ChooseApartmentView: UIView {
21 21
22 22 var logoImage: UIImageView = {
23 23 var obj = UIImageView()
24   - obj.image = UIImage(named: "InterQR")
  24 + obj.image = UIImage(named: .Image.interQR)
25 25 return obj
26 26 }()
27 27
28 28 var tickImage: UIImageView = {
29 29 var obj = UIImageView()
30   - obj.image = UIImage(named: "Mask")
  30 + obj.image = UIImage(named: .Image.mask)
31 31 return obj
32 32 }()
33 33
34 34 let apartmentsLabel: UILabel = {
35 35 var obj = UILabel()
36 36 obj.font = .skModernist(type: .bold, ofSize: 35)
37   - obj.text = "Choose\napartman"
  37 + obj.text = .Text.chooseApartment
38 38 obj.numberOfLines = 0
39 39 return obj
40 40 }()
... ...
... ... @@ -21,9 +21,9 @@ class ChooseApartmentsViewController: UIViewController {
21 21 }
22 22
23 23 func initViewController() {
24   - mainView.backButton.addTarget(self, action: #selector(backToSettingsVC), for: .touchUpInside)
25 24 mainView.tableView.delegate = self
26 25 mainView.tableView.dataSource = self
  26 + mainView.backButton.addTarget(self, action: #selector(backToSettingsVC), for: .touchUpInside)
27 27 mainView.tableView.register(ChooseApartmentsTableViewCell.self, forCellReuseIdentifier: ChooseApartmentsTableViewCell.id)
28 28 }
29 29
... ... @@ -49,7 +49,5 @@ extension ChooseApartmentsViewController: UITableViewDelegate, UITableViewDataSo
49 49 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
50 50 let vc = ResidentsViewController()
51 51 navigationController?.pushViewController(vc, animated: true)
52   - print("❌")
53   -
54 52 }
55 53 }
... ...
... ... @@ -11,11 +11,8 @@ import ContactsUI
11 11
12 12 class ContactPickerViewController: CNContactPickerViewController {
13 13 var phoneNumber = ""
14   -
15   - override func viewDidLoad() {
16   -// delegate = self
17   - }
18 14 }
  15 +
19 16 //MARK: - Contact picker delegate
20 17 extension ContactPickerViewController: CNContactPickerDelegate {
21 18 func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
... ...
... ... @@ -20,7 +20,7 @@ class HomeTableViewCell: UITableViewCell {
20 20
21 21 var leftStatusImage: UIImageView = {
22 22 var obj = UIImageView()
23   - obj.image = UIImage(named: "LeftBlue")
  23 + obj.image = UIImage(named: .Image.leftBlue)
24 24 obj.contentMode = .scaleAspectFill
25 25 return obj
26 26 }()
... ... @@ -29,7 +29,7 @@ class HomeTableViewCell: UITableViewCell {
29 29 var obj = UILabel()
30 30 obj.font = .skModernist(type: .bold, ofSize: 16)
31 31 obj.textColor = .TextColor.darkBlue
32   - obj.text = "Front Door"
  32 + obj.text = .Text.frontDoor
33 33 return obj
34 34 }()
35 35
... ... @@ -37,34 +37,34 @@ class HomeTableViewCell: UITableViewCell {
37 37 var obj = UILabel()
38 38 obj.textColor = .TextColor.lightGrey
39 39 obj.font = .skModernist(type: .regular, ofSize: 14)
40   - obj.text = "Home"
  40 + obj.text = .Text.home
41 41 return obj
42 42 }()
43 43
44 44 var lockStatusLabel: UILabel = {
45 45 var obj = UILabel()
46   - obj.textColor = UIColor(red: 0, green: 0.267, blue: 0.545, alpha: 1)
  46 + obj.textColor = .TextColor.darkBlue
47 47 obj.font = .skModernist(type: .bold, ofSize: 15)
48   - obj.text = "Locked"
  48 + obj.text = .Text.locked
49 49 return obj
50 50 }()
51 51
52 52 var rightStatusImage: UIImageView = {
53 53 var obj = UIImageView()
54   - obj.image = UIImage(named: "RightBlue")
  54 + obj.image = UIImage(named: .Image.rightStatus)
55 55 return obj
56 56 }()
57 57
58 58 override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
59 59 super.init(style: style, reuseIdentifier: reuseIdentifier)
60   - layout()
  60 + setup()
61 61 }
62 62
63 63 required init?(coder: NSCoder) {
64 64 fatalError("init(coder:) has not been implemented")
65 65 }
66 66
67   - func layout() {
  67 + func setup() {
68 68 selectionStyle = .none
69 69
70 70 addSubview(containerView)
... ... @@ -106,12 +106,5 @@ class HomeTableViewCell: UITableViewCell {
106 106 $0.top.equalTo(snp.top).offset(19)
107 107 }
108 108 }
109   - // func configureWithItem(_ item: DoorsModel) {
110   -
111   - // doorTypeLabel.text = item.purpose
112   - // doorLocationLabel.text = item.type
113   - // configureStatus(status: item.lockStatus)
114   - // rightStatusImageView.isHidden = false
115   - // }
116 109 }
117 110
... ...
... ... @@ -8,65 +8,71 @@
8 8 import UIKit
9 9
10 10 class HomeView: UIView {
11   -
12 11 var logoView: UIImageView = {
13 12 var obj = UIImageView()
14   - obj.image = UIImage(named: "InterQR")
  13 + obj.image = UIImage(named: .Image.interQR)
15 14 return obj
16 15 }()
  16 +
17 17 var settingsButton: UIButton = {
18 18 var obj = UIButton()
19   - obj.setImage(UIImage(named: "Setting"), for: .normal)
  19 + obj.setImage(UIImage(named: .Image.setting), for: .normal)
20 20 obj.layer.borderWidth = 1
21   - obj.layer.borderColor = UIColor(red: 0.882, green: 0.91, blue: 0.91, alpha: 1).cgColor
  21 + obj.layer.borderColor = .BorderColor.lightGrey
22 22 obj.layer.cornerRadius = 13
23 23 return obj
24 24 }()
  25 +
25 26 var homeImage: UIImageView = {
26 27 var obj = UIImageView()
27   - obj.image = UIImage(named: "Home")
  28 + obj.image = UIImage(named: .Image.home)
28 29 return obj
29 30 }()
  31 +
30 32 var welcomeLabel: UILabel = {
31 33 var obj = UILabel()
32 34 obj.font = .skModernist(type: .bold, ofSize: 35)
33   - obj.text = "Welcome"
  35 + obj.text = .Text.welcome
34 36 return obj
35 37 }()
  38 +
36 39 var doorsLabel: UILabel = {
37 40 var obj = UILabel()
38 41 obj.font = .skModernist(type: .bold, ofSize: 20)
39   - obj.text = "My doors"
  42 + obj.text = .Text.myDoors
40 43 return obj
41 44 }()
  45 +
42 46 var tableView: UITableView = {
43 47 var obj = UITableView()
44 48 obj.separatorStyle = .none
45 49 obj.showsVerticalScrollIndicator = false
46 50 return obj
47 51 }()
  52 +
48 53 var gradientView: UIImageView = {
49 54 var obj = UIImageView()
50   - obj.image = UIImage(named: "Gradient")
  55 + obj.image = UIImage(named: .Image.gradient)
51 56 return obj
52 57 }()
  58 +
53 59 var passwordButton: UIButton = {
54 60 var obj = UIButton()
55   - obj.setImage(UIImage(named: "Password"), for: .normal)
  61 + obj.setImage(UIImage(named: .Image.password), for: .normal)
56 62 return obj
57 63 }()
58 64
59 65 override init(frame: CGRect) {
60 66 super.init(frame: frame)
61 67 backgroundColor = .white
62   - layout()
  68 + setup()
63 69 }
64 70
65 71 required init?(coder: NSCoder) {
66 72 fatalError("init(coder:) has not been implemented")
67 73 }
68 74
69   - func layout() {
  75 + func setup() {
70 76 addSubview(logoView)
71 77 addSubview(settingsButton)
72 78 addSubview(welcomeLabel)
... ... @@ -80,33 +86,40 @@ class HomeView: UIView {
80 86 $0.top.equalTo(77)
81 87 $0.leading.equalTo(24)
82 88 }
  89 +
83 90 settingsButton.snp.makeConstraints {
84 91 $0.top.equalTo(snp.top).offset(63)
85 92 $0.trailing.equalTo(snp.trailing).offset(-27)
86 93 $0.height.width.equalTo(45)
87 94 }
  95 +
88 96 welcomeLabel.snp.makeConstraints {
89 97 $0.top.equalTo(logoView.snp.bottom).offset(63)
90 98 $0.leading.equalTo(logoView.snp.leading)
91 99 }
  100 +
92 101 homeImage.snp.makeConstraints {
93 102 $0.top.equalTo(settingsButton.snp.bottom)
94 103 $0.trailing.equalTo(snp.trailing).offset(5)
95 104 }
  105 +
96 106 doorsLabel.snp.makeConstraints {
97 107 $0.top.equalTo(homeImage.snp.bottom).offset(31)
98 108 $0.leading.equalTo(logoView.snp.leading)
99 109 }
  110 +
100 111 tableView.snp.makeConstraints {
101 112 $0.top.equalTo(doorsLabel.snp.bottom).offset(28)
102 113 $0.leading.equalTo(snp.leading).offset(20)
103 114 $0.trailing.equalTo(snp.trailing).offset(-27)
104 115 $0.bottom.equalToSuperview()
105 116 }
  117 +
106 118 gradientView.snp.makeConstraints {
107 119 $0.leading.trailing.bottom.equalToSuperview()
108 120 $0.height.equalTo(75)
109 121 }
  122 +
110 123 passwordButton.snp.makeConstraints {
111 124 $0.trailing.equalTo(gradientView.snp.trailing).offset(-48)
112 125 $0.bottom.equalTo(gradientView.snp.bottom).offset(-18)
... ...
... ... @@ -8,7 +8,6 @@
8 8 import UIKit
9 9
10 10 class HomeViewController: UIViewController {
11   -
12 11 var mainView = HomeView()
13 12
14 13 override func loadView() {
... ... @@ -28,8 +27,7 @@ class HomeViewController: UIViewController {
28 27 }
29 28
30 29 extension HomeViewController {
31   -
32   - @objc func didShowSettingsVC() {
  30 + @objc private func didShowSettingsVC() {
33 31 let vc = SettingsViewController()
34 32 navigationController?.pushViewController(vc, animated: true)
35 33 }
... ...
... ... @@ -15,9 +15,9 @@ class CodeVerificationView: UIView {
15 15
16 16 var backButton: UIButton = {
17 17 var obj = UIButton()
18   - obj.setImage(UIImage(named: "BackPointer"), for: .normal)
  18 + obj.setImage(UIImage(named: .Image.backPointer), for: .normal)
19 19 obj.backgroundColor = .white
20   - obj.layer.borderColor = UIColor(red: 224/255, green: 231/255, blue: 232/255, alpha: 1).cgColor
  20 + obj.layer.borderColor = .BorderColor.lightGrey
21 21 obj.layer.cornerRadius = 13
22 22 obj.layer.borderWidth = 1
23 23 return obj
... ... @@ -25,81 +25,33 @@ class CodeVerificationView: UIView {
25 25
26 26 var logoImage: UIImageView = {
27 27 var obj = UIImageView()
28   - obj.image = UIImage(named: "InterQR")
  28 + obj.image = UIImage(named: .Image.interQR)
29 29 return obj
30 30 }()
31 31
32 32 var shieldImage: UIImageView = {
33 33 var obj = UIImageView()
34   - obj.image = UIImage(named: "Lock")
  34 + obj.image = UIImage(named: .Image.lock)
35 35 return obj
36 36 }()
37 37
38 38 var descriptionLabel: UILabel = {
39 39 var obj = UILabel()
40   - obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 35)
41   - obj.text = "Enter your\nverification code"
  40 + obj.font = .skModernist(type: .bold, ofSize: 35)
  41 + obj.text = .Text.enterYourVerificationCode
42 42 obj.numberOfLines = 2
43 43 return obj
44 44 }()
45 45
46   - var textField: UITextField = {
47   - let obj = UITextField()
48   - obj.returnKeyType = .done
49   - obj.keyboardType = .numberPad
50   - obj.becomeFirstResponder()
51   - obj.isHidden = true
52   - return obj
53   - }()
54   -
55   - var firstDigitLabel: UILabel = {
56   - let obj = UILabel()
57   - obj.font = .skModernist(type: .bold, ofSize: 16)
58   - obj.textColor = .black
59   - obj.textAlignment = .center
60   - obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1)
61   - obj.layer.cornerRadius = 15
62   - obj.clipsToBounds = true
63   - return obj
64   - }()
65   -
66   - var secondDigitLabel: UILabel = {
67   - let obj = UILabel()
68   - obj.font = .skModernist(type: .bold, ofSize: 16)
69   - obj.textColor = .black
70   - obj.textAlignment = .center
71   - obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1)
72   - obj.layer.cornerRadius = 15
73   - obj.clipsToBounds = true
74   - return obj
75   - }()
76   -
77   - var thirdDigitLabel: UILabel = {
78   - let obj = UILabel()
79   - obj.font = .skModernist(type: .bold, ofSize: 16)
80   - obj.textColor = .black
81   - obj.textAlignment = .center
82   - obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1)
83   - obj.layer.cornerRadius = 15
84   - obj.clipsToBounds = true
85   - return obj
86   - }()
87   -
88   - var fourthDigitLabel: UILabel = {
89   - let obj = UILabel()
90   - obj.font = .skModernist(type: .bold, ofSize: 16)
91   - obj.textColor = .black
92   - obj.textAlignment = .center
93   - obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1)
94   - obj.layer.cornerRadius = 15
95   - obj.clipsToBounds = true
  46 + let otpView: OTPView = {
  47 + let obj = OTPView()
96 48 return obj
97 49 }()
98 50
99 51 var errorAlertLabel: UILabel = {
100 52 var obj = UILabel()
101   - obj.text = "Please, enter valid verification code"
102   - obj.font = UIFont(name: SkModernistFontType.regular.rawValue, size: 14)
  53 + obj.text = .Text.pleaseEnterValidCode
  54 + obj.font = .skModernist(type: .regular, ofSize: 14)
103 55 obj.textColor = UIColor(red: 255/255, green: 0/255, blue: 46/255, alpha: 1)
104 56 obj.isHidden = true
105 57 return obj
... ... @@ -107,7 +59,7 @@ class CodeVerificationView: UIView {
107 59
108 60 var verifyButton: UIButton = {
109 61 var obj = UIButton()
110   - obj.setImage(UIImage(named: "RectangleWithShadow"), for: .normal)
  62 + obj.setImage(UIImage(named: .Image.RectangleWithShadow), for: .normal)
111 63 return obj
112 64 }()
113 65
... ... @@ -115,39 +67,53 @@ class CodeVerificationView: UIView {
115 67 var obj = UILabel()
116 68 obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16)
117 69 obj.textColor = .white
118   - obj.text = "Verify"
  70 + obj.text = .Text.verify
119 71 return obj
120 72 }()
121 73
122 74 var tickImage: UIImageView = {
123 75 var obj = UIImageView()
124   - obj.image = UIImage(named: "Tick")
  76 + obj.image = UIImage(named: .Image.tick)
  77 + return obj
  78 + }()
  79 +
  80 + let spinner: UIActivityIndicatorView = {
  81 + var obj = UIActivityIndicatorView(style: .large)
  82 + obj.hidesWhenStopped = true
  83 +
  84 + return obj
  85 + }()
  86 +
  87 + let loadingView: UIView = {
  88 + var obj = UIView()
  89 + obj.alpha = 0.25
  90 + obj.backgroundColor = .black
  91 + obj.clipsToBounds = true
  92 + obj.layer.cornerRadius = 13
125 93 return obj
126 94 }()
127 95
128 96 override init(frame: CGRect) {
129 97 super.init(frame: frame)
130   - layout()
  98 + setup()
131 99 }
132 100
133 101 required init?(coder: NSCoder) {
134 102 fatalError("init(coder:) has not been implemented")
135 103 }
136 104
137   - func layout() {
  105 + func setup() {
138 106 backgroundColor = .white
139 107
140   - addSubview(textField)
141 108 addSubview(backButton)
142 109 addSubview(logoImage)
143 110 addSubview(shieldImage)
144   -
145 111 addSubview(containerView)
  112 + addSubview(spinner)
  113 + spinner.addSubview(loadingView)
  114 +
146 115 containerView.addSubview(descriptionLabel)
147   - containerView.addSubview(firstDigitLabel)
148   - containerView.addSubview(secondDigitLabel)
149   - containerView.addSubview(thirdDigitLabel)
150   - containerView.addSubview(fourthDigitLabel)
  116 + containerView.addSubview(otpView)
151 117 containerView.addSubview(errorAlertLabel)
152 118
153 119 containerView.addSubview(verifyButton)
... ... @@ -181,41 +147,19 @@ class CodeVerificationView: UIView {
181 147 $0.top.equalTo(containerView.snp.top)
182 148 }
183 149
184   - firstDigitLabel.snp.makeConstraints {
185   - $0.leading.equalTo(containerView.snp.leading).offset(25)
186   - $0.top.equalTo(descriptionLabel.snp.bottom).offset(28)
187   - $0.height.equalTo(55)
188   - }
189   -
190   - secondDigitLabel.snp.makeConstraints {
191   - $0.leading.equalTo(firstDigitLabel.snp.trailing).offset(12)
192   - $0.centerY.equalTo(firstDigitLabel)
193   - $0.width.equalTo(firstDigitLabel.snp.width)
194   - $0.height.equalTo(55)
195   - }
196   -
197   - thirdDigitLabel.snp.makeConstraints {
198   - $0.leading.equalTo(secondDigitLabel.snp.trailing).offset(12)
199   - $0.centerY.equalTo(firstDigitLabel)
200   - $0.width.equalTo(firstDigitLabel.snp.width)
201   - $0.height.equalTo(55)
202   - }
203   -
204   - fourthDigitLabel.snp.makeConstraints {
205   - $0.leading.equalTo(thirdDigitLabel.snp.trailing).offset(12)
206   - $0.centerY.equalTo(firstDigitLabel)
207   - $0.trailing.equalTo(containerView.snp.trailing).offset(-25)
208   - $0.width.equalTo(firstDigitLabel.snp.width)
209   - $0.height.equalTo(55)
  150 + otpView.snp.makeConstraints { make in
  151 + make.leading.trailing.equalToSuperview().inset(25)
  152 + make.top.equalTo(descriptionLabel.snp.bottom).offset(28)
  153 + make.height.equalTo(55)
210 154 }
211 155
212 156 errorAlertLabel.snp.makeConstraints {
213   - $0.top.equalTo(firstDigitLabel.snp.bottom).offset(8)
214   - $0.leading.equalTo(firstDigitLabel.snp.leading)
  157 + $0.top.equalTo(otpView.snp.bottom).offset(8)
  158 + $0.leading.equalTo(otpView.snp.leading)
215 159 }
216 160
217 161 verifyButton.snp.makeConstraints {
218   - $0.top.equalTo(firstDigitLabel.snp.bottom).offset(67)
  162 + $0.top.equalTo(otpView.snp.bottom).offset(67)
219 163 $0.left.right.equalToSuperview()
220 164 }
221 165
... ... @@ -228,5 +172,12 @@ class CodeVerificationView: UIView {
228 172 $0.right.equalToSuperview().offset(-47)
229 173 $0.centerY.equalTo(verifyLabel)
230 174 }
  175 + spinner.snp.makeConstraints { make in
  176 + make.centerX.centerY.equalToSuperview()
  177 + }
  178 + loadingView.snp.makeConstraints { make in
  179 + make.edges.equalTo(snp.edges)
  180 + }
231 181 }
232 182 }
  183 +
... ...
  1 +//
  2 +// OTPView.swift
  3 +// InterQR-Internship
  4 +//
  5 +// Created by Дмитрий Тимофеев on 02.07.2022.
  6 +//
  7 +
  8 +import Foundation
  9 +import UIKit
  10 +protocol OTPViewDelegate: AnyObject {
  11 + func didFullCodeCompletion(_ otpView: OTPView)
  12 +}
  13 +
  14 +class OTPView: UIView {
  15 + weak var delegate: OTPViewDelegate?
  16 +
  17 + var digitViews: [UILabel] = []
  18 +
  19 + var code: String? {
  20 + return textField.text
  21 + }
  22 +
  23 + var isError: Bool = false {
  24 + didSet {
  25 + handleErrorUI(isError)
  26 + }
  27 + }
  28 +
  29 + let textField: UITextField = {
  30 + let obj = UITextField()
  31 + obj.isHidden = true
  32 + obj.keyboardType = .numberPad
  33 + return obj
  34 + }()
  35 +
  36 + private lazy var stackView: UIStackView = {
  37 + let obj = UIStackView(arrangedSubviews: digitViews)
  38 + obj.axis = .horizontal
  39 + obj.spacing = 11
  40 + obj.distribution = .fillEqually
  41 + obj.semanticContentAttribute = .forceLeftToRight
  42 + return obj
  43 + }()
  44 +
  45 + override init(frame: CGRect) {
  46 + super.init(frame: frame)
  47 + initDigits()
  48 + setup()
  49 + }
  50 +
  51 + required init?(coder: NSCoder) {
  52 + super.init(coder: coder)
  53 + setup()
  54 + }
  55 +
  56 + private func initDigits() {
  57 + for i in 0...3 {
  58 + digitViews.append(initLabel())
  59 + }
  60 + }
  61 +
  62 + private func initLabel() -> UILabel {
  63 + let obj = UILabel()
  64 + obj.font = .skModernist(type: .bold, ofSize: 16)
  65 + obj.textColor = .black
  66 + obj.textAlignment = .center
  67 + obj.backgroundColor = .TextFieldColor.general
  68 + obj.layer.cornerRadius = 15
  69 + obj.clipsToBounds = true
  70 + return obj
  71 + }
  72 +
  73 + private func setup() {
  74 + addSubview(textField)
  75 + addSubview(stackView)
  76 +
  77 + stackView.snp.makeConstraints { make in
  78 + make.edges.equalToSuperview()
  79 + }
  80 +
  81 + textField.addTarget(self, action: #selector(didTextFieldChanged(_:)), for: .editingChanged)
  82 + }
  83 +
  84 + override func addSubview(_ view: UIView) {
  85 + super.addSubview(view)
  86 + textField.becomeFirstResponder()
  87 + }
  88 +
  89 + @objc func didTextFieldChanged(_ sender: UITextField) {
  90 + guard var code = sender.text else {
  91 + return
  92 + }
  93 + if code.count > 4 {
  94 + code.removeLast()
  95 + } else {
  96 + if code.count == 4 {
  97 + delegate?.didFullCodeCompletion(self)
  98 + textField.resignFirstResponder()
  99 + }
  100 + }
  101 +
  102 + digitViews.enumerated().forEach { index, item in
  103 + item.text = (code.count-1 >= index ? String(code[code.index(code.startIndex, offsetBy: index)]) : "")
  104 + }
  105 + }
  106 +
  107 + private func handleErrorUI(_ isError: Bool) {
  108 + colorСhanger()
  109 + }
  110 +
  111 + private func colorСhanger() {
  112 + digitViews.self.forEach { label in
  113 + label.backgroundColor = .TextFieldColor.error
  114 + label.textColor = .TextColor.redError
  115 + }
  116 + }
  117 +}
... ...
... ... @@ -8,12 +8,12 @@
8 8 import UIKit
9 9
10 10 class CodeVerificationViewController: UIViewController {
11   - var otp: String = ""
  11 +// var otp: String = ""
12 12
13 13 var isKeyboardAppear = false
14 14
15 15 private let mainView = CodeVerificationView()
16   -
  16 + private let networkManager = AuthNetworkManager()
17 17 override func loadView() {
18 18 view = mainView
19 19 }
... ... @@ -23,10 +23,9 @@ class CodeVerificationViewController: UIViewController {
23 23 }
24 24
25 25 private func initViewController() {
26   - mainView.textField.delegate = self
27   -
  26 + mainView.otpView.delegate = self
28 27 mainView.backButton.addTarget(self, action: #selector(didDismissVC), for: .touchUpInside)
29   - mainView.verifyButton.addTarget(self, action: #selector(didVerifyCode), for: .touchUpInside)
  28 + mainView.verifyButton.addTarget(self, action: #selector(didTapVerifyButton), for: .touchUpInside)
30 29
31 30 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
32 31 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
... ... @@ -36,41 +35,81 @@ class CodeVerificationViewController: UIViewController {
36 35 NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
37 36 NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
38 37 }
  38 +
  39 + func networkingVerify() {
  40 + guard let verifyUrl = URL(string: Constants.APIRoutes.verifyURL.urlString) else { return }
  41 + let verifyModel = verifyModelFilling()
  42 + networkManager.verifyRequest(verifyUrl, model: verifyModel!) { response in
  43 + print("3️⃣✅\(response.data)")
  44 + print("\(response.message)✅")
  45 + self.mainView.spinner.startAnimating()
  46 + } fail: { error in
  47 + print("3️⃣\(error)")
  48 + }
  49 + }
  50 +
  51 + func networkingLogin() {
  52 + guard let loginUrl = URL(string: Constants.APIRoutes.loginURL.urlString) else { return }
  53 + guard let loginModel = loginModelFilling() else { return }
  54 +
  55 + self.networkManager.loginRequest(loginUrl, model: loginModel) { response in
  56 + guard let message = response.message else { return }
  57 + print("4️⃣✅\(message)✅")
  58 + } fail: { error in
  59 + print("4️⃣⛔️\(error)⛔️")
  60 + }
  61 + }
  62 +
  63 + func verifyModelFilling() -> VerifyRequestModel? {
  64 + let email = "test@interqr.com"
  65 + guard let code = mainView.otpView.code else { return nil }
  66 + return VerifyRequestModel(emailOrNumber: email, code: code, secondAuthToken: "asdas")
  67 + }
  68 +
  69 + func loginModelFilling() -> LoginRequestModel? {
  70 + guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else {
  71 + return nil
  72 + }
  73 + return LoginRequestModel(deviceUUID: deviceUUID)
  74 + }
39 75 }
40 76 //MARK: - Targets
41 77 extension CodeVerificationViewController {
  78 + @objc private func didTapVerifyButton() {
  79 + errorProcessing()
  80 + networkingVerify()
  81 + }
42 82
43   - @objc private func didDismissVC() {
44   - navigationController?.popViewController(animated: true)
  83 + private func showHomeVC() {
  84 + let viewController = HomeViewController()
  85 + navigationController?.pushViewController(viewController, animated: true)
45 86 }
46 87
47   - @objc private func didVerifyCode() {
48   - if mainView.fourthDigitLabel.text == nil {
49   - let alert = UIAlertController(title: "❌❌❌", message: "Some fields are empty, please fill in all", preferredStyle: .alert)
50   - let _: Void = alert.addAction(UIAlertAction(title: "Close", style: .cancel, handler: nil))
  88 + private func errorProcessing() {
  89 + guard let code = mainView.otpView.code else { return }
  90 + if code.count < 4 {
  91 + let alert = UIAlertController(title: "❌", message: "Enter all fields", preferredStyle: .alert)
  92 + alert.addAction(UIAlertAction(title: "Close", style: .cancel, handler: nil))
51 93 present(alert, animated: true, completion: nil)
52   -
53 94 } else {
54   - mainView.firstDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)
55   - mainView.firstDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)
56   -
57   - mainView.secondDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)
58   - mainView.secondDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)
59   -
60   - mainView.thirdDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)
61   - mainView.thirdDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)
62   -
63   - mainView.fourthDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)
64   - mainView.fourthDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)
65   - mainView.errorAlertLabel.isHidden = false
66   -
67   - DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
68   - let vc = HomeViewController()
69   - vc.navigationItem.hidesBackButton = true
70   - self.navigationController?.pushViewController(vc, animated: true)
  95 + if code != "8327" {
  96 + mainView.otpView.isError.toggle()
  97 + mainView.errorAlertLabel.isHidden = false
  98 + mainView.otpView.textField.becomeFirstResponder()
  99 + } else {
  100 + DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  101 + self.networkingLogin()
  102 + self.mainView.spinner.stopAnimating()
  103 + self.showHomeVC()
  104 + }
  105 +
71 106 }
72 107 }
73 108 }
  109 +
  110 + @objc private func didDismissVC() {
  111 + navigationController?.popViewController(animated: true)
  112 + }
74 113
75 114 @objc private func keyboardWillShow(notification: NSNotification) {
76 115 let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
... ... @@ -107,27 +146,10 @@ extension CodeVerificationViewController {
107 146 }
108 147 }
109 148
110   -//MARK: - TextField delegate
111   -extension CodeVerificationViewController: UITextFieldDelegate {
  149 +//MARK: - OTPView delegate
  150 +extension CodeVerificationViewController: OTPViewDelegate {
112 151
113   - func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
114   - otp += string
115   -
116   - otp.enumerated().forEach { index,item in
117   - switch index {
118   - case 0:
119   - mainView.firstDigitLabel.text = String(item)
120   - case 1:
121   - mainView.secondDigitLabel.text = String(item)
122   - case 2:
123   - mainView.thirdDigitLabel.text = String(item)
124   - case 3:
125   - mainView.fourthDigitLabel.text = String(item)
126   - mainView.textField.endEditing(true)
127   - default:
128   - mainView.textField.endEditing(true)
129   - }
130   - }
131   - return true
  152 + func didFullCodeCompletion(_ otpView: OTPView) {
  153 + print("code -> \(String(describing: otpView.code))")
132 154 }
133 155 }
... ...
... ... @@ -50,7 +50,7 @@ class ResidentTableViewCell: UITableViewCell {
50 50
51 51 var managerButton: SquereCheckbox = {
52 52 var obj = SquereCheckbox()
53   - obj.checkboxTitle = "Manager"
  53 + obj.checkboxTitle = .Text.manager
54 54 obj.setTitleColor(.TextColor.lightGrey, for: .normal)
55 55 obj.setTitleColor(.TextColor.darkBlue, for: .selected)
56 56 obj.isSelected = false
... ... @@ -59,7 +59,7 @@ class ResidentTableViewCell: UITableViewCell {
59 59
60 60 var hiddenButton: SquereCheckbox = {
61 61 var obj = SquereCheckbox()
62   - obj.checkboxTitle = "Hidden"
  62 + obj.checkboxTitle = .Text.hidden
63 63 obj.setTitleColor(.TextColor.lightGrey, for: .normal)
64 64 obj.setTitleColor(.TextColor.darkBlue, for: .selected)
65 65 obj.isSelected = false
... ... @@ -68,21 +68,21 @@ class ResidentTableViewCell: UITableViewCell {
68 68
69 69 var heartButton: UIButton = {
70 70 var obj = UIButton()
71   - obj.setImage(UIImage(named: "Heart"), for: .normal)
72   - obj.setImage(UIImage(named: "HeartRed"), for: .selected)
  71 + obj.setImage(UIImage(named: .Image.heart), for: .normal)
  72 + obj.setImage(UIImage(named: .Image.heartRed), for: .selected)
73 73 return obj
74 74 }()
75 75
76 76 var removeCellButton: UIButton = {
77 77 var obj = UIButton()
78   - obj.setImage(UIImage(named: "Bin"), for: .normal)
  78 + obj.setImage(UIImage(named: .Image.bin), for: .normal)
79 79 return obj
80 80 }()
81 81
82 82 var gradientBG: CAGradientLayer = {
83 83 let obj = CAGradientLayer()
84   - var leftColor = UIColor(red: 0/255, green: 68/255, blue: 139/255, alpha: 1).cgColor
85   - var rightColor = UIColor(red: 0/255, green: 122/255, blue: 191/255, alpha: 1).cgColor
  84 + var leftColor = UIColor.GradientBlue.left
  85 + var rightColor = UIColor.GradientBlue.right
86 86 obj.colors = [leftColor, rightColor]
87 87 obj.startPoint = CGPoint(x: 0, y: 0.5)
88 88 obj.endPoint = CGPoint(x: 1, y: 0.5)
... ... @@ -91,14 +91,14 @@ class ResidentTableViewCell: UITableViewCell {
91 91
92 92 override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
93 93 super.init(style: style, reuseIdentifier: reuseIdentifier)
94   - layout()
  94 + setup()
95 95 }
96 96
97 97 required init?(coder: NSCoder) {
98 98 fatalError("init(coder:) has not been implemented")
99 99 }
100 100
101   - func layout() {
  101 + func setup() {
102 102 selectionStyle = .none
103 103 serialNumberView.layer.insertSublayer(gradientBG, at: 0)
104 104
... ... @@ -112,12 +112,12 @@ class ResidentTableViewCell: UITableViewCell {
112 112 containerView.addSubview(hiddenButton)
113 113 containerView.addSubview(heartButton)
114 114 containerView.addSubview(removeCellButton)
115   -
  115 +
116 116 containerView.snp.makeConstraints {
117 117 $0.leading.trailing.equalToSuperview().inset(25)
118 118 $0.bottom.top.equalToSuperview().inset(8)
119 119 }
120   -
  120 +
121 121 serialNumberView.snp.makeConstraints {
122 122 $0.height.width.equalTo(41)
123 123 $0.leading.equalToSuperview().offset(23)
... ... @@ -127,34 +127,34 @@ class ResidentTableViewCell: UITableViewCell {
127 127 serialNumberLabel.snp.makeConstraints {
128 128 $0.centerX.centerY.equalToSuperview()
129 129 }
130   -
  130 +
131 131 nameLabel.snp.makeConstraints {
132 132 $0.leading.equalTo(serialNumberView.snp.trailing).offset(18)
133 133 $0.top.equalToSuperview().offset(22)
134 134 }
135   -
  135 +
136 136 removeCellButton.snp.makeConstraints {
137 137 $0.centerY.equalTo(nameLabel.snp.centerY)
138 138 $0.trailing.equalToSuperview().offset(-22.5)
139 139 }
140   -
  140 +
141 141 phoneNumberLabel.snp.makeConstraints {
142 142 $0.leading.equalTo(nameLabel.snp.leading)
143 143 $0.top.equalTo(nameLabel.snp.bottom).offset(1)
144 144 }
145   -
  145 +
146 146 managerButton.snp.makeConstraints {
147 147 $0.top.equalTo(phoneNumberLabel.snp.bottom).offset(30)
148 148 $0.leading.equalToSuperview().offset(24)
149 149 $0.height.equalTo(20)
150 150 }
151   -
  151 +
152 152 hiddenButton.snp.makeConstraints {
153 153 $0.leading.equalTo(managerButton.snp.trailing).offset(23)
154 154 $0.centerY.equalTo(managerButton)
155 155 $0.height.equalTo(20)
156 156 }
157   -
  157 +
158 158 heartButton.snp.makeConstraints {
159 159 $0.centerY.equalTo(hiddenButton)
160 160 $0.bottom.equalToSuperview().offset(-18)
... ... @@ -166,4 +166,14 @@ class ResidentTableViewCell: UITableViewCell {
166 166 super.layoutSubviews()
167 167 gradientBG.frame = serialNumberView.bounds
168 168 }
  169 +
  170 + func model(_ item: ResidentModel) {
  171 + nameLabel.text = item.name
  172 + phoneNumberLabel.text = item.mobileNumber
  173 + managerButton.isSelected = item.manager
  174 + hiddenButton.isSelected = item.hidden
  175 + heartButton.isSelected = item.heart
  176 + }
  177 +
  178 +
169 179 }
... ...
... ... @@ -8,10 +8,9 @@
8 8 import UIKit
9 9
10 10 class ResidentsView: UIView {
11   -
12 11 var backButton: UIButton = {
13 12 var obj = UIButton()
14   - obj.setImage(UIImage(named: "BackPointer"), for: .normal)
  13 + obj.setImage(UIImage(named: .Image.backPointer), for: .normal)
15 14 obj.backgroundColor = .white
16 15 obj.layer.borderColor = .BorderColor.lightGrey
17 16 obj.layer.cornerRadius = 13
... ... @@ -21,36 +20,36 @@ class ResidentsView: UIView {
21 20
22 21 var logoImage: UIImageView = {
23 22 var obj = UIImageView()
24   - obj.image = UIImage(named: "InterQR")
  23 + obj.image = UIImage(named: .Image.interQR)
25 24 return obj
26 25 }()
27 26
28 27 let apartNameLabel: UILabel = {
29 28 var obj = UILabel()
30 29 obj.font = .skModernist(type: .bold, ofSize: 35)
31   - obj.text = "My apart name"
  30 + obj.text = .Text.myApartName
32 31 return obj
33 32 }()
34 33
35 34 var dividingLineView: UIView = {
36 35 var view = UIView()
37   - view.backgroundColor = UIColor(red: 246/255, green: 246/255, blue: 246/255, alpha: 1)
  36 + view.backgroundColor = .Background.lightGrey
38 37 return view
39 38 }()
40 39
41 40 var residentsLabel: UILabel = {
42 41 var obj = UILabel()
43 42 obj.font = .skModernist(type: .bold, ofSize: 20)
44   - obj.text = "Residents"
  43 + obj.text = .Text.residents
45 44 return obj
46 45 }()
47 46
48 47 var addResidentsButton: UIButton = {
49 48 var obj = UIButton()
50 49 obj.layer.borderWidth = 1
51   - obj.layer.borderColor = UIColor(red: 0.882, green: 0.91, blue: 0.91, alpha: 1).cgColor
  50 + obj.layer.borderColor = .BorderColor.lightGrey
52 51 obj.layer.cornerRadius = 13
53   - obj.setImage(UIImage(named: "Edit"), for: .normal)
  52 + obj.setImage(UIImage(named: .Image.edit), for: .normal)
54 53 return obj
55 54 }()
56 55
... ... @@ -71,14 +70,14 @@ class ResidentsView: UIView {
71 70 override init(frame: CGRect) {
72 71 super.init(frame: frame)
73 72 backgroundColor = .white
74   - layout()
  73 + setup()
75 74 }
76 75
77 76 required init?(coder: NSCoder) {
78 77 fatalError("init(coder:) has not been implemented")
79 78 }
80 79
81   - func layout() {
  80 + func setup() {
82 81
83 82 addSubview(backButton)
84 83 addSubview(logoImage)
... ... @@ -94,33 +93,40 @@ class ResidentsView: UIView {
94 93 $0.leading.equalTo(snp.leading).offset(25)
95 94 $0.height.width.equalTo(45)
96 95 }
  96 +
97 97 logoImage.snp.makeConstraints {
98 98 $0.leading.equalTo(backButton.snp.trailing).offset(20)
99 99 $0.top.equalTo(snp.top).offset(79)
100 100 }
  101 +
101 102 apartNameLabel.snp.makeConstraints {
102 103 $0.leading.equalTo(backButton.snp.leading)
103 104 $0.top.equalTo(backButton.snp.bottom).offset(46)
104 105 }
  106 +
105 107 dividingLineView.snp.makeConstraints {
106 108 $0.leading.trailing.equalToSuperview()
107 109 $0.height.equalTo(1)
108 110 $0.top.equalTo(apartNameLabel.snp.bottom).offset(42)
109 111 }
  112 +
110 113 residentsLabel.snp.makeConstraints {
111 114 $0.leading.equalToSuperview().offset(24)
112 115 $0.top.equalTo(dividingLineView.snp.bottom).offset(43)
113 116 }
  117 +
114 118 addResidentsButton.snp.makeConstraints {
115 119 $0.height.width.equalTo(45)
116 120 $0.top.equalTo(dividingLineView.snp.bottom).offset(32)
117 121 $0.trailing.equalToSuperview().offset(-29)
118 122 }
  123 +
119 124 tableView.snp.makeConstraints {
120 125 $0.top.equalTo(residentsLabel.snp.bottom).offset(30)
121 126 $0.leading.trailing.equalToSuperview()
122 127 $0.bottom.equalToSuperview()
123 128 }
  129 +
124 130 addResidentView.snp.makeConstraints {
125 131 $0.top.trailing.leading.bottom.equalToSuperview()
126 132 }
... ...
... ... @@ -12,7 +12,7 @@ class ResidentsViewController: UIViewController {
12 12 var myData: [ResidentModel] = []
13 13
14 14 let addResidentsVC = AddResidentsViewController()
15   - let networkManager = NetworkManager()
  15 + let networkManager = AuthNetworkManager()
16 16
17 17 override func loadView() {
18 18 view = mainView
... ... @@ -22,49 +22,46 @@ class ResidentsViewController: UIViewController {
22 22 initViewController()
23 23 networking()
24 24 }
25   - func modelFilling() -> RequestModel? {
  25 +
  26 + func initViewController() {
  27 + mainView.tableView.delegate = self
  28 + mainView.tableView.dataSource = self
  29 + mainView.tableView.register(ResidentTableViewCell.self, forCellReuseIdentifier: ResidentTableViewCell.id)
  30 +
  31 + mainView.backButton.addTarget(self, action: #selector(didShowChooseApartVC), for: .touchUpInside)
  32 + mainView.addResidentsButton.addTarget(self, action: #selector(willShowAddResidentVC), for: .touchUpInside)
  33 + }
  34 +
  35 + func modelFilling() -> InitRequestModel? {
26 36 guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else {
27 37 return nil
28 38 }
29 39 guard let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else {
30 40 return nil
31 41 }
32   - return RequestModel(deviceUUID: deviceUUID,
33   - manufacturer: "Apple",
34   - model: UIDevice.current.model,
35   - platform: UIDevice.current.systemName,
36   - osVersion: UIDevice.current.systemVersion,
37   - appVersion: appVersion)
38   -
39   -
  42 + return InitRequestModel(deviceUUID: deviceUUID,
  43 + manufacturer: .Text.apple,
  44 + model: UIDevice.current.model,
  45 + platform: UIDevice.current.systemName,
  46 + osVersion: UIDevice.current.systemVersion,
  47 + appVersion: appVersion)
40 48 }
  49 +
41 50 func networking() {
42   - guard let url = URL(string: Constant.URL.rawValue) else { return }
  51 + guard let initUrl = URL(string: Constants.APIRoutes.initURL.urlString) else { return }
43 52 guard let model = modelFilling() else { return }
44   - networkManager.authorizationRequest(url, model: model) { responseModel in
45   - <#code#>
46   - } fail: { <#Error#> in
47   - <#code#>
  53 + networkManager.initRequest(initUrl, model: model) { responseModel in
  54 + print("1️⃣✅\(responseModel.message)✅")
  55 + } fail: { error in
  56 + print("1️⃣\(error)")
48 57 }
49   -
50   -
51   - print("")
52   -
53   - }
54   - func initViewController() {
55   - mainView.tableView.delegate = self
56   - mainView.tableView.dataSource = self
57   - mainView.tableView.register(ResidentTableViewCell.self, forCellReuseIdentifier: ResidentTableViewCell.id)
58   -
59   - mainView.backButton.addTarget(self, action: #selector(didShowChooseApartVC), for: .touchUpInside)
60   - mainView.addResidentsButton.addTarget(self, action: #selector(willShowAddResidentVC), for: .touchUpInside)
61 58 }
62 59
63   - @objc func didShowChooseApartVC() {
  60 + @objc private func didShowChooseApartVC() {
64 61 navigationController?.popViewController(animated: true)
65 62 }
66 63
67   - @objc func willShowAddResidentVC() {
  64 + @objc private func willShowAddResidentVC() {
68 65 addResidentsVC.modalPresentationStyle = .overCurrentContext
69 66 addResidentsVC.modalTransitionStyle = .crossDissolve
70 67 addResidentsVC.delegate = self
... ... @@ -75,22 +72,37 @@ class ResidentsViewController: UIViewController {
75 72 //MARK: - TableView delegate & data source
76 73 extension ResidentsViewController: UITableViewDelegate, UITableViewDataSource {
77 74 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
78   - addResidentsVC.savedResidents.count
  75 + myData.count
79 76 }
80 77
81 78 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
82 79 guard let cell = tableView.dequeueReusableCell(withIdentifier: ResidentTableViewCell.id, for: indexPath) as? ResidentTableViewCell else { return UITableViewCell() }
83   - // cell.configureWithItem(doors[indexPath.row])
84 80 cell.serialNumberLabel.text = "\(indexPath.row + 1)"
85   - cell.nameLabel.text = myData[indexPath.row].name
86   - cell.phoneNumberLabel.text = myData[indexPath.row].mobileNumber
87   - cell.managerButton.isSelected = myData[indexPath.row].manager
88   - cell.hiddenButton.isSelected = myData[indexPath.row].hidden
89   - cell.heartButton.isSelected = myData[indexPath.row].heart
  81 + let data = myData[indexPath.row]
  82 + cell.model(data)
  83 +
  84 + cell.removeCellButton.addTarget(self, action: #selector(removeCell(_:)), for: .touchUpInside)
  85 + cell.managerButton.addTarget(self, action: #selector(didTapManagerButton), for: .touchUpInside)
  86 + cell.hiddenButton.addTarget(self, action: #selector(didTapManagerButton), for: .touchUpInside)
  87 + cell.heartButton.addTarget(self, action: #selector(didTapManagerButton), for: .touchUpInside)
90 88 return cell
91 89 }
  90 +
  91 + @objc private func removeCell(_ sender: UIButton) {
  92 + myData.remove(at: sender.tag)
  93 + mainView.tableView.deleteRows(at: [IndexPath(row: sender.tag, section: 0)], with: .fade)
  94 + mainView.tableView.reloadData()
  95 + }
  96 +
  97 + @objc private func didTapManagerButton(_ sender: UIButton) {
  98 + if !sender.isSelected {
  99 + sender.isSelected = true
  100 + } else {
  101 + sender.isSelected = false
  102 + }
  103 + }
92 104 }
93   -//MARK: - Protocol delegate
  105 +//MARK: - ResidentSavable delegate
94 106 extension ResidentsViewController: ResidentSavable {
95 107 func save(_ data: [ResidentModel]) {
96 108 self.myData = data
... ...
... ... @@ -15,8 +15,6 @@ enum SettingsModel: CaseIterable {
15 15 case editResidents
16 16 case widgetLock
17 17
18   -
19   -
20 18 func getTitle() -> String {
21 19 switch self {
22 20 case .displayName :
... ... @@ -28,7 +26,7 @@ enum SettingsModel: CaseIterable {
28 26 case .widgetLock:
29 27 return "Widget lock"
30 28 case .ringtone:
31   - return "Rringtone"
  29 + return "Ringtone"
32 30 }
33 31 }
34 32
... ...
... ... @@ -10,30 +10,34 @@ import UIKit
10 10 class DisplayNameCell: UITableViewCell, Reusable {
11 11 var settingsIcon: UIImageView = {
12 12 var obj = UIImageView()
13   - obj.image = UIImage(named: "Profile")
  13 + obj.image = UIImage(named: .Image.profile)
14 14 return obj
15 15 }()
  16 +
16 17 var titleLabel: UILabel = {
17 18 var obj = UILabel()
18   - obj.text = "Your display name"
  19 + obj.text = .Text.yourDisplayName
19 20 obj.font = .skModernist(type: .bold, ofSize: 16)
20   - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1)
  21 + obj.textColor = .TextColor.darkBlue
21 22 return obj
22 23 }()
  24 +
23 25 var descriptionLabel: UILabel = {
24 26 var obj = UILabel()
25   - obj.text = "This name will be displayed everywhere"
  27 + obj.text = .Text.nameWillBeDisplay
26 28 obj.font = .skModernist(type: .regular, ofSize: 14)
27   - obj.textColor = UIColor(red: 0.725, green: 0.725, blue: 0.725, alpha: 1)
  29 + obj.textColor = .TextColor.lightGrey
28 30 return obj
29 31 }()
30   - var displayNameTextField: UITextField = {
31   - var obj = UITextField()
32   - obj.text = "John Doe"
  32 +
  33 + var displayNameTextField: TextFieldWithPadding = {
  34 + var obj = TextFieldWithPadding()
  35 + obj.text = .Text.johnDoe
33 36 obj.returnKeyType = .done
34   - obj.backgroundColor = UIColor(red: 0.971, green: 0.967, blue: 0.967, alpha: 1)
  37 + obj.backgroundColor = .TextFieldColor.general
35 38 obj.clipsToBounds = true
36 39 obj.layer.cornerRadius = 15
  40 + obj.textPadding = UIEdgeInsets(top: 0, left: 24, bottom: 0, right: 15)
37 41 return obj
38 42 }()
39 43
... ... @@ -57,14 +61,17 @@ class DisplayNameCell: UITableViewCell, Reusable {
57 61 make.top.equalToSuperview()
58 62 make.leading.equalTo(snp.leading).offset(32)
59 63 }
  64 +
60 65 titleLabel.snp.makeConstraints { make in
61 66 make.top.equalTo(settingsIcon.snp.top)
62 67 make.leading.equalTo(settingsIcon.snp.trailing).offset(18)
63 68 }
  69 +
64 70 descriptionLabel.snp.makeConstraints { make in
65 71 make.top.equalTo(titleLabel.snp.bottom).offset(5)
66 72 make.leading.equalTo(titleLabel.snp.leading)
67 73 }
  74 +
68 75 displayNameTextField.snp.makeConstraints { make in
69 76 make.top.equalTo(descriptionLabel.snp.bottom).offset(20)
70 77 make.leading.equalTo(snp.leading).offset(66)
... ... @@ -72,7 +79,6 @@ class DisplayNameCell: UITableViewCell, Reusable {
72 79 make.height.equalTo(47)
73 80 make.bottom.equalToSuperview().offset(-30)
74 81 }
75   -
76 82 }
77 83 }
78 84
... ...
... ... @@ -8,25 +8,24 @@
8 8 import UIKit
9 9
10 10 class SettingsSwitchCell: UITableViewCell, Reusable {
11   -
12 11 var settingsIcon: UIImageView = {
13 12 var obj = UIImageView()
14   - obj.image = UIImage(named: "Notification")
  13 + obj.image = UIImage(named: .Image.notification)
15 14 return obj
16 15 }()
17 16
18 17 var titleLabel: UILabel = {
19 18 var obj = UILabel()
20   - obj.text = "Do not disturb"
21   - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1)
  19 + obj.text = .Text.doNotDisturb
  20 + obj.textColor = .TextColor.darkBlue
22 21 obj.font = .skModernist(type: .bold, ofSize: 16)
23 22 return obj
24 23 }()
25 24
26 25 var descriptionLabel: UILabel = {
27 26 var obj = UILabel()
28   - obj.text = "You will not be notified of any calls for one day. Auto reset at midnight"
29   - obj.textColor = UIColor(red: 0.725, green: 0.725, blue: 0.725, alpha: 1)
  27 + obj.text = .Text.youWillNotBeNotified
  28 + obj.textColor = .TextColor.lightGrey
30 29 obj.font = .skModernist(type: .regular, ofSize: 14)
31 30 obj.numberOfLines = 0
32 31 return obj
... ... @@ -60,21 +59,23 @@ class SettingsSwitchCell: UITableViewCell, Reusable {
60 59 make.leading.equalToSuperview().offset(31)
61 60 make.top.equalToSuperview().offset(38)
62 61 }
  62 +
63 63 titleLabel.snp.makeConstraints { make in
64 64 make.leading.equalTo(settingsIcon.snp.trailing).offset(17.5)
65 65 make.top.equalToSuperview().offset(38)
66 66 }
  67 +
67 68 descriptionLabel.snp.makeConstraints { make in
68 69 make.top.equalTo(titleLabel.snp.bottom).offset(5)
69 70 make.leading.equalTo(titleLabel.snp.leading)
70 71 make.bottom.equalToSuperview().offset(-22)
71 72 }
  73 +
72 74 notificationSwitch.snp.makeConstraints { make in
73 75 make.top.equalTo(snp.top).offset(36)
74 76 make.trailing.equalTo(snp.trailing).offset(-28)
75 77 }
76 78 }
77   -
78 79 }
79 80
80 81
... ...
... ... @@ -10,31 +10,32 @@ import Foundation
10 10 import UIKit
11 11
12 12 class SettingsTableViewCell: UITableViewCell, Reusable {
13   -
14 13 var settingsIcon: UIImageView = {
15 14 var obj = UIImageView()
16   - obj.image = UIImage(named: "Edit")
  15 + obj.image = UIImage(named: .Image.edit)
17 16 obj.contentMode = .scaleAspectFill
18 17 return obj
19 18 }()
20 19
21 20 var titleLabel: UILabel = {
22 21 var obj = UILabel()
23   - obj.text = "Edit residents"
24   - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1)
  22 + obj.text = .Text.editResidents
  23 + obj.textColor = .TextColor.darkBlue
25 24 obj.font = .skModernist(type: .bold, ofSize: 16)
26 25 return obj
27 26 }()
  27 +
28 28 var descriptionLabel: UILabel = {
29 29 var obj = UILabel()
30   - obj.text = "Edit the residents and their information"
31   - obj.textColor = UIColor(red: 0.725, green: 0.725, blue: 0.725, alpha: 1)
  30 + obj.text = .Text.editResidentsAndInfo
  31 + obj.textColor = .TextColor.lightGrey
32 32 obj.font = .skModernist(type: .regular, ofSize: 14)
33 33 return obj
34 34 }()
  35 +
35 36 var arrowImageView: UIImageView = {
36 37 var obj = UIImageView()
37   - obj.image = UIImage(named: "NextPointer")
  38 + obj.image = UIImage(named: .Image.nextPointer)
38 39 return obj
39 40 }()
40 41
... ... @@ -60,15 +61,18 @@ class SettingsTableViewCell: UITableViewCell, Reusable {
60 61 make.leading.equalToSuperview().offset(32)
61 62 make.height.width.equalTo(18)
62 63 }
  64 +
63 65 titleLabel.snp.makeConstraints { make in
64 66 make.top.equalToSuperview().offset(26)
65 67 make.leading.equalTo(settingsIcon.snp.trailing).offset(15)
66 68 }
  69 +
67 70 descriptionLabel.snp.makeConstraints { make in
68 71 make.top.equalTo(titleLabel.snp.bottom).offset(5)
69 72 make.leading.equalTo(titleLabel.snp.leading)
70 73 make.bottom.equalToSuperview().offset(-22)
71 74 }
  75 +
72 76 arrowImageView.snp.makeConstraints { make in
73 77 make.centerY.equalToSuperview()
74 78 make.trailing.equalTo(snp.trailing).offset(-28)
... ...
... ... @@ -10,9 +10,9 @@ import UIKit
10 10 class SettingsView: UIView {
11 11 var backButton: UIButton = {
12 12 var obj = UIButton()
13   - obj.setImage(UIImage(named: "BackPointer"), for: .normal)
  13 + obj.setImage(UIImage(named: .Image.backPointer), for: .normal)
14 14 obj.backgroundColor = .white
15   - obj.layer.borderColor = UIColor(red: 224/255, green: 231/255, blue: 232/255, alpha: 1).cgColor
  15 + obj.layer.borderColor = .BorderColor.lightGrey
16 16 obj.layer.cornerRadius = 13
17 17 obj.layer.borderWidth = 1
18 18 return obj
... ... @@ -20,20 +20,20 @@ class SettingsView: UIView {
20 20
21 21 var logoImage: UIImageView = {
22 22 var obj = UIImageView()
23   - obj.image = UIImage(named: "InterQR")
  23 + obj.image = UIImage(named: .Image.interQR)
24 24 return obj
25 25 }()
26 26
27 27 var gearImage: UIImageView = {
28 28 var obj = UIImageView()
29   - obj.image = UIImage(named: "Gear")
  29 + obj.image = UIImage(named: .Image.gear)
30 30 return obj
31 31 }()
32 32
33 33 let settingsLabel: UILabel = {
34 34 var obj = UILabel()
35 35 obj.font = .skModernist(type: .bold, ofSize: 35)
36   - obj.text = "Settings"
  36 + obj.text = .Text.settings
37 37 return obj
38 38 }()
39 39
... ... @@ -44,9 +44,9 @@ class SettingsView: UIView {
44 44
45 45 var logoutButton: UIButton = {
46 46 var obj = UIButton()
47   - obj.backgroundColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 0.07)
48   - obj.setTitle("Logout", for: .normal)
49   - obj.setTitleColor(UIColor(red: 1, green: 0, blue: 0.18, alpha: 0.98), for: .normal)
  47 + obj.backgroundColor = .Background.lightRed?.withAlphaComponent(0.07)
  48 + obj.setTitle(.Text.logout, for: .normal)
  49 + obj.setTitleColor(.TextColor.redError, for: .normal)
50 50 obj.layer.cornerRadius = 15
51 51 return obj
52 52 }()
... ... @@ -54,14 +54,14 @@ class SettingsView: UIView {
54 54 override init(frame: CGRect) {
55 55 super.init(frame: frame)
56 56 backgroundColor = .white
57   - layout()
  57 + setup()
58 58 }
59 59
60 60 required init?(coder: NSCoder) {
61 61 fatalError("init(coder:) has not been implemented")
62 62 }
63 63
64   - func layout() {
  64 + func setup() {
65 65 addSubview(backButton)
66 66 addSubview(logoImage)
67 67 addSubview(gearImage)
... ... @@ -74,14 +74,17 @@ class SettingsView: UIView {
74 74 $0.leading.equalTo(snp.leading).offset(25)
75 75 $0.height.width.equalTo(45)
76 76 }
  77 +
77 78 logoImage.snp.makeConstraints {
78 79 $0.leading.equalTo(backButton.snp.trailing).offset(20)
79 80 $0.top.equalTo(snp.top).offset(79)
80 81 }
  82 +
81 83 gearImage.snp.makeConstraints {
82 84 $0.trailing.equalTo(snp.trailing)
83 85 $0.top.equalTo(snp.top).offset(106)
84 86 }
  87 +
85 88 settingsLabel.snp.makeConstraints {
86 89 $0.leading.equalTo(backButton.snp.leading)
87 90 $0.top.equalTo(backButton.snp.bottom).offset(46)
... ...
... ... @@ -8,8 +8,8 @@
8 8 import UIKit
9 9
10 10 class SettingsViewController: UIViewController {
11   -
12 11 var mainView = SettingsView()
  12 + var networkManager = AuthNetworkManager()
13 13
14 14 let settingsModel = SettingsModel.allCases
15 15
... ... @@ -22,27 +22,44 @@ class SettingsViewController: UIViewController {
22 22 }
23 23
24 24 private func initViewController() {
25   - mainView.backButton.addTarget(self, action: #selector(didShowHomeVC), for: .touchUpInside)
26   - mainView.logoutButton.addTarget(self, action: #selector(didLogoutAndShowVerificationVC), for: .touchUpInside)
  25 + mainView.settingsTableView.delegate = self
  26 + mainView.settingsTableView.dataSource = self
27 27
28 28 mainView.settingsTableView.registerReusableCell(DisplayNameCell.self)
29 29 mainView.settingsTableView.registerReusableCell(SettingsSwitchCell.self)
30 30 mainView.settingsTableView.registerReusableCell(SettingsTableViewCell.self)
31 31
32   - mainView.settingsTableView.delegate = self
33   - mainView.settingsTableView.dataSource = self
  32 + mainView.backButton.addTarget(self, action: #selector(didShowHomeVC), for: .touchUpInside)
  33 + mainView.logoutButton.addTarget(self, action: #selector(didLogoutAndShowVerificationVC), for: .touchUpInside)
34 34 }
35 35 }
36 36
37 37 extension SettingsViewController {
38   -
39   - @objc func didShowHomeVC() {
  38 + @objc private func didShowHomeVC() {
40 39 navigationController?.popViewController(animated: true)
41 40 }
42 41
43   - @objc func didLogoutAndShowVerificationVC() {
  42 + @objc private func didLogoutAndShowVerificationVC() {
44 43 let vc = VerificationViewController()
45 44 navigationController?.pushViewController(vc, animated: true)
  45 + networking()
  46 + }
  47 +
  48 + func networking() {
  49 + guard let logoutUrl = URL(string: Constants.APIRoutes.logoutURL.urlString) else { return }
  50 + guard let logoutModel = logoutModelFilling() else { return }
  51 + networkManager.logoutRequest(logoutUrl, model: logoutModel) { response in
  52 + print("5️⃣❇️\(response.message ?? "Data not received!")❇️")
  53 + } fail: { error in
  54 + print("5️⃣❗️\(error)❗️")
  55 + }
  56 + }
  57 +
  58 + func logoutModelFilling() -> LogoutRequestModel? {
  59 + guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else {
  60 + return nil
  61 + }
  62 + return LogoutRequestModel(deviceUUID: deviceUUID)
46 63 }
47 64 }
48 65
... ... @@ -68,7 +85,6 @@ extension SettingsViewController: UITableViewDelegate, UITableViewDataSource {
68 85 cell.titleLabel.text = model.getTitle()
69 86 cell.descriptionLabel.text = model.getDescription()
70 87 cell.settingsIcon.image = model.getIcon()
71   - // cell.delegate = self
72 88 return cell
73 89 case .editResidents, .widgetLock:
74 90 let cell: SettingsTableViewCell = tableView.dequeueReusableCell(for: indexPath)
... ... @@ -83,7 +99,6 @@ extension SettingsViewController: UITableViewDelegate, UITableViewDataSource {
83 99 let vc = ChooseApartmentsViewController()
84 100 navigationController?.pushViewController(vc, animated: true)
85 101 }
86   -
87 102 }
88 103 }
89 104
... ...
... ... @@ -9,7 +9,6 @@ import UIKit
9 9 import CoreTelephony
10 10
11 11 class PhoneNumberView: UIView {
12   -
13 12 var containerPickerView: UIView = {
14 13 var view = UIView()
15 14 view.backgroundColor = .systemRed
... ... @@ -18,16 +17,16 @@ class PhoneNumberView: UIView {
18 17
19 18 var titleButton: UIButton = {
20 19 var obj = UIButton()
21   - obj.setTitle("Select your country", for: .normal)
22   - obj.setTitleColor(UIColor(red: 50/255, green: 55/255, blue: 85/255, alpha: 1), for: .normal)
23   - obj.titleLabel?.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 18)
  20 + obj.setTitle(.Text.selectYourCountry, for: .normal)
  21 + obj.setTitleColor(.TextColor.darkBlue, for: .normal)
  22 + obj.titleLabel?.font = .skModernist(type: .bold, ofSize: 18)
24 23 obj.titleLabel?.textAlignment = .center
25 24 return obj
26 25 }()
27 26
28 27 var dividingLineView: UIView = {
29 28 var view = UIView()
30   - view.backgroundColor = UIColor(red: 246/255, green: 246/255, blue: 246/255, alpha: 1)
  29 + view.backgroundColor = .Background.lightGrey
31 30 return view
32 31 }()
33 32
... ... @@ -36,19 +35,27 @@ class PhoneNumberView: UIView {
36 35 return picker
37 36 }()
38 37
  38 + var gradientBG: CAGradientLayer = {
  39 + let obj = CAGradientLayer()
  40 + var leftColor = CGColor.GradientBlue.left
  41 + var rightColor = CGColor.GradientBlue.right
  42 + obj.colors = [leftColor, rightColor]
  43 + obj.startPoint = CGPoint(x: 0, y: 0.5)
  44 + obj.endPoint = CGPoint(x: 1, y: 0.5)
  45 + return obj
  46 + }()
  47 +
39 48 var selectButton: UIButton = {
40 49 var button = UIButton()
41   -
42   - button.backgroundColor = UIColor(red: 2/255, green: 115/255, blue: 185/255, alpha: 1)
43 50 button.clipsToBounds = true
44   -
  51 + button.layer.masksToBounds = true
45 52 return button
46 53 }()
47 54
48 55 var selectLabel: UILabel = {
49 56 var label = UILabel()
50   - label.text = "Select"
51   - label.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16)
  57 + label.text = .Text.select
  58 + label.font = .skModernist(type: .bold, ofSize: 16)
52 59 label.textColor = .white
53 60 return label
54 61 }()
... ... @@ -71,6 +78,7 @@ class PhoneNumberView: UIView {
71 78 addSubview(phoneNumberPicker)
72 79 addSubview(selectButton)
73 80
  81 + selectButton.layer.addSublayer(gradientBG)
74 82 selectButton.addSubview(selectLabel)
75 83
76 84 titleButton.snp.makeConstraints { make in
... ... @@ -99,12 +107,15 @@ class PhoneNumberView: UIView {
99 107 $0.top.equalTo(selectButton.snp.top).offset(20)
100 108 }
101 109 }
  110 +
  111 + override func layoutSubviews() {
  112 + super.layoutSubviews()
  113 + gradientBG.frame = selectButton.bounds
  114 + }
102 115 }
103 116
104 117 extension PhoneNumberView {
105   -
106 118 func setup() {
107   -
108 119 let countryCode: String
109 120 if let carrier = CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.first?.value,
110 121 let code = carrier.isoCountryCode?.uppercased() {
... ... @@ -112,11 +123,8 @@ extension PhoneNumberView {
112 123 } else {
113 124 countryCode = "USA"
114 125 }
115   -
116 126 phoneNumberPicker.selectRow(0, inComponent: 0, animated: true)
117   -
118 127 phoneNumberPicker.subviews[1].backgroundColor = .clear
119   -
120 128 }
121 129 }
122 130
... ...
... ... @@ -17,27 +17,27 @@ final class PickerView: UIView {
17 17 }()
18 18 private let label: UILabel = {
19 19 var obj = UILabel()
20   - obj.textColor = UIColor(red: 50/255, green: 55/255, blue: 85/255, alpha: 1)
21   - obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 15)
  20 + obj.textColor = .TextColor.darkBlue
  21 + obj.font = .skModernist(type: .bold, ofSize: 15)
22 22 return obj
23 23 }()
24 24 private let countryCode: UILabel = {
25 25 var obj = UILabel()
26   - obj.textColor = UIColor(red: 50/255, green: 55/255, blue: 85/255, alpha: 1)
27   - obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 15)
  26 + obj.textColor = .TextColor.darkBlue
  27 + obj.font = .skModernist(type: .bold, ofSize: 15)
28 28 return obj
29 29 }()
30 30 override init(frame: CGRect) {
31 31 super.init(frame: frame)
32   - layout()
  32 + setup()
33 33 }
34 34
35 35 required init?(coder: NSCoder) {
36 36 super.init(coder: coder)
37   - layout()
  37 + setup()
38 38 }
39 39
40   - private func layout() {
  40 + private func setup() {
41 41 addSubview(iconView)
42 42 addSubview(label)
43 43 addSubview(countryCode)
... ... @@ -45,7 +45,6 @@ final class PickerView: UIView {
45 45 iconView.snp.makeConstraints { make in
46 46 make.leading.equalToSuperview().offset(25)
47 47 make.centerY.equalTo(snp.centerY)
48   -// make.top.bottom.equalToSuperview()
49 48 make.height.width.equalTo(20)
50 49 }
51 50
... ...
... ... @@ -9,73 +9,80 @@ import Foundation
9 9 import UIKit
10 10
11 11 class VerificationView: UIView {
12   -
13 12 var isShow: Bool = false
14   -
  13 + var isChanged: Bool = false {
  14 + didSet {
  15 + handleUI(isChanged)
  16 + }
  17 + }
15 18 var logoImage: UIImageView = {
16 19 var view = UIImageView()
17   - view.image = UIImage(named: "InterQR")
  20 + view.image = UIImage(named: .Image.interQR)
18 21 return view
19 22 }()
  23 +
20 24 var greetingsLabel: UILabel = {
21 25 var label = UILabel()
22   - label.text = "Hello"
23   - label.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 35)
  26 + label.text = .Text.hello
  27 + label.font = .skModernist(type: .bold, ofSize: 35)
24 28 return label
25 29 }()
  30 +
26 31 var verifyLabel: UILabel = {
27 32 var label = UILabel()
28   - label.text = "Lets verify your \naccount"
  33 + label.text = .Text.letsVerifyYourAccount
29 34 label.numberOfLines = 2
30   - label.font = UIFont(name: SkModernistFontType.regular.rawValue, size: 28)
  35 + label.font = .skModernist(type: .regular, ofSize: 38)
31 36 return label
32 37 }()
  38 +
33 39 var shieldImage: UIImageView = {
34 40 var view = UIImageView()
35   - view.image = UIImage(named: "Shield")
  41 + view.image = UIImage(named: .Image.shield)
36 42 return view
37 43 }()
  44 +
38 45 var chooseLabel: UILabel = {
39 46 var label = UILabel()
40   - label.text = "Choose what to start with"
41   - label.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16)
42   - label.font = .systemFont(ofSize: 16, weight: .bold)
  47 + label.text = .Text.chooseWhatToStartWith
  48 + label.font = .skModernist(type: .bold, ofSize: 16)
43 49 return label
44 50 }()
  51 +
45 52 var emailButton: Checkbox = {
46 53 var button = Checkbox()
47   - button.checkboxTitle = "Email"
  54 + button.checkboxTitle = .Text.email
48 55 button.isSelected = true
49 56 return button
50 57 }()
51   -
  58 +
52 59 var phoneNumberButton: Checkbox = {
53 60 var button = Checkbox()
54   - button.checkboxTitle = "Phone Number"
  61 + button.checkboxTitle = .Text.phoneNumber
55 62 return button
56 63 }()
57   -
  64 +
58 65 var dividingLineView: UIView = {
59 66 var view = UIView()
60   - view.backgroundColor = UIColor(red: 246/255, green: 246/255, blue: 246/255, alpha: 1)
  67 + view.backgroundColor = .Background.lightGrey
61 68 return view
62 69 }()
63 70
64 71 var enterChosenAuthenticatorLabel: UILabel = {
65 72 var label = UILabel()
66   - label.text = "Enter your email address"
  73 + label.text = .Text.enterYourEmailAddress
67 74 label.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16)
68 75 return label
69 76 }()
70 77
71 78 var emailTextField: UITextField = {
72 79 var textField = UITextField()
73   - textField.backgroundColor = UIColor(red: 243/255, green: 243/255, blue: 243/255, alpha: 1)
  80 + textField.backgroundColor = .TextFieldColor.general
74 81 textField.textAlignment = .left
75 82 textField.layer.cornerRadius = 15
76 83 textField.keyboardType = .emailAddress
77   - textField.placeholder = "Example: john.doe@gmail.com"
78   - textField.font = UIFont(name: SkModernistFontType.regular.rawValue, size: 15)
  84 + textField.placeholder = .Text.exampleEmail
  85 + textField.font = .skModernist(type: .regular, ofSize: 15)
79 86 textField.layer.masksToBounds = true
80 87 textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 22, height: textField.frame.height))
81 88 textField.leftViewMode = .always
... ... @@ -85,29 +92,29 @@ class VerificationView: UIView {
85 92
86 93 var phoneTextField: TextFieldWithPadding = {
87 94 var textField = TextFieldWithPadding()
88   - textField.backgroundColor = UIColor(red: 243/255, green: 243/255, blue: 243/255, alpha: 1)
  95 + textField.backgroundColor = .TextFieldColor.general
89 96 textField.textAlignment = .left
90 97 textField.layer.cornerRadius = 15
91 98 textField.keyboardType = .numberPad
92   - textField.text = "+1"
93   - textField.font = UIFont(name: SkModernistFontType.regular.rawValue, size: 15)
  99 + textField.text = .Text.plusOne
  100 + textField.font = .skModernist(type: .regular, ofSize: 15)
94 101 textField.layer.masksToBounds = true
95 102 textField.isHidden = true
  103 + textField.textPadding = UIEdgeInsets(top: 0, left: 75, bottom: 0, right: 15)
96 104 return textField
97 105 }()
98 106
99 107 var verificationDescriptionLabel: UILabel = {
100 108 var label = UILabel()
101 109 label.numberOfLines = 0
102   - label.text = "Verification code will be sent to your e-mail"
103   - label.font = UIFont(name: "Sk-Modernist", size: 14)
104   - label.font = .systemFont(ofSize: 14, weight: .regular)
  110 + label.text = .Text.verificationCodeWillBeSentToYourEmail
  111 + label.font = .skModernist(type: .regular, ofSize: 14)
105 112 return label
106 113 }()
107 114
108 115 var continueButton: UIButton = {
109 116 var button = UIButton()
110   - button.setImage(UIImage(named: "RectangleWithShadow"), for: .normal)
  117 + button.setImage(UIImage(named: .Image.RectangleWithShadow), for: .normal)
111 118 button.clipsToBounds = true
112 119 button.contentMode = .scaleAspectFit
113 120 button.layer.cornerRadius = 15
... ... @@ -116,15 +123,15 @@ class VerificationView: UIView {
116 123
117 124 var continueLabel: UILabel = {
118 125 var label = UILabel()
119   - label.text = "Continue"
120   - label.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16)
  126 + label.text = .Text.continueText
  127 + label.font = .skModernist(type: .bold, ofSize: 16)
121 128 label.textColor = .white
122 129 return label
123 130 }()
124 131
125 132 var pointerImage: UIImageView = {
126 133 var image = UIImageView()
127   - image.image = UIImage(named: "Pointer")
  134 + image.image = UIImage(named: .Image.pointer)
128 135 return image
129 136 }()
130 137
... ... @@ -142,7 +149,7 @@ class VerificationView: UIView {
142 149
143 150 var flagPickerView: UIImageView = {
144 151 var image = UIImageView()
145   - image.image = UIImage(named: "USA")
  152 + image.image = UIImage(named: .Image.USA)
146 153 image.layer.cornerRadius = 11
147 154 image.contentMode = .scaleAspectFit
148 155 return image
... ... @@ -150,22 +157,21 @@ class VerificationView: UIView {
150 157
151 158 var flagPointerView: UIImageView = {
152 159 var image = UIImageView()
153   - image.image = UIImage(named: "FlagPointer")
  160 + image.image = UIImage(named: .Image.flagPointer)
154 161 return image
155 162 }()
156 163
157 164 override init(frame: CGRect) {
158 165 super.init(frame: frame)
159 166 backgroundColor = .white
160   - layout()
  167 + setup()
161 168 }
162 169
163 170 required init?(coder: NSCoder) {
164 171 fatalError("init(coder:) has not been implemented")
165 172 }
166 173
167   - func layout() {
168   -
  174 + func setup() {
169 175 addSubview(logoImage)
170 176 addSubview(greetingsLabel)
171 177 addSubview(verifyLabel)
... ... @@ -195,119 +201,112 @@ class VerificationView: UIView {
195 201 $0.top.equalTo(snp.top).offset(80)
196 202 $0.left.equalTo(snp.left).offset(27)
197 203 }
  204 +
198 205 greetingsLabel.snp.makeConstraints {
199 206 $0.top.equalTo(logoImage.snp.bottom).offset(42)
200 207 $0.left.equalTo(snp.left).offset(24)
201 208 }
  209 +
202 210 shieldImage.snp.makeConstraints {
203 211 $0.right.equalToSuperview()
204 212 $0.top.equalTo(logoImage.snp.bottom).offset(27)
205 213 }
  214 +
206 215 verifyLabel.snp.makeConstraints {
207 216 $0.left.equalTo(27)
208 217 $0.top.equalTo(greetingsLabel.snp.bottom).offset(10)
209 218 }
  219 +
210 220 chooseLabel.snp.makeConstraints {
211 221 $0.top.equalTo(shieldImage.snp.bottom).offset(52)
212 222 $0.left.equalTo(snp.left).offset(27)
213 223 }
  224 +
214 225 emailButton.snp.makeConstraints {
215 226 $0.left.equalTo(snp.left).offset(27)
216 227 $0.top.equalTo(chooseLabel.snp.bottom).offset(29)
217 228 $0.height.equalTo(20)
218 229 }
  230 +
219 231 phoneNumberButton.snp.makeConstraints {
220 232 $0.top.equalTo(emailButton.snp.top)
221 233 $0.height.equalTo(20)
222 234 $0.left.equalTo(emailButton.snp.right).offset(44)
223 235 }
  236 +
224 237 dividingLineView.snp.makeConstraints {
225 238 $0.left.right.equalToSuperview()
226 239 $0.top.equalTo(emailButton.snp.bottom).offset(41)
227 240 $0.height.equalTo(1)
228 241 }
  242 +
229 243 enterChosenAuthenticatorLabel.snp.makeConstraints {
230 244 $0.top.equalTo(dividingLineView.snp.bottom).offset(39)
231 245 $0.left.equalTo(logoImage.snp.left)
232 246 }
  247 +
233 248 emailTextField.snp.makeConstraints {
234 249 $0.left.equalTo(logoImage.snp.left)
235 250 $0.right.equalTo(snp.right).offset(-27)
236 251 $0.top.equalTo(enterChosenAuthenticatorLabel.snp.bottom).offset(23)
237 252 $0.height.equalTo(57)
238 253 }
  254 +
239 255 phoneTextField.snp.makeConstraints {
240 256 $0.left.equalTo(logoImage.snp.left)
241 257 $0.right.equalTo(snp.right).offset(-27)
242 258 $0.top.equalTo(enterChosenAuthenticatorLabel.snp.bottom).offset(23)
243 259 $0.height.equalTo(57)
244 260 }
  261 +
245 262 verificationDescriptionLabel.snp.makeConstraints {
246 263 $0.top.equalTo(emailTextField.snp.bottom).offset(8)
247 264 $0.left.equalTo(snp.left).offset(46)
248 265 $0.right.equalTo(snp.right).offset(-22)
249 266 }
  267 +
250 268 continueButton.snp.makeConstraints {
251 269 $0.left.equalTo(snp.left)
252 270 $0.right.equalTo(snp.right)
253 271 $0.top.equalTo(emailTextField.snp.bottom).offset(90)
254 272 $0.height.equalTo(125)
255 273 }
  274 +
256 275 continueLabel.snp.makeConstraints {
257 276 $0.left.equalTo(snp.left).offset(48)
258 277 $0.top.equalTo(continueButton.snp.top).offset(33)
259 278 }
  279 +
260 280 pointerImage.snp.makeConstraints {
261 281 $0.top.equalTo(continueButton.snp.top).offset(31)
262 282 $0.right.equalTo(snp.right).offset(-51.5)
263 283 }
  284 +
264 285 phonePickerView.snp.makeConstraints { make in
265 286 make.leading.trailing.equalToSuperview()
266 287 make.height.equalTo(390)
267 288 make.top.equalTo(self.snp.bottom)
268 289 }
  290 +
269 291 showPickerButton.snp.makeConstraints {
270 292 $0.height.equalTo(22)
271 293 $0.width.equalTo(50)
272 294 $0.left.equalTo(emailTextField.snp.left).offset(22)
273 295 $0.top.equalTo(emailTextField.snp.top).offset(18)
274 296 }
  297 +
275 298 flagPickerView.snp.makeConstraints {
276 299 $0.left.equalToSuperview()
277   -// $0.top.equalToSuperview()
278 300 $0.size.equalTo(20)
279 301 $0.centerY.equalTo(showPickerButton.snp.centerY)
280 302 }
  303 +
281 304 flagPointerView.snp.makeConstraints {
282 305 $0.left.equalTo(flagPickerView.snp.right).offset(10)
283 306 $0.centerYWithinMargins.equalTo(flagPickerView.snp.centerYWithinMargins)
284 307 }
285 308 }
286 309
287   -// @objc func choosePhoneCode() {
288   -// emailTextField.isHidden = true
289   -// phoneTextField.isHidden = false
290   -// phoneNumberButton.isSelected = true
291   -// emailButton.isSelected = true
292   -// phoneNumberButton.image(for: .normal)
293   -// verificationDescriptionLabel.text = "Verification code will be sent to\nyour phone number"
294   -// enterChosenAuthenticatorLabel.text = "Enter your phone number"
295   -// emailTextField.text = "+1"
296   -// showPickerButton.isHidden = false
297   -// }
298   -//
299   -// @objc func chooseEmail() {
300   -// emailTextField.isHidden = false
301   -// phoneTextField.isHidden = true
302   -// phoneNumberButton.isSelected = false
303   -// emailButton.isSelected = false
304   -// verificationDescriptionLabel.text = "Verification code will be sent to your e-mail"
305   -// enterChosenAuthenticatorLabel.text = "Enter your email address"
306   -// emailTextField.text = ""
307   -// emailTextField.placeholder = "Example: john.doe@gmail.com"
308   -// showPickerButton.isHidden = true
309   -// }
310   -
311 310 func showPickerView() {
312 311 UIView.animate(withDuration: 0.3) {
313 312 self.phonePickerView.snp.updateConstraints { make in
... ... @@ -325,4 +324,31 @@ class VerificationView: UIView {
325 324 self.layoutIfNeeded()
326 325 }
327 326 }
  327 +
  328 + func handleUI(_ isChanged: Bool) {
  329 + switch isChanged {
  330 + case emailButton.isSelected :
  331 + emailTextField.isHidden = false
  332 + phoneTextField.isHidden = true
  333 + phoneNumberButton.isSelected = false
  334 + emailButton.isSelected = true
  335 + verificationDescriptionLabel.text = .Text.verificationCodeWillBeSentToYourEmail
  336 + enterChosenAuthenticatorLabel.text = .Text.enterYourEmailAddress
  337 + emailTextField.text = ""
  338 + emailTextField.placeholder = .Text.exampleEmail
  339 + showPickerButton.isHidden = true
  340 + case phoneNumberButton.isSelected :
  341 + emailTextField.isHidden = true
  342 + phoneTextField.isHidden = false
  343 + phoneNumberButton.isSelected = true
  344 + emailButton.isSelected = false
  345 + phoneNumberButton.image(for: .normal)
  346 + verificationDescriptionLabel.text = .Text.verificationCodeWillBeSentToYourNumber
  347 + enterChosenAuthenticatorLabel.text = .Text.enterYourPhoneNumber
  348 + emailTextField.text = .Text.plusOne
  349 + showPickerButton.isHidden = false
  350 + default :
  351 + return
  352 + }
  353 + }
328 354 }
... ...
... ... @@ -8,7 +8,7 @@
8 8 import UIKit
9 9
10 10 class VerificationViewController: UIViewController {
11   -
  11 + var networkManager = AuthNetworkManager()
12 12 var isKeyboardAppear = false
13 13 private let mainView = VerificationView()
14 14
... ... @@ -30,25 +30,46 @@ class VerificationViewController: UIViewController {
30 30 override func loadView() {
31 31 view = mainView
32 32 }
  33 +
33 34 override func viewDidLoad() {
34 35 super.viewDidLoad()
35 36 initViewController()
36 37 }
37 38
38   -
39 39 private func initViewController() {
40 40 mainView.phonePickerView.phoneNumberPicker.delegate = self
41 41 mainView.phonePickerView.phoneNumberPicker.dataSource = self
  42 +
42 43 mainView.phoneNumberButton.addTarget(self, action: #selector(didCheckboxTapped(_:)), for: .touchUpInside)
43 44 mainView.emailButton.addTarget(self, action: #selector(didCheckboxTapped(_:)), for: .touchUpInside)
44 45 mainView.showPickerButton.addTarget(self, action: #selector(didshowPickerButtonTapped(_:)), for: .touchUpInside)
45 46 mainView.phonePickerView.selectButton.addTarget(self, action: #selector(didshowPickerButtonTapped(_:)), for: .touchUpInside)
46 47 mainView.phonePickerView.titleButton.addTarget(self, action: #selector(didshowPickerButtonTapped(_:)), for: .touchDragInside)
47   - mainView.continueButton.addTarget(self, action: #selector(didShowCodeVerificationVC), for: .touchUpInside)
  48 +
  49 + mainView.continueButton.addTarget(self, action: #selector(didTapContinueButton), for: .touchUpInside)
48 50 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
49 51 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
50 52 }
51 53
  54 + func networking() {
  55 + guard let startUrl = URL(string: Constants.APIRoutes.startURL.urlString) else { return }
  56 + guard let startModel = startModelFilling() else { return }
  57 + networkManager.startRequest(startUrl, model: startModel) { response in
  58 + print("2️⃣✅\(response.message)✅")
  59 + } fail: { error in
  60 + print("2️⃣❌\(error)❌")
  61 + }
  62 + }
  63 +
  64 + func startModelFilling() -> StartRequestModel? {
  65 + let number = mainView.phoneTextField.text
  66 + let email = mainView.emailTextField.text
  67 + if number == nil {
  68 + return StartRequestModel(emailOrNumber: (String(describing: email)))
  69 + } else {
  70 + return StartRequestModel(emailOrNumber: (String(describing: number)))
  71 + }
  72 + }
52 73 }
53 74
54 75 //MARK: helpers and handlers
... ... @@ -58,32 +79,9 @@ extension VerificationViewController {
58 79
59 80 //MARK: targets
60 81 extension VerificationViewController {
61   -
62 82 @objc private func didCheckboxTapped(_ sender: Checkbox) {
63   - switch sender {
64   - case mainView.emailButton :
65   - mainView.emailTextField.isHidden = false
66   - mainView.phoneTextField.isHidden = true
67   - mainView.phoneNumberButton.isSelected = false
68   - mainView.emailButton.isSelected = true
69   - mainView.verificationDescriptionLabel.text = "Verification code will be sent to your e-mail"
70   - mainView.enterChosenAuthenticatorLabel.text = "Enter your email address"
71   - mainView.emailTextField.text = ""
72   - mainView.emailTextField.placeholder = "Example: john.doe@gmail.com"
73   - mainView.showPickerButton.isHidden = true
74   - case mainView.phoneNumberButton:
75   - mainView.emailTextField.isHidden = true
76   - mainView.phoneTextField.isHidden = false
77   - mainView.phoneNumberButton.isSelected = true
78   - mainView.emailButton.isSelected = false
79   - mainView.phoneNumberButton.image(for: .normal)
80   - mainView.verificationDescriptionLabel.text = "Verification code will be sent to\nyour phone number"
81   - mainView.enterChosenAuthenticatorLabel.text = "Enter your phone number"
82   - mainView.emailTextField.text = "+1"
83   - mainView.showPickerButton.isHidden = false
84   - default :
85   - return
86   - }
  83 + mainView.isChanged ? mainView.handleUI(true) : mainView.handleUI(false)
  84 + mainView.isChanged.toggle()
87 85 }
88 86
89 87 @objc private func didshowPickerButtonTapped(_ sender: UIButton) {
... ... @@ -91,13 +89,33 @@ extension VerificationViewController {
91 89 mainView.isShow.toggle()
92 90 }
93 91
94   - @objc private func didShowCodeVerificationVC() {
95   - let vc = CodeVerificationViewController()
96   - vc.navigationItem.hidesBackButton = true
97   - navigationController?.pushViewController(vc, animated: true)
  92 + @objc private func didTapContinueButton() {
  93 + didShowCodeVerificationVC()
  94 + }
  95 +
  96 + private func didShowCodeVerificationVC() {
  97 + guard let email = mainView.emailTextField.text else { return }
  98 + guard let number = mainView.phoneTextField.text else { return }
  99 + let userCode: String = .Text.userCode
  100 + if email.isEmpty || number.isEmpty{
  101 + let alert = UIAlertController(title: "Enter email or number fields", message: "", preferredStyle: .alert)
  102 + alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
  103 + present(alert, animated: true)
  104 + } else { if email == userCode || number == userCode {
  105 + let vc = CodeVerificationViewController()
  106 + vc.navigationItem.hidesBackButton = true
  107 + navigationController?.pushViewController(vc, animated: true)
  108 + networking()
  109 + } else { if email != userCode || number != userCode {
  110 + let alert = UIAlertController(title: "User does not exist", message: "", preferredStyle: .alert)
  111 + alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
  112 + present(alert, animated: true)
  113 + }
  114 + }
  115 + }
98 116 }
99 117
100   - @objc func keyboardWillShow(notification: NSNotification) {
  118 + @objc private func keyboardWillShow(notification: NSNotification) {
101 119 let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
102 120 if !isKeyboardAppear {
103 121 UIView.animate(withDuration: duration ?? 0) {
... ... @@ -116,9 +134,9 @@ extension VerificationViewController {
116 134 }
117 135 }
118 136
119   - @objc func keyboardWillHide(notification: NSNotification) {
  137 + @objc private func keyboardWillHide(notification: NSNotification) {
120 138 let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
121   -
  139 +
122 140 if isKeyboardAppear {
123 141
124 142 UIView.animate(withDuration: duration ?? 0) {
... ... @@ -139,8 +157,9 @@ extension VerificationViewController {
139 157 }
140 158
141 159 extension VerificationViewController: UIPickerViewDataSource, UIPickerViewDelegate {
142   -
143   - func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 }
  160 + func numberOfComponents(in pickerView: UIPickerView) -> Int {
  161 + return 1
  162 + }
144 163
145 164 func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
146 165 return phonePickerModels.count
... ...
  1 +//
  2 +// NetworkManager.swift
  3 +// InterQR-Internship
  4 +//
  5 +// Created by Дмитрий Тимофеев on 25.06.2022.
  6 +//
  7 +
  8 +import Foundation
  9 +import Alamofire
  10 +
  11 +class AuthNetworkManager {
  12 + var networkToken: String? {
  13 + get {
  14 + // обязательно ключи на подобии NETWORK_TOKEN выносить в Constants.networkTokenKey
  15 + return UserDefaults.standard.string(forKey: "NETWORK_TOKEN")
  16 + }
  17 +
  18 + set (newValue) {
  19 + UserDefaults.standard.set(newValue, forKey: "NETWORK_TOKEN")
  20 + }
  21 + }
  22 +
  23 + typealias InitWebServiceResponse = (InitResponseModel) -> Void
  24 + typealias StartWebServiceResponse = (StartResponseModel) -> Void
  25 + typealias VerifyWebServiceResponse = (VerifyResponseModel) -> Void
  26 + typealias LoginWebServiceResponse = (LoginResponseModel) -> Void
  27 + typealias LogoutWebServiceResponse = (LogoutResponseModel) -> Void
  28 +
  29 + typealias FailedHandler = (Error) -> Void
  30 +
  31 + func initRequest(_ url: URL, model: InitRequestModel, completion: @escaping InitWebServiceResponse, fail: @escaping FailedHandler) {
  32 +
  33 + let params = ["device_uuid": model.deviceUUID,
  34 + "manufacturer": model.manufacturer,
  35 + "model": model.model,
  36 + "platform": model.platform,
  37 + "os_version": model.osVersion,
  38 + "app_version": model.appVersion] as [String: Any]
  39 +
  40 + AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: InitResponseModel.self ) { response in
  41 +
  42 + if let error = response.error {
  43 + fail(error)
  44 + } else {
  45 + if let res = response.value {
  46 + completion(res)
  47 + }
  48 + }
  49 + }
  50 + }
  51 +
  52 + func startRequest(_ url: URL, model: StartRequestModel, completion: @escaping StartWebServiceResponse, fail: @escaping FailedHandler) {
  53 +
  54 + let params = ["email_or_number": model.emailOrNumber] as [String: Any]
  55 +
  56 + AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: StartResponseModel.self ) { response in
  57 +
  58 + if let error = response.error {
  59 + fail(error)
  60 + } else {
  61 + if let res = response.value {
  62 + completion(res)
  63 + }
  64 + }
  65 + }
  66 + }
  67 +
  68 + func verifyRequest(_ url: URL, model: VerifyRequestModel, completion: @escaping VerifyWebServiceResponse, fail: @escaping FailedHandler) {
  69 +
  70 + let params = ["email_or_number": model.emailOrNumber,
  71 + "code": model.code,
  72 + "second_auth_token": model.secondAuthToken] as [String: Any]
  73 +
  74 + AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: VerifyResponseModel.self ) { response in
  75 +
  76 + if let error = response.error {
  77 + fail(error)
  78 + } else {
  79 + if let res = response.value {
  80 + self.networkToken = res.data.token
  81 + completion(res)
  82 + }
  83 + }
  84 + }
  85 + }
  86 +
  87 + func loginRequest(_ url: URL, model: LoginRequestModel, completion: @escaping LoginWebServiceResponse, fail: @escaping FailedHandler) {
  88 + let headers = ["Authorization": "Bearer \(self.networkToken ?? "")"]
  89 + 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 + fail(error)
  93 + } else {
  94 + if let res = response.value {
  95 + completion(res)
  96 + }
  97 + }
  98 + }
  99 + }
  100 +
  101 + func logoutRequest(_ url: URL, model: LogoutRequestModel, completion: @escaping LogoutWebServiceResponse, fail: @escaping FailedHandler) {
  102 + let headers = ["Authorization": "Bearer \(self.networkToken ?? "")"]
  103 + let params = ["device_uuid": model.deviceUUID] as [String: Any]
  104 +
  105 + AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: HTTPHeaders(headers), interceptor: nil).responseDecodable(of: LogoutResponseModel.self ) { response in
  106 +
  107 + if let error = response.error {
  108 + fail(error)
  109 + } else {
  110 + if let res = response.value {
  111 + completion(res)
  112 + }
  113 + }
  114 + }
  115 + }
  116 +}
... ...
1   -//
2   -// NetworkManager.swift
3   -// InterQR-Internship
4   -//
5   -// Created by Дмитрий Тимофеев on 25.06.2022.
6   -//
7   -
8   -import Foundation
9   -import Alamofire
10   -struct RequestModel: Codable {
11   - var deviceUUID: String
12   - var manufacturer: String
13   - var model: String
14   - var platform: String
15   - var osVersion: String
16   - var appVersion: String
17   -}
18   -class NetworkManager {
19   - typealias WebServiceResponse = (RequestModel) -> Void
20   - typealias FailedHandler = (Error) -> Void
21   -
22   - func authorizationRequest(_ url: URL, model: RequestModel, completion: @escaping WebServiceResponse, fail: @escaping FailedHandler) {
23   -
24   - let params = ["device_uuid": model.deviceUUID,
25   - "manufacturer": model.manufacturer,
26   - "model": model.model,
27   - "platform": model.platform,
28   - "os_version": model.osVersion,
29   - "app_version": model.appVersion] as [String: Any]
30   -
31   - AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: RequestModel.self ) { response in
32   -
33   - if let error = response.error {
34   - fail(error)
35   - } else {
36   - if let res = response.value {
37   - completion(res)
38   - }
39   - }
40   - }
41   -
42   - // AF.request(url).response { response in
43   - // guard let data = response.data else { return }
44   - // do {
45   - // let decoder = JSONDecoder()
46   - // let json = try decoder.decode(Initialize.self, from: data)
47   - //
48   - // DispatchQueue.main.async {
49   - // completion(json)
50   - // }
51   - // }
52   - // catch {
53   - // print("❌\(error)❌")
54   - // }
55   - // }
56   - }
57   -}
... ... @@ -7,6 +7,7 @@
7 7
8 8 import Foundation
9 9 import ContactsUI
  10 +
10 11 protocol ResidentSavable: AnyObject {
11 12 func save(_ data: [ResidentModel])
12 13 }
... ...
Please register or login to post a comment