diff --git a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift index c157b7086..be3f4dbab 100644 --- a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift +++ b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift @@ -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, diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift index 15919120c..eee318170 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift @@ -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)? diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift index 2838bbd85..95ec5ff97 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift @@ -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