Skip to content

Commit

Permalink
Add leadImage property to MediaListItem.
Browse files Browse the repository at this point in the history
  • Loading branch information
staykids committed Jul 1, 2021
1 parent 5b6235d commit 83d154d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Wikipedia/Code/ArticleViewController+Media.swift
Expand Up @@ -46,7 +46,7 @@ extension ArticleViewController {
case .failure(let error):
self.showError(error)
case .success(let mediaList):
self.showImage(in: mediaList, item: nil)
self.showImage(in: mediaList, item: mediaList.items.first(where: { $0.isLeadImage }))
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions Wikipedia/Code/MediaList.swift
Expand Up @@ -24,22 +24,25 @@ public struct MediaListItem: Codable {
public let sectionID: Int
public let type: String
public let showInGallery: Bool
public let isLeadImage: Bool
public let sources: [MediaListItemSource]?
public let audioType: String?
enum CodingKeys: String, CodingKey {
case title
case sectionID = "section_id"
case showInGallery
case isLeadImage = "leadImage"
case sources = "srcset"
case type
case audioType
}

public init(title: String?, sectionID: Int, type: String, showInGallery: Bool, sources: [MediaListItemSource]?, audioType: String? = nil) {
public init(title: String?, sectionID: Int, type: String, showInGallery: Bool, isLeadImage: Bool, sources: [MediaListItemSource]?, audioType: String? = nil) {
self.title = title
self.sectionID = sectionID
self.type = type
self.showInGallery = showInGallery
self.isLeadImage = isLeadImage
self.sources = sources
self.audioType = audioType
}
Expand Down Expand Up @@ -72,7 +75,7 @@ public struct MediaList: Codable {
MediaListItemSource(urlString: urlString, scale: "1.5x")
]

let mediaListItem = MediaListItem(title: filename, sectionID: 0, type: "image", showInGallery: true, sources: sources, audioType: nil)
let mediaListItem = MediaListItem(title: filename, sectionID: 0, type: "image", showInGallery: true, isLeadImage: true, sources: sources, audioType: nil)
self = MediaList(items: [mediaListItem])
}
}

0 comments on commit 83d154d

Please sign in to comment.