From 30fd465f06e35fd1de6ef0276a512b5ba254ab20 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sat, 12 Sep 2020 11:38:07 +0300 Subject: [PATCH] Fix for outdated plate numbers --- AutoCat.xcodeproj/project.pbxproj | 4 ++-- AutoCat/AppDelegate.swift | 2 +- AutoCat/Cells/VehicleCell.swift | 6 +++++- AutoCat/Controllers/ReportController.swift | 6 +++++- AutoCat/Models/Vehicle.swift | 11 +++++++++++ AutoCat/Utils/Constants.swift | 4 ++-- AutoCat/Views/PlateView.swift | 4 ++-- 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 12fd9c0..3d42460 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -743,7 +743,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -765,7 +765,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index e3a5230..32cb538 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -23,7 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let config = Realm.Configuration( - schemaVersion: 16, + schemaVersion: 17, migrationBlock: { migration, oldSchemaVersion in if oldSchemaVersion <= 3 { var numbers: [String] = [] diff --git a/AutoCat/Cells/VehicleCell.swift b/AutoCat/Cells/VehicleCell.swift index 025827d..05a06f1 100644 --- a/AutoCat/Cells/VehicleCell.swift +++ b/AutoCat/Cells/VehicleCell.swift @@ -18,7 +18,11 @@ class VehicleCell: UITableViewCell { func configure(with vehicle: Vehicle) { self.name.text = vehicle.brand?.name?.original ?? "" self.plate.number = PlateNumber(vehicle.number) - self.plate.unrecognized = vehicle.unrecognized + if vehicle.unrecognized { + self.plate.foreground = .systemRed + } else if vehicle.outdated { + self.plate.foreground = .systemGray2 + } self.date.text = formatter.string(from: Date(timeIntervalSince1970: vehicle.addedDate/1000)) } diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 952e3eb..7dfa227 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -202,7 +202,11 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti if let idSection = ReportIdSection(rawValue: indexPath.item) { switch idSection { case .number: - cell?.configure(param: idSection.description, value: vehicle.number) + var num = vehicle.number + if vehicle.outdated, let current = vehicle.currentNumber { + num = "\(vehicle.number) (\(current))" + } + cell?.configure(param: idSection.description, value: num) break case .vin: cell?.configure(param: idSection.description, value: vehicle.vin1 ?? "") diff --git a/AutoCat/Models/Vehicle.swift b/AutoCat/Models/Vehicle.swift index 3113b9e..acffe89 100644 --- a/AutoCat/Models/Vehicle.swift +++ b/AutoCat/Models/Vehicle.swift @@ -74,6 +74,7 @@ class Vehicle: Object, Decodable, IdentifiableType { @objc dynamic var category: String? @objc dynamic var engine: VehicleEngine? @objc dynamic var number: String = "" + @objc dynamic var currentNumber: String? @objc dynamic var vin1: String? @objc dynamic var vin2: String? @objc dynamic var sts: String? @@ -96,6 +97,7 @@ class Vehicle: Object, Decodable, IdentifiableType { case category case engine case number + case currentNumber case vin1 case vin2 case sts @@ -118,6 +120,7 @@ class Vehicle: Object, Decodable, IdentifiableType { self.category = try container.decodeIfPresent(String.self, forKey: .category) self.engine = try container.decodeIfPresent(VehicleEngine.self, forKey: .engine) self.number = try container.decode(String.self, forKey: .number) + self.currentNumber = try container.decodeIfPresent(String.self, forKey: .currentNumber) self.vin1 = try container.decodeIfPresent(String.self, forKey: .vin1) self.vin2 = try container.decodeIfPresent(String.self, forKey: .vin2) self.sts = try container.decodeIfPresent(String.self, forKey: .sts) @@ -156,4 +159,12 @@ class Vehicle: Object, Decodable, IdentifiableType { var unrecognized: Bool { return self.brand == nil } + + var outdated: Bool { + if let current = self.currentNumber { + return current != self.number + } else { + return false + } + } } diff --git a/AutoCat/Utils/Constants.swift b/AutoCat/Utils/Constants.swift index 0ce0772..5afbb1c 100644 --- a/AutoCat/Utils/Constants.swift +++ b/AutoCat/Utils/Constants.swift @@ -3,9 +3,9 @@ import Foundation enum Constants { static var baseUrl: String { #if DEBUG - //return "http://127.0.0.1:3000/" + return "http://127.0.0.1:3000/" //return "http://192.168.1.67:3000/" - return "https://vps.aliencat.pro:8443/" + //return "https://vps.aliencat.pro:8443/" #else return "https://vps.aliencat.pro:8443/" #endif diff --git a/AutoCat/Views/PlateView.swift b/AutoCat/Views/PlateView.swift index 94506ae..1a4c8e4 100644 --- a/AutoCat/Views/PlateView.swift +++ b/AutoCat/Views/PlateView.swift @@ -20,7 +20,7 @@ class PlateView: UIView { } } - var unrecognized: Bool = false { + var foreground: UIColor? { didSet { self.layoutSubviews() } @@ -70,7 +70,7 @@ class PlateView: UIView { guard let fgColorMain = UIColor(named: "PlateForeground")?.cgColor else { return } guard let bgColor = UIColor(named: "PlateBackground")?.cgColor else { return } - let fgColor = self.unrecognized ? /*fgColorErr*/UIColor.systemRed.cgColor : fgColorMain + let fgColor = self.foreground?.cgColor ?? fgColorMain self.bgLayer.backgroundColor = fgColor self.bgLayer.frame = self.bounds