2022-10-18 13:01:31 +02:00
|
|
|
|
//
|
|
|
|
|
// ComposeContentToolbarView.swift
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Created by MainasuK on 22/10/18.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import MastodonCore
|
|
|
|
|
import MastodonAsset
|
2022-10-21 13:12:44 +02:00
|
|
|
|
import MastodonLocalization
|
2022-10-18 13:01:31 +02:00
|
|
|
|
import MastodonSDK
|
|
|
|
|
|
|
|
|
|
extension ComposeContentToolbarView {
|
|
|
|
|
class ViewModel: ObservableObject {
|
|
|
|
|
|
2022-10-21 13:12:44 +02:00
|
|
|
|
weak var delegate: ComposeContentToolbarViewDelegate?
|
|
|
|
|
|
2022-10-18 13:01:31 +02:00
|
|
|
|
// input
|
|
|
|
|
@Published var backgroundColor = ThemeService.shared.currentTheme.value.composeToolbarBackgroundColor
|
2023-01-24 01:50:10 +01:00
|
|
|
|
@Published var suggestedLanguages: [String] = []
|
|
|
|
|
@Published var highConfidenceSuggestedLanguage: String?
|
2022-10-18 13:01:31 +02:00
|
|
|
|
@Published var visibility: Mastodon.Entity.Status.Visibility = .public
|
|
|
|
|
var allVisibilities: [Mastodon.Entity.Status.Visibility] {
|
|
|
|
|
return [.public, .private, .direct]
|
|
|
|
|
}
|
2023-03-02 11:06:13 +01:00
|
|
|
|
@Published var isVisibilityButtonEnabled = false
|
2022-10-21 13:12:44 +02:00
|
|
|
|
@Published var isPollActive = false
|
|
|
|
|
@Published var isEmojiActive = false
|
|
|
|
|
@Published var isContentWarningActive = false
|
|
|
|
|
|
2022-11-13 15:08:26 +01:00
|
|
|
|
@Published var isAttachmentButtonEnabled = false
|
|
|
|
|
@Published var isPollButtonEnabled = false
|
|
|
|
|
|
2023-01-24 01:50:10 +01:00
|
|
|
|
@Published var language = Locale.current.languageCode ?? "en"
|
|
|
|
|
@Published var recentLanguages: [String] = []
|
|
|
|
|
|
2022-10-28 13:06:18 +02:00
|
|
|
|
@Published public var maxTextInputLimit = 500
|
|
|
|
|
@Published public var contentWeightedLength = 0
|
|
|
|
|
@Published public var contentWarningWeightedLength = 0
|
|
|
|
|
|
2022-10-18 13:01:31 +02:00
|
|
|
|
// output
|
|
|
|
|
|
2022-10-21 13:12:44 +02:00
|
|
|
|
init(delegate: ComposeContentToolbarViewDelegate) {
|
|
|
|
|
self.delegate = delegate
|
|
|
|
|
// end init
|
|
|
|
|
|
2022-10-18 13:01:31 +02:00
|
|
|
|
ThemeService.shared.currentTheme
|
|
|
|
|
.map { $0.composeToolbarBackgroundColor }
|
|
|
|
|
.assign(to: &$backgroundColor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension ComposeContentToolbarView.ViewModel {
|
|
|
|
|
enum Action: CaseIterable {
|
|
|
|
|
case attachment
|
|
|
|
|
case poll
|
|
|
|
|
case emoji
|
|
|
|
|
case contentWarning
|
|
|
|
|
case visibility
|
2023-01-24 01:50:10 +01:00
|
|
|
|
case language
|
2022-10-18 13:01:31 +02:00
|
|
|
|
|
2022-10-21 13:12:44 +02:00
|
|
|
|
var activeImage: UIImage {
|
|
|
|
|
switch self {
|
|
|
|
|
case .attachment:
|
|
|
|
|
return Asset.Scene.Compose.media.image.withRenderingMode(.alwaysTemplate)
|
|
|
|
|
case .poll:
|
|
|
|
|
return Asset.Scene.Compose.pollFill.image.withRenderingMode(.alwaysTemplate)
|
|
|
|
|
case .emoji:
|
|
|
|
|
return Asset.Scene.Compose.emojiFill.image.withRenderingMode(.alwaysTemplate)
|
|
|
|
|
case .contentWarning:
|
|
|
|
|
return Asset.Scene.Compose.chatWarningFill.image.withRenderingMode(.alwaysTemplate)
|
|
|
|
|
case .visibility:
|
|
|
|
|
return Asset.Scene.Compose.earth.image.withRenderingMode(.alwaysTemplate)
|
2023-01-24 01:50:10 +01:00
|
|
|
|
case .language:
|
|
|
|
|
fatalError("Language’s active image is never accessed")
|
2022-10-21 13:12:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var inactiveImage: UIImage {
|
2022-10-18 13:01:31 +02:00
|
|
|
|
switch self {
|
|
|
|
|
case .attachment:
|
2022-10-21 13:12:44 +02:00
|
|
|
|
return Asset.Scene.Compose.media.image.withRenderingMode(.alwaysTemplate)
|
2022-10-18 13:01:31 +02:00
|
|
|
|
case .poll:
|
2022-10-21 13:12:44 +02:00
|
|
|
|
return Asset.Scene.Compose.poll.image.withRenderingMode(.alwaysTemplate)
|
2022-10-18 13:01:31 +02:00
|
|
|
|
case .emoji:
|
2022-10-21 13:12:44 +02:00
|
|
|
|
return Asset.Scene.Compose.emoji.image.withRenderingMode(.alwaysTemplate)
|
2022-10-18 13:01:31 +02:00
|
|
|
|
case .contentWarning:
|
2022-10-21 13:12:44 +02:00
|
|
|
|
return Asset.Scene.Compose.chatWarning.image.withRenderingMode(.alwaysTemplate)
|
2022-10-18 13:01:31 +02:00
|
|
|
|
case .visibility:
|
2022-10-21 13:12:44 +02:00
|
|
|
|
return Asset.Scene.Compose.earth.image.withRenderingMode(.alwaysTemplate)
|
2023-01-24 01:50:10 +01:00
|
|
|
|
case .language:
|
|
|
|
|
fatalError("Language’s inactive image is never accessed")
|
2022-10-18 13:01:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-21 13:12:44 +02:00
|
|
|
|
|
|
|
|
|
enum AttachmentAction: CaseIterable {
|
|
|
|
|
case photoLibrary
|
|
|
|
|
case camera
|
|
|
|
|
case browse
|
|
|
|
|
|
|
|
|
|
var title: String {
|
|
|
|
|
switch self {
|
|
|
|
|
case .photoLibrary: return L10n.Scene.Compose.MediaSelection.photoLibrary
|
|
|
|
|
case .camera: return L10n.Scene.Compose.MediaSelection.camera
|
|
|
|
|
case .browse: return L10n.Scene.Compose.MediaSelection.browse
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var image: UIImage {
|
|
|
|
|
switch self {
|
|
|
|
|
case .photoLibrary: return UIImage(systemName: "photo.on.rectangle")!
|
|
|
|
|
case .camera: return UIImage(systemName: "camera")!
|
|
|
|
|
case .browse: return UIImage(systemName: "ellipsis")!
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension ComposeContentToolbarView.ViewModel {
|
|
|
|
|
func image(for action: Action) -> UIImage {
|
|
|
|
|
switch action {
|
|
|
|
|
case .poll:
|
|
|
|
|
return isPollActive ? action.activeImage : action.inactiveImage
|
|
|
|
|
case .emoji:
|
|
|
|
|
return isEmojiActive ? action.activeImage : action.inactiveImage
|
|
|
|
|
case .contentWarning:
|
|
|
|
|
return isContentWarningActive ? action.activeImage : action.inactiveImage
|
2023-01-24 01:50:10 +01:00
|
|
|
|
case .language:
|
|
|
|
|
fatalError("Language’s image is never accessed")
|
2022-10-21 13:12:44 +02:00
|
|
|
|
default:
|
|
|
|
|
return action.inactiveImage
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-07 02:49:12 +01:00
|
|
|
|
|
|
|
|
|
func label(for action: Action) -> String {
|
|
|
|
|
switch action {
|
|
|
|
|
case .attachment:
|
|
|
|
|
return L10n.Scene.Compose.Accessibility.appendAttachment
|
|
|
|
|
case .poll:
|
|
|
|
|
return isPollActive ? L10n.Scene.Compose.Accessibility.removePoll : L10n.Scene.Compose.Accessibility.appendPoll
|
|
|
|
|
case .emoji:
|
|
|
|
|
return L10n.Scene.Compose.Accessibility.customEmojiPicker
|
|
|
|
|
case .contentWarning:
|
|
|
|
|
return isContentWarningActive ? L10n.Scene.Compose.Accessibility.disableContentWarning : L10n.Scene.Compose.Accessibility.enableContentWarning
|
|
|
|
|
case .visibility:
|
|
|
|
|
return L10n.Scene.Compose.Accessibility.postVisibilityMenu
|
2023-01-24 01:50:10 +01:00
|
|
|
|
case .language:
|
|
|
|
|
return "[[language]]"
|
2022-11-07 02:49:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-18 13:01:31 +02:00
|
|
|
|
}
|