2021-07-05 10:07:17 +02:00
|
|
|
//
|
|
|
|
// ThemeService.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-7-5.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Combine
|
2022-04-13 14:43:16 +02:00
|
|
|
import MastodonCommon
|
2021-07-05 10:07:17 +02:00
|
|
|
|
|
|
|
// ref: https://zamzam.io/protocol-oriented-themes-for-ios-apps/
|
2022-04-13 14:43:16 +02:00
|
|
|
public final class ThemeService {
|
2021-10-29 08:58:09 +02:00
|
|
|
|
2022-04-13 14:43:16 +02:00
|
|
|
public static let tintColor: UIColor = .label
|
2021-07-05 10:07:17 +02:00
|
|
|
|
|
|
|
// MARK: - Singleton
|
|
|
|
public static let shared = ThemeService()
|
|
|
|
|
2022-04-13 14:43:16 +02:00
|
|
|
public let currentTheme: CurrentValueSubject<Theme, Never>
|
2021-07-05 10:07:17 +02:00
|
|
|
|
|
|
|
private init() {
|
|
|
|
let theme = ThemeName(rawValue: UserDefaults.shared.currentThemeNameRawValue)?.theme ?? ThemeName.mastodon.theme
|
|
|
|
currentTheme = CurrentValueSubject(theme)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-04-13 14:43:16 +02:00
|
|
|
|
|
|
|
extension ThemeName {
|
|
|
|
public var theme: Theme {
|
|
|
|
switch self {
|
|
|
|
case .system: return SystemTheme()
|
|
|
|
case .mastodon: return MastodonTheme()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|