feat: Implement translation progress indicator on status
This commit is contained in:
parent
1020ca531a
commit
dc174b4b6d
|
@ -360,6 +360,12 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
|
|||
return
|
||||
}
|
||||
|
||||
if let cell = cell as? StatusTableViewCell {
|
||||
DispatchQueue.main.async {
|
||||
cell.statusView.viewModel.isCurrentlyTranslating = true
|
||||
}
|
||||
}
|
||||
|
||||
try await DataSourceFacade.responseToMenuAction(
|
||||
dependency: self,
|
||||
action: action,
|
||||
|
|
|
@ -44,7 +44,12 @@ extension StatusView {
|
|||
@Published public var isMyself = false
|
||||
@Published public var isMuting = false
|
||||
@Published public var isBlocking = false
|
||||
@Published public var translatedFromLanguage: String?
|
||||
|
||||
// Translation
|
||||
@Published public var isCurrentlyTranslating = false
|
||||
@Published public var translatedFromLanguage: String? {
|
||||
didSet { isCurrentlyTranslating = false }
|
||||
}
|
||||
|
||||
@Published public var timestamp: Date?
|
||||
public var timestampFormatter: ((_ date: Date) -> String)?
|
||||
|
|
|
@ -176,6 +176,12 @@ public final class StatusView: UIView {
|
|||
indicatorView.stopAnimating()
|
||||
return indicatorView
|
||||
}()
|
||||
let isTranslatingLoadingView: UIActivityIndicatorView = {
|
||||
let activityIndicatorView = UIActivityIndicatorView(style: .medium)
|
||||
activityIndicatorView.hidesWhenStopped = true
|
||||
activityIndicatorView.stopAnimating()
|
||||
return activityIndicatorView
|
||||
}()
|
||||
private let translatedInfoLabel = UILabel()
|
||||
lazy var translatedInfoView: UIView = {
|
||||
let containerView = UIView()
|
||||
|
@ -199,8 +205,9 @@ public final class StatusView: UIView {
|
|||
containerView.heightAnchor.constraint(equalToConstant: 20),
|
||||
translatedInfoLabel.centerYAnchor.constraint(equalTo: containerView.centerYAnchor),
|
||||
translatedInfoLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 16),
|
||||
revertButton.centerYAnchor.constraint(equalTo: containerView.centerYAnchor),
|
||||
revertButton.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -16)
|
||||
revertButton.topAnchor.constraint(equalTo: containerView.topAnchor),
|
||||
revertButton.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -16),
|
||||
revertButton.bottomAnchor.constraint(equalTo: containerView.bottomAnchor)
|
||||
])
|
||||
|
||||
containerView.isHidden = true
|
||||
|
@ -472,6 +479,7 @@ extension StatusView.Style {
|
|||
])
|
||||
|
||||
// translated info
|
||||
statusView.containerStackView.addArrangedSubview(statusView.isTranslatingLoadingView)
|
||||
statusView.containerStackView.addArrangedSubview(statusView.translatedInfoView)
|
||||
}
|
||||
|
||||
|
@ -687,6 +695,18 @@ extension StatusView: MastodonMenuDelegate {
|
|||
|
||||
extension StatusView {
|
||||
func setupTranslationIndicator() {
|
||||
viewModel.$isCurrentlyTranslating
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] isTranslating in
|
||||
switch isTranslating {
|
||||
case true:
|
||||
self?.isTranslatingLoadingView.startAnimating()
|
||||
case false:
|
||||
self?.isTranslatingLoadingView.stopAnimating()
|
||||
}
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
viewModel.$translatedFromLanguage
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] translatedFromLanguage in
|
||||
|
|
Loading…
Reference in New Issue