2021-04-02 12:13:45 +02:00
|
|
|
//
|
|
|
|
// ProfileRelationshipActionButton.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-30.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
final class ProfileRelationshipActionButton: RoundedEdgesButton {
|
|
|
|
|
2021-04-09 11:31:43 +02:00
|
|
|
let actvityIndicatorView: UIActivityIndicatorView = {
|
|
|
|
let activityIndicatorView = UIActivityIndicatorView(style: .medium)
|
|
|
|
activityIndicatorView.color = .white
|
|
|
|
return activityIndicatorView
|
|
|
|
}()
|
|
|
|
|
2021-04-02 12:13:45 +02:00
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ProfileRelationshipActionButton {
|
|
|
|
private func _init() {
|
2021-04-15 05:05:19 +02:00
|
|
|
titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold)
|
|
|
|
|
2021-04-09 11:31:43 +02:00
|
|
|
actvityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
addSubview(actvityIndicatorView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
actvityIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor),
|
|
|
|
actvityIndicatorView.centerYAnchor.constraint(equalTo: centerYAnchor),
|
|
|
|
])
|
|
|
|
|
|
|
|
actvityIndicatorView.hidesWhenStopped = true
|
|
|
|
actvityIndicatorView.stopAnimating()
|
2021-04-02 12:13:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ProfileRelationshipActionButton {
|
|
|
|
func configure(actionOptionSet: ProfileViewModel.RelationshipActionOptionSet) {
|
|
|
|
setTitle(actionOptionSet.title, for: .normal)
|
|
|
|
setTitleColor(.white, for: .normal)
|
|
|
|
setTitleColor(UIColor.white.withAlphaComponent(0.5), for: .highlighted)
|
|
|
|
setBackgroundImage(.placeholder(color: actionOptionSet.backgroundColor), for: .normal)
|
|
|
|
setBackgroundImage(.placeholder(color: actionOptionSet.backgroundColor.withAlphaComponent(0.5)), for: .highlighted)
|
2021-04-08 10:53:32 +02:00
|
|
|
setBackgroundImage(.placeholder(color: actionOptionSet.backgroundColor.withAlphaComponent(0.5)), for: .disabled)
|
2021-04-06 11:12:25 +02:00
|
|
|
|
2021-04-09 11:31:43 +02:00
|
|
|
actvityIndicatorView.stopAnimating()
|
|
|
|
|
2021-04-08 11:05:10 +02:00
|
|
|
if let option = actionOptionSet.highPriorityAction(except: .editOptions), option == .blocked || option == .suspended {
|
2021-04-06 11:12:25 +02:00
|
|
|
isEnabled = false
|
2021-04-09 11:31:43 +02:00
|
|
|
} else if actionOptionSet.contains(.updating) {
|
|
|
|
isEnabled = false
|
|
|
|
actvityIndicatorView.startAnimating()
|
2021-04-06 11:12:25 +02:00
|
|
|
} else {
|
|
|
|
isEnabled = true
|
|
|
|
}
|
2021-04-02 12:13:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|