1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-12 08:36:02 +01:00
mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonUI/View/Content/NewsView+Configuration.swift

44 lines
1.3 KiB
Swift
Raw Normal View History

//
// NewsView+Configuration.swift
//
//
// Created by MainasuK on 2022-4-13.
//
import UIKit
import MastodonSDK
import MastodonLocalization
import AlamofireImage
extension NewsView {
public func configure(link: Mastodon.Entity.Link) {
providerNameLabel.text = link.providerName
headlineLabel.text = link.title
2022-04-15 11:22:30 +02:00
footnoteLabel.text = L10n.Plural.peopleTalking(link.talkingPeopleCount ?? 0)
let configuration = MediaView.Configuration(
info: .image(info: .init(
aspectRadio: CGSize(width: link.width, height: link.height),
assetURL: link.image
)),
blurhash: link.blurhash
)
imageView.setup(configuration: configuration)
if let previewURL = configuration.previewURL,
let url = URL(string: previewURL)
{
let placeholder = UIImage.placeholder(color: .systemGray6)
let request = URLRequest(url: url)
ImageDownloader.default.download(request, completion: { response in
switch response.result {
case .success(let image):
configuration.previewImage = image
case .failure:
configuration.previewImage = placeholder
}
})
}
} // end func
}