Fixed bug when vehicle was not updated in case of error

This commit is contained in:
Selim Mustafaev 2022-03-12 23:56:55 +03:00
parent 3124e7251d
commit 130f029ff4
7 changed files with 75 additions and 41 deletions

View File

@ -1080,7 +1080,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 87;
CURRENT_PROJECT_VERSION = 88;
DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
@ -1105,7 +1105,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 87;
CURRENT_PROJECT_VERSION = 88;
DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;

View File

@ -26,7 +26,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let config = Realm.Configuration(
schemaVersion: 35,
schemaVersion: 37,
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion <= 3 {
var numbers: [String] = []
@ -148,6 +148,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
new?["id"] = newId
}
}
if oldSchemaVersion <= 36 {
migration.enumerateObjects(ofType: "Vehicle") { old, new in
new?["synchronized"] = true
}
}
})
Realm.Configuration.defaultConfiguration = config

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="pme-aR-UNJ">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="pme-aR-UNJ">
<device id="retina4_7" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@ -173,14 +173,14 @@
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="EventCell" id="QIb-Hv-tvk" customClass="EventCell" customModule="AutoCat" customModuleProvider="target">
<rect key="frame" x="0.0" y="44.5" width="375" height="132"/>
<rect key="frame" x="0.0" y="44.5" width="375" height="132.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="QIb-Hv-tvk" id="Ypt-ch-fGT">
<rect key="frame" x="0.0" y="0.0" width="375" height="132"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="132.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="HP8-oO-yhP">
<rect key="frame" x="8" y="8" width="359" height="116"/>
<rect key="frame" x="8" y="8" width="359" height="116.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xcQ-Wz-gJ0">
<rect key="frame" x="0.0" y="0.0" width="359" height="50"/>
@ -189,7 +189,7 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1tQ-zM-6T9">
<rect key="frame" x="0.0" y="58" width="359" height="58"/>
<rect key="frame" x="0.0" y="58" width="359" height="58.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
@ -269,33 +269,41 @@
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="VehicleCell" id="VEP-QD-i6y" customClass="VehicleCell" customModule="AutoCat" customModuleProvider="target">
<rect key="frame" x="0.0" y="44.5" width="375" height="82.5"/>
<rect key="frame" x="0.0" y="44.5" width="375" height="84.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="VEP-QD-i6y" id="8hH-8I-XLB">
<rect key="frame" x="0.0" y="0.0" width="375" height="82.5"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="84.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="E0H-HY-s2L">
<rect key="frame" x="8" y="8" width="359" height="66.5"/>
<rect key="frame" x="8" y="8" width="359" height="68.5"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="KFu-ew-wX3">
<rect key="frame" x="0.0" y="0.0" width="359" height="18"/>
<rect key="frame" x="0.0" y="0.0" width="359" height="20"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" horizontalCompressionResistancePriority="749" text="Kia Optima" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wCR-6h-HgF">
<rect key="frame" x="0.0" y="0.0" width="319" height="18"/>
<rect key="frame" x="0.0" y="0.0" width="293" height="20"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" image="text.bubble" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="k5v-Ic-Stn">
<rect key="frame" x="323" y="0.5" width="18" height="17.5"/>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="exclamationmark.arrow.triangle.2.circlepath" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="Qo7-51-ou9">
<rect key="frame" x="297" y="0.5" width="20" height="19"/>
<color key="tintColor" systemColor="systemOrangeColor"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="M1i-uQ-eYH"/>
<constraint firstAttribute="width" constant="18" id="wyl-SJ-L78"/>
<constraint firstAttribute="width" constant="20" id="Pct-H5-e3e"/>
<constraint firstAttribute="height" constant="20" id="UBl-5J-zAY"/>
</constraints>
</imageView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" image="text.bubble" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="k5v-Ic-Stn">
<rect key="frame" x="321" y="0.5" width="20" height="19.5"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="M1i-uQ-eYH"/>
<constraint firstAttribute="width" constant="20" id="wyl-SJ-L78"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="12" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QnE-Cx-aUe">
<rect key="frame" x="345" y="0.0" width="14" height="18"/>
<rect key="frame" x="345" y="0.0" width="14" height="20"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCallout"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
@ -303,7 +311,7 @@
</subviews>
</stackView>
<stackView opaque="NO" tag="8" contentMode="scaleToFill" alignment="bottom" translatesAutoresizingMaskIntoConstraints="NO" id="vMC-Bk-8rZ">
<rect key="frame" x="0.0" y="26" width="359" height="40.5"/>
<rect key="frame" x="0.0" y="28" width="359" height="40.5"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cvf-vM-QnT" customClass="PlateView" customModule="AutoCat" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.5" width="303" height="40"/>
@ -348,6 +356,7 @@
<outlet property="name" destination="wCR-6h-HgF" id="rXr-iq-H2Y"/>
<outlet property="notesCount" destination="QnE-Cx-aUe" id="KlD-As-G9y"/>
<outlet property="plate" destination="cvf-vM-QnT" id="8Bm-gA-bbm"/>
<outlet property="syncImage" destination="Qo7-51-ou9" id="4fV-fJ-Q4y"/>
<outlet property="updatedDate" destination="RPA-NR-0C6" id="c0e-Ew-Bc3"/>
</connections>
</tableViewCell>
@ -615,33 +624,41 @@
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="VehicleCell" id="3ON-lr-UlV" customClass="VehicleCell" customModule="AutoCat" customModuleProvider="target">
<rect key="frame" x="0.0" y="44.5" width="375" height="82.5"/>
<rect key="frame" x="0.0" y="44.5" width="375" height="84.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="3ON-lr-UlV" id="IGw-UK-ebp">
<rect key="frame" x="0.0" y="0.0" width="375" height="82.5"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="84.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="6IZ-gM-D28">
<rect key="frame" x="8" y="8" width="359" height="66.5"/>
<rect key="frame" x="8" y="8" width="359" height="68.5"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="Rz6-wH-O1q">
<rect key="frame" x="0.0" y="0.0" width="359" height="18"/>
<rect key="frame" x="0.0" y="0.0" width="359" height="20"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" horizontalCompressionResistancePriority="749" text="Kia Optima" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h3N-1o-J20">
<rect key="frame" x="0.0" y="0.0" width="319" height="18"/>
<rect key="frame" x="0.0" y="0.0" width="293" height="20"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" image="text.bubble" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="It0-Zx-REl">
<rect key="frame" x="323" y="0.5" width="18" height="17.5"/>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="exclamationmark.arrow.triangle.2.circlepath" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="pdg-uR-pUn">
<rect key="frame" x="297" y="0.5" width="20" height="19"/>
<color key="tintColor" systemColor="systemOrangeColor"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="2hp-7v-GVx"/>
<constraint firstAttribute="width" constant="18" id="sDL-E7-jY4"/>
<constraint firstAttribute="height" constant="20" id="9HI-9d-T5A"/>
<constraint firstAttribute="width" constant="20" id="YAB-Lz-sqG"/>
</constraints>
</imageView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" image="text.bubble" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="It0-Zx-REl">
<rect key="frame" x="321" y="0.5" width="20" height="19.5"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="2hp-7v-GVx"/>
<constraint firstAttribute="width" constant="20" id="sDL-E7-jY4"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="12" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XA5-vL-FV1">
<rect key="frame" x="345" y="0.0" width="14" height="18"/>
<rect key="frame" x="345" y="0.0" width="14" height="20"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCallout"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
@ -649,11 +666,12 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" alignment="bottom" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="nX1-KA-jqp">
<rect key="frame" x="0.0" y="26" width="359" height="40.5"/>
<rect key="frame" x="0.0" y="28" width="359" height="40.5"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VHX-o0-3BP" customClass="PlateView" customModule="AutoCat" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.5" width="295" height="40"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<color key="tintColor" systemColor="systemOrangeColor"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="vzo-oF-mWb"/>
</constraints>
@ -694,6 +712,7 @@
<outlet property="name" destination="h3N-1o-J20" id="jcM-B4-bEJ"/>
<outlet property="notesCount" destination="XA5-vL-FV1" id="UjX-bm-6uo"/>
<outlet property="plate" destination="VHX-o0-3BP" id="D8N-L7-O8b"/>
<outlet property="syncImage" destination="pdg-uR-pUn" id="DRx-XJ-WNa"/>
<outlet property="updatedDate" destination="rKr-3e-WYb" id="RpZ-NF-Bcg"/>
</connections>
</tableViewCell>
@ -1059,6 +1078,7 @@
<image name="check" width="25" height="25"/>
<image name="check-compact" width="18" height="18"/>
<image name="doc.on.doc" catalog="system" width="116" height="128"/>
<image name="exclamationmark.arrow.triangle.2.circlepath" catalog="system" width="128" height="101"/>
<image name="line.horizontal.3.decrease" catalog="system" width="128" height="73"/>
<image name="map" catalog="system" width="128" height="110"/>
<image name="play.fill" catalog="system" width="116" height="128"/>
@ -1079,6 +1099,9 @@
<systemColor name="systemBlueColor">
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemOrangeColor">
<color red="1" green="0.58431372549019611" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemTealColor">
<color red="0.18823529411764706" green="0.69019607843137254" blue="0.7803921568627451" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>

View File

@ -9,6 +9,7 @@ class VehicleCell: UITableViewCell, ConfigurableCell {
@IBOutlet weak var updatedDate: UILabel!
@IBOutlet weak var bubbleImage: UIImageView!
@IBOutlet weak var notesCount: UILabel!
@IBOutlet weak var syncImage: UIImageView!
let formatter = DateFormatter()
@ -39,6 +40,8 @@ class VehicleCell: UITableViewCell, ConfigurableCell {
self.updatedDate.text = formatter.string(from: Date(timeIntervalSince1970: vehicle.updatedDate))
}
self.syncImage.isHidden = vehicle.synchronized
self.bubbleImage.isHidden = vehicle.notes.isEmpty
self.notesCount.isHidden = vehicle.notes.isEmpty
if !vehicle.notes.isEmpty {

View File

@ -225,7 +225,7 @@ class CheckController: UIViewController, UITableViewDelegate, UITextFieldDelegat
HUD.show(.progress)
self.check(number: numberNormalized, action: .receiveAndSend, notes: [], events: events).subscribe { (vehicle, errors) in
if !vehicle.unrecognized {
if !vehicle.unrecognized && errors.isEmpty {
self.updateDetailController(with: vehicle)
}
HUD.hide()
@ -413,12 +413,13 @@ class CheckController: UIViewController, UITableViewDelegate, UITextFieldDelegat
RxLocationManager.resetLastEvent()
if vehicleResult.vehicle.unrecognized {
if vehicleResult.error != nil {
let realm = try Realm()
if let event = eventResult.event {
try realm.write {
vehicleResult.vehicle.events.append(event)
vehicleResult.vehicle.updatedDate = Date().timeIntervalSince1970
vehicleResult.vehicle.synchronized = false
}
}
return .just((vehicle: vehicleResult.vehicle, errors: errors))

View File

@ -185,6 +185,7 @@ public class Vehicle: Object, Decodable, Identifiable, Differentiable, Cloneable
public var ads = List<VehicleAd>()
public var notes = List<VehicleNote>()
@objc public dynamic var debugInfo: DebugInfo?
@objc public dynamic var synchronized: Bool = true
lazy var formatter: DateFormatter = {
let f = DateFormatter()
@ -272,6 +273,9 @@ public class Vehicle: Object, Decodable, Identifiable, Differentiable, Cloneable
if let notes = try container.decodeIfPresent([VehicleNote].self, forKey: .notes) {
self.notes.append(objectsIn: notes)
}
// All vehicles received from API are synchronized by definition
self.synchronized = true
}
required init() {
@ -282,6 +286,7 @@ public class Vehicle: Object, Decodable, Identifiable, Differentiable, Cloneable
self.number = number
self.addedDate = Date().timeIntervalSince1970
self.updatedDate = self.addedDate
self.synchronized = false
}
public func getNumber() -> String {
@ -352,6 +357,8 @@ public class Vehicle: Object, Decodable, Identifiable, Differentiable, Cloneable
let notes = List<VehicleNote>()
notes.append(objectsIn: copy.notes.map { $0.clone() })
self.notes = notes
self.synchronized = copy.synchronized
}
// MARK: - Exportable

View File

@ -225,10 +225,7 @@ public class Api {
body["events"] = AnyEncodable(events)
}
return self.makeBodyRequest(api: "vehicles/check", body: body).map { (vehicle: Vehicle) -> Vehicle in
vehicle.addedDate = Date().timeIntervalSince1970
return vehicle
}
return self.makeBodyRequest(api: "vehicles/check", body: body)
}
}
@ -258,10 +255,7 @@ public class Api {
public static func add(event: VehicleEvent, to number: String) -> Single<Vehicle> {
let body = ["number": AnyEncodable(number), "event": AnyEncodable(event)]
return self.makeBodyRequest(api: "events", body: body).map { (vehicle: Vehicle) -> Vehicle in
vehicle.addedDate = Date().timeIntervalSince1970
return vehicle
}
return self.makeBodyRequest(api: "events", body: body)
}
public static func remove(event id: String) -> Single<Vehicle> {