Fix problem with electric vehicles (engine volume is 0)

This commit is contained in:
Selim Mustafaev 2020-10-23 23:17:04 +03:00
parent 8fc14fdfbe
commit a0bb646623
9 changed files with 36 additions and 22 deletions

View File

@ -728,7 +728,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 48;
CURRENT_PROJECT_VERSION = 49;
DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
@ -750,7 +750,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 48;
CURRENT_PROJECT_VERSION = 49;
DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;

View File

@ -14,35 +14,35 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>8</integer>
<integer>5</integer>
</dict>
<key>DifferenceKit (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>9</integer>
<integer>6</integer>
</dict>
<key>DifferenceKit (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>7</integer>
<integer>4</integer>
</dict>
<key>Eureka (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
<integer>8</integer>
</dict>
<key>Eureka (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>4</integer>
<integer>9</integer>
</dict>
<key>Eureka (Playground) 3.xcscheme</key>
<dict>
@ -70,7 +70,7 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
<integer>7</integer>
</dict>
<key>GettingStarted (Playground) 1.xcscheme</key>
<dict>
@ -112,42 +112,42 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>13</integer>
<integer>12</integer>
</dict>
<key>Rx (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>6</integer>
<integer>1</integer>
</dict>
<key>Rx (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>5</integer>
<integer>3</integer>
</dict>
<key>Rx (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>1</integer>
<integer>2</integer>
</dict>
<key>SwiftDate (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>10</integer>
<integer>11</integer>
</dict>
<key>SwiftDate (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>12</integer>
<integer>13</integer>
</dict>
<key>SwiftDate (Playground) 3.xcscheme</key>
<dict>
@ -175,7 +175,7 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>11</integer>
<integer>10</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>

View File

@ -25,7 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let config = Realm.Configuration(
schemaVersion: 21,
schemaVersion: 22,
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion <= 3 {
var numbers: [String] = []
@ -80,6 +80,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}
if oldSchemaVersion <= 21 {
migration.enumerateObjects(ofType: "Vehicle") { old, new in
if let oldEngineVolume = (old?["engine"] as? MigrationObject)?["volume"] as? Int {
(new?["engine"] as? MigrationObject)?["volume"] = RealmOptional(oldEngineVolume)
} else {
(new?["engine"] as? MigrationObject)?["volume"] = RealmOptional(0)
}
}
}
})
Realm.Configuration.defaultConfiguration = config

View File

@ -241,7 +241,7 @@ class CheckController: UIViewController, UITableViewDelegate, UITextFieldDelegat
return Single.just(event)
}
if let event = LocationManager.lastEvent, (Date().timeIntervalSince1970 - event.date) < 30 {
if let event = LocationManager.lastEvent, (Date().timeIntervalSince1970 - event.date) < 10 {
return Single<VehicleEvent>.just(event)
} else {
return LocationManager.requestCurrentLocation()

View File

@ -233,7 +233,7 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti
cell?.configure(param: engineSection.description, value: engine.fuelType ?? "<unknown>")
break
case .volume:
cell?.configure(param: engineSection.description, value: String(engine.volume))
cell?.configure(param: engineSection.description, value: String(engine.volume.value ?? 0))
break
case .powerHp:
cell?.configure(param: engineSection.description, value: String(engine.powerHp))

View File

@ -110,7 +110,7 @@ extension Vehicle {
y += cellHeight
self.drawCell(y: y, width: w, height: cellHeight, title: "Fuel type", value: self.engine?.fuelType ?? "<unknown>", context: ctx)
y += cellHeight
self.drawCell(y: y, width: w, height: cellHeight, title: "Volume (cm³)", value: String(self.engine?.volume ?? 0), context: ctx)
self.drawCell(y: y, width: w, height: cellHeight, title: "Volume (cm³)", value: String(self.engine?.volume.value ?? 0), context: ctx)
y += cellHeight
self.drawCell(y: y, width: w, height: cellHeight, title: "Power (HP)", value: String(self.engine?.powerHp ?? 0), context: ctx)
y += cellHeight

View File

@ -18,7 +18,7 @@ class VehicleModel: Object, Decodable {
class VehicleEngine: Object, Decodable {
@objc dynamic var number: String?
@objc dynamic var volume: Int = 0
var volume: RealmOptional<Int> = RealmOptional(0)
@objc dynamic var powerHp: Float = 0
@objc dynamic var powerKw: Float = 0
@objc dynamic var fuelType: String?

View File

@ -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

View File

@ -23,6 +23,7 @@ class RealmSectionedDataSource<Item,Cell>: NSObject, UITableViewDataSource where
self.sections = self.data.groupedByDate()
self.tv.reloadData()
case .update(_, let deletions, let insertions, let modifications):
print("Deletions: \(deletions.count), Insertions: \(insertions.count), Modifications: \(modifications.count)")
let newSections = self.data.groupedByDate()
let changeset = StagedChangeset(source: self.sections, target: newSections, section: 0)
@ -32,7 +33,10 @@ class RealmSectionedDataSource<Item,Cell>: NSObject, UITableViewDataSource where
self.tv.insertRows(at: insertions.map(self.indexPath), with: .automatic)
self.tv.reloadRows(at: modifications.map(self.indexPath), with: .automatic)
print("Changesets count: \(changeset.count)")
if let firstChangeset = changeset.first {
print("Deletions: \(firstChangeset.elementDeleted.map { $0.element })")
print("Insertions: \(firstChangeset.elementInserted.map { $0.element })")
self.tv.deleteSections(IndexSet(firstChangeset.elementDeleted.map { $0.element }), with: .automatic)
self.tv.insertSections(IndexSet(firstChangeset.elementInserted.map { $0.element }), with: .automatic)
}