From 0f069d7cbc4f90cd147a81fbc0f1fb92bfbbaebe Mon Sep 17 00:00:00 2001 From: Alexander Karpov Date: Sun, 2 Sep 2018 19:09:07 +0300 Subject: [PATCH 1/3] Added position & something about versions for stories after backend update --- Stepic/StoriesPresenter.swift | 2 ++ Stepic/Story.swift | 3 +++ Stepic/StoryTemplatesAPI.swift | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Stepic/StoriesPresenter.swift b/Stepic/StoriesPresenter.swift index 547e9b72bc..c131e4e850 100644 --- a/Stepic/StoriesPresenter.swift +++ b/Stepic/StoriesPresenter.swift @@ -72,6 +72,8 @@ class StoriesPresenter: StoriesPresenterProtocol { strongSelf.stories = stories.filter { strongSelf.isSupported(story: $0) }.sorted(by: { + $0.position >= $1.position + }).sorted(by: { !($0.isViewed.value) || ($1.isViewed.value) }) strongSelf.view?.set(state: strongSelf.stories.isEmpty ? .empty : .normal) diff --git a/Stepic/Story.swift b/Stepic/Story.swift index f633127734..d0df87784c 100644 --- a/Stepic/Story.swift +++ b/Stepic/Story.swift @@ -16,6 +16,7 @@ class Story: JSONSerializable { self.title = json["title"].stringValue self.parts = json["parts"].arrayValue.map { StoryPart(json: $0) } self.isViewed = CachedValue(key: "isViewed_id\(id)", defaultValue: false) + self.position = json["position"].intValue } var id: Int @@ -23,6 +24,7 @@ class Story: JSONSerializable { var title: String var isViewed: CachedValue var parts: [StoryPart] + var position: Int required init(json: JSON) { self.id = json["id"].intValue @@ -32,6 +34,7 @@ class Story: JSONSerializable { self.parts = json["parts"].arrayValue.compactMap { Story.buildStoryPart(json: $0) } + self.position = json["position"].intValue } private static func buildStoryPart(json: JSON) -> StoryPart? { diff --git a/Stepic/StoryTemplatesAPI.swift b/Stepic/StoryTemplatesAPI.swift index 43a49469f0..7139f21e2f 100644 --- a/Stepic/StoryTemplatesAPI.swift +++ b/Stepic/StoryTemplatesAPI.swift @@ -16,9 +16,10 @@ class StoryTemplatesAPI: APIEndpoint { func retrieve(isPublished: Bool, language: ContentLanguage, page: Int = 1) -> Promise<([Story], Meta)> { return Promise { seal in let params: Parameters = [ - "is_published": isPublished ? "true" : "false", + "is_published": /*isPublished ? "true" : */ "false", "page": page, - "language": language.languageString + "language": language.languageString, + "max_version": 1 ] retrieve.request( From 070e68153617318cbb8701b268292fcd9b70ba92 Mon Sep 17 00:00:00 2001 From: Alexander Karpov Date: Mon, 3 Sep 2018 17:43:27 +0300 Subject: [PATCH 2/3] added version --- Stepic/ApplicationInfo.swift | 3 +++ Stepic/Config.plist | 5 +++++ Stepic/StepicApplicationsInfo.swift | 5 +++++ Stepic/StoriesPresenter.swift | 2 +- Stepic/StoryTemplatesAPI.swift | 4 ++-- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Stepic/ApplicationInfo.swift b/Stepic/ApplicationInfo.swift index f34c48db1b..43e8501e7e 100644 --- a/Stepic/ApplicationInfo.swift +++ b/Stepic/ApplicationInfo.swift @@ -65,6 +65,9 @@ class ApplicationInfo { struct Modules { static let tabs = "modules.tabs" } + struct Versions { + static let stories = "versions.stories" + } } private var settings: NSDictionary? diff --git a/Stepic/Config.plist b/Stepic/Config.plist index 0eac12365d..264bb1e6db 100644 --- a/Stepic/Config.plist +++ b/Stepic/Config.plist @@ -2,6 +2,11 @@ + versions + + stories + 1 + modules tabs diff --git a/Stepic/StepicApplicationsInfo.swift b/Stepic/StepicApplicationsInfo.swift index b1f9afbe62..954731b988 100644 --- a/Stepic/StepicApplicationsInfo.swift +++ b/Stepic/StepicApplicationsInfo.swift @@ -87,4 +87,9 @@ struct StepicApplicationsInfo { struct Modules { static let tabs = StepicApplicationsInfo.stepikConfigDic?.get(for: Root.Modules.tabs) as? [String] } + + // Section: Versions + struct Versions { + static let stories = StepicApplicationsInfo.stepikConfigDic?.get(for: Root.Versions.stories) as? Int + } } diff --git a/Stepic/StoriesPresenter.swift b/Stepic/StoriesPresenter.swift index c131e4e850..fba7442d62 100644 --- a/Stepic/StoriesPresenter.swift +++ b/Stepic/StoriesPresenter.swift @@ -65,7 +65,7 @@ class StoriesPresenter: StoriesPresenterProtocol { func refresh() { view?.set(state: .loading) - storyTemplatesAPI.retrieve(isPublished: true, language: ContentLanguage.sharedContentLanguage).done { [weak self] stories, _ in + storyTemplatesAPI.retrieve(isPublished: true, language: ContentLanguage.sharedContentLanguage, maxVersion: StepicApplicationsInfo.Versions.stories ?? 0).done { [weak self] stories, _ in guard let strongSelf = self else { return } diff --git a/Stepic/StoryTemplatesAPI.swift b/Stepic/StoryTemplatesAPI.swift index 7139f21e2f..ec88416aaa 100644 --- a/Stepic/StoryTemplatesAPI.swift +++ b/Stepic/StoryTemplatesAPI.swift @@ -13,13 +13,13 @@ import Alamofire class StoryTemplatesAPI: APIEndpoint { override var name: String { return "story-templates" } - func retrieve(isPublished: Bool, language: ContentLanguage, page: Int = 1) -> Promise<([Story], Meta)> { + func retrieve(isPublished: Bool, language: ContentLanguage, maxVersion: Int, page: Int = 1) -> Promise<([Story], Meta)> { return Promise { seal in let params: Parameters = [ "is_published": /*isPublished ? "true" : */ "false", "page": page, "language": language.languageString, - "max_version": 1 + "max_version": maxVersion ] retrieve.request( From d69a73a23a16a265c53f7afb4af583e1ed035b95 Mon Sep 17 00:00:00 2001 From: Alexander Karpov Date: Wed, 5 Sep 2018 01:46:48 +0300 Subject: [PATCH 3/3] Removed debug hardcode --- Stepic/StoryTemplatesAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stepic/StoryTemplatesAPI.swift b/Stepic/StoryTemplatesAPI.swift index ec88416aaa..49773e9af6 100644 --- a/Stepic/StoryTemplatesAPI.swift +++ b/Stepic/StoryTemplatesAPI.swift @@ -16,7 +16,7 @@ class StoryTemplatesAPI: APIEndpoint { func retrieve(isPublished: Bool, language: ContentLanguage, maxVersion: Int, page: Int = 1) -> Promise<([Story], Meta)> { return Promise { seal in let params: Parameters = [ - "is_published": /*isPublished ? "true" : */ "false", + "is_published": isPublished ? "true" : "false", "page": page, "language": language.languageString, "max_version": maxVersion