From 41b871008728ae347a533d267897cda13b9c0f3b Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Sat, 2 Dec 2017 17:00:22 +0300 Subject: [PATCH] [xc8Ma3wD] Add priority field for event [xc8Ma3wD] Up realm version --- .../Resources/Storyboards/LaunchScreen.storyboard | 13 +++++++------ .../Helpers/TranslationEventPlainObject.swift | 1 + .../Sources/Model/Entities/EventEntity.swift | 1 + .../Sources/Model/Helpers/RealmController.swift | 2 +- .../Event/EventPlainObject+Requests.swift | 2 ++ .../Model/PlainObjects/Event/EventPlainObject.swift | 1 + .../Feed/Main/MainViewDisplayCollection.swift | 2 +- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHMeetupApp/Resources/Storyboards/LaunchScreen.storyboard b/CHMeetupApp/Resources/Storyboards/LaunchScreen.storyboard index eb25fcc4..49ccfa7c 100644 --- a/CHMeetupApp/Resources/Storyboards/LaunchScreen.storyboard +++ b/CHMeetupApp/Resources/Storyboards/LaunchScreen.storyboard @@ -1,11 +1,11 @@ - + - + @@ -27,14 +27,14 @@ - + - - + + + diff --git a/CHMeetupApp/Sources/Common/Helpers/TranslationEventPlainObject.swift b/CHMeetupApp/Sources/Common/Helpers/TranslationEventPlainObject.swift index 436fdc4f..1131dc96 100644 --- a/CHMeetupApp/Sources/Common/Helpers/TranslationEventPlainObject.swift +++ b/CHMeetupApp/Sources/Common/Helpers/TranslationEventPlainObject.swift @@ -13,6 +13,7 @@ struct EventPlainObjectTranslation: PlainObjectTranslation { static func addToRealm(plainObject: EventPlainObject, to parent: EventEntity? = nil) { let event = EventEntity() event.id = plainObject.id + event.priority = plainObject.priority event.title = plainObject.title event.startDate = plainObject.startDate event.endDate = plainObject.endDate diff --git a/CHMeetupApp/Sources/Model/Entities/EventEntity.swift b/CHMeetupApp/Sources/Model/Entities/EventEntity.swift index be7d9639..a08d9502 100644 --- a/CHMeetupApp/Sources/Model/Entities/EventEntity.swift +++ b/CHMeetupApp/Sources/Model/Entities/EventEntity.swift @@ -67,6 +67,7 @@ final class EventEntity: TemplatableObject, TemplateEntity { dynamic var endDate: Date = Date() dynamic var photoURL: String = "" + dynamic var priority: Int = 0 dynamic var statusValue: String = "unknown" var status: EventRegistrationStatus { diff --git a/CHMeetupApp/Sources/Model/Helpers/RealmController.swift b/CHMeetupApp/Sources/Model/Helpers/RealmController.swift index b0a5b8e8..30b821d5 100644 --- a/CHMeetupApp/Sources/Model/Helpers/RealmController.swift +++ b/CHMeetupApp/Sources/Model/Helpers/RealmController.swift @@ -14,7 +14,7 @@ class RealmController { static var shared: RealmController = RealmController() func setup() { - Realm.Configuration.defaultConfiguration = Realm.Configuration(schemaVersion: 23, migrationBlock: nil) + Realm.Configuration.defaultConfiguration = Realm.Configuration(schemaVersion: 24, migrationBlock: nil) do { mainRealm = try Realm() diff --git a/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject+Requests.swift b/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject+Requests.swift index 60449680..ac199929 100644 --- a/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject+Requests.swift +++ b/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject+Requests.swift @@ -39,6 +39,7 @@ extension EventPlainObject: PlainObjectType { let placeJson = json["place"] as? JSONDictionary, let speakersJson = json["speakers_photos"] as? [String], let registrationStatus = json["status"] as? String, + let priority = json["priority"] as? Int, let place = PlacePlainObject(json: placeJson) else { return nil } @@ -51,6 +52,7 @@ extension EventPlainObject: PlainObjectType { self.endDate = Date(timeIntervalSince1970: endDate) self.registrationStatus = registrationStatus + self.priority = priority var photos: [URL] = [] speakersJson.forEach { photoUrl in guard let url = URL(string: photoUrl) else { return } diff --git a/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject.swift b/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject.swift index fecf6f3c..6e5d8057 100644 --- a/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject.swift +++ b/CHMeetupApp/Sources/Model/PlainObjects/Event/EventPlainObject.swift @@ -18,4 +18,5 @@ struct EventPlainObject { let endDate: Date let speakersPhotos: [URL] let registrationStatus: String + let priority: Int } diff --git a/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewDisplayCollection.swift b/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewDisplayCollection.swift index ba6b6755..1f3f8590 100644 --- a/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewDisplayCollection.swift +++ b/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewDisplayCollection.swift @@ -34,7 +34,7 @@ class MainViewDisplayCollection: DisplayCollection, DisplayCollectionAction { var modelCollection: TemplateModelCollection = { let predicate = NSPredicate(format: "endDate > %@", NSDate()) var dataCollection = DataModelCollection(type: EventEntity.self).filtered(predicate) - dataCollection = dataCollection.sorted(byKeyPath: #keyPath(EventEntity.endDate), ascending: false) + dataCollection = dataCollection.sorted(byKeyPath: #keyPath(EventEntity.priority), ascending: false) return TemplateModelCollection(dataCollection: dataCollection) }()