2021-02-03 06:01:50 +01:00
|
|
|
//
|
|
|
|
// TimelineLoaderTableViewCell.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/2/3.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Combine
|
|
|
|
|
|
|
|
class TimelineLoaderTableViewCell: UITableViewCell {
|
|
|
|
|
2021-02-24 11:40:47 +01:00
|
|
|
static let cellHeight: CGFloat = 44 + TimelineLoaderTableViewCell.extraTopPadding + TimelineLoaderTableViewCell.bottomPadding
|
2021-02-25 04:48:16 +01:00
|
|
|
static let extraTopPadding: CGFloat = 0 // the status cell already has 10pt bottom padding
|
2021-02-24 11:40:47 +01:00
|
|
|
static let bottomPadding: CGFloat = StatusTableViewCell.bottomPaddingHeight + TimelineLoaderTableViewCell.extraTopPadding // make balance
|
2021-02-03 06:01:50 +01:00
|
|
|
|
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
let loadMoreButton: UIButton = {
|
|
|
|
let button = UIButton(type: .system)
|
|
|
|
button.titleLabel?.font = .preferredFont(forTextStyle: .headline)
|
|
|
|
button.setTitle(L10n.Common.Controls.Timeline.loadMore, for: .normal)
|
|
|
|
return button
|
|
|
|
}()
|
|
|
|
|
|
|
|
let activityIndicatorView: UIActivityIndicatorView = {
|
|
|
|
let activityIndicatorView = UIActivityIndicatorView(style: .medium)
|
|
|
|
activityIndicatorView.tintColor = .white
|
|
|
|
activityIndicatorView.hidesWhenStopped = true
|
|
|
|
return activityIndicatorView
|
|
|
|
}()
|
|
|
|
|
|
|
|
override func prepareForReuse() {
|
|
|
|
super.prepareForReuse()
|
|
|
|
disposeBag.removeAll()
|
|
|
|
}
|
|
|
|
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func _init() {
|
|
|
|
selectionStyle = .none
|
2021-02-05 04:53:21 +01:00
|
|
|
backgroundColor = Asset.Colors.Background.secondarySystemBackground.color
|
|
|
|
|
2021-02-03 06:01:50 +01:00
|
|
|
loadMoreButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(loadMoreButton)
|
|
|
|
NSLayoutConstraint.activate([
|
2021-02-24 11:40:47 +01:00
|
|
|
loadMoreButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: TimelineLoaderTableViewCell.extraTopPadding),
|
2021-02-03 06:01:50 +01:00
|
|
|
loadMoreButton.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
|
|
|
|
contentView.readableContentGuide.trailingAnchor.constraint(equalTo: loadMoreButton.trailingAnchor),
|
2021-02-24 11:40:47 +01:00
|
|
|
contentView.bottomAnchor.constraint(equalTo: loadMoreButton.bottomAnchor, constant: TimelineLoaderTableViewCell.bottomPadding),
|
|
|
|
loadMoreButton.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh),
|
2021-02-03 06:01:50 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
addSubview(activityIndicatorView)
|
|
|
|
NSLayoutConstraint.activate([
|
2021-02-24 11:40:47 +01:00
|
|
|
activityIndicatorView.centerXAnchor.constraint(equalTo: loadMoreButton.centerXAnchor),
|
|
|
|
activityIndicatorView.centerYAnchor.constraint(equalTo: loadMoreButton.centerYAnchor),
|
2021-02-03 06:01:50 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
loadMoreButton.isHidden = true
|
|
|
|
activityIndicatorView.isHidden = true
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|