diff --git a/submodules/LegacyDataImport/Sources/LegacyPreferencesImport.swift b/submodules/LegacyDataImport/Sources/LegacyPreferencesImport.swift index 25f27cc612..8038feac0e 100644 --- a/submodules/LegacyDataImport/Sources/LegacyPreferencesImport.swift +++ b/submodules/LegacyDataImport/Sources/LegacyPreferencesImport.swift @@ -215,11 +215,11 @@ func importLegacyPreferences(accountManager: AccountManager, account: TemporaryA } switch autoNightPreferences.mode { 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: - 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: - settings.automaticThemeSwitchSetting = AutomaticThemeSwitchSetting(trigger: .brightness(threshold: Double(autoNightPreferences.brightnessThreshold)), theme: nightTheme) + settings.automaticThemeSwitchSetting = AutomaticThemeSwitchSetting(trigger: .brightness(threshold: Double(autoNightPreferences.brightnessThreshold)), theme: .builtin(nightTheme)) default: break } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightSettingsController.swift index dc23c933cc..68a10725da 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightSettingsController.swift @@ -24,14 +24,16 @@ private enum TimeBasedManualField { } private final class ThemeAutoNightSettingsControllerArguments { + let context: AccountContext let updateMode: (TriggerMode) -> Void let updateTimeBasedAutomatic: (Bool) -> Void let openTimeBasedManual: (TimeBasedManualField) -> Void let updateTimeBasedAutomaticLocation: () -> 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.updateTimeBasedAutomatic = updateTimeBasedAutomatic self.openTimeBasedManual = openTimeBasedManual @@ -61,8 +63,7 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry { case settingInfo(PresentationTheme, String) case themeHeader(PresentationTheme, String) - case themeNightBlue(PresentationTheme, String, Bool) - case themeNight(PresentationTheme, String, Bool) + case themeItem(PresentationTheme, PresentationStrings, [PresentationThemeReference], PresentationThemeReference, [Int64: PresentationThemeAccentColor]) var section: ItemListSectionId { switch self { @@ -70,7 +71,7 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry { return ThemeAutoNightSettingsControllerSection.mode.rawValue case .settingsHeader, .timeBasedAutomaticLocation, .timeBasedAutomaticLocationValue, .timeBasedManualFrom, .timeBasedManualTo, .brightnessValue, .settingInfo: return ThemeAutoNightSettingsControllerSection.settings.rawValue - case .themeHeader, .themeNightBlue, .themeNight: + case .themeHeader, .themeItem: return ThemeAutoNightSettingsControllerSection.theme.rawValue } } @@ -99,10 +100,8 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry { return 9 case .themeHeader: return 10 - case .themeNightBlue: + case .themeItem: return 11 - case .themeNight: - return 12 } } @@ -174,14 +173,8 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry { } else { return false } - case let .themeNightBlue(lhsTheme, lhsTitle, lhsValue): - if case let .themeNightBlue(rhsTheme, rhsTitle, rhsValue) = rhs, lhsTheme === rhsTheme, lhsTitle == rhsTitle, lhsValue == rhsValue { - 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 { + case let .themeItem(lhsTheme, lhsStrings, lhsThemes, lhsCurrentTheme, lhsThemeAccentColors): + 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 @@ -233,19 +226,16 @@ private enum ThemeAutoNightSettingsControllerEntry: ItemListNodeEntry { return ItemListTextItem(theme: theme, text: .plain(text), sectionId: self.section) case let .themeHeader(theme, title): return ItemListSectionHeaderItem(theme: theme, text: title, sectionId: self.section) - case let .themeNightBlue(theme, title, value): - return ItemListCheckboxItem(theme: theme, title: title, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { - arguments.updateTheme(.nightAccent) - }) - 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) + 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 + arguments.updateTheme(theme) + }, longTapped: { _ in }) } } } -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] = [] let activeTriggerMode: TriggerMode @@ -297,8 +287,7 @@ private func themeAutoNightSettingsControllerEntries(theme: PresentationTheme, s break case .timeBased, .brightness: entries.append(.themeHeader(theme, strings.AutoNightTheme_PreferredTheme)) - entries.append(.themeNightBlue(theme, strings.Appearance_ThemeCarouselTintedNight, switchSetting.theme == .nightAccent)) - entries.append(.themeNight(theme, strings.Appearance_ThemeCarouselNewNight, switchSetting.theme == .night)) + entries.append(.themeItem(theme, strings, availableThemes, switchSetting.theme, settings.themeSpecificAccentColors)) } return entries @@ -389,7 +378,7 @@ public func themeAutoNightSettingsController(context: AccountContext) -> ViewCon updateLocationDisposable.set(disposable) } - let arguments = ThemeAutoNightSettingsControllerArguments(updateMode: { mode in + let arguments = ThemeAutoNightSettingsControllerArguments(context: context, updateMode: { mode in var updateLocation = false updateSettings { settings in 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) - |> map { presentationData, sharedData, stagingSettings -> (ItemListControllerState, (ItemListNodeState, ThemeAutoNightSettingsControllerEntry.ItemGenerationArguments)) in + let cloudThemes = Promise<[TelegramTheme]>() + 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.ItemGenerationArguments)) in 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 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)) } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeNameGenerator.swift b/submodules/SettingsUI/Sources/Themes/ThemeNameGenerator.swift index e45c190e37..30e62dbc18 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeNameGenerator.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeNameGenerator.swift @@ -103,7 +103,6 @@ private let colors: [UInt32: String] = [ ] private let adjectives = [ - "Always", "Ancient", "Antique", "Autumn", diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift index 7c29d9a472..fd3627c7f6 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift @@ -87,12 +87,15 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { 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.motionEnabled = previewTheme.chat.defaultWallpaper.settings?.motion ?? false + self.instantChatBackgroundNode.view.contentMode = .scaleAspectFill self.remoteChatBackgroundNode = TransformImageNode() self.remoteChatBackgroundNode.backgroundColor = previewTheme.chatList.backgroundColor + self.remoteChatBackgroundNode.view.contentMode = .scaleAspectFill self.blurredNode = BlurredImageNode() self.blurredNode.clipsToBounds = true + self.blurredNode.blurView.contentMode = .scaleAspectFill self.toolbarNode = WallpaperGalleryToolbarNode(theme: self.previewTheme, strings: self.presentationData.strings) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift index 73d7ff6082..ee5d080a37 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift @@ -36,7 +36,7 @@ func themeDisplayName(strings: PresentationStrings, reference: PresentationTheme private final class ThemeSettingsControllerArguments { let context: AccountContext - let selectTheme: (PresentationThemeReference) -> Void + let updateTheme: (PresentationThemeReference) -> Void let selectFontSize: (PresentationFontSize) -> Void let openWallpaperSettings: () -> Void let selectAccentColor: (PresentationThemeAccentColor) -> Void @@ -48,9 +48,9 @@ private final class ThemeSettingsControllerArguments { let presentThemeMenu: (PresentationThemeReference, Bool) -> 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.selectTheme = selectTheme + self.updateTheme = updateTheme self.selectFontSize = selectFontSize self.openWallpaperSettings = openWallpaperSettings self.selectAccentColor = selectAccentColor @@ -290,14 +290,14 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { }) case let .themeListHeader(theme, text): 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 if case let .cloud(theme) = theme, theme.theme.file == nil { if theme.theme.isCreator { arguments.editTheme(theme) } } else { - arguments.selectTheme(theme) + arguments.updateTheme(theme) } }, longTapped: { theme in arguments.presentThemeMenu(theme, theme.index == currentTheme.index) @@ -370,7 +370,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The var presentControllerImpl: ((ViewController, Any?) -> Void)? var getNavigationControllerImpl: (() -> NavigationController?)? - var selectThemeImpl: ((PresentationThemeReference) -> Void)? + var updateThemeImpl: ((PresentationThemeReference) -> Void)? var moreImpl: (() -> Void)? 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) cloudThemes.set(updatedCloudThemes) - let arguments = ThemeSettingsControllerArguments(context: context, selectTheme: { theme in - selectThemeImpl?(theme) + let arguments = ThemeSettingsControllerArguments(context: context, updateTheme: { theme in + updateThemeImpl?(theme) }, selectFontSize: { size 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) @@ -474,7 +474,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The } else { newTheme = .builtin(.nightAccent) } - selectThemeImpl?(newTheme) + updateThemeImpl?(newTheme) } 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 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 resolvedWallpaper: Signal diff --git a/submodules/TelegramPresentationData/Sources/PresentationData.swift b/submodules/TelegramPresentationData/Sources/PresentationData.swift index daf5512ea4..c38327099b 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationData.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationData.swift @@ -254,7 +254,7 @@ public func currentPresentationDataAndSettings(accountManager: AccountManager) - let parameters = AutomaticThemeSwitchParameters(settings: themeSettings.automaticThemeSwitchSetting) if automaticThemeShouldSwitchNow(parameters, currentTheme: themeSettings.theme) { - effectiveTheme = .builtin(themeSettings.automaticThemeSwitchSetting.theme) + effectiveTheme = themeSettings.automaticThemeSwitchSetting.theme } else { effectiveTheme = themeSettings.theme } @@ -301,7 +301,7 @@ private enum PreparedAutomaticThemeSwitchTrigger { private struct AutomaticThemeSwitchParameters { let trigger: PreparedAutomaticThemeSwitchTrigger - let theme: PresentationBuiltinThemeReference + let theme: PresentationThemeReference init(settings: AutomaticThemeSwitchSetting) { let trigger: PreparedAutomaticThemeSwitchTrigger @@ -514,7 +514,7 @@ public func updatedPresentationData(accountManager: AccountManager, applicationI var effectiveChatWallpaper: TelegramWallpaper = currentWallpaper if shouldSwitch { - let automaticTheme: PresentationThemeReference = .builtin(themeSettings.automaticThemeSwitchSetting.theme) + let automaticTheme = themeSettings.automaticThemeSwitchSetting.theme if let themeSpecificWallpaper = themeSettings.themeSpecificChatWallpapers[automaticTheme.index] { effectiveChatWallpaper = themeSpecificWallpaper } diff --git a/submodules/TelegramUI/TelegramUI/ThemeUpdateManager.swift b/submodules/TelegramUI/TelegramUI/ThemeUpdateManager.swift index 79b60e573e..be6dc72e98 100644 --- a/submodules/TelegramUI/TelegramUI/ThemeUpdateManager.swift +++ b/submodules/TelegramUI/TelegramUI/ThemeUpdateManager.swift @@ -66,6 +66,10 @@ final class ThemeUpdateManagerImpl: ThemeUpdateManager { validIds.insert(themeSettings.theme.index) 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 { for id in validIds { @@ -126,20 +130,25 @@ final class ThemeUpdateManagerImpl: ThemeUpdateManager { current = PresentationThemeSettings.defaultSettings } - let chatWallpaper: TelegramWallpaper - if let themeSpecificWallpaper = current.themeSpecificChatWallpapers[updatedTheme.index] { - chatWallpaper = themeSpecificWallpaper - } else if let presentationTheme = presentationTheme { - if case let .cloud(info) = updatedTheme, let resolvedWallpaper = info.resolvedWallpaper { - chatWallpaper = resolvedWallpaper - } else { - chatWallpaper = presentationTheme.chat.defaultWallpaper - } + var chatWallpaper = current.chatWallpaper + var automaticThemeSwitchSetting = current.automaticThemeSwitchSetting + if isAutoNight { + automaticThemeSwitchSetting.theme = updatedTheme } else { - chatWallpaper = current.chatWallpaper + if let themeSpecificWallpaper = current.themeSpecificChatWallpapers[updatedTheme.index] { + chatWallpaper = themeSpecificWallpaper + } else if let presentationTheme = presentationTheme { + if case let .cloud(info) = updatedTheme, let resolvedWallpaper = info.resolvedWallpaper { + chatWallpaper = resolvedWallpaper + } else { + chatWallpaper = presentationTheme.chat.defaultWallpaper + } + } else { + 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() } diff --git a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift index e8eae936c2..b3d2a9cde4 100644 --- a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift @@ -271,21 +271,27 @@ public enum AutomaticThemeSwitchTrigger: PostboxCoding, Equatable { public struct AutomaticThemeSwitchSetting: PostboxCoding, Equatable { 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.theme = theme } public init(decoder: PostboxDecoder) { 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) { 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 { - 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) { @@ -499,7 +505,7 @@ public struct PresentationThemeSettings: PreferencesEntry { } 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.disableAnimations = decoder.decodeBoolForKey("disableAnimations", orElse: true) }