Change button to "Send" if visibility is direct

This commit is contained in:
Justin Mazzocchi 2021-03-01 17:09:14 -08:00
parent a0141f7750
commit 425062cf2e
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
2 changed files with 28 additions and 8 deletions

View File

@ -269,6 +269,7 @@
"search.scope.statuses.post" = "Posts"; "search.scope.statuses.post" = "Posts";
"search.scope.statuses.toot" = "Toots"; "search.scope.statuses.toot" = "Toots";
"search.scope.tags" = "Hashtags"; "search.scope.tags" = "Hashtags";
"send" = "Send";
"share" = "Share"; "share" = "Share";
"share-extension-error.no-account-found" = "No account found"; "share-extension-error.no-account-found" = "No account found";
"status.accessibility.view-author-profile" = "View author's profile"; "status.accessibility.view-author-profile" = "View author's profile";

View File

@ -2,6 +2,7 @@
import AVFoundation import AVFoundation
import Combine import Combine
import Mastodon
import PhotosUI import PhotosUI
import SwiftUI import SwiftUI
import UniformTypeIdentifiers import UniformTypeIdentifiers
@ -78,14 +79,9 @@ final class NewStatusViewController: UIViewController {
primaryAction: UIAction { [weak self] _ in self?.dismiss() }) primaryAction: UIAction { [weak self] _ in self?.dismiss() })
navigationItem.rightBarButtonItem = postButton navigationItem.rightBarButtonItem = postButton
let postActionTitle: String let postActionTitle = self.postActionTitle(
statusWord: viewModel.identityContext.appPreferences.statusWord,
switch viewModel.identityContext.appPreferences.statusWord { visibility: viewModel.visibility)
case .toot:
postActionTitle = NSLocalizedString("toot", comment: "")
case .post:
postActionTitle = NSLocalizedString("post", comment: "")
}
postButton.primaryAction = UIAction(title: postActionTitle) { [weak self] _ in postButton.primaryAction = UIAction(title: postActionTitle) { [weak self] _ in
self?.viewModel.post() self?.viewModel.post()
@ -273,6 +269,18 @@ private extension NewStatusViewController {
} }
} }
.store(in: &cancellables) .store(in: &cancellables)
viewModel.$visibility.removeDuplicates().sink { [weak self] in
guard let self = self else { return }
let postActionTitle = self.postActionTitle(
statusWord: self.viewModel.identityContext.appPreferences.statusWord,
visibility: $0)
self.postButton.primaryAction = UIAction(title: postActionTitle) { [weak self] _ in
self?.viewModel.post()
}
}
.store(in: &cancellables)
} }
func presentMediaPicker(compositionViewModel: CompositionViewModel) { func presentMediaPicker(compositionViewModel: CompositionViewModel) {
@ -468,5 +476,16 @@ private extension NewStatusViewController {
self.scrollView.contentInset.bottom = contentInsetBottom self.scrollView.contentInset.bottom = contentInsetBottom
self.scrollView.verticalScrollIndicatorInsets.bottom = contentInsetBottom self.scrollView.verticalScrollIndicatorInsets.bottom = contentInsetBottom
} }
func postActionTitle(statusWord: AppPreferences.StatusWord, visibility: Status.Visibility) -> String {
switch (statusWord, visibility) {
case (_, .direct):
return NSLocalizedString("send", comment: "")
case (.toot, _):
return NSLocalizedString("toot", comment: "")
case (.post, _):
return NSLocalizedString("post", comment: "")
}
}
} }
// swiftlint:enable file_length // swiftlint:enable file_length