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.toot" = "Toots";
"search.scope.tags" = "Hashtags";
"send" = "Send";
"share" = "Share";
"share-extension-error.no-account-found" = "No account found";
"status.accessibility.view-author-profile" = "View author's profile";

View file

@ -2,6 +2,7 @@
import AVFoundation
import Combine
import Mastodon
import PhotosUI
import SwiftUI
import UniformTypeIdentifiers
@ -78,14 +79,9 @@ final class NewStatusViewController: UIViewController {
primaryAction: UIAction { [weak self] _ in self?.dismiss() })
navigationItem.rightBarButtonItem = postButton
let postActionTitle: String
switch viewModel.identityContext.appPreferences.statusWord {
case .toot:
postActionTitle = NSLocalizedString("toot", comment: "")
case .post:
postActionTitle = NSLocalizedString("post", comment: "")
}
let postActionTitle = self.postActionTitle(
statusWord: viewModel.identityContext.appPreferences.statusWord,
visibility: viewModel.visibility)
postButton.primaryAction = UIAction(title: postActionTitle) { [weak self] _ in
self?.viewModel.post()
@ -273,6 +269,18 @@ private extension NewStatusViewController {
}
}
.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) {
@ -468,5 +476,16 @@ private extension NewStatusViewController {
self.scrollView.contentInset.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