extension WMFFeedDisplayType { public func imageWidthCompatibleWithTraitCollection(_ traitCollection: UITraitCollection) -> Int { switch self { case .pageWithPreview, .relatedPagesSourceArticle, .random, .continueReading: return traitCollection.wmf_leadImageWidth default: return traitCollection.wmf_nearbyThumbnailWidth } } } extension WMFContentGroup { public func imageURLsCompatibleWithTraitCollection(_ traitCollection: UITraitCollection, dataStore: MWKDataStore, viewSize: CGSize? = nil) -> Set? { switch contentGroupKind { case .pictureOfTheDay: guard let imageInfo = contentPreview as? WMFFeedImage else { return nil } let fallback: (WMFFeedImage, UITraitCollection) -> URL = { imageInfo, traitCollection in let imageURL = URL(string: WMFChangeImageSourceURLSizePrefix(imageInfo.imageThumbURL.absoluteString, traitCollection.wmf_leadImageWidth)) ?? imageInfo.imageThumbURL return imageURL } guard let viewSize = viewSize else { return [fallback(imageInfo, traitCollection)] } let scaledViewSize = CGSize(width: UIScreen.main.scale * viewSize.width, height: UIScreen.main.scale * viewSize.height) let imageURL = imageInfo.getImageURL(forWidth: Double(scaledViewSize.width), height: Double(scaledViewSize.height)) ?? fallback(imageInfo, traitCollection) return [imageURL] case .announcement: guard let announcement = contentPreview as? WMFAnnouncement else { return nil } guard let imageURL = announcement.imageURL else { return nil } return [imageURL] default: let count = countOfPreviewItems guard count > 0 else { return nil } var imageURLs: Set = [] imageURLs.reserveCapacity(count) for index in 0.. URL? { let displayType = displayTypeForItem(at: index) var index = index switch displayType { case .relatedPagesSourceArticle: return articleURL case .relatedPages: index -= 1 case .ranked: guard let content = contentPreview as? [WMFFeedTopReadArticlePreview], content.count > index else { return nil } return content[index].articleURL default: break } if let contentURL = contentPreview as? URL { return contentURL } guard let content = contentPreview as? [URL], content.count > index else { return nil } return content[index] } public var isSelectable: Bool { guard undoType == .none else { return false } switch contentGroupKind { case .announcement, .notification, .theme, .readingList: return false default: return true } } public var previewArticleKeys: Set { guard countOfPreviewItems > 0 else { return [] } var articleKeys: Set = [] articleKeys.reserveCapacity(countOfPreviewItems) for i in 0...countOfPreviewItems { guard let key = previewArticleURLForItemAtIndex(i)?.wmf_inMemoryKey else { continue } articleKeys.insert(key) } return articleKeys } }