diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index a5e0457..31827b7 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -728,7 +728,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -751,7 +751,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 707459d..3d50db4 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -15,6 +15,7 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource var vehicle: Vehicle? { didSet { loadViewIfNeeded() + self.updateReport() self.form.allSections.forEach { $0.reload() } self.navigationController?.setNavigationBarHidden(self.vehicle == nil, animated: false) } @@ -45,91 +46,106 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource } form +++ Section() - <<< LabelRow().cellUpdate { cell, _ in - cell.detailTextLabel?.text = self.vehicle?.brand?.name?.original ?? "" - cell.imageView?.kf.setImage(with: URL(string: self.vehicle?.brand?.logo ?? ""), placeholder: self.logoPlaceholder) - } + <<< LabelRow("Model").cellUpdate { cell, _ in cell.imageView?.kf.setImage(with: URL(string: self.vehicle?.brand?.logo ?? ""), placeholder: self.logoPlaceholder) } - let generalSection = Section("General") - form +++ generalSection - <<< LabelRow() { $0.title = "Year" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = String(self.vehicle?.year ?? 0) } - <<< LabelRow() { $0.title = "Color" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.vehicle?.color ?? "" } - <<< 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") } + form +++ Section("General") + <<< LabelRow("Year") { $0.title = "Year" } + <<< LabelRow("Color") { $0.title = "Color" } + <<< LabelRow("Category") { $0.title = "Category" } + <<< LabelRow("STP") { $0.title = "Steering wheel position" } + <<< LabelRow("Japanese") { $0.title = "Japanese" } form +++ Section("Identifiers") - <<< LabelRow() { $0.title = "Number" }.cellUpdate { cell, _ in - guard let vehicle = self.vehicle else { - cell.detailTextLabel?.text = "" - return - } - - var num = vehicle.getNumber() - if vehicle.outdated, let current = vehicle.currentNumber { - num = "\(vehicle.getNumber()) (\(current))" - } - cell.detailTextLabel?.text = num - } - <<< LabelRow() { $0.title = "VIN" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.vehicle?.vin1 ?? "" } - <<< LabelRow() { $0.title = "STS" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.vehicle?.sts ?? "" } - <<< LabelRow() { $0.title = "PTS" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.vehicle?.pts ?? "" } + <<< LabelRow("PlateNumber") { $0.title = "Number" } + <<< LabelRow("VIN") { $0.title = "VIN" } + <<< LabelRow("STS") { $0.title = "STS" } + <<< LabelRow("PTS") { $0.title = "PTS" } form +++ Section("Engine") - <<< LabelRow() { $0.title = "Number" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.vehicle?.engine?.number ?? "" } - <<< LabelRow() { $0.title = "Fuel type" }.cellUpdate { cell, _ in cell.detailTextLabel?.text = self.vehicle?.engine?.fuelType ?? "" } - <<< 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) } + <<< LabelRow("EngineNumber") { $0.title = "Number" } + <<< LabelRow("FuelType") { $0.title = "Fuel type" } + <<< LabelRow("Volume") { $0.title = "Volume (cm³)" } + <<< LabelRow("PowerHP") { $0.title = "Power (HP)" } + <<< LabelRow("PowerKw") { $0.title = "Power (kw)" } - 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 - } + form +++ Section("History") + <<< LabelRow("Events") { $0.title = "Events" } + .cellUpdate { cell, _ in 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) - } + + <<< LabelRow("OSAGO") { $0.title = "OSAGO" } + .cellUpdate { cell, _ in cell.accessoryType = .disclosureIndicator } .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) } + + <<< LabelRow("Owners") { row in + row.title = "Owners" + row.disabled = "$Owners == '0'" + } + .cellUpdate { cell, _ in cell.accessoryType = .disclosureIndicator } + .onCellSelection { _, row in + if row.value != "0" { + 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) + } + } + + <<< LabelRow("Photos") { row in + row.title = "Photos" + row.disabled = "$Photos == '0'" + } + .cellUpdate { cell, _ in cell.accessoryType = .disclosureIndicator } + .onCellSelection { _, row in + if row.value != "0" { + 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 row(_ tag: String) -> LabelRow? { + self.form.rowBy(tag: tag) as? LabelRow + } + + func updateReport() { + self.row("Model")?.value = self.vehicle?.brand?.name?.original ?? "" + self.row("Year")?.value = String(self.vehicle?.year ?? 0) + self.row("Color")?.value = self.vehicle?.color ?? "" + self.row("Category")?.value = self.vehicle?.category ?? "" + self.row("STP")?.value = self.stringFromBool(self.vehicle?.isRightWheel.value, yes: "Right", no: "Left") + self.row("Japanese")?.value = self.stringFromBool(self.vehicle?.isJapanese.value, yes: "Yes", no: "No") - 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) - } + var num = self.vehicle?.getNumber() ?? "" + if self.vehicle?.outdated ?? false, let current = self.vehicle?.currentNumber { + num = "\(self.vehicle!.getNumber()) (\(current))" } + self.row("PlateNumber")?.value = num - 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) - } - } + self.row("VIN")?.value = self.vehicle?.vin1 ?? "" + self.row("STS")?.value = self.vehicle?.sts ?? "" + self.row("PTS")?.value = self.vehicle?.pts ?? "" + self.row("EngineNumber")?.value = self.vehicle?.engine?.number ?? "" + self.row("FuelType")?.value = self.vehicle?.engine?.fuelType ?? "" + self.row("Volume")?.value = String(self.vehicle?.engine?.volume.value ?? 0) + self.row("PowerHP")?.value = String(self.vehicle?.engine?.powerHp ?? 0) + self.row("PowerKw")?.value = String(self.vehicle?.engine?.powerKw.value ?? 0) + self.row("Events")?.value = String(self.vehicle?.events.count ?? 0) + self.row("OSAGO")?.value = String(self.vehicle?.osagoContracts.count ?? 0) + self.row("Owners")?.value = String(self.vehicle?.ownershipPeriods.count ?? 0) + self.row("Photos")?.value = String(self.vehicle?.photos.count ?? 0) } func stringFromBool(_ value: Bool?, yes: String, no: String) -> String {