diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 618c809..1966bb6 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -63,5 +63,26 @@ landmarkType = "7"> + + + + + + + + diff --git a/AutoCat/Controllers/Location/EventsController.swift b/AutoCat/Controllers/Location/EventsController.swift index f2789d5..250e1c9 100644 --- a/AutoCat/Controllers/Location/EventsController.swift +++ b/AutoCat/Controllers/Location/EventsController.swift @@ -344,7 +344,7 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele @discardableResult func update(vehicle: Vehicle) -> Bool { do { - if let realm = self.vehicle?.realm { + if let v = self.vehicle, let realm = v.realm, !v.isFrozen { try ExceptionCatcher.catch { try realm.write { realm.add(vehicle, update: .all) diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 4e116a4..dbd1741 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -136,48 +136,54 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource } } - func row(_ tag: String) -> LabelRow? { - self.form.rowBy(tag: tag) as? LabelRow + func update(row tag: String, with value: String) { + if let row = self.form.rowBy(tag: tag) as? LabelRow { + row.value = value + row.reload() + } } - func sourceStatusRow(_ tag: String) -> SourceStatusRow? { - self.form.rowBy(tag: tag) as? SourceStatusRow + func update(sourceStatusRow tag: String, with value: DebugInfoEntry) { + if let row = self.form.rowBy(tag: tag) as? SourceStatusRow { + row.value = value + row.reload() + } } 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: NSLocalizedString("Right", comment: ""), no: NSLocalizedString("Left", comment: "")) - self.row("Japanese")?.value = self.stringFromBool(self.vehicle?.isJapanese.value, yes: NSLocalizedString("Yes", comment: ""), no: NSLocalizedString("No", comment: "")) + self.update(row: "Model", with: self.vehicle?.brand?.name?.original ?? "") + self.update(row: "Year", with: String(self.vehicle?.year ?? 0)) + self.update(row: "Color", with: self.vehicle?.color ?? "") + self.update(row: "Category", with: self.vehicle?.category ?? "") + self.update(row: "STP", with: self.stringFromBool(self.vehicle?.isRightWheel.value, yes: NSLocalizedString("Right", comment: ""), no: NSLocalizedString("Left", comment: ""))) + self.update(row: "Japanese", with: self.stringFromBool(self.vehicle?.isJapanese.value, yes: NSLocalizedString("Yes", comment: ""), no: NSLocalizedString("No", comment: ""))) 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 + self.update(row: "PlateNumber", with: num) - 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) - self.row("Ads")?.value = String(self.vehicle?.ads.count ?? 0) + self.update(row: "VIN", with: self.vehicle?.vin1 ?? "") + self.update(row: "STS", with: self.vehicle?.sts ?? "") + self.update(row: "PTS", with: self.vehicle?.pts ?? "") + self.update(row: "EngineNumber", with: self.vehicle?.engine?.number ?? "") + self.update(row: "FuelType", with: self.vehicle?.engine?.fuelType ?? "") + self.update(row: "Volume", with: String(self.vehicle?.engine?.volume.value ?? 0)) + self.update(row: "PowerHP", with: String(self.vehicle?.engine?.powerHp ?? 0)) + self.update(row: "PowerKw", with: String(self.vehicle?.engine?.powerKw.value ?? 0)) + self.update(row: "Events", with: String(self.vehicle?.events.count ?? 0)) + self.update(row: "OSAGO", with: String(self.vehicle?.osagoContracts.count ?? 0)) + self.update(row: "Owners", with: String(self.vehicle?.ownershipPeriods.count ?? 0)) + self.update(row: "Photos", with: String(self.vehicle?.photos.count ?? 0)) + self.update(row: "Ads", with: String(self.vehicle?.ads.count ?? 0)) if let dInfo = self.vehicle?.debugInfo { - self.sourceStatusRow("DebugAutocod")?.value = dInfo.autocod - self.sourceStatusRow("DebugVin01Vin")?.value = dInfo.vin01vin - self.sourceStatusRow("DebugVin01Base")?.value = dInfo.vin01base - self.sourceStatusRow("DebugVin01History")?.value = dInfo.vin01history - self.sourceStatusRow("DebugNomerogram")?.value = dInfo.nomerogram + self.update(sourceStatusRow: "DebugAutocod", with: dInfo.autocod) + self.update(sourceStatusRow: "DebugVin01Vin", with: dInfo.vin01vin) + self.update(sourceStatusRow: "DebugVin01Base", with: dInfo.vin01base) + self.update(sourceStatusRow: "DebugVin01History", with: dInfo.vin01history) + self.update(sourceStatusRow: "DebugNomerogram", with: dInfo.nomerogram) } } @@ -199,7 +205,7 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource break } - self.form.allSections.forEach { $0.reload() } + self.updateReport() } // MARK: - MediaBrowserViewControllerDataSource & MediaBrowserViewControllerDelegate diff --git a/AutoCat/Controllers/SearchController.swift b/AutoCat/Controllers/SearchController.swift index ea0e72d..a32c53d 100644 --- a/AutoCat/Controllers/SearchController.swift +++ b/AutoCat/Controllers/SearchController.swift @@ -171,7 +171,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe self.show(error: error) } - let frozenVehicle = newVehicle.realm != nil ? newVehicle.freeze() : newVehicle + let frozenVehicle = newVehicle.realm != nil ? newVehicle.clone() : newVehicle self.datasource.set(item: frozenVehicle, at: indexPath) self.updateDetailController(with: frozenVehicle) } onError: { err in