Move setupTranslationIndicator into StatusView.ViewModel
This commit is contained in:
parent
97f5132977
commit
32fbbc37c1
|
@ -356,6 +356,18 @@ extension StatusView.ViewModel {
|
|||
statusView.authorView.contentSensitiveeToggleButton.setImage(image, for: .normal)
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
$isCurrentlyTranslating
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { isTranslating in
|
||||
switch isTranslating {
|
||||
case true:
|
||||
statusView.isTranslatingLoadingView.startAnimating()
|
||||
case false:
|
||||
statusView.isTranslatingLoadingView.stopAnimating()
|
||||
}
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
|
||||
private func bindMedia(statusView: StatusView) {
|
||||
|
@ -820,7 +832,31 @@ extension StatusView.ViewModel {
|
|||
}
|
||||
.assign(to: \.toolbarActions, on: statusView)
|
||||
.store(in: &disposeBag)
|
||||
|
||||
|
||||
let translatedFromLabel = Publishers.CombineLatest($translatedFromLanguage, $translatedUsingProvider)
|
||||
.map { (language, provider) -> String? in
|
||||
if let language {
|
||||
return L10n.Common.Controls.Status.Translation.translatedFrom(
|
||||
Locale.current.localizedString(forIdentifier: language) ?? L10n.Common.Controls.Status.Translation.unknownLanguage,
|
||||
provider ?? L10n.Common.Controls.Status.Translation.unknownProvider
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
translatedFromLabel
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { label in
|
||||
if let label {
|
||||
statusView.translatedInfoLabel.text = label
|
||||
statusView.translatedInfoView.accessibilityValue = label
|
||||
statusView.translatedInfoView.isHidden = false
|
||||
} else {
|
||||
statusView.translatedInfoView.isHidden = true
|
||||
}
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
Publishers.CombineLatest3(
|
||||
shortAuthorAccessibilityLabel,
|
||||
contentAccessibilityLabel,
|
||||
|
|
|
@ -190,7 +190,7 @@ public final class StatusView: UIView {
|
|||
activityIndicatorView.stopAnimating()
|
||||
return activityIndicatorView
|
||||
}()
|
||||
private let translatedInfoLabel: UILabel = {
|
||||
let translatedInfoLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .regular))
|
||||
label.textColor = Asset.Colors.Label.secondary.color
|
||||
|
@ -286,7 +286,6 @@ public final class StatusView: UIView {
|
|||
setPollDisplay(isDisplay: false)
|
||||
setFilterHintLabelDisplay(isDisplay: false)
|
||||
setStatusCardControlDisplay(isDisplay: false)
|
||||
setupTranslationIndicator()
|
||||
}
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
|
@ -753,43 +752,6 @@ 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)
|
||||
|
||||
Publishers.CombineLatest(
|
||||
viewModel.$translatedFromLanguage,
|
||||
viewModel.$translatedUsingProvider
|
||||
)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] translatedFromLanguage, translatedUsingProvider in
|
||||
guard let self = self else { return }
|
||||
if let translatedFromLanguage = translatedFromLanguage {
|
||||
let label = L10n.Common.Controls.Status.Translation.translatedFrom(
|
||||
Locale.current.localizedString(forIdentifier: translatedFromLanguage) ?? L10n.Common.Controls.Status.Translation.unknownLanguage,
|
||||
translatedUsingProvider ?? L10n.Common.Controls.Status.Translation.unknownProvider
|
||||
)
|
||||
self.translatedInfoLabel.text = label
|
||||
self.translatedInfoView.accessibilityValue = label
|
||||
self.translatedInfoView.isHidden = false
|
||||
} else {
|
||||
self.translatedInfoView.isHidden = true
|
||||
}
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: StatusCardControlDelegate
|
||||
extension StatusView: StatusCardControlDelegate {
|
||||
public func statusCardControl(_ statusCardControl: StatusCardControl, didTapURL url: URL) {
|
||||
|
|
Loading…
Reference in New Issue