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

64 lines
1.5 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 os.log
2021-03-11 08:41:27 +01:00
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 {
2021-03-11 08:41:27 +01:00
let logger = Logger(subsystem: "ComposeViewModel", category: "ViewModel")
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 kind: ComposeContentViewModel.Kind
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,
kind: ComposeContentViewModel.Kind
2021-03-11 08:41:27 +01:00
) {
self.context = context
self.authContext = authContext
self.kind = kind
// end init
self.title = {
switch kind {
case .post, .hashtag, .mention: return L10n.Scene.Compose.Title.newPost
case .reply: return L10n.Scene.Compose.Title.newReply
}
}()
2021-03-11 08:41:27 +01:00
}
deinit {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
}
2021-03-11 08:41:27 +01:00
}