From 4d71ae195fb42349d65ca26b57870780795fbdb2 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 30 Aug 2019 12:26:43 +0300 Subject: [PATCH] Reset theme-specific wallpaper on repeated save Show theme-default wallpaper in wallpapers list --- .../Sources/Themes/ThemeGridController.swift | 41 ++++++------------- .../Themes/ThemeGridControllerNode.swift | 16 +++++++- .../Themes/ThemePreviewController.swift | 4 +- .../Sources/WallpaperResources.swift | 2 +- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift index e8a2c66b8a..c5b352c669 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift @@ -177,23 +177,14 @@ final class ThemeGridController: ViewController { } for wallpaper in wallpapers { if wallpaper == strongSelf.presentationData.chatWallpaper { + let presentationData = strongSelf.presentationData let _ = (updatePresentationThemeSettingsInteractively(accountManager: strongSelf.context.sharedContext.accountManager, { current in - var fallbackWallpaper: TelegramWallpaper = .builtin(WallpaperSettings()) - if case let .builtin(theme) = current.theme { - switch theme { - case .day: - fallbackWallpaper = .color(0xffffff) - case .night: - fallbackWallpaper = .color(0x000000) - case .nightAccent: - fallbackWallpaper = .color(0x18222d) - default: - fallbackWallpaper = .builtin(WallpaperSettings()) - } + var fallbackWallpaper = presentationData.theme.chat.defaultWallpaper + if case let .cloud(info) = current.theme, let resolvedWallpaper = info.resolvedWallpaper { + fallbackWallpaper = resolvedWallpaper } - var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers - themeSpecificChatWallpapers[current.theme.index] = fallbackWallpaper + themeSpecificChatWallpapers[current.theme.index] = nil return PresentationThemeSettings(chatWallpaper: fallbackWallpaper, theme: current.theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: themeSpecificChatWallpapers, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) })).start() break @@ -243,6 +234,7 @@ final class ThemeGridController: ViewController { strongSelf.present(controller, in: .window(.root)) let _ = resetWallpapers(account: strongSelf.context.account).start(completed: { [weak self, weak controller] in + let presentationData = strongSelf.presentationData let _ = (strongSelf.context.sharedContext.accountManager.transaction { transaction -> Void in transaction.updateSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings, { entry in let current: PresentationThemeSettings @@ -251,22 +243,13 @@ final class ThemeGridController: ViewController { } else { current = PresentationThemeSettings.defaultSettings } - let wallpaper: TelegramWallpaper - if case let .builtin(theme) = current.theme { - switch theme { - case .day: - wallpaper = .color(0xffffff) - case .night: - wallpaper = .color(0x000000) - case .nightAccent: - wallpaper = .color(0x18222d) - default: - wallpaper = .builtin(WallpaperSettings()) - } - } else { - wallpaper = .builtin(WallpaperSettings()) + var fallbackWallpaper = presentationData.theme.chat.defaultWallpaper + if case let .cloud(info) = current.theme, let resolvedWallpaper = info.resolvedWallpaper { + fallbackWallpaper = resolvedWallpaper } - return PresentationThemeSettings(chatWallpaper: wallpaper, theme: current.theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: [:], fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) + var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers + themeSpecificChatWallpapers[current.theme.index] = nil + return PresentationThemeSettings(chatWallpaper: fallbackWallpaper, theme: current.theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: [:], fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) }) }).start() diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift index 3334ad3b97..fce443bb25 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift @@ -366,6 +366,16 @@ final class ThemeGridControllerNode: ASDisplayNode { entries.insert(ThemeGridControllerEntry(index: 0, wallpaper: presentationData.chatWallpaper, selected: true), at: 0) + var defaultWallpaper: TelegramWallpaper? + if !areWallpapersEqual(presentationData.chatWallpaper, presentationData.theme.chat.defaultWallpaper) { + if case .builtin = presentationData.theme.chat.defaultWallpaper { + } else { + defaultWallpaper = presentationData.theme.chat.defaultWallpaper + entries.insert(ThemeGridControllerEntry(index: 1, wallpaper: presentationData.theme.chat.defaultWallpaper, selected: false), at: 1) + index += 1 + } + } + var sortedWallpapers: [TelegramWallpaper] = [] if presentationData.theme.overallDarkAppearance { var darkWallpapers: [TelegramWallpaper] = [] @@ -386,7 +396,11 @@ final class ThemeGridControllerNode: ASDisplayNode { continue } let selected = areWallpapersEqual(presentationData.chatWallpaper, wallpaper) - if !selected { + var isDefault = false + if let defaultWallpaper = defaultWallpaper, areWallpapersEqual(defaultWallpaper, wallpaper) { + isDefault = true + } + if !selected && !isDefault { entries.append(ThemeGridControllerEntry(index: index, wallpaper: wallpaper, selected: false)) } index += 1 diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift index 55b0411bd7..2729fd4a86 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift @@ -249,7 +249,9 @@ public final class ThemePreviewController: ViewController { return context.sharedContext.accountManager.transaction { transaction -> Void in transaction.updateSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings, { entry in let current = entry as? PresentationThemeSettings ?? PresentationThemeSettings.defaultSettings - return PresentationThemeSettings(chatWallpaper: resolvedWallpaper ?? previewTheme.chat.defaultWallpaper, theme: theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: current.themeSpecificChatWallpapers, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) + var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers + themeSpecificChatWallpapers[theme.index] = nil + return PresentationThemeSettings(chatWallpaper: resolvedWallpaper ?? previewTheme.chat.defaultWallpaper, theme: theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: themeSpecificChatWallpapers, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) }) } } diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 29075a0ec9..02bcd1d806 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -851,7 +851,7 @@ public func themeImage(account: Account, accountManager: AccountManager, fileRef c.draw(thumbnailImage, in: CGRect(origin: CGPoint(), size: thumbnailContextSize)) } telegramFastBlurMore(Int32(thumbnailContextSize.width), Int32(thumbnailContextSize.height), Int32(thumbnailContext.bytesPerRow), thumbnailContext.bytes) - + telegramFastBlurMore(Int32(thumbnailContextSize.width), Int32(thumbnailContextSize.height), Int32(thumbnailContext.bytesPerRow), thumbnailContext.bytes) var thumbnailContextFittingSize = CGSize(width: floor(arguments.drawingSize.width * 0.5), height: floor(arguments.drawingSize.width * 0.5)) if thumbnailContextFittingSize.width < 150.0 || thumbnailContextFittingSize.height < 150.0 { thumbnailContextFittingSize = thumbnailContextFittingSize.aspectFilled(CGSize(width: 150.0, height: 150.0))