mastodon-ios/Mastodon/Scene/Compose/ComposeViewModel.swift

76 lines
1.8 KiB
Swift
Raw Normal View History

2021-03-11 08:41:27 +01:00
//
// ComposeViewModel.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-3-11.
//
import UIKit
import Combine
import CoreData
import CoreDataStack
2021-03-18 10:33:07 +01:00
import GameplayKit
import MastodonSDK
import MastodonAsset
2022-10-08 07:43:06 +02:00
import MastodonCore
import MastodonLocalization
import MastodonMeta
import MastodonUI
2021-03-11 08:41:27 +01:00
final class ComposeViewModel {
enum Context {
case composeStatus
case editStatus(status: Status, statusSource: Mastodon.Entity.StatusSource)
}
var disposeBag = Set<AnyCancellable>()
2021-07-26 14:09:23 +02:00
let id = UUID()
2021-03-11 08:41:27 +01:00
// input
let context: AppContext
let authContext: AuthContext
let composeContext: Context
let destination: ComposeContentViewModel.Destination
let initialContent: String
let traitCollectionDidChangePublisher = CurrentValueSubject<Void, Never>(Void()) // use CurrentValueSubject to make initial event emit
2021-03-11 08:41:27 +01:00
// output
// UI & UX
@Published var title: String
2021-03-23 11:47:21 +01:00
2021-03-11 08:41:27 +01:00
init(
context: AppContext,
authContext: AuthContext,
composeContext: ComposeViewModel.Context,
destination: ComposeContentViewModel.Destination,
initialContent: String = ""
2021-03-11 08:41:27 +01:00
) {
self.context = context
self.authContext = authContext
self.destination = destination
self.initialContent = initialContent
self.composeContext = composeContext
// end init
let title: String
switch composeContext {
case .composeStatus:
switch destination {
case .topLevel:
title = L10n.Scene.Compose.Title.newPost
case .reply:
title = L10n.Scene.Compose.Title.newReply
}
case .editStatus(_, _):
title = L10n.Scene.Compose.Title.editPost
}
self.title = title
}
2021-03-11 08:41:27 +01:00
}