mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Cloud themes support
This commit is contained in:
@@ -11,10 +11,15 @@ import AccountContext
|
||||
import ShareController
|
||||
import CounterContollerTitleView
|
||||
|
||||
public enum ThemePreviewSource {
|
||||
case theme(TelegramTheme)
|
||||
case media(AnyMediaReference)
|
||||
}
|
||||
|
||||
public final class ThemePreviewController: ViewController {
|
||||
private let context: AccountContext
|
||||
private let previewTheme: PresentationTheme
|
||||
private let media: AnyMediaReference
|
||||
private let source: ThemePreviewSource
|
||||
|
||||
private var controllerNode: ThemePreviewControllerNode {
|
||||
return self.displayNode as! ThemePreviewControllerNode
|
||||
@@ -25,21 +30,28 @@ public final class ThemePreviewController: ViewController {
|
||||
private var presentationData: PresentationData
|
||||
private var presentationDataDisposable: Disposable?
|
||||
|
||||
public init(context: AccountContext, previewTheme: PresentationTheme, media: AnyMediaReference) {
|
||||
public init(context: AccountContext, previewTheme: PresentationTheme, source: ThemePreviewSource) {
|
||||
self.context = context
|
||||
self.previewTheme = previewTheme
|
||||
self.media = media
|
||||
self.source = source
|
||||
|
||||
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
|
||||
super.init(navigationBarPresentationData: NavigationBarPresentationData(presentationTheme: self.previewTheme, presentationStrings: self.presentationData.strings))
|
||||
|
||||
let themeName: String
|
||||
if case let .theme(theme) = source {
|
||||
themeName = theme.title
|
||||
} else {
|
||||
themeName = previewTheme.name.string
|
||||
}
|
||||
|
||||
if let author = previewTheme.author {
|
||||
let titleView = CounterContollerTitleView(theme: self.previewTheme)
|
||||
titleView.title = CounterContollerTitle(title: self.previewTheme.name.string, counter: author)
|
||||
titleView.title = CounterContollerTitle(title: themeName, counter: author)
|
||||
self.navigationItem.titleView = titleView
|
||||
} else {
|
||||
self.title = previewTheme.name.string
|
||||
self.title = themeName
|
||||
}
|
||||
self.statusBar.statusBarStyle = self.previewTheme.rootController.statusBarStyle.style
|
||||
self.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait)
|
||||
@@ -83,6 +95,13 @@ public final class ThemePreviewController: ViewController {
|
||||
}
|
||||
}, apply: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
let theme: PresentationThemeReference
|
||||
if case let .theme(info) = strongSelf.source {
|
||||
theme = .cloud(info)
|
||||
} else {
|
||||
theme = .builtin(.day)
|
||||
}
|
||||
|
||||
let _ = (strongSelf.context.sharedContext.accountManager.transaction { transaction -> Void in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings, { entry in
|
||||
let current: PresentationThemeSettings
|
||||
@@ -92,7 +111,7 @@ public final class ThemePreviewController: ViewController {
|
||||
current = PresentationThemeSettings.defaultSettings
|
||||
}
|
||||
|
||||
return PresentationThemeSettings(chatWallpaper: .color(0xffffff), theme: .builtin(.day), themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: current.themeSpecificChatWallpapers, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations)
|
||||
return PresentationThemeSettings(chatWallpaper: .color(0xffffff), theme: theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: current.themeSpecificChatWallpapers, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations)
|
||||
})
|
||||
}).start(completed: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
@@ -122,7 +141,22 @@ public final class ThemePreviewController: ViewController {
|
||||
}
|
||||
|
||||
@objc private func actionPressed() {
|
||||
let controller = ShareController(context: self.context, subject: .media(self.media))
|
||||
let subject: ShareControllerSubject
|
||||
let preferredAction: ShareControllerPreferredAction
|
||||
switch self.source {
|
||||
case let .theme(theme):
|
||||
subject = .url("https://t.me/addtheme/\(theme.slug)")
|
||||
preferredAction = .default
|
||||
case let .media(media):
|
||||
subject = .media(media)
|
||||
preferredAction = .custom(action: ShareControllerAction(title: "Publish", action: { [weak self] in
|
||||
if let strongSelf = self, let file = media.media as? TelegramMediaFile {
|
||||
let controller = createThemeController(context: strongSelf.context, theme: strongSelf.previewTheme, resource: file.resource)
|
||||
strongSelf.present(controller, in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet), blockInteraction: true)
|
||||
}
|
||||
}))
|
||||
}
|
||||
let controller = ShareController(context: self.context, subject: subject, preferredAction: preferredAction)
|
||||
self.present(controller, in: .window(.root), blockInteraction: true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user