Added support for cloud themes selection for auto-night mode

This commit is contained in:
Ilya Laktyushin
2019-09-03 17:32:11 +03:00
parent b67095c97e
commit 4c03783ca0
8 changed files with 80 additions and 64 deletions

View File

@@ -215,11 +215,11 @@ func importLegacyPreferences(accountManager: AccountManager, account: TemporaryA
} }
switch autoNightPreferences.mode { switch autoNightPreferences.mode {
case TGPresentationAutoNightModeSunsetSunrise: case TGPresentationAutoNightModeSunsetSunrise:
settings.automaticThemeSwitchSetting = AutomaticThemeSwitchSetting(trigger: .timeBased(setting: .automatic(latitude: Double(autoNightPreferences.latitude), longitude: Double(autoNightPreferences.longitude), localizedName: autoNightPreferences.cachedLocationName)), theme: nightTheme) settings.automaticThemeSwitchSetting = AutomaticThemeSwitchSetting(trigger: .timeBased(setting: .automatic(latitude: Double(autoNightPreferences.latitude), longitude: Double(autoNightPreferences.longitude), localizedName: autoNightPreferences.cachedLocationName)), theme: .builtin(nightTheme))
case TGPresentationAutoNightModeScheduled: case TGPresentationAutoNightModeScheduled:
settings.automaticThemeSwitchSetting = AutomaticThemeSwitchSetting(trigger: .timeBased(setting: .manual(fromSeconds: autoNightPreferences.scheduleStart, toSeconds: autoNightPreferences.scheduleEnd)), theme: nightTheme) settings.automaticThemeSwitchSetting = AutomaticThemeSwitchSetting(trigger: .timeBased(setting: .manual(fromSeconds: autoNightPreferences.scheduleStart, toSeconds: autoNightPreferences.scheduleEnd)), theme: .builtin(nightTheme))
case TGPresentationAutoNightModeBrightness: case TGPresentationAutoNightModeBrightness:
settings.automaticThemeSwitchSetting = AutomaticThemeSwitchSetting(trigger: .brightness(threshold: Double(autoNightPreferences.brightnessThreshold)), theme: nightTheme) settings.automaticThemeSwitchSetting = AutomaticThemeSwitchSetting(trigger: .brightness(threshold: Double(autoNightPreferences.brightnessThreshold)), theme: .builtin(nightTheme))
default: default:
break break
} }

View File

@@ -24,14 +24,16 @@ private enum TimeBasedManualField {
} }
private final class ThemeAutoNightSettingsControllerArguments { private final class ThemeAutoNightSettingsControllerArguments {
let context: AccountContext
let updateMode: (TriggerMode) -> Void let updateMode: (TriggerMode) -> Void
let updateTimeBasedAutomatic: (Bool) -> Void let updateTimeBasedAutomatic: (Bool) -> Void
let openTimeBasedManual: (TimeBasedManualField) -> Void let openTimeBasedManual: (TimeBasedManualField) -> Void
let updateTimeBasedAutomaticLocation: () -> Void let updateTimeBasedAutomaticLocation: () -> Void
let updateAutomaticBrightness: (Double) -> Void let updateAutomaticBrightness: (Double) -> Void
let updateTheme: (PresentationBuiltinThemeReference) -> Void let updateTheme: (PresentationThemeReference) -> Void
init(updateMode: @escaping (TriggerMode) -> Void, updateTimeBasedAutomatic: @escaping (Bool) -> Void, openTimeBasedManual: @escaping (TimeBasedManualField) -> Void, updateTimeBasedAutomaticLocation: @escaping () -> Void, updateAutomaticBrightness: @escaping (Double) -> Void, updateTheme: @escaping (PresentationBuiltinThemeReference) -> Void) { init(context: AccountContext, updateMode: @escaping (TriggerMode) -> Void, updateTimeBasedAutomatic: @escaping (Bool) -> Void, openTimeBasedManual: @escaping (TimeBasedManualField) -> Void, updateTimeBasedAutomaticLocation: @escaping () -> Void, updateAutomaticBrightness: @escaping (Double) -> Void, updateTheme: @escaping (PresentationThemeReference) -> Void) {
self.context = context
self.updateMode = updateMode self.updateMode = updateMode
self.updateTimeBasedAutomatic = updateTimeBasedAutomatic self.updateTimeBasedAutomatic = updateTimeBasedAutomatic
self.openTimeBasedManual = openTimeBasedManual self.openTimeBasedManual = openTimeBasedManual
@@ -61,8 +63,7 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry {
case settingInfo(PresentationTheme, String) case settingInfo(PresentationTheme, String)
case themeHeader(PresentationTheme, String) case themeHeader(PresentationTheme, String)
case themeNightBlue(PresentationTheme, String, Bool) case themeItem(PresentationTheme, PresentationStrings, [PresentationThemeReference], PresentationThemeReference, [Int64: PresentationThemeAccentColor])
case themeNight(PresentationTheme, String, Bool)
var section: ItemListSectionId { var section: ItemListSectionId {
switch self { switch self {
@@ -70,7 +71,7 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry {
return ThemeAutoNightSettingsControllerSection.mode.rawValue return ThemeAutoNightSettingsControllerSection.mode.rawValue
case .settingsHeader, .timeBasedAutomaticLocation, .timeBasedAutomaticLocationValue, .timeBasedManualFrom, .timeBasedManualTo, .brightnessValue, .settingInfo: case .settingsHeader, .timeBasedAutomaticLocation, .timeBasedAutomaticLocationValue, .timeBasedManualFrom, .timeBasedManualTo, .brightnessValue, .settingInfo:
return ThemeAutoNightSettingsControllerSection.settings.rawValue return ThemeAutoNightSettingsControllerSection.settings.rawValue
case .themeHeader, .themeNightBlue, .themeNight: case .themeHeader, .themeItem:
return ThemeAutoNightSettingsControllerSection.theme.rawValue return ThemeAutoNightSettingsControllerSection.theme.rawValue
} }
} }
@@ -99,10 +100,8 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry {
return 9 return 9
case .themeHeader: case .themeHeader:
return 10 return 10
case .themeNightBlue: case .themeItem:
return 11 return 11
case .themeNight:
return 12
} }
} }
@@ -174,14 +173,8 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry {
} else { } else {
return false return false
} }
case let .themeNightBlue(lhsTheme, lhsTitle, lhsValue): case let .themeItem(lhsTheme, lhsStrings, lhsThemes, lhsCurrentTheme, lhsThemeAccentColors):
if case let .themeNightBlue(rhsTheme, rhsTitle, rhsValue) = rhs, lhsTheme === rhsTheme, lhsTitle == rhsTitle, lhsValue == rhsValue { if case let .themeItem(rhsTheme, rhsStrings, rhsThemes, rhsCurrentTheme, rhsThemeAccentColors) = rhs, lhsTheme === rhsTheme, lhsStrings === rhsStrings, lhsThemes == rhsThemes, lhsCurrentTheme == rhsCurrentTheme, lhsThemeAccentColors == rhsThemeAccentColors {
return true
} else {
return false
}
case let .themeNight(lhsTheme, lhsTitle, lhsValue):
if case let .themeNight(rhsTheme, rhsTitle, rhsValue) = rhs, lhsTheme === rhsTheme, lhsTitle == rhsTitle, lhsValue == rhsValue {
return true return true
} else { } else {
return false return false
@@ -233,19 +226,16 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry {
return ItemListTextItem(theme: theme, text: .plain(text), sectionId: self.section) return ItemListTextItem(theme: theme, text: .plain(text), sectionId: self.section)
case let .themeHeader(theme, title): case let .themeHeader(theme, title):
return ItemListSectionHeaderItem(theme: theme, text: title, sectionId: self.section) return ItemListSectionHeaderItem(theme: theme, text: title, sectionId: self.section)
case let .themeNightBlue(theme, title, value): case let .themeItem(theme, strings, themes, currentTheme, themeSpecificAccentColors):
return ItemListCheckboxItem(theme: theme, title: title, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { return ThemeSettingsThemeItem(context: arguments.context, theme: theme, strings: strings, sectionId: self.section, themes: themes, themeSpecificAccentColors: themeSpecificAccentColors, currentTheme: currentTheme, updatedTheme: { theme in
arguments.updateTheme(.nightAccent) arguments.updateTheme(theme)
}) }, longTapped: { _ in
case let .themeNight(theme, title, value):
return ItemListCheckboxItem(theme: theme, title: title, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: {
arguments.updateTheme(.night)
}) })
} }
} }
} }
private func themeAutoNightSettingsControllerEntries(theme: PresentationTheme, strings: PresentationStrings, switchSetting: AutomaticThemeSwitchSetting, dateTimeFormat: PresentationDateTimeFormat) -> [ThemeAutoNightSettingsControllerEntry] { private func themeAutoNightSettingsControllerEntries(theme: PresentationTheme, strings: PresentationStrings, settings: PresentationThemeSettings, switchSetting: AutomaticThemeSwitchSetting, availableThemes: [PresentationThemeReference], dateTimeFormat: PresentationDateTimeFormat) -> [ThemeAutoNightSettingsControllerEntry] {
var entries: [ThemeAutoNightSettingsControllerEntry] = [] var entries: [ThemeAutoNightSettingsControllerEntry] = []
let activeTriggerMode: TriggerMode let activeTriggerMode: TriggerMode
@@ -297,8 +287,7 @@ private func themeAutoNightSettingsControllerEntries(theme: PresentationTheme, s
break break
case .timeBased, .brightness: case .timeBased, .brightness:
entries.append(.themeHeader(theme, strings.AutoNightTheme_PreferredTheme)) entries.append(.themeHeader(theme, strings.AutoNightTheme_PreferredTheme))
entries.append(.themeNightBlue(theme, strings.Appearance_ThemeCarouselTintedNight, switchSetting.theme == .nightAccent)) entries.append(.themeItem(theme, strings, availableThemes, switchSetting.theme, settings.themeSpecificAccentColors))
entries.append(.themeNight(theme, strings.Appearance_ThemeCarouselNewNight, switchSetting.theme == .night))
} }
return entries return entries
@@ -389,7 +378,7 @@ public func themeAutoNightSettingsController(context: AccountContext) -> ViewCon
updateLocationDisposable.set(disposable) updateLocationDisposable.set(disposable)
} }
let arguments = ThemeAutoNightSettingsControllerArguments(updateMode: { mode in let arguments = ThemeAutoNightSettingsControllerArguments(context: context, updateMode: { mode in
var updateLocation = false var updateLocation = false
updateSettings { settings in updateSettings { settings in
var settings = settings var settings = settings
@@ -515,12 +504,22 @@ public func themeAutoNightSettingsController(context: AccountContext) -> ViewCon
} }
}) })
let signal = combineLatest(context.sharedContext.presentationData |> deliverOnMainQueue, sharedData |> deliverOnMainQueue, stagingSettingsPromise.get() |> deliverOnMainQueue) let cloudThemes = Promise<[TelegramTheme]>()
|> map { presentationData, sharedData, stagingSettings -> (ItemListControllerState, (ItemListNodeState<ThemeAutoNightSettingsControllerEntry>, ThemeAutoNightSettingsControllerEntry.ItemGenerationArguments)) in let updatedCloudThemes = telegramThemes(postbox: context.account.postbox, network: context.account.network, accountManager: context.sharedContext.accountManager)
cloudThemes.set(updatedCloudThemes)
let signal = combineLatest(context.sharedContext.presentationData |> deliverOnMainQueue, sharedData |> deliverOnMainQueue, cloudThemes.get() |> deliverOnMainQueue, stagingSettingsPromise.get() |> deliverOnMainQueue)
|> map { presentationData, sharedData, cloudThemes, stagingSettings -> (ItemListControllerState, (ItemListNodeState<ThemeAutoNightSettingsControllerEntry>, ThemeAutoNightSettingsControllerEntry.ItemGenerationArguments)) in
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings
let defaultThemes: [PresentationThemeReference] = [.builtin(.night), .builtin(.nightAccent)]
let cloudThemes: [PresentationThemeReference] = cloudThemes.map { .cloud(PresentationCloudTheme(theme: $0, resolvedWallpaper: nil)) }
var availableThemes = defaultThemes
availableThemes.append(contentsOf: cloudThemes)
let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(presentationData.strings.AutoNightTheme_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back)) let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(presentationData.strings.AutoNightTheme_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
let listState = ItemListNodeState(entries: themeAutoNightSettingsControllerEntries(theme: presentationData.theme, strings: presentationData.strings, switchSetting: stagingSettings ?? settings.automaticThemeSwitchSetting, dateTimeFormat: presentationData.dateTimeFormat), style: .blocks, animateChanges: false) let listState = ItemListNodeState(entries: themeAutoNightSettingsControllerEntries(theme: presentationData.theme, strings: presentationData.strings, settings: settings, switchSetting: stagingSettings ?? settings.automaticThemeSwitchSetting, availableThemes: availableThemes, dateTimeFormat: presentationData.dateTimeFormat), style: .blocks, animateChanges: false)
return (controllerState, (listState, arguments)) return (controllerState, (listState, arguments))
} }

View File

@@ -103,7 +103,6 @@ private let colors: [UInt32: String] = [
] ]
private let adjectives = [ private let adjectives = [
"Always",
"Ancient", "Ancient",
"Antique", "Antique",
"Autumn", "Autumn",

View File

@@ -87,12 +87,15 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate {
self.instantChatBackgroundNode.displaysAsynchronously = false self.instantChatBackgroundNode.displaysAsynchronously = false
self.instantChatBackgroundNode.image = chatControllerBackgroundImage(theme: previewTheme, wallpaper: previewTheme.chat.defaultWallpaper, mediaBox: context.sharedContext.accountManager.mediaBox, knockoutMode: context.sharedContext.immediateExperimentalUISettings.knockoutWallpaper) self.instantChatBackgroundNode.image = chatControllerBackgroundImage(theme: previewTheme, wallpaper: previewTheme.chat.defaultWallpaper, mediaBox: context.sharedContext.accountManager.mediaBox, knockoutMode: context.sharedContext.immediateExperimentalUISettings.knockoutWallpaper)
self.instantChatBackgroundNode.motionEnabled = previewTheme.chat.defaultWallpaper.settings?.motion ?? false self.instantChatBackgroundNode.motionEnabled = previewTheme.chat.defaultWallpaper.settings?.motion ?? false
self.instantChatBackgroundNode.view.contentMode = .scaleAspectFill
self.remoteChatBackgroundNode = TransformImageNode() self.remoteChatBackgroundNode = TransformImageNode()
self.remoteChatBackgroundNode.backgroundColor = previewTheme.chatList.backgroundColor self.remoteChatBackgroundNode.backgroundColor = previewTheme.chatList.backgroundColor
self.remoteChatBackgroundNode.view.contentMode = .scaleAspectFill
self.blurredNode = BlurredImageNode() self.blurredNode = BlurredImageNode()
self.blurredNode.clipsToBounds = true self.blurredNode.clipsToBounds = true
self.blurredNode.blurView.contentMode = .scaleAspectFill
self.toolbarNode = WallpaperGalleryToolbarNode(theme: self.previewTheme, strings: self.presentationData.strings) self.toolbarNode = WallpaperGalleryToolbarNode(theme: self.previewTheme, strings: self.presentationData.strings)

View File

@@ -36,7 +36,7 @@ func themeDisplayName(strings: PresentationStrings, reference: PresentationTheme
private final class ThemeSettingsControllerArguments { private final class ThemeSettingsControllerArguments {
let context: AccountContext let context: AccountContext
let selectTheme: (PresentationThemeReference) -> Void let updateTheme: (PresentationThemeReference) -> Void
let selectFontSize: (PresentationFontSize) -> Void let selectFontSize: (PresentationFontSize) -> Void
let openWallpaperSettings: () -> Void let openWallpaperSettings: () -> Void
let selectAccentColor: (PresentationThemeAccentColor) -> Void let selectAccentColor: (PresentationThemeAccentColor) -> Void
@@ -48,9 +48,9 @@ private final class ThemeSettingsControllerArguments {
let presentThemeMenu: (PresentationThemeReference, Bool) -> Void let presentThemeMenu: (PresentationThemeReference, Bool) -> Void
let editTheme: (PresentationCloudTheme) -> Void let editTheme: (PresentationCloudTheme) -> Void
init(context: AccountContext, selectTheme: @escaping (PresentationThemeReference) -> Void, selectFontSize: @escaping (PresentationFontSize) -> Void, openWallpaperSettings: @escaping () -> Void, selectAccentColor: @escaping (PresentationThemeAccentColor) -> Void, openAccentColorPicker: @escaping (PresentationThemeReference, PresentationThemeAccentColor?) -> Void, openAutoNightTheme: @escaping () -> Void, toggleLargeEmoji: @escaping (Bool) -> Void, disableAnimations: @escaping (Bool) -> Void, selectAppIcon: @escaping (String) -> Void, presentThemeMenu: @escaping (PresentationThemeReference, Bool) -> Void, editTheme: @escaping (PresentationCloudTheme) -> Void) { init(context: AccountContext, updateTheme: @escaping (PresentationThemeReference) -> Void, selectFontSize: @escaping (PresentationFontSize) -> Void, openWallpaperSettings: @escaping () -> Void, selectAccentColor: @escaping (PresentationThemeAccentColor) -> Void, openAccentColorPicker: @escaping (PresentationThemeReference, PresentationThemeAccentColor?) -> Void, openAutoNightTheme: @escaping () -> Void, toggleLargeEmoji: @escaping (Bool) -> Void, disableAnimations: @escaping (Bool) -> Void, selectAppIcon: @escaping (String) -> Void, presentThemeMenu: @escaping (PresentationThemeReference, Bool) -> Void, editTheme: @escaping (PresentationCloudTheme) -> Void) {
self.context = context self.context = context
self.selectTheme = selectTheme self.updateTheme = updateTheme
self.selectFontSize = selectFontSize self.selectFontSize = selectFontSize
self.openWallpaperSettings = openWallpaperSettings self.openWallpaperSettings = openWallpaperSettings
self.selectAccentColor = selectAccentColor self.selectAccentColor = selectAccentColor
@@ -290,14 +290,14 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry {
}) })
case let .themeListHeader(theme, text): case let .themeListHeader(theme, text):
return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section) return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section)
case let .themeItem(theme, strings, themes, currentTheme, themeSpecificAccentColors, currentColor): case let .themeItem(theme, strings, themes, currentTheme, themeSpecificAccentColors, _):
return ThemeSettingsThemeItem(context: arguments.context, theme: theme, strings: strings, sectionId: self.section, themes: themes, themeSpecificAccentColors: themeSpecificAccentColors, currentTheme: currentTheme, updatedTheme: { theme in return ThemeSettingsThemeItem(context: arguments.context, theme: theme, strings: strings, sectionId: self.section, themes: themes, themeSpecificAccentColors: themeSpecificAccentColors, currentTheme: currentTheme, updatedTheme: { theme in
if case let .cloud(theme) = theme, theme.theme.file == nil { if case let .cloud(theme) = theme, theme.theme.file == nil {
if theme.theme.isCreator { if theme.theme.isCreator {
arguments.editTheme(theme) arguments.editTheme(theme)
} }
} else { } else {
arguments.selectTheme(theme) arguments.updateTheme(theme)
} }
}, longTapped: { theme in }, longTapped: { theme in
arguments.presentThemeMenu(theme, theme.index == currentTheme.index) arguments.presentThemeMenu(theme, theme.index == currentTheme.index)
@@ -370,7 +370,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
var presentControllerImpl: ((ViewController, Any?) -> Void)? var presentControllerImpl: ((ViewController, Any?) -> Void)?
var getNavigationControllerImpl: (() -> NavigationController?)? var getNavigationControllerImpl: (() -> NavigationController?)?
var selectThemeImpl: ((PresentationThemeReference) -> Void)? var updateThemeImpl: ((PresentationThemeReference) -> Void)?
var moreImpl: (() -> Void)? var moreImpl: (() -> Void)?
let _ = telegramWallpapers(postbox: context.account.postbox, network: context.account.network).start() let _ = telegramWallpapers(postbox: context.account.postbox, network: context.account.network).start()
@@ -391,8 +391,8 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
let updatedCloudThemes = telegramThemes(postbox: context.account.postbox, network: context.account.network, accountManager: context.sharedContext.accountManager) let updatedCloudThemes = telegramThemes(postbox: context.account.postbox, network: context.account.network, accountManager: context.sharedContext.accountManager)
cloudThemes.set(updatedCloudThemes) cloudThemes.set(updatedCloudThemes)
let arguments = ThemeSettingsControllerArguments(context: context, selectTheme: { theme in let arguments = ThemeSettingsControllerArguments(context: context, updateTheme: { theme in
selectThemeImpl?(theme) updateThemeImpl?(theme)
}, selectFontSize: { size in }, selectFontSize: { size in
let _ = updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current in let _ = updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current in
return PresentationThemeSettings(chatWallpaper: current.chatWallpaper, theme: current.theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: current.themeSpecificChatWallpapers, fontSize: size, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) return PresentationThemeSettings(chatWallpaper: current.chatWallpaper, theme: current.theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: current.themeSpecificChatWallpapers, fontSize: size, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations)
@@ -474,7 +474,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
} else { } else {
newTheme = .builtin(.nightAccent) newTheme = .builtin(.nightAccent)
} }
selectThemeImpl?(newTheme) updateThemeImpl?(newTheme)
} }
let _ = deleteThemeInteractively(account: context.account, accountManager: context.sharedContext.accountManager, theme: theme.theme).start() let _ = deleteThemeInteractively(account: context.account, accountManager: context.sharedContext.accountManager, theme: theme.theme).start()
@@ -551,7 +551,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
getNavigationControllerImpl = { [weak controller] in getNavigationControllerImpl = { [weak controller] in
return controller?.navigationController as? NavigationController return controller?.navigationController as? NavigationController
} }
selectThemeImpl = { theme in updateThemeImpl = { theme in
let presentationTheme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: theme, accentColor: nil, serviceBackgroundColor: .black, baseColor: nil) let presentationTheme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: theme, accentColor: nil, serviceBackgroundColor: .black, baseColor: nil)
let resolvedWallpaper: Signal<TelegramWallpaper?, NoError> let resolvedWallpaper: Signal<TelegramWallpaper?, NoError>

View File

@@ -254,7 +254,7 @@ public func currentPresentationDataAndSettings(accountManager: AccountManager) -
let parameters = AutomaticThemeSwitchParameters(settings: themeSettings.automaticThemeSwitchSetting) let parameters = AutomaticThemeSwitchParameters(settings: themeSettings.automaticThemeSwitchSetting)
if automaticThemeShouldSwitchNow(parameters, currentTheme: themeSettings.theme) { if automaticThemeShouldSwitchNow(parameters, currentTheme: themeSettings.theme) {
effectiveTheme = .builtin(themeSettings.automaticThemeSwitchSetting.theme) effectiveTheme = themeSettings.automaticThemeSwitchSetting.theme
} else { } else {
effectiveTheme = themeSettings.theme effectiveTheme = themeSettings.theme
} }
@@ -301,7 +301,7 @@ private enum PreparedAutomaticThemeSwitchTrigger {
private struct AutomaticThemeSwitchParameters { private struct AutomaticThemeSwitchParameters {
let trigger: PreparedAutomaticThemeSwitchTrigger let trigger: PreparedAutomaticThemeSwitchTrigger
let theme: PresentationBuiltinThemeReference let theme: PresentationThemeReference
init(settings: AutomaticThemeSwitchSetting) { init(settings: AutomaticThemeSwitchSetting) {
let trigger: PreparedAutomaticThemeSwitchTrigger let trigger: PreparedAutomaticThemeSwitchTrigger
@@ -514,7 +514,7 @@ public func updatedPresentationData(accountManager: AccountManager, applicationI
var effectiveChatWallpaper: TelegramWallpaper = currentWallpaper var effectiveChatWallpaper: TelegramWallpaper = currentWallpaper
if shouldSwitch { if shouldSwitch {
let automaticTheme: PresentationThemeReference = .builtin(themeSettings.automaticThemeSwitchSetting.theme) let automaticTheme = themeSettings.automaticThemeSwitchSetting.theme
if let themeSpecificWallpaper = themeSettings.themeSpecificChatWallpapers[automaticTheme.index] { if let themeSpecificWallpaper = themeSettings.themeSpecificChatWallpapers[automaticTheme.index] {
effectiveChatWallpaper = themeSpecificWallpaper effectiveChatWallpaper = themeSpecificWallpaper
} }

View File

@@ -66,6 +66,10 @@ final class ThemeUpdateManagerImpl: ThemeUpdateManager {
validIds.insert(themeSettings.theme.index) validIds.insert(themeSettings.theme.index)
themes[themeSettings.theme.index] = (themeSettings.theme, false) themes[themeSettings.theme.index] = (themeSettings.theme, false)
} }
if case .cloud = themeSettings.automaticThemeSwitchSetting.theme, themeSettings.automaticThemeSwitchSetting.trigger != .none {
validIds.insert(themeSettings.automaticThemeSwitchSetting.theme.index)
themes[themeSettings.automaticThemeSwitchSetting.theme.index] = (themeSettings.automaticThemeSwitchSetting.theme, true)
}
if previousIds != validIds { if previousIds != validIds {
for id in validIds { for id in validIds {
@@ -126,7 +130,11 @@ final class ThemeUpdateManagerImpl: ThemeUpdateManager {
current = PresentationThemeSettings.defaultSettings current = PresentationThemeSettings.defaultSettings
} }
let chatWallpaper: TelegramWallpaper var chatWallpaper = current.chatWallpaper
var automaticThemeSwitchSetting = current.automaticThemeSwitchSetting
if isAutoNight {
automaticThemeSwitchSetting.theme = updatedTheme
} else {
if let themeSpecificWallpaper = current.themeSpecificChatWallpapers[updatedTheme.index] { if let themeSpecificWallpaper = current.themeSpecificChatWallpapers[updatedTheme.index] {
chatWallpaper = themeSpecificWallpaper chatWallpaper = themeSpecificWallpaper
} else if let presentationTheme = presentationTheme { } else if let presentationTheme = presentationTheme {
@@ -138,8 +146,9 @@ final class ThemeUpdateManagerImpl: ThemeUpdateManager {
} else { } else {
chatWallpaper = current.chatWallpaper chatWallpaper = current.chatWallpaper
} }
}
return PresentationThemeSettings(chatWallpaper: chatWallpaper, theme: updatedTheme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: current.themeSpecificChatWallpapers, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) return PresentationThemeSettings(chatWallpaper: chatWallpaper, theme: updatedTheme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: current.themeSpecificChatWallpapers, fontSize: current.fontSize, automaticThemeSwitchSetting: automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations)
}) })
}).start() }).start()
} }

View File

@@ -271,21 +271,27 @@ public enum AutomaticThemeSwitchTrigger: PostboxCoding, Equatable {
public struct AutomaticThemeSwitchSetting: PostboxCoding, Equatable { public struct AutomaticThemeSwitchSetting: PostboxCoding, Equatable {
public var trigger: AutomaticThemeSwitchTrigger public var trigger: AutomaticThemeSwitchTrigger
public var theme: PresentationBuiltinThemeReference public var theme: PresentationThemeReference
public init(trigger: AutomaticThemeSwitchTrigger, theme: PresentationBuiltinThemeReference) { public init(trigger: AutomaticThemeSwitchTrigger, theme: PresentationThemeReference) {
self.trigger = trigger self.trigger = trigger
self.theme = theme self.theme = theme
} }
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
self.trigger = decoder.decodeObjectForKey("trigger", decoder: { AutomaticThemeSwitchTrigger(decoder: $0) }) as! AutomaticThemeSwitchTrigger self.trigger = decoder.decodeObjectForKey("trigger", decoder: { AutomaticThemeSwitchTrigger(decoder: $0) }) as! AutomaticThemeSwitchTrigger
self.theme = PresentationBuiltinThemeReference(rawValue: decoder.decodeInt32ForKey("theme", orElse: 0))! if let theme = decoder.decodeObjectForKey("theme_v2", decoder: { PresentationThemeReference(decoder: $0) }) as? PresentationThemeReference {
self.theme = theme
} else if let legacyValue = decoder.decodeOptionalInt32ForKey("theme") {
self.theme = .builtin(PresentationBuiltinThemeReference(rawValue: legacyValue) ?? .nightAccent)
} else {
self.theme = .builtin(.nightAccent)
}
} }
public func encode(_ encoder: PostboxEncoder) { public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.trigger, forKey: "trigger") encoder.encodeObject(self.trigger, forKey: "trigger")
encoder.encodeInt32(self.theme.rawValue, forKey: "theme") encoder.encodeObject(self.theme, forKey: "theme_v2")
} }
} }
@@ -443,7 +449,7 @@ public struct PresentationThemeSettings: PreferencesEntry {
} }
public static var defaultSettings: PresentationThemeSettings { public static var defaultSettings: PresentationThemeSettings {
return PresentationThemeSettings(chatWallpaper: .builtin(WallpaperSettings()), theme: .builtin(.dayClassic), themeSpecificAccentColors: [:], themeSpecificChatWallpapers: [:], fontSize: .regular, automaticThemeSwitchSetting: AutomaticThemeSwitchSetting(trigger: .none, theme: .nightAccent), largeEmoji: true, disableAnimations: true) return PresentationThemeSettings(chatWallpaper: .builtin(WallpaperSettings()), theme: .builtin(.dayClassic), themeSpecificAccentColors: [:], themeSpecificChatWallpapers: [:], fontSize: .regular, automaticThemeSwitchSetting: AutomaticThemeSwitchSetting(trigger: .none, theme: .builtin(.nightAccent)), largeEmoji: true, disableAnimations: true)
} }
public init(chatWallpaper: TelegramWallpaper, theme: PresentationThemeReference, themeSpecificAccentColors: [Int64: PresentationThemeAccentColor], themeSpecificChatWallpapers: [Int64: TelegramWallpaper], fontSize: PresentationFontSize, automaticThemeSwitchSetting: AutomaticThemeSwitchSetting, largeEmoji: Bool, disableAnimations: Bool) { public init(chatWallpaper: TelegramWallpaper, theme: PresentationThemeReference, themeSpecificAccentColors: [Int64: PresentationThemeAccentColor], themeSpecificChatWallpapers: [Int64: TelegramWallpaper], fontSize: PresentationFontSize, automaticThemeSwitchSetting: AutomaticThemeSwitchSetting, largeEmoji: Bool, disableAnimations: Bool) {
@@ -499,7 +505,7 @@ public struct PresentationThemeSettings: PreferencesEntry {
} }
self.fontSize = PresentationFontSize(rawValue: decoder.decodeInt32ForKey("f", orElse: PresentationFontSize.regular.rawValue)) ?? .regular self.fontSize = PresentationFontSize(rawValue: decoder.decodeInt32ForKey("f", orElse: PresentationFontSize.regular.rawValue)) ?? .regular
self.automaticThemeSwitchSetting = (decoder.decodeObjectForKey("automaticThemeSwitchSetting", decoder: { AutomaticThemeSwitchSetting(decoder: $0) }) as? AutomaticThemeSwitchSetting) ?? AutomaticThemeSwitchSetting(trigger: .none, theme: .nightAccent) self.automaticThemeSwitchSetting = (decoder.decodeObjectForKey("automaticThemeSwitchSetting", decoder: { AutomaticThemeSwitchSetting(decoder: $0) }) as? AutomaticThemeSwitchSetting) ?? AutomaticThemeSwitchSetting(trigger: .none, theme: .builtin(.nightAccent))
self.largeEmoji = decoder.decodeBoolForKey("largeEmoji", orElse: true) self.largeEmoji = decoder.decodeBoolForKey("largeEmoji", orElse: true)
self.disableAnimations = decoder.decodeBoolForKey("disableAnimations", orElse: true) self.disableAnimations = decoder.decodeBoolForKey("disableAnimations", orElse: true)
} }