2021-02-24 15:47:42 +01:00
|
|
|
//
|
|
|
|
// PickServerCell.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by BradGao on 2021/2/24.
|
|
|
|
//
|
|
|
|
|
2021-03-05 15:50:20 +01:00
|
|
|
import os.log
|
2021-02-24 15:47:42 +01:00
|
|
|
import UIKit
|
2021-03-06 05:55:52 +01:00
|
|
|
import Combine
|
2021-02-24 15:47:42 +01:00
|
|
|
import MastodonSDK
|
2021-03-05 12:30:17 +01:00
|
|
|
import AlamofireImage
|
2021-03-02 05:01:11 +01:00
|
|
|
import Kanna
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
|
|
|
import MastodonLocalization
|
2021-02-24 15:47:42 +01:00
|
|
|
|
2021-05-08 05:03:34 +02:00
|
|
|
protocol PickServerCellDelegate: AnyObject {
|
2022-01-04 11:30:21 +01:00
|
|
|
// func pickServerCell(_ cell: PickServerCell, expandButtonPressed button: UIButton)
|
2021-02-24 15:47:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class PickServerCell: UITableViewCell {
|
|
|
|
|
|
|
|
weak var delegate: PickServerCellDelegate?
|
|
|
|
|
2021-03-06 05:55:52 +01:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
2022-01-04 11:30:21 +01:00
|
|
|
|
|
|
|
let containerView: UIStackView = {
|
|
|
|
let view = UIStackView()
|
|
|
|
view.axis = .vertical
|
|
|
|
view.spacing = 4
|
2021-02-24 15:47:42 +01:00
|
|
|
return view
|
|
|
|
}()
|
|
|
|
|
2021-03-05 15:50:20 +01:00
|
|
|
let domainLabel: UILabel = {
|
2021-02-24 15:47:42 +01:00
|
|
|
let label = UILabel()
|
2022-01-04 11:30:21 +01:00
|
|
|
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 20, weight: .semibold))
|
2021-04-06 10:42:45 +02:00
|
|
|
label.textColor = Asset.Colors.Label.primary.color
|
2021-02-24 15:47:42 +01:00
|
|
|
label.adjustsFontForContentSizeCategory = true
|
|
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return label
|
|
|
|
}()
|
|
|
|
|
2021-03-05 15:50:20 +01:00
|
|
|
let checkbox: UIImageView = {
|
2021-02-24 15:47:42 +01:00
|
|
|
let imageView = UIImageView()
|
2021-02-25 07:09:19 +01:00
|
|
|
imageView.preferredSymbolConfiguration = UIImage.SymbolConfiguration(textStyle: .body)
|
2021-04-06 10:42:45 +02:00
|
|
|
imageView.tintColor = Asset.Colors.Label.secondary.color
|
2021-02-24 15:47:42 +01:00
|
|
|
imageView.contentMode = .scaleAspectFill
|
|
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
2021-03-05 15:50:20 +01:00
|
|
|
let descriptionLabel: UILabel = {
|
2021-02-24 15:47:42 +01:00
|
|
|
let label = UILabel()
|
2022-01-04 11:30:21 +01:00
|
|
|
label.font = UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .systemFont(ofSize: 13, weight: .regular))
|
2021-02-24 15:47:42 +01:00
|
|
|
label.numberOfLines = 0
|
2021-04-06 10:42:45 +02:00
|
|
|
label.textColor = Asset.Colors.Label.primary.color
|
2021-02-24 15:47:42 +01:00
|
|
|
label.adjustsFontForContentSizeCategory = true
|
|
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return label
|
|
|
|
}()
|
|
|
|
|
2021-03-05 15:50:20 +01:00
|
|
|
let infoStackView: UIStackView = {
|
2021-02-24 15:47:42 +01:00
|
|
|
let stackView = UIStackView()
|
|
|
|
stackView.axis = .horizontal
|
2022-01-04 11:30:21 +01:00
|
|
|
stackView.spacing = 16
|
2021-02-24 15:47:42 +01:00
|
|
|
return stackView
|
|
|
|
}()
|
|
|
|
|
2021-06-16 08:24:19 +02:00
|
|
|
let separator: UIView = {
|
2021-02-24 15:47:42 +01:00
|
|
|
let view = UIView()
|
2022-01-04 11:30:21 +01:00
|
|
|
view.backgroundColor = Asset.Theme.System.separator.color
|
2021-02-24 15:47:42 +01:00
|
|
|
return view
|
|
|
|
}()
|
|
|
|
|
2021-03-05 15:50:20 +01:00
|
|
|
let langValueLabel: UILabel = {
|
2021-02-24 15:47:42 +01:00
|
|
|
let label = UILabel()
|
2021-04-06 10:42:45 +02:00
|
|
|
label.textColor = Asset.Colors.Label.primary.color
|
2022-01-04 11:30:21 +01:00
|
|
|
label.font = UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .systemFont(ofSize: 12, weight: .regular))
|
2021-02-24 15:47:42 +01:00
|
|
|
label.textAlignment = .center
|
|
|
|
label.adjustsFontForContentSizeCategory = true
|
|
|
|
return label
|
|
|
|
}()
|
|
|
|
|
2021-03-05 15:50:20 +01:00
|
|
|
let usersValueLabel: UILabel = {
|
2021-02-24 15:47:42 +01:00
|
|
|
let label = UILabel()
|
2021-04-06 10:42:45 +02:00
|
|
|
label.textColor = Asset.Colors.Label.primary.color
|
2022-01-04 11:30:21 +01:00
|
|
|
label.font = UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .systemFont(ofSize: 12, weight: .regular))
|
2021-02-24 15:47:42 +01:00
|
|
|
label.adjustsFontForContentSizeCategory = true
|
|
|
|
return label
|
|
|
|
}()
|
|
|
|
|
|
|
|
private var collapseConstraints: [NSLayoutConstraint] = []
|
|
|
|
private var expandConstraints: [NSLayoutConstraint] = []
|
|
|
|
|
2021-03-04 08:29:46 +01:00
|
|
|
override func prepareForReuse() {
|
|
|
|
super.prepareForReuse()
|
|
|
|
|
2021-03-06 05:55:52 +01:00
|
|
|
disposeBag.removeAll()
|
2021-03-04 08:29:46 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 15:47:42 +01:00
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
2021-03-05 15:50:20 +01:00
|
|
|
|
2021-02-24 15:47:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Methods to configure appearance
|
|
|
|
extension PickServerCell {
|
|
|
|
private func _init() {
|
|
|
|
selectionStyle = .none
|
2022-02-15 11:15:58 +01:00
|
|
|
backgroundColor = Asset.Scene.Onboarding.background.color
|
2022-01-04 11:30:21 +01:00
|
|
|
|
|
|
|
checkbox.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(checkbox)
|
2021-02-24 15:47:42 +01:00
|
|
|
NSLayoutConstraint.activate([
|
2022-01-04 11:30:21 +01:00
|
|
|
checkbox.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor, constant: 1),
|
|
|
|
checkbox.heightAnchor.constraint(equalToConstant: 32).priority(.required - 1),
|
|
|
|
checkbox.widthAnchor.constraint(equalToConstant: 32).priority(.required - 1),
|
2021-02-24 15:47:42 +01:00
|
|
|
])
|
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
containerView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(containerView)
|
2021-03-04 08:29:46 +01:00
|
|
|
NSLayoutConstraint.activate([
|
2022-01-04 11:30:21 +01:00
|
|
|
containerView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 11),
|
|
|
|
containerView.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: 22),
|
|
|
|
containerView.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor),
|
|
|
|
contentView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: 11),
|
|
|
|
checkbox.centerYAnchor.constraint(equalTo: containerView.centerYAnchor),
|
2021-03-04 08:29:46 +01:00
|
|
|
])
|
2021-02-24 15:47:42 +01:00
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
containerView.addArrangedSubview(domainLabel)
|
|
|
|
containerView.addArrangedSubview(descriptionLabel)
|
|
|
|
containerView.setCustomSpacing(6, after: descriptionLabel)
|
|
|
|
containerView.addArrangedSubview(infoStackView)
|
2021-02-24 15:47:42 +01:00
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
infoStackView.addArrangedSubview(usersValueLabel)
|
|
|
|
infoStackView.addArrangedSubview(langValueLabel)
|
|
|
|
infoStackView.addArrangedSubview(UIView())
|
2021-10-08 12:10:06 +02:00
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
separator.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(separator)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
separator.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
|
|
|
|
contentView.readableContentGuide.trailingAnchor.constraint(equalTo: separator.trailingAnchor),
|
|
|
|
separator.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
|
|
separator.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: contentView)).priority(.required - 1),
|
|
|
|
])
|
2021-10-08 12:10:06 +02:00
|
|
|
}
|
|
|
|
|
2021-02-25 07:09:19 +01:00
|
|
|
override func setSelected(_ selected: Bool, animated: Bool) {
|
|
|
|
super.setSelected(selected, animated: animated)
|
|
|
|
if selected {
|
|
|
|
checkbox.image = UIImage(systemName: "checkmark.circle.fill")
|
2022-01-04 11:30:21 +01:00
|
|
|
checkbox.tintColor = Asset.Colors.Label.primary.color
|
2021-02-25 07:09:19 +01:00
|
|
|
} else {
|
|
|
|
checkbox.image = UIImage(systemName: "circle")
|
2022-01-04 11:30:21 +01:00
|
|
|
checkbox.tintColor = Asset.Colors.Label.secondary.color
|
2021-02-25 07:09:19 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 15:47:42 +01:00
|
|
|
|
2021-10-08 12:10:06 +02:00
|
|
|
}
|
|
|
|
|