From 425062cf2e728ec4545d6d82c491a7c3728c8591 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Mon, 1 Mar 2021 17:09:14 -0800 Subject: [PATCH] Change button to "Send" if visibility is direct --- Localizations/Localizable.strings | 1 + .../NewStatusViewController.swift | 35 ++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index c30c36f..2ec09a3 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -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"; diff --git a/View Controllers/NewStatusViewController.swift b/View Controllers/NewStatusViewController.swift index 786b1b0..2661540 100644 --- a/View Controllers/NewStatusViewController.swift +++ b/View Controllers/NewStatusViewController.swift @@ -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