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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let cell = cell as? StatusTableViewCell {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
cell.statusView.viewModel.isCurrentlyTranslating = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try await DataSourceFacade.responseToMenuAction(
|
try await DataSourceFacade.responseToMenuAction(
|
||||||
dependency: self,
|
dependency: self,
|
||||||
action: action,
|
action: action,
|
||||||
|
|
|
@ -44,7 +44,12 @@ extension StatusView {
|
||||||
@Published public var isMyself = false
|
@Published public var isMyself = false
|
||||||
@Published public var isMuting = false
|
@Published public var isMuting = false
|
||||||
@Published public var isBlocking = 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?
|
@Published public var timestamp: Date?
|
||||||
public var timestampFormatter: ((_ date: Date) -> String)?
|
public var timestampFormatter: ((_ date: Date) -> String)?
|
||||||
|
|
|
@ -176,6 +176,12 @@ public final class StatusView: UIView {
|
||||||
indicatorView.stopAnimating()
|
indicatorView.stopAnimating()
|
||||||
return indicatorView
|
return indicatorView
|
||||||
}()
|
}()
|
||||||
|
let isTranslatingLoadingView: UIActivityIndicatorView = {
|
||||||
|
let activityIndicatorView = UIActivityIndicatorView(style: .medium)
|
||||||
|
activityIndicatorView.hidesWhenStopped = true
|
||||||
|
activityIndicatorView.stopAnimating()
|
||||||
|
return activityIndicatorView
|
||||||
|
}()
|
||||||
private let translatedInfoLabel = UILabel()
|
private let translatedInfoLabel = UILabel()
|
||||||
lazy var translatedInfoView: UIView = {
|
lazy var translatedInfoView: UIView = {
|
||||||
let containerView = UIView()
|
let containerView = UIView()
|
||||||
|
@ -199,8 +205,9 @@ public final class StatusView: UIView {
|
||||||
containerView.heightAnchor.constraint(equalToConstant: 20),
|
containerView.heightAnchor.constraint(equalToConstant: 20),
|
||||||
translatedInfoLabel.centerYAnchor.constraint(equalTo: containerView.centerYAnchor),
|
translatedInfoLabel.centerYAnchor.constraint(equalTo: containerView.centerYAnchor),
|
||||||
translatedInfoLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 16),
|
translatedInfoLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 16),
|
||||||
revertButton.centerYAnchor.constraint(equalTo: containerView.centerYAnchor),
|
revertButton.topAnchor.constraint(equalTo: containerView.topAnchor),
|
||||||
revertButton.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -16)
|
revertButton.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -16),
|
||||||
|
revertButton.bottomAnchor.constraint(equalTo: containerView.bottomAnchor)
|
||||||
])
|
])
|
||||||
|
|
||||||
containerView.isHidden = true
|
containerView.isHidden = true
|
||||||
|
@ -472,6 +479,7 @@ extension StatusView.Style {
|
||||||
])
|
])
|
||||||
|
|
||||||
// translated info
|
// translated info
|
||||||
|
statusView.containerStackView.addArrangedSubview(statusView.isTranslatingLoadingView)
|
||||||
statusView.containerStackView.addArrangedSubview(statusView.translatedInfoView)
|
statusView.containerStackView.addArrangedSubview(statusView.translatedInfoView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -687,6 +695,18 @@ extension StatusView: MastodonMenuDelegate {
|
||||||
|
|
||||||
extension StatusView {
|
extension StatusView {
|
||||||
func setupTranslationIndicator() {
|
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
|
viewModel.$translatedFromLanguage
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] translatedFromLanguage in
|
.sink { [weak self] translatedFromLanguage in
|
||||||
|
|
Loading…
Reference in New Issue