diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 5c80193..a5e0457 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 7A000AA224C2EEDE001F5B00 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A000AA124C2EEDE001F5B00 /* Location.swift */; }; + 7A0420AA25619AEC00034941 /* Osago.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0420A925619AEC00034941 /* Osago.swift */; }; + 7A0420AD2561A0B100034941 /* OsagoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0420AC2561A0B100034941 /* OsagoController.swift */; }; + 7A0420B12561A0E100034941 /* OsagoAddController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0420B02561A0E100034941 /* OsagoAddController.swift */; }; 7A051611241412CA00FC55AC /* SwiftDate in Frameworks */ = {isa = PBXBuildFile; productRef = 7A051610241412CA00FC55AC /* SwiftDate */; }; 7A05161A2414FF0900FC55AC /* DateSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0516192414FF0900FC55AC /* DateSection.swift */; }; 7A1090E824A394F100B4F0B2 /* AudioRecordCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1090E724A394F100B4F0B2 /* AudioRecordCell.swift */; }; @@ -99,6 +102,9 @@ /* Begin PBXFileReference section */ 7A000AA124C2EEDE001F5B00 /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = ""; }; + 7A0420A925619AEC00034941 /* Osago.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Osago.swift; sourceTree = ""; }; + 7A0420AC2561A0B100034941 /* OsagoController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OsagoController.swift; sourceTree = ""; }; + 7A0420B02561A0E100034941 /* OsagoAddController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OsagoAddController.swift; sourceTree = ""; }; 7A0516192414FF0900FC55AC /* DateSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateSection.swift; sourceTree = ""; }; 7A1090E724A394F100B4F0B2 /* AudioRecordCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRecordCell.swift; sourceTree = ""; }; 7A1090E924A3A26300B4F0B2 /* AudioPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayer.swift; sourceTree = ""; }; @@ -206,6 +212,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 7A0420AF2561A0C100034941 /* Osago */ = { + isa = PBXGroup; + children = ( + 7A0420AC2561A0B100034941 /* OsagoController.swift */, + 7A0420B02561A0E100034941 /* OsagoAddController.swift */, + ); + path = Osago; + sourceTree = ""; + }; 7A1146F423FDE7E500B424AF = { isa = PBXGroup; children = ( @@ -248,6 +263,7 @@ 7A11471423FDEAF800B424AF /* Controllers */ = { isa = PBXGroup; children = ( + 7A0420AF2561A0C100034941 /* Osago */, 7A813DC7250B5C6E00CC93B9 /* Location */, 7A11471523FDEB2A00B424AF /* MainSplitController.swift */, 7A11471723FDEBFA00B424AF /* ReportController.swift */, @@ -304,6 +320,7 @@ 7AB562B9249C9E9B00473D53 /* Region.swift */, 7A659B5824A2B1BA0043A0F2 /* AudioRecord.swift */, 7AAE6AD224CDDF950023860B /* VehicleEvent.swift */, + 7A0420A925619AEC00034941 /* Osago.swift */, ); path = Models; sourceTree = ""; @@ -537,6 +554,7 @@ 7A96AE2D246B2B7400297C33 /* GoogleSignInController.swift in Sources */, 7A15051224DB3E3000F39631 /* AnyEncodable.swift in Sources */, 7A1090EA24A3A26300B4F0B2 /* AudioPlayer.swift in Sources */, + 7A0420B12561A0E100034941 /* OsagoAddController.swift in Sources */, 7A11474723FF2AA500B424AF /* User.swift in Sources */, 7A11471623FDEB2A00B424AF /* MainSplitController.swift in Sources */, 7A813DC5250AAF3C00CC93B9 /* LocationEditController.swift in Sources */, @@ -547,8 +565,10 @@ 7A11470323FDE7E500B424AF /* SceneDelegate.swift in Sources */, 7A530B7E24017FEE00CBFE6E /* VehicleCell.swift in Sources */, 7A813DCB250B5DC900CC93B9 /* LocationPickerController.swift in Sources */, + 7A0420AA25619AEC00034941 /* Osago.swift in Sources */, 7A11474423FF06CA00B424AF /* Api.swift in Sources */, 7A9FEEC82529AB23001CA50E /* RxRealmDataSource.swift in Sources */, + 7A0420AD2561A0B100034941 /* OsagoController.swift in Sources */, 7AB67E8E2435D1A000258F61 /* CustomButton.swift in Sources */, 7A21112A24FC3D7E003BBF6F /* AudioEngine.swift in Sources */, 7A8A220B248D67B60073DFD9 /* VehicleReportImage.swift in Sources */, @@ -708,7 +728,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 54; + CURRENT_PROJECT_VERSION = 55; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -731,7 +751,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 54; + CURRENT_PROJECT_VERSION = 55; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index b501f40..e8b4862 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -25,7 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let config = Realm.Configuration( - schemaVersion: 24, + schemaVersion: 25, migrationBlock: { migration, oldSchemaVersion in if oldSchemaVersion <= 3 { var numbers: [String] = [] diff --git a/AutoCat/Base.lproj/Main.storyboard b/AutoCat/Base.lproj/Main.storyboard index 0d81553..7d0c147 100644 --- a/AutoCat/Base.lproj/Main.storyboard +++ b/AutoCat/Base.lproj/Main.storyboard @@ -57,6 +57,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutoCat/Controllers/Osago/OsagoAddController.swift b/AutoCat/Controllers/Osago/OsagoAddController.swift new file mode 100644 index 0000000..c9aa474 --- /dev/null +++ b/AutoCat/Controllers/Osago/OsagoAddController.swift @@ -0,0 +1,42 @@ +import UIKit +import Eureka + +enum OsagoCheckSource: Equatable, CustomStringConvertible { + case plateNumber(number: String) + case vin(number: String) + + var description: String { + switch self { + case .plateNumber(let number): + return "Plate number (\(number))" + case .vin(let number): + return "VIN (\(number))" + } + } +} + +class OsagoAddController: FormViewController { + + var checkSources: [OsagoCheckSource] = [] + + override func viewDidLoad() { + super.viewDidLoad() + self.title = "OSAGO check" + + form +++ Section("Check parameters") + <<< DateTimeInlineRow() { row in + row.title = "Check date" + row.value = Date() + } + <<< PickerInlineRow() { row in + row.title = "Check by" + row.value = .plateNumber(number: "А123АА161") + row.options = self.checkSources + } + + form +++ Section() + <<< ButtonRow() { $0.title = "Check" }.onCellSelection { _, _ in + print("Check") + } + } +} diff --git a/AutoCat/Controllers/Osago/OsagoController.swift b/AutoCat/Controllers/Osago/OsagoController.swift new file mode 100644 index 0000000..2720d2f --- /dev/null +++ b/AutoCat/Controllers/Osago/OsagoController.swift @@ -0,0 +1,29 @@ +import UIKit +import Eureka + +class OsagoController: FormViewController { + + var vehicle: Vehicle? { + didSet { + self.form.allSections.forEach { $0.reload() } + } + } + + override func viewDidLoad() { + super.viewDidLoad() + self.title = "OSAGO contracts" + self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(checkNewDate(_:))) + } + + @objc func checkNewDate(_ sender: UIBarButtonItem) { + guard let vehicle = self.vehicle else { return } + + let sb = UIStoryboard(name: "Main", bundle: nil) + let controller = sb.instantiateViewController(identifier: "OsagoAddController") as OsagoAddController + controller.checkSources = [.plateNumber(number: vehicle.getNumber())] + if let vin = vehicle.vin1, !vin.contains("*") { + controller.checkSources.append(.vin(number: vin)) + } + self.navigationController?.pushViewController(controller, animated: true) + } +} diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 58f0768..707459d 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -57,42 +57,6 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource <<< LabelRow() { $0.title = "Category" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.vehicle?.category ?? "" } <<< LabelRow() { $0.title = "Steering wheel position" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.stringFromBool(self.vehicle?.isRightWheel.value, yes: "Right", no: "Left") } <<< LabelRow() { $0.title = "Japanese" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.stringFromBool(self.vehicle?.isJapanese.value, yes: "Yes", no: "No") } - <<< LabelRow() { $0.title = "Events" }.cellUpdate { cell, _ in - cell.detailTextLabel?.text = String(self.vehicle?.events.count ?? 0) - cell.accessoryType = .disclosureIndicator - } - .onCellSelection { _, _ in - let sb = UIStoryboard(name: "Main", bundle: nil) - let controller = sb.instantiateViewController(identifier: "EventsController") as EventsController - controller.vehicle = self.vehicle - self.navigationController?.pushViewController(controller, animated: true) - } - - if self.vehicle?.ownershipPeriods.count ?? 0 > 0 { - generalSection <<< LabelRow() { $0.title = "Owners" }.cellUpdate { cell, _ in - cell.detailTextLabel?.text = String(self.vehicle?.ownershipPeriods.count ?? 0) - cell.accessoryType = .disclosureIndicator - } - .onCellSelection { _, _ in - let sb = UIStoryboard(name: "Main", bundle: nil) - let controller = sb.instantiateViewController(identifier: "OwnersController") as OwnersController - controller.owners = self.vehicle?.ownershipPeriods.toArray() ?? [] - self.navigationController?.pushViewController(controller, animated: true) - } - } - - if self.vehicle?.photos.count ?? 0 > 0 { - generalSection <<< LabelRow() { $0.title = "Photos" }.cellUpdate { cell, _ in - cell.detailTextLabel?.text = String(self.vehicle?.photos.count ?? 0) - cell.accessoryType = .disclosureIndicator - } - .onCellSelection { _, _ in - let mediaBrowser = MediaBrowserViewController(index: 0, dataSource: self, delegate: self) - mediaBrowser.shouldShowTitle = true - mediaBrowser.title = self.vehicle?.photos.first?.description - self.present(mediaBrowser, animated: true, completion: nil) - } - } form +++ Section("Identifiers") <<< LabelRow() { $0.title = "Number" }.cellUpdate { cell, _ in @@ -117,6 +81,55 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource <<< LabelRow() { $0.title = "Volume (cm³)" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = String(self.vehicle?.engine?.volume.value ?? 0) } <<< LabelRow() { $0.title = "Power (HP)" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = String(self.vehicle?.engine?.powerHp ?? 0) } <<< LabelRow() { $0.title = "Power (kw)" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = String(self.vehicle?.engine?.powerKw.value ?? 0) } + + let historySection = Section("History") + form +++ historySection + <<< LabelRow() { $0.title = "Events" }.cellUpdate { cell, _ in + cell.detailTextLabel?.text = String(self.vehicle?.events.count ?? 0) + cell.accessoryType = .disclosureIndicator + } + .onCellSelection { _, _ in + let sb = UIStoryboard(name: "Main", bundle: nil) + let controller = sb.instantiateViewController(identifier: "EventsController") as EventsController + controller.vehicle = self.vehicle + self.navigationController?.pushViewController(controller, animated: true) + } + <<< LabelRow() { $0.title = "OSAGO" }.cellUpdate { cell, _ in + cell.accessoryType = .disclosureIndicator + cell.detailTextLabel?.text = String(self.vehicle?.osagoContracts.count ?? 0) + } + .onCellSelection { _, _ in + let sb = UIStoryboard(name: "Main", bundle: nil) + let controller = sb.instantiateViewController(identifier: "OsagoController") as OsagoController + controller.vehicle = self.vehicle + self.navigationController?.pushViewController(controller, animated: true) + } + + if self.vehicle?.ownershipPeriods.count ?? 0 > 0 { + historySection <<< LabelRow() { $0.title = "Owners" }.cellUpdate { cell, _ in + cell.detailTextLabel?.text = String(self.vehicle?.ownershipPeriods.count ?? 0) + cell.accessoryType = .disclosureIndicator + } + .onCellSelection { _, _ in + let sb = UIStoryboard(name: "Main", bundle: nil) + let controller = sb.instantiateViewController(identifier: "OwnersController") as OwnersController + controller.owners = self.vehicle?.ownershipPeriods.toArray() ?? [] + self.navigationController?.pushViewController(controller, animated: true) + } + } + + if self.vehicle?.photos.count ?? 0 > 0 { + historySection <<< LabelRow() { $0.title = "Photos" }.cellUpdate { cell, _ in + cell.detailTextLabel?.text = String(self.vehicle?.photos.count ?? 0) + cell.accessoryType = .disclosureIndicator + } + .onCellSelection { _, _ in + let mediaBrowser = MediaBrowserViewController(index: 0, dataSource: self, delegate: self) + mediaBrowser.shouldShowTitle = true + mediaBrowser.title = self.vehicle?.photos.first?.description + self.present(mediaBrowser, animated: true, completion: nil) + } + } } func stringFromBool(_ value: Bool?, yes: String, no: String) -> String { diff --git a/AutoCat/Models/Osago.swift b/AutoCat/Models/Osago.swift new file mode 100644 index 0000000..e8166df --- /dev/null +++ b/AutoCat/Models/Osago.swift @@ -0,0 +1,12 @@ +import Foundation +import RealmSwift + +class Osago: Object, Decodable { + @objc dynamic var number: String + @objc dynamic var name: String + @objc dynamic var status: String + @objc dynamic var restrictions: String + @objc dynamic var insurant: String? + @objc dynamic var owner: String? + @objc dynamic var usageRegion: String? +} diff --git a/AutoCat/Models/Vehicle.swift b/AutoCat/Models/Vehicle.swift index 540eb8a..7ca84dc 100644 --- a/AutoCat/Models/Vehicle.swift +++ b/AutoCat/Models/Vehicle.swift @@ -111,6 +111,7 @@ class Vehicle: Object, Decodable, Identifiable, Differentiable { let photos = List() let ownershipPeriods = List() let events = List() + let osagoContracts = List() var identifier: String = "" var id: String {