From 7d1811171e4088f22bd679ebb59dfaf1bfbe7be6 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Mon, 29 Aug 2022 01:41:34 +0300 Subject: [PATCH] Sheet for adding new number --- AutoCat2.xcodeproj/project.pbxproj | 44 ++++++++++-- .../xcschemes/xcschememanagement.plist | 4 +- AutoCat2/Controllers/AuthController.swift | 4 +- AutoCat2/SceneDelegate.swift | 2 +- AutoCat2SUI/AutoCat2SUI.entitlements | 10 +-- AutoCat2SUI/AutoCat2SUIApp.swift | 6 +- AutoCat2SUI/Extensions/View.swift | 14 ++++ AutoCat2SUI/Screens/Auth/AuthVM.swift | 2 +- .../Screens/CheckNumber/CheckNumber.swift | 56 +++++++++++++++ AutoCat2SUI/Screens/Main/MainView.swift | 23 ++++++- .../VehiclesList/VehiclesListView.swift | 30 ++++++++ AutoCat2SUI/Views/PlateNumberView.swift | 68 +++++++++++++++++++ AutoCat2SUI/Views/RootView.swift | 2 +- .../{Settings.swift => MainSettings.swift} | 8 ++- AutoCatCore/Utils/Api.swift | 2 +- AutoCatCore/Utils/Constants.swift | 4 +- AutoCatCoreTests/SettingsTests.swift | 2 +- 17 files changed, 253 insertions(+), 28 deletions(-) create mode 100644 AutoCat2SUI/Extensions/View.swift create mode 100644 AutoCat2SUI/Screens/CheckNumber/CheckNumber.swift create mode 100644 AutoCat2SUI/Screens/VehiclesList/VehiclesListView.swift create mode 100644 AutoCat2SUI/Views/PlateNumberView.swift rename AutoCatCore/Models/{Settings.swift => MainSettings.swift} (82%) diff --git a/AutoCat2.xcodeproj/project.pbxproj b/AutoCat2.xcodeproj/project.pbxproj index b026622..6f7249e 100644 --- a/AutoCat2.xcodeproj/project.pbxproj +++ b/AutoCat2.xcodeproj/project.pbxproj @@ -21,6 +21,8 @@ 7A0391D6285933EF000EE522 /* AutoCatCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A49F4D727D4064500AEAAE0 /* AutoCatCore.framework */; }; 7A0391D7285933EF000EE522 /* AutoCatCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7A49F4D727D4064500AEAAE0 /* AutoCatCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 7A0391DD28593DBC000EE522 /* SidebarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0391DC28593DBC000EE522 /* SidebarController.swift */; }; + 7A163BF128BBE9ED0005A0A4 /* VehiclesListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A163BF028BBE9ED0005A0A4 /* VehiclesListView.swift */; }; + 7A163BF328BBEAFC0005A0A4 /* PlateNumberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A163BF228BBEAFC0005A0A4 /* PlateNumberView.swift */; }; 7A1D80E027F1F275007BD64F /* DifferenceKit in Frameworks */ = {isa = PBXBuildFile; productRef = 7A1D80DF27F1F275007BD64F /* DifferenceKit */; }; 7A1D80E627F20FCB007BD64F /* DifferenceKit in Frameworks */ = {isa = PBXBuildFile; productRef = 7A1D80E527F20FCB007BD64F /* DifferenceKit */; }; 7A1D80E827F30399007BD64F /* VModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1D80E727F30399007BD64F /* VModel.swift */; }; @@ -79,7 +81,7 @@ 7A49F50D27D406CB00AEAAE0 /* Vehicle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A49F50627D406CB00AEAAE0 /* Vehicle.swift */; }; 7A49F50E27D406CB00AEAAE0 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A49F50727D406CB00AEAAE0 /* User.swift */; }; 7A49F50F27D406CB00AEAAE0 /* Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A49F50827D406CB00AEAAE0 /* Response.swift */; }; - 7A49F51027D406CB00AEAAE0 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A49F50927D406CB00AEAAE0 /* Settings.swift */; }; + 7A49F51027D406CB00AEAAE0 /* MainSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A49F50927D406CB00AEAAE0 /* MainSettings.swift */; }; 7A49F51127D406CB00AEAAE0 /* PlateNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A49F50A27D406CB00AEAAE0 /* PlateNumber.swift */; }; 7A49F51227D406CB00AEAAE0 /* VName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A49F50B27D406CB00AEAAE0 /* VName.swift */; }; 7A49F51527D40C6100AEAAE0 /* AutoCat2.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 7A49F51327D40C6100AEAAE0 /* AutoCat2.xcdatamodeld */; }; @@ -98,6 +100,8 @@ 7AE32D6927F06536004EF6E0 /* CoreDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE32D6827F06536004EF6E0 /* CoreDataSource.swift */; }; 7AE32D6E27F06D2D004EF6E0 /* SwiftDate in Frameworks */ = {isa = PBXBuildFile; productRef = 7AE32D6D27F06D2D004EF6E0 /* SwiftDate */; }; 7AE32D7127F06DA4004EF6E0 /* DateSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE32D7027F06DA4004EF6E0 /* DateSection.swift */; }; + 7AF1D0D828BB577E004E19F7 /* CheckNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AF1D0D728BB577E004E19F7 /* CheckNumber.swift */; }; + 7AF1D0DA28BB5BF5004E19F7 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AF1D0D928BB5BF5004E19F7 /* View.swift */; }; 7AFD7AE02871823E00BCCD37 /* SidebarSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AFD7ADF2871823E00BCCD37 /* SidebarSection.swift */; }; 7AFD7AE22871826D00BCCD37 /* SidebarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AFD7AE12871826D00BCCD37 /* SidebarItem.swift */; }; 7AFD7AE4287182CD00BCCD37 /* SidebarFilterItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AFD7AE3287182CD00BCCD37 /* SidebarFilterItem.swift */; }; @@ -217,6 +221,8 @@ 6841AFB465BF16E122875D9A /* ACButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ACButton.swift; sourceTree = ""; }; 6841AFE790F6FC06838B1E2C /* UIControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIControl.swift; sourceTree = ""; }; 7A0391DC28593DBC000EE522 /* SidebarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarController.swift; sourceTree = ""; }; + 7A163BF028BBE9ED0005A0A4 /* VehiclesListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehiclesListView.swift; sourceTree = ""; }; + 7A163BF228BBEAFC0005A0A4 /* PlateNumberView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlateNumberView.swift; sourceTree = ""; }; 7A1D80E727F30399007BD64F /* VModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VModel.swift; sourceTree = ""; }; 7A24C19527EE212E00049E7F /* RoadNumbers.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = RoadNumbers.otf; sourceTree = ""; }; 7A24C19627EE212E00049E7F /* RoadNumbers2.0.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = RoadNumbers2.0.otf; sourceTree = ""; }; @@ -269,7 +275,7 @@ 7A49F50627D406CB00AEAAE0 /* Vehicle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Vehicle.swift; sourceTree = ""; }; 7A49F50727D406CB00AEAAE0 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; 7A49F50827D406CB00AEAAE0 /* Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Response.swift; sourceTree = ""; }; - 7A49F50927D406CB00AEAAE0 /* Settings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; + 7A49F50927D406CB00AEAAE0 /* MainSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainSettings.swift; sourceTree = ""; }; 7A49F50A27D406CB00AEAAE0 /* PlateNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlateNumber.swift; sourceTree = ""; }; 7A49F50B27D406CB00AEAAE0 /* VName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VName.swift; sourceTree = ""; }; 7A49F51427D40C6100AEAAE0 /* Shared.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Shared.xcdatamodel; sourceTree = ""; }; @@ -293,6 +299,8 @@ 7AE32D6527F063A1004EF6E0 /* UIEdgeInsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIEdgeInsets.swift; sourceTree = ""; }; 7AE32D6827F06536004EF6E0 /* CoreDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataSource.swift; sourceTree = ""; }; 7AE32D7027F06DA4004EF6E0 /* DateSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateSection.swift; sourceTree = ""; }; + 7AF1D0D728BB577E004E19F7 /* CheckNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckNumber.swift; sourceTree = ""; }; + 7AF1D0D928BB5BF5004E19F7 /* View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = ""; }; 7AFD7ADF2871823E00BCCD37 /* SidebarSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarSection.swift; sourceTree = ""; }; 7AFD7AE12871826D00BCCD37 /* SidebarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarItem.swift; sourceTree = ""; }; 7AFD7AE3287182CD00BCCD37 /* SidebarFilterItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarFilterItem.swift; sourceTree = ""; }; @@ -433,6 +441,14 @@ path = Controllers; sourceTree = ""; }; + 7A163BEF28BBE9DA0005A0A4 /* VehiclesList */ = { + isa = PBXGroup; + children = ( + 7A163BF028BBE9ED0005A0A4 /* VehiclesListView.swift */, + ); + path = VehiclesList; + sourceTree = ""; + }; 7A24C19427EE212E00049E7F /* Fonts */ = { isa = PBXGroup; children = ( @@ -504,6 +520,8 @@ 7A4951C3288D3AF000C644B6 /* Screens */ = { isa = PBXGroup; children = ( + 7A163BEF28BBE9DA0005A0A4 /* VehiclesList */, + 7AF1D0D628BB5768004E19F7 /* CheckNumber */, 7A4951CE288D5C1300C644B6 /* Main */, 7A4951CD288D5C0800C644B6 /* Auth */, ); @@ -532,6 +550,7 @@ children = ( 7A4951B8288D3A6100C644B6 /* RootView.swift */, 7A4951D0288D5C4300C644B6 /* ACProgressView.swift */, + 7A163BF228BBEAFC0005A0A4 /* PlateNumberView.swift */, ); path = Views; sourceTree = ""; @@ -540,6 +559,7 @@ isa = PBXGroup; children = ( 7A4951D4288D5ED000C644B6 /* Alert.swift */, + 7AF1D0D928BB5BF5004E19F7 /* View.swift */, ); path = Extensions; sourceTree = ""; @@ -668,7 +688,7 @@ 7A49F50627D406CB00AEAAE0 /* Vehicle.swift */, 7A49F50727D406CB00AEAAE0 /* User.swift */, 7A49F50827D406CB00AEAAE0 /* Response.swift */, - 7A49F50927D406CB00AEAAE0 /* Settings.swift */, + 7A49F50927D406CB00AEAAE0 /* MainSettings.swift */, 7A49F50A27D406CB00AEAAE0 /* PlateNumber.swift */, 7AFD7AE528718BF000BCCD37 /* Filter.swift */, ); @@ -758,6 +778,14 @@ path = DataSource; sourceTree = ""; }; + 7AF1D0D628BB5768004E19F7 /* CheckNumber */ = { + isa = PBXGroup; + children = ( + 7AF1D0D728BB577E004E19F7 /* CheckNumber.swift */, + ); + path = CheckNumber; + sourceTree = ""; + }; 7AFD7ADE2871822000BCCD37 /* Sidebar */ = { isa = PBXGroup; children = ( @@ -1088,9 +1116,13 @@ buildActionMask = 2147483647; files = ( 7A4951D3288D5E2800C644B6 /* AuthVM.swift in Sources */, + 7A163BF128BBE9ED0005A0A4 /* VehiclesListView.swift in Sources */, 7A4951B9288D3A6100C644B6 /* RootView.swift in Sources */, 7A4951C7288D3BDD00C644B6 /* MainView.swift in Sources */, + 7AF1D0D828BB577E004E19F7 /* CheckNumber.swift in Sources */, 7A4951B7288D3A6100C644B6 /* AutoCat2SUIApp.swift in Sources */, + 7AF1D0DA28BB5BF5004E19F7 /* View.swift in Sources */, + 7A163BF328BBEAFC0005A0A4 /* PlateNumberView.swift in Sources */, 7A4951D1288D5C4300C644B6 /* ACProgressView.swift in Sources */, 7A4951C5288D3BCF00C644B6 /* AuthView.swift in Sources */, 7A4951D5288D5ED000C644B6 /* Alert.swift in Sources */, @@ -1167,7 +1199,7 @@ 7A36E55E27FB5A260025AACB /* LoginMethodMock.swift in Sources */, 7A49F50C27D406CB00AEAAE0 /* VBrand.swift in Sources */, 7A36E55C27FB55570025AACB /* Testing.swift in Sources */, - 7A49F51027D406CB00AEAAE0 /* Settings.swift in Sources */, + 7A49F51027D406CB00AEAAE0 /* MainSettings.swift in Sources */, 929EDE9027F8F76300E55F65 /* DebugInfo.swift in Sources */, 7A36E55D27FB5A220025AACB /* ApiMethodMock.swift in Sources */, 929EDE8927F8E65500E55F65 /* VAd.swift in Sources */, @@ -1309,7 +1341,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 12.4; + MACOSX_DEPLOYMENT_TARGET = 13.0; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = pro.aliencat.AutoCat2SUI; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1348,7 +1380,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 12.4; + MACOSX_DEPLOYMENT_TARGET = 13.0; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = pro.aliencat.AutoCat2SUI; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/AutoCat2.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist b/AutoCat2.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist index aecfc2a..27a99e0 100644 --- a/AutoCat2.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/AutoCat2.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist @@ -17,12 +17,12 @@ AutoCat2Mac.xcscheme_^#shared#^_ orderHint - 1 + 2 AutoCat2SUI.xcscheme_^#shared#^_ orderHint - 2 + 1 AutoCat2UITests.testExample.xcscheme diff --git a/AutoCat2/Controllers/AuthController.swift b/AutoCat2/Controllers/AuthController.swift index 92a7ba2..bd131a1 100644 --- a/AutoCat2/Controllers/AuthController.swift +++ b/AutoCat2/Controllers/AuthController.swift @@ -76,7 +76,7 @@ class AuthController: UIViewController { do { HUD.show(.progress) - Settings.shared.user = try await Api.shared.login(email: email, password: password) + MainSettings.shared.user = try await Api.shared.login(email: email, password: password) view.window?.rootViewController = MainTabController() HUD.hide() } catch { @@ -92,7 +92,7 @@ class AuthController: UIViewController { do { HUD.show(.progress) - Settings.shared.user = try await Api.shared.signup(email: email, password: password) + MainSettings.shared.user = try await Api.shared.signup(email: email, password: password) view.window?.rootViewController = MainTabController() HUD.hide() } catch { diff --git a/AutoCat2/SceneDelegate.swift b/AutoCat2/SceneDelegate.swift index db94ff6..4bb2285 100644 --- a/AutoCat2/SceneDelegate.swift +++ b/AutoCat2/SceneDelegate.swift @@ -21,7 +21,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { self.window = UIWindow(windowScene: scene) - if Settings.shared.user.token.isEmpty { + if MainSettings.shared.user.token.isEmpty { self.window?.rootViewController = AuthController() } else { self.window?.rootViewController = MainTabController() diff --git a/AutoCat2SUI/AutoCat2SUI.entitlements b/AutoCat2SUI/AutoCat2SUI.entitlements index f2ef3ae..625af03 100644 --- a/AutoCat2SUI/AutoCat2SUI.entitlements +++ b/AutoCat2SUI/AutoCat2SUI.entitlements @@ -2,9 +2,11 @@ - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + com.apple.security.network.client + diff --git a/AutoCat2SUI/AutoCat2SUIApp.swift b/AutoCat2SUI/AutoCat2SUIApp.swift index 155972b..08a9b6a 100644 --- a/AutoCat2SUI/AutoCat2SUIApp.swift +++ b/AutoCat2SUI/AutoCat2SUIApp.swift @@ -26,15 +26,15 @@ struct AutoCat2SUIApp: App { } func getTestSettings() -> TestSettings { - guard let settings = Settings.shared as? TestSettings else { + guard let settings = MainSettings.shared as? TestSettings else { fatalError("Error getting settings") } return settings } - func getSettings() -> Settings { - guard let settings = Settings.shared as? Settings else { + func getSettings() -> MainSettings { + guard let settings = MainSettings.shared as? MainSettings else { fatalError("Error getting settings") } diff --git a/AutoCat2SUI/Extensions/View.swift b/AutoCat2SUI/Extensions/View.swift new file mode 100644 index 0000000..488a3d3 --- /dev/null +++ b/AutoCat2SUI/Extensions/View.swift @@ -0,0 +1,14 @@ +// +// View.swift +// AutoCat2SUI +// +// Created by Selim Mustafaev on 28.08.2022. +// + +import SwiftUI + +extension View { + func hidden(_ shouldHide: Bool) -> some View { + opacity(shouldHide ? 0 : 1) + } +} diff --git a/AutoCat2SUI/Screens/Auth/AuthVM.swift b/AutoCat2SUI/Screens/Auth/AuthVM.swift index b4c8a28..adc6bbe 100644 --- a/AutoCat2SUI/Screens/Auth/AuthVM.swift +++ b/AutoCat2SUI/Screens/Auth/AuthVM.swift @@ -12,7 +12,7 @@ public class AuthVM: ObservableObject { private let api: ApiProtocol private var settings: any SettingsProtocol - init(api: ApiProtocol = Api.shared, settings: any SettingsProtocol = Settings.shared) { + init(api: ApiProtocol = Api.shared, settings: any SettingsProtocol = MainSettings.shared) { self.api = api self.settings = settings diff --git a/AutoCat2SUI/Screens/CheckNumber/CheckNumber.swift b/AutoCat2SUI/Screens/CheckNumber/CheckNumber.swift new file mode 100644 index 0000000..68dd889 --- /dev/null +++ b/AutoCat2SUI/Screens/CheckNumber/CheckNumber.swift @@ -0,0 +1,56 @@ +// +// CheckNumber.swift +// AutoCat2SUI +// +// Created by Selim Mustafaev on 28.08.2022. +// + +import SwiftUI +import AutoCatCore + +struct CheckNumber: View { + + @Environment(\.presentationMode) var presentation + @State var plateNumber: String = "" + @State var showProgress = false + @State private var alert: AlertMessage? = nil + + var body: some View { + VStack(alignment: .center, spacing: 8) { + Text("Check new plate number") + TextField("qwe", text: $plateNumber, prompt: Text("Plate number")) + .disabled(showProgress) + ProgressView() + .progressViewStyle(CircularProgressViewStyle()) + .hidden(!showProgress) + HStack { + Button("Cancel") { + self.presentation.wrappedValue.dismiss() + } + .disabled(showProgress) + Button("Check") { + Task.init { + showProgress = true + do { + try await VehicleService.shared.check(plateNumber: plateNumber.uppercased(), force: false) + self.presentation.wrappedValue.dismiss() + } catch { + alert = .error(error: error) + } + showProgress = false + } + } + .alert(item: $alert, content: Alert.init) + .disabled(showProgress) + } + } + .padding() + .frame(minWidth: 300) + } +} + +struct CheckNumber_Previews: PreviewProvider { + static var previews: some View { + CheckNumber() + } +} diff --git a/AutoCat2SUI/Screens/Main/MainView.swift b/AutoCat2SUI/Screens/Main/MainView.swift index 1e72e0f..4cc8eff 100644 --- a/AutoCat2SUI/Screens/Main/MainView.swift +++ b/AutoCat2SUI/Screens/Main/MainView.swift @@ -13,6 +13,7 @@ struct MainView: View { @FetchRequest(entity: CDVehicle.entity(), sortDescriptors: []) var vehicles: FetchedResults @State private var selectedFilter: Filter? + @State private var checkSheetPresented = false private var historyFilters: [Filter] = [ .allLocal, @@ -30,7 +31,8 @@ struct MainView: View { Section("History") { ForEach(historyFilters) { filter in NavigationLink(value: filter) { - Label(filter.name, image: filter.iconName) + Label(filter.name, systemImage: filter.iconName) + .badge(vehicles.count) } } } @@ -38,11 +40,28 @@ struct MainView: View { Section("Remote") { ForEach(remoteFilters) { filter in NavigationLink(value: filter) { - Label(filter.name, image: filter.iconName) + Label(filter.name, systemImage: filter.iconName) } } } } + .toolbar { + ToolbarItemGroup(placement: .primaryAction) { + Spacer() + Button { + checkSheetPresented = true + } label: { + Image(systemName: "plus") + } + .sheet(isPresented: $checkSheetPresented) { + CheckNumber() + } + + } + } + .navigationDestination(for: Filter.self) { filter in + VehiclesListView(vehicles: [], selection: nil) + } } content: { Text("Content") } detail: { diff --git a/AutoCat2SUI/Screens/VehiclesList/VehiclesListView.swift b/AutoCat2SUI/Screens/VehiclesList/VehiclesListView.swift new file mode 100644 index 0000000..a099ab8 --- /dev/null +++ b/AutoCat2SUI/Screens/VehiclesList/VehiclesListView.swift @@ -0,0 +1,30 @@ +// +// VehiclesListView.swift +// AutoCat2SUI +// +// Created by Selim Mustafaev on 28.08.2022. +// + +import SwiftUI +import AutoCatCore + +struct VehiclesListView: View { + + var vehicles: [CDVehicle] + @State var selection: CDVehicle? + + var body: some View { + List(selection: $selection) { + ForEach(vehicles, id: \.self) { vehicle in + let number = PlateNumber(vehicle.number ?? "") + PlateNumberView(number: number, unrecognized: vehicle.unrecognized, outdated: vehicle.outdated) + } + } + } +} + +struct VehiclesListView_Previews: PreviewProvider { + static var previews: some View { + VehiclesListView(vehicles: []) + } +} diff --git a/AutoCat2SUI/Views/PlateNumberView.swift b/AutoCat2SUI/Views/PlateNumberView.swift new file mode 100644 index 0000000..8167cbe --- /dev/null +++ b/AutoCat2SUI/Views/PlateNumberView.swift @@ -0,0 +1,68 @@ +// +// PlateNumberView.swift +// AutoCat2SUI +// +// Created by Selim Mustafaev on 28.08.2022. +// + +import SwiftUI +import AutoCatCore + +struct PlateNumberView: View { + + let number: PlateNumber + let unrecognized: Bool + let outdated: Bool + + private var fgColor: Color { + if unrecognized { + return Color("PlateBackgroundError") + } else { + return Color("PlateForeground") + } + } + + var body: some View { + ZStack { + RoundedRectangle(cornerRadius: 6) + .fill(fgColor) + GeometryReader { geometry in + HStack(alignment: .center, spacing: 2) { + ZStack { + RoundedRectangle(cornerRadius: 4) + .fill(Color("PlateBackground")) + Text(number.mainPart()) + .font(Font.custom("RoadNumbers", size: geometry.size.height*0.9)) + } + .frame(width: geometry.size.width*0.73 - 1) + ZStack { + RoundedRectangle(cornerRadius: 4) + .fill(Color("PlateBackground")) + VStack(spacing: 0) { + Text(number.region()) + .frame(height: geometry.size.height*0.65, alignment: .center) + HStack { + + } + .frame(height: geometry.size.height*0.35, alignment: .center) + } + } + .frame(width: geometry.size.width*0.27 - 1) + } + } + .padding(2) + } + .aspectRatio(520.0/112.0, contentMode: .fit) + } +} + +struct PlateNumberView_Previews: PreviewProvider { + static var previews: some View { + Group { + PlateNumberView(number: PlateNumber("Е201АМ761"), unrecognized: false, outdated: false) + PlateNumberView(number: PlateNumber("Е201АМ761"), unrecognized: true, outdated: false) + PlateNumberView(number: PlateNumber("Е201АМ761"), unrecognized: false, outdated: true) + } + .previewLayout(.fixed(width: 200, height: 50)) + } +} diff --git a/AutoCat2SUI/Views/RootView.swift b/AutoCat2SUI/Views/RootView.swift index 41018c1..cb9e0c5 100644 --- a/AutoCat2SUI/Views/RootView.swift +++ b/AutoCat2SUI/Views/RootView.swift @@ -27,6 +27,6 @@ struct RootView: View where T: SettingsProtocol { struct RootView_Previews: PreviewProvider { static var previews: some View { - RootView(settings: Settings()) + RootView(settings: MainSettings()) } } diff --git a/AutoCatCore/Models/Settings.swift b/AutoCatCore/Models/MainSettings.swift similarity index 82% rename from AutoCatCore/Models/Settings.swift rename to AutoCatCore/Models/MainSettings.swift index 0a76c40..722b08e 100644 --- a/AutoCatCore/Models/Settings.swift +++ b/AutoCatCore/Models/MainSettings.swift @@ -7,9 +7,9 @@ public protocol SettingsProtocol: ObservableObject { } -public class Settings: SettingsProtocol { +public class MainSettings: SettingsProtocol { private let defaults: UserDefaults - public static var shared: any SettingsProtocol = Testing.isUITesting ? TestSettings() : Settings() + public static var shared: any SettingsProtocol = Testing.isUITesting ? TestSettings() : MainSettings() @Published public var user: User { @@ -31,6 +31,10 @@ public class Settings: SettingsProtocol { public init(defaults: UserDefaults = .standard) { self.defaults = defaults +// if let bundleID = Bundle.main.bundleIdentifier { +// UserDefaults.standard.removePersistentDomain(forName: bundleID) +// } + self.defaults.register(defaults: [ "showDebugInfo": false ]) diff --git a/AutoCatCore/Utils/Api.swift b/AutoCatCore/Utils/Api.swift index 05896e1..b5f3c88 100644 --- a/AutoCatCore/Utils/Api.swift +++ b/AutoCatCore/Utils/Api.swift @@ -14,7 +14,7 @@ public class Api: ApiProtocol { public static let shared = Api() - public init(session: URLSession? = nil, settings: any SettingsProtocol = Settings.shared) { + public init(session: URLSession? = nil, settings: any SettingsProtocol = MainSettings.shared) { self.settings = settings diff --git a/AutoCatCore/Utils/Constants.swift b/AutoCatCore/Utils/Constants.swift index 21b54cc..eae0d2e 100644 --- a/AutoCatCore/Utils/Constants.swift +++ b/AutoCatCore/Utils/Constants.swift @@ -3,8 +3,8 @@ import Foundation public struct Constants { public static var baseUrl: String { #if DEBUG - return "http://127.0.0.1:3000/" - //return "http://192.168.1.67:3000/" + //return "http://127.0.0.1:3000/" + return "http://192.168.1.1:3000/" //return "https://vps.aliencat.pro:8443/" #else return "https://vps.aliencat.pro:8443/" diff --git a/AutoCatCoreTests/SettingsTests.swift b/AutoCatCoreTests/SettingsTests.swift index d7c9d3b..137b5ef 100644 --- a/AutoCatCoreTests/SettingsTests.swift +++ b/AutoCatCoreTests/SettingsTests.swift @@ -22,7 +22,7 @@ class SettingsTests: XCTestCase { throw TestError.createDefaultsFailed } userDefaults.removePersistentDomain(forName: #file) - self.settings = Settings(defaults: userDefaults) + self.settings = MainSettings(defaults: userDefaults) } override func tearDownWithError() throws {