Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story improvements #358

Merged
merged 3 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Stepic/ApplicationInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class ApplicationInfo {
struct Modules {
static let tabs = "modules.tabs"
}
struct Versions {
static let stories = "versions.stories"
}
}

private var settings: NSDictionary?
Expand Down
5 changes: 5 additions & 0 deletions Stepic/Config.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>versions</key>
<dict>
<key>stories</key>
<integer>1</integer>
</dict>
<key>modules</key>
<dict>
<key>tabs</key>
Expand Down
5 changes: 5 additions & 0 deletions Stepic/StepicApplicationsInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 3 additions & 1 deletion Stepic/StoriesPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ 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
}
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)
Expand Down
3 changes: 3 additions & 0 deletions Stepic/Story.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ class Story: JSONSerializable {
self.title = json["title"].stringValue
self.parts = json["parts"].arrayValue.map { StoryPart(json: $0) }
self.isViewed = CachedValue<Bool>(key: "isViewed_id\(id)", defaultValue: false)
self.position = json["position"].intValue
}

var id: Int
var coverPath: String
var title: String
var isViewed: CachedValue<Bool>
var parts: [StoryPart]
var position: Int

required init(json: JSON) {
self.id = json["id"].intValue
Expand All @@ -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? {
Expand Down
5 changes: 3 additions & 2 deletions Stepic/StoryTemplatesAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +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
"language": language.languageString,
"max_version": maxVersion
]

retrieve.request(
Expand Down