From cbb1f30d3152d2611d11b80bc484b54ef8cdfee5 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Wed, 4 Dec 2024 21:50:44 +0300 Subject: [PATCH] Adding new "not updated" filter to history list --- AutoCat/Controllers/CheckController.swift | 43 +++++++++++++---------- AutoCat/ru.lproj/Localizable.strings | 2 ++ AutoCatCore/Models/DTO/VehicleDto.swift | 4 +++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/AutoCat/Controllers/CheckController.swift b/AutoCat/Controllers/CheckController.swift index a01c545..4d51255 100644 --- a/AutoCat/Controllers/CheckController.swift +++ b/AutoCat/Controllers/CheckController.swift @@ -15,6 +15,7 @@ enum HistoryFilter { case all case unrecognized case outdated + case notSynced } extension String.StringInterpolation { @@ -185,16 +186,22 @@ class CheckController: UIViewController, UITableViewDelegate, UISearchResultsUpd self.historyDataSource.setFilterPredicate { $0.outdated } self.historyFilter = .outdated } + let notUpdated = UIAlertAction(title: NSLocalizedString("Not updated", comment: ""), style: .default) { _ in + self.historyDataSource.setFilterPredicate { $0.needSync } + self.historyFilter = .notSynced + } switch self.historyFilter { case .all: all.setValue(true, forKey: "checked") case .unrecognized: unrecognized.setValue(true, forKey: "checked") case .outdated: outdated.setValue(true, forKey: "checked") + case .notSynced: notUpdated.setValue(true, forKey: "checked") } sheet.addAction(all) sheet.addAction(unrecognized) sheet.addAction(outdated) + sheet.addAction(notUpdated) sheet.addAction(cancel) sheet.popoverPresentationController?.barButtonItem = sender self.present(sheet, animated: true) @@ -252,25 +259,25 @@ class CheckController: UIViewController, UITableViewDelegate, UISearchResultsUpd func updateDetailController(with vehicle: VehicleDto) { if let splitViewController = self.view.window?.rootViewController as? UISplitViewController { -// var detail: UINavigationController? -// if splitViewController.viewControllers.count == 2 { -// detail = splitViewController.viewControllers.last as? UINavigationController -// } else { -// let storyboard = UIStoryboard(name: "Main", bundle: nil) -// detail = storyboard.instantiateViewController(identifier: "ReportNavController") -// } -// -// if let detail = detail { -// detail.popToRootViewController(animated: true) -// let report = detail.viewControllers.first as? ReportController -// report?.number = vehicle.getNumber() -// splitViewController.showDetailViewController(detail, sender: self) -// } - - Task { - let coordinator = ReportCoordinator(splitController: splitViewController, vehicle: vehicle, isPersistent: true) - try? await coordinator.start() + var detail: UINavigationController? + if splitViewController.viewControllers.count == 2 { + detail = splitViewController.viewControllers.last as? UINavigationController + } else { + let storyboard = UIStoryboard(name: "Main", bundle: nil) + detail = storyboard.instantiateViewController(identifier: "ReportNavController") } + + if let detail = detail { + detail.popToRootViewController(animated: true) + let report = detail.viewControllers.first as? ReportController + report?.number = vehicle.getNumber() + splitViewController.showDetailViewController(detail, sender: self) + } + +// Task { +// let coordinator = ReportCoordinator(splitController: splitViewController, vehicle: vehicle, isPersistent: true) +// try? await coordinator.start() +// } } } diff --git a/AutoCat/ru.lproj/Localizable.strings b/AutoCat/ru.lproj/Localizable.strings index e45d450..cf1a784 100644 --- a/AutoCat/ru.lproj/Localizable.strings +++ b/AutoCat/ru.lproj/Localizable.strings @@ -413,3 +413,5 @@ "ZIP (or OKTMO) code" = "Индекс (или ОКТМО)"; "Server" = "Сервер"; + +"Not updated" = "Не обновленные"; diff --git a/AutoCatCore/Models/DTO/VehicleDto.swift b/AutoCatCore/Models/DTO/VehicleDto.swift index 055b3d0..7fcc7ab 100644 --- a/AutoCatCore/Models/DTO/VehicleDto.swift +++ b/AutoCatCore/Models/DTO/VehicleDto.swift @@ -176,4 +176,8 @@ extension VehicleDto { return false } } + + public var needSync: Bool { + !synchronized && !unrecognized + } }