mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Reset theme-specific wallpaper on repeated save
Show theme-default wallpaper in wallpapers list
This commit is contained in:
@@ -177,23 +177,14 @@ final class ThemeGridController: ViewController {
|
|||||||
}
|
}
|
||||||
for wallpaper in wallpapers {
|
for wallpaper in wallpapers {
|
||||||
if wallpaper == strongSelf.presentationData.chatWallpaper {
|
if wallpaper == strongSelf.presentationData.chatWallpaper {
|
||||||
|
let presentationData = strongSelf.presentationData
|
||||||
let _ = (updatePresentationThemeSettingsInteractively(accountManager: strongSelf.context.sharedContext.accountManager, { current in
|
let _ = (updatePresentationThemeSettingsInteractively(accountManager: strongSelf.context.sharedContext.accountManager, { current in
|
||||||
var fallbackWallpaper: TelegramWallpaper = .builtin(WallpaperSettings())
|
var fallbackWallpaper = presentationData.theme.chat.defaultWallpaper
|
||||||
if case let .builtin(theme) = current.theme {
|
if case let .cloud(info) = current.theme, let resolvedWallpaper = info.resolvedWallpaper {
|
||||||
switch theme {
|
fallbackWallpaper = resolvedWallpaper
|
||||||
case .day:
|
|
||||||
fallbackWallpaper = .color(0xffffff)
|
|
||||||
case .night:
|
|
||||||
fallbackWallpaper = .color(0x000000)
|
|
||||||
case .nightAccent:
|
|
||||||
fallbackWallpaper = .color(0x18222d)
|
|
||||||
default:
|
|
||||||
fallbackWallpaper = .builtin(WallpaperSettings())
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers
|
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)
|
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()
|
})).start()
|
||||||
break
|
break
|
||||||
@@ -243,6 +234,7 @@ final class ThemeGridController: ViewController {
|
|||||||
strongSelf.present(controller, in: .window(.root))
|
strongSelf.present(controller, in: .window(.root))
|
||||||
|
|
||||||
let _ = resetWallpapers(account: strongSelf.context.account).start(completed: { [weak self, weak controller] in
|
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
|
let _ = (strongSelf.context.sharedContext.accountManager.transaction { transaction -> Void in
|
||||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings, { entry in
|
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings, { entry in
|
||||||
let current: PresentationThemeSettings
|
let current: PresentationThemeSettings
|
||||||
@@ -251,22 +243,13 @@ final class ThemeGridController: ViewController {
|
|||||||
} else {
|
} else {
|
||||||
current = PresentationThemeSettings.defaultSettings
|
current = PresentationThemeSettings.defaultSettings
|
||||||
}
|
}
|
||||||
let wallpaper: TelegramWallpaper
|
var fallbackWallpaper = presentationData.theme.chat.defaultWallpaper
|
||||||
if case let .builtin(theme) = current.theme {
|
if case let .cloud(info) = current.theme, let resolvedWallpaper = info.resolvedWallpaper {
|
||||||
switch theme {
|
fallbackWallpaper = resolvedWallpaper
|
||||||
case .day:
|
|
||||||
wallpaper = .color(0xffffff)
|
|
||||||
case .night:
|
|
||||||
wallpaper = .color(0x000000)
|
|
||||||
case .nightAccent:
|
|
||||||
wallpaper = .color(0x18222d)
|
|
||||||
default:
|
|
||||||
wallpaper = .builtin(WallpaperSettings())
|
|
||||||
}
|
}
|
||||||
} else {
|
var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers
|
||||||
wallpaper = .builtin(WallpaperSettings())
|
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)
|
||||||
return PresentationThemeSettings(chatWallpaper: wallpaper, theme: current.theme, themeSpecificAccentColors: current.themeSpecificAccentColors, themeSpecificChatWallpapers: [:], fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations)
|
|
||||||
})
|
})
|
||||||
}).start()
|
}).start()
|
||||||
|
|
||||||
|
|||||||
@@ -366,6 +366,16 @@ final class ThemeGridControllerNode: ASDisplayNode {
|
|||||||
|
|
||||||
entries.insert(ThemeGridControllerEntry(index: 0, wallpaper: presentationData.chatWallpaper, selected: true), at: 0)
|
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] = []
|
var sortedWallpapers: [TelegramWallpaper] = []
|
||||||
if presentationData.theme.overallDarkAppearance {
|
if presentationData.theme.overallDarkAppearance {
|
||||||
var darkWallpapers: [TelegramWallpaper] = []
|
var darkWallpapers: [TelegramWallpaper] = []
|
||||||
@@ -386,7 +396,11 @@ final class ThemeGridControllerNode: ASDisplayNode {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let selected = areWallpapersEqual(presentationData.chatWallpaper, wallpaper)
|
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))
|
entries.append(ThemeGridControllerEntry(index: index, wallpaper: wallpaper, selected: false))
|
||||||
}
|
}
|
||||||
index += 1
|
index += 1
|
||||||
|
|||||||
@@ -249,7 +249,9 @@ public final class ThemePreviewController: ViewController {
|
|||||||
return context.sharedContext.accountManager.transaction { transaction -> Void in
|
return context.sharedContext.accountManager.transaction { transaction -> Void in
|
||||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings, { entry in
|
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings, { entry in
|
||||||
let current = entry as? PresentationThemeSettings ?? PresentationThemeSettings.defaultSettings
|
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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -851,7 +851,7 @@ public func themeImage(account: Account, accountManager: AccountManager, fileRef
|
|||||||
c.draw(thumbnailImage, in: CGRect(origin: CGPoint(), size: thumbnailContextSize))
|
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)
|
||||||
|
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))
|
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 {
|
if thumbnailContextFittingSize.width < 150.0 || thumbnailContextFittingSize.height < 150.0 {
|
||||||
thumbnailContextFittingSize = thumbnailContextFittingSize.aspectFilled(CGSize(width: 150.0, height: 150.0))
|
thumbnailContextFittingSize = thumbnailContextFittingSize.aspectFilled(CGSize(width: 150.0, height: 150.0))
|
||||||
|
|||||||
Reference in New Issue
Block a user