2019-09-15 19:01:35 +00:00
|
|
|
//
|
|
|
|
// InstanceTableViewCell.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/15/19.
|
|
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Pachyderm
|
|
|
|
|
|
|
|
class InstanceTableViewCell: UITableViewCell {
|
|
|
|
|
|
|
|
@IBOutlet weak var thumbnailImageView: UIImageView!
|
|
|
|
@IBOutlet weak var domainLabel: UILabel!
|
|
|
|
@IBOutlet weak var adultLabel: UILabel!
|
2020-01-18 21:00:38 +00:00
|
|
|
@IBOutlet weak var descriptionTextView: ContentTextView!
|
2019-09-15 19:01:35 +00:00
|
|
|
|
2023-12-04 22:55:03 +00:00
|
|
|
var instance: InstanceV1?
|
2019-09-15 19:01:35 +00:00
|
|
|
var selectorInstance: InstanceSelector.Instance?
|
|
|
|
|
|
|
|
var thumbnailURL: URL?
|
2020-01-25 15:06:27 +00:00
|
|
|
var thumbnailRequest: ImageCache.Request?
|
2019-09-15 19:01:35 +00:00
|
|
|
|
|
|
|
override func awakeFromNib() {
|
|
|
|
super.awakeFromNib()
|
|
|
|
|
|
|
|
thumbnailImageView.layer.masksToBounds = true
|
|
|
|
thumbnailImageView.layer.cornerRadius = 5
|
|
|
|
|
2022-11-05 01:47:39 +00:00
|
|
|
domainLabel.font = UIFontMetrics(forTextStyle: .title1).scaledFont(for: .systemFont(ofSize: 22, weight: .bold))
|
|
|
|
domainLabel.adjustsFontForContentSizeCategory = true
|
|
|
|
|
2019-09-15 19:01:35 +00:00
|
|
|
adultLabel.layer.masksToBounds = true
|
|
|
|
adultLabel.layer.cornerRadius = 0.5 * adultLabel.bounds.height
|
2022-11-05 01:47:39 +00:00
|
|
|
|
|
|
|
descriptionTextView.adjustsFontForContentSizeCategory = true
|
2019-09-15 19:01:35 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 04:02:11 +00:00
|
|
|
override func updateConfiguration(using state: UICellConfigurationState) {
|
2023-04-16 22:46:37 +00:00
|
|
|
backgroundConfiguration = .appListGroupedCell(for: state)
|
2023-02-03 04:02:11 +00:00
|
|
|
}
|
|
|
|
|
2019-09-15 19:01:35 +00:00
|
|
|
func updateUI(instance: InstanceSelector.Instance) {
|
|
|
|
self.selectorInstance = instance
|
|
|
|
self.instance = nil
|
|
|
|
|
|
|
|
domainLabel.text = instance.domain
|
2020-01-19 00:49:10 +00:00
|
|
|
adultLabel.isHidden = instance.category != "adult"
|
2023-12-23 01:44:46 +00:00
|
|
|
descriptionTextView.setBodyTextFromHTML(instance.description)
|
2019-09-15 19:01:35 +00:00
|
|
|
updateThumbnail(url: instance.proxiedThumbnailURL)
|
|
|
|
}
|
|
|
|
|
2023-12-04 22:55:03 +00:00
|
|
|
func updateUI(instance: InstanceV1) {
|
2019-09-15 19:01:35 +00:00
|
|
|
self.instance = instance
|
|
|
|
self.selectorInstance = nil
|
|
|
|
|
|
|
|
domainLabel.text = URLComponents(string: instance.uri)?.host ?? instance.uri
|
|
|
|
adultLabel.isHidden = true
|
2023-12-23 01:44:46 +00:00
|
|
|
descriptionTextView.setBodyTextFromHTML(instance.shortDescription ?? instance.description)
|
2019-09-15 19:01:35 +00:00
|
|
|
|
|
|
|
if let thumbnail = instance.thumbnail {
|
|
|
|
updateThumbnail(url: thumbnail)
|
|
|
|
} else {
|
|
|
|
thumbnailImageView.image = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func updateThumbnail(url: URL) {
|
|
|
|
thumbnailImageView.image = nil
|
|
|
|
thumbnailURL = url
|
2021-01-16 20:24:15 +00:00
|
|
|
thumbnailRequest = ImageCache.attachments.get(url) { [weak self] (_, image) in
|
|
|
|
guard let self = self, self.thumbnailURL == url, let image = image else { return }
|
2020-01-25 15:06:27 +00:00
|
|
|
self.thumbnailRequest = nil
|
2019-09-15 19:01:35 +00:00
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.thumbnailImageView.image = image
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-25 15:06:27 +00:00
|
|
|
|
|
|
|
override func prepareForReuse() {
|
|
|
|
super.prepareForReuse()
|
|
|
|
|
|
|
|
thumbnailRequest?.cancel()
|
|
|
|
instance = nil
|
|
|
|
selectorInstance = nil
|
|
|
|
}
|
2019-09-15 19:01:35 +00:00
|
|
|
|
|
|
|
}
|