From 240d93c1573b7604294ace007839df81abaa764b Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 26 Dec 2019 22:10:16 +0300 Subject: [PATCH] Theme fixes --- .../Sources/Themes/EditThemeController.swift | 2 +- .../Themes/ThemeAccentColorController.swift | 14 +++++----- .../ThemeAccentColorControllerNode.swift | 12 ++++----- .../Themes/ThemePreviewController.swift | 2 +- .../Themes/ThemeSettingsController.swift | 26 ++++++++++++++----- .../Themes/WallpaperColorPanelNode.swift | 2 +- .../Themes/WallpaperGalleryController.swift | 6 ++--- .../TelegramUI/OpenChatMessage.swift | 4 +-- .../TelegramUI/OpenResolvedUrl.swift | 4 +-- 9 files changed, 43 insertions(+), 29 deletions(-) diff --git a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift index 728bad5cb1..1787297084 100644 --- a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift +++ b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift @@ -290,7 +290,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll if let wallpaper = wallpaper { return theme.withUpdated(name: nil, defaultWallpaper: wallpaper.wallpaper) } else { - return theme.withUpdated(name: nil, defaultWallpaper: .color(Int32(bitPattern: theme.chatList.backgroundColor.rgb))) + return theme.withUpdated(name: nil, defaultWallpaper: .color(Int32(bitPattern: theme.chatList.backgroundColor.argb))) } })) } else { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift index 0961a2f17f..072080e977 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift @@ -152,8 +152,8 @@ final class ThemeAccentColorController: ViewController { var coloredWallpaper: TelegramWallpaper? if let backgroundColors = state.backgroundColors { - let color = Int32(bitPattern: backgroundColors.0.rgb) - let bottomColor = backgroundColors.1.flatMap { Int32(bitPattern: $0.rgb) } + let color = Int32(bitPattern: backgroundColors.0.argb) + let bottomColor = backgroundColors.1.flatMap { Int32(bitPattern: $0.argb) } if let patternWallpaper = state.patternWallpaper { coloredWallpaper = patternWallpaper.withUpdatedSettings(WallpaperSettings(motion: state.motion, color: color, bottomColor: bottomColor, intensity: state.patternIntensity, rotation: state.rotation)) @@ -167,7 +167,7 @@ final class ThemeAccentColorController: ViewController { let prepare: Signal if let patternWallpaper = state.patternWallpaper, case let .file(file) = patternWallpaper, let backgroundColors = state.backgroundColors { let resource = file.file.resource - let representation = CachedPatternWallpaperRepresentation(color: Int32(bitPattern: backgroundColors.0.rgb), bottomColor: backgroundColors.1.flatMap { Int32(bitPattern: $0.rgb) }, intensity: state.patternIntensity, rotation: state.rotation) + let representation = CachedPatternWallpaperRepresentation(color: Int32(bitPattern: backgroundColors.0.argb), bottomColor: backgroundColors.1.flatMap { Int32(bitPattern: $0.argb) }, intensity: state.patternIntensity, rotation: state.rotation) var data: Data? if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) { @@ -218,7 +218,7 @@ final class ThemeAccentColorController: ViewController { if hasSettings, let baseTheme = baseTheme { var messageColors: (Int32, Int32)? if let colors = state.messagesColors { - messageColors = (Int32(bitPattern: colors.0.rgb), Int32(bitPattern: colors.1?.rgb ?? colors.0.rgb)) + messageColors = (Int32(bitPattern: colors.0.argb), Int32(bitPattern: colors.1?.argb ?? colors.0.argb)) } settings = TelegramThemeSettings(baseTheme: baseTheme, accentColor: state.accentColor, messageColors: state.messagesColors, wallpaper: coloredWallpaper) @@ -473,7 +473,7 @@ final class ThemeAccentColorController: ViewController { if let colors = themeSettings.messageColors { let topMessageColor = UIColor(argb: UInt32(bitPattern: colors.top)) let bottomMessageColor = UIColor(argb: UInt32(bitPattern: colors.bottom)) - if topMessageColor.rgb == bottomMessageColor.rgb { + if topMessageColor.argb == bottomMessageColor.argb { messageColors = (topMessageColor, nil) } else { messageColors = (topMessageColor, bottomMessageColor) @@ -545,7 +545,7 @@ final class ThemeAccentColorController: ViewController { let topMessageColor = theme.chat.message.outgoing.bubble.withWallpaper.fill let bottomMessageColor = theme.chat.message.outgoing.bubble.withWallpaper.gradientFill - if topMessageColor.rgb == bottomMessageColor.rgb { + if topMessageColor.argb == bottomMessageColor.argb { messageColors = (topMessageColor, nil) } else { messageColors = (topMessageColor, bottomMessageColor) @@ -565,7 +565,7 @@ final class ThemeAccentColorController: ViewController { let topMessageColor = theme.chat.message.outgoing.bubble.withWallpaper.fill let bottomMessageColor = theme.chat.message.outgoing.bubble.withWallpaper.gradientFill - if topMessageColor.rgb == bottomMessageColor.rgb { + if topMessageColor.argb == bottomMessageColor.argb { messageColors = (topMessageColor, nil) } else { messageColors = (topMessageColor, bottomMessageColor) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift index a12c10070e..531f1531f6 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift @@ -423,8 +423,8 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate if let backgroundColors = backgroundColors { if let patternWallpaper = state.patternWallpaper, case let .file(file) = patternWallpaper { - let color = Int32(bitPattern: backgroundColors.0.rgb) - let bottomColor = backgroundColors.1.flatMap { Int32(bitPattern: $0.rgb) } + let color = Int32(bitPattern: backgroundColors.0.argb) + let bottomColor = backgroundColors.1.flatMap { Int32(bitPattern: $0.argb) } wallpaper = patternWallpaper.withUpdatedSettings(WallpaperSettings(motion: state.motion, color: color, bottomColor: bottomColor, intensity: state.patternIntensity, rotation: state.rotation)) let dimensions = file.file.dimensions ?? PixelDimensions(width: 100, height: 100) @@ -436,10 +436,10 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate wallpaperSignal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: true) } else if let bottomColor = backgroundColors.1 { - wallpaper = .gradient(Int32(bitPattern: backgroundColors.0.rgb), Int32(bitPattern: bottomColor.rgb), WallpaperSettings(rotation: state.rotation)) + wallpaper = .gradient(Int32(bitPattern: backgroundColors.0.argb), Int32(bitPattern: bottomColor.argb), WallpaperSettings(rotation: state.rotation)) wallpaperSignal = gradientImage([backgroundColors.0, bottomColor], rotation: state.rotation) } else { - wallpaper = .color(Int32(bitPattern: backgroundColors.0.rgb)) + wallpaper = .color(Int32(bitPattern: backgroundColors.0.argb)) } } else if let themeReference = mode.themeReference, case let .builtin(theme) = themeReference, state.initialWallpaper == nil { var suggestedWallpaper: TelegramWallpaper @@ -447,12 +447,12 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate case .dayClassic: let topColor = accentColor.withMultiplied(hue: 1.010, saturation: 0.414, brightness: 0.957) let bottomColor = accentColor.withMultiplied(hue: 1.019, saturation: 0.867, brightness: 0.965) - suggestedWallpaper = .gradient(Int32(bitPattern: topColor.rgb), Int32(bitPattern: bottomColor.rgb), WallpaperSettings()) + suggestedWallpaper = .gradient(Int32(bitPattern: topColor.argb), Int32(bitPattern: bottomColor.argb), WallpaperSettings()) wallpaperSignal = gradientImage([topColor, bottomColor], rotation: state.rotation) backgroundColors = (topColor, bottomColor) case .nightAccent: let color = accentColor.withMultiplied(hue: 1.024, saturation: 0.573, brightness: 0.18) - suggestedWallpaper = .color(Int32(bitPattern: color.rgb)) + suggestedWallpaper = .color(Int32(bitPattern: color.argb)) backgroundColors = (color, nil) default: suggestedWallpaper = .builtin(WallpaperSettings()) diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift index 1872935f98..b28bffa2a8 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift @@ -207,7 +207,7 @@ public final class ThemePreviewController: ViewController { } else if case let .file(file) = previewTheme.chat.defaultWallpaper, file.id == 0 { self.controllerNode.wallpaperPromise.set(cachedWallpaper(account: self.context.account, slug: file.slug, settings: file.settings) |> mapToSignal { wallpaper in - return .single(wallpaper?.wallpaper ?? .color(Int32(bitPattern: previewTheme.chatList.backgroundColor.rgb))) + return .single(wallpaper?.wallpaper ?? .color(Int32(bitPattern: previewTheme.chatList.backgroundColor.argb))) }) } else { self.controllerNode.wallpaperPromise.set(.single(previewTheme.chat.defaultWallpaper)) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift index 9a997d6e43..d87bfb173c 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift @@ -539,6 +539,9 @@ 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 removedThemeIndexesPromise = Promise>(Set()) + let removedThemeIndexes = Atomic>(value: Set()) + let arguments = ThemeSettingsControllerArguments(context: context, selectTheme: { theme in selectThemeImpl?(theme) }, selectFontSize: { fontSize in @@ -700,7 +703,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The var items: [ActionSheetItem] = [] items.append(ActionSheetButtonItem(title: presentationData.strings.Appearance_RemoveThemeConfirmation, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() - let _ = (cloudThemes.get() |> delay(0.5, queue: Queue.mainQueue()) + let _ = (cloudThemes.get() |> take(1) |> deliverOnMainQueue).start(next: { themes in if isCurrent, let currentThemeIndex = themes.firstIndex(where: { $0.id == theme.theme.id }) { @@ -716,9 +719,14 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The } selectThemeImpl?(newTheme) } - } + removedThemeIndexesPromise.set(.single(removedThemeIndexes.modify({ value in + var updated = value + updated.insert(theme.theme.id) + return updated + }))) + let _ = deleteThemeInteractively(account: context.account, accountManager: context.sharedContext.accountManager, theme: theme.theme).start() }) })) @@ -896,7 +904,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The var items: [ActionSheetItem] = [] items.append(ActionSheetButtonItem(title: presentationData.strings.Appearance_RemoveThemeConfirmation, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() - let _ = (cloudThemes.get() |> delay(0.5, queue: Queue.mainQueue()) + let _ = (cloudThemes.get() |> take(1) |> deliverOnMainQueue).start(next: { themes in if isCurrent, let settings = cloudTheme.theme.settings { @@ -919,6 +927,12 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The } } + removedThemeIndexesPromise.set(.single(removedThemeIndexes.modify({ value in + var updated = value + updated.insert(cloudTheme.theme.id) + return updated + }))) + let _ = deleteThemeInteractively(account: context.account, accountManager: context.sharedContext.accountManager, theme: cloudTheme.theme).start() }) })) @@ -940,8 +954,8 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The let previousThemeReference = Atomic(value: nil) let previousAccentColor = Atomic(value: nil) - let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.presentationThemeSettings]), cloudThemes.get(), availableAppIcons, currentAppIconName.get()) - |> map { presentationData, sharedData, cloudThemes, availableAppIcons, currentAppIconName -> (ItemListControllerState, (ItemListNodeState, Any)) in + let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.presentationThemeSettings]), cloudThemes.get(), availableAppIcons, currentAppIconName.get(), removedThemeIndexesPromise.get()) + |> map { presentationData, sharedData, cloudThemes, availableAppIcons, currentAppIconName, removedThemeIndexes -> (ItemListControllerState, (ItemListNodeState, Any)) in let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings let fontSize = presentationData.fontSize @@ -969,7 +983,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The } defaultThemes.append(contentsOf: [.builtin(.night), .builtin(.nightAccent)]) - let cloudThemes: [PresentationThemeReference] = cloudThemes.map { .cloud(PresentationCloudTheme(theme: $0, resolvedWallpaper: nil)) } + let cloudThemes: [PresentationThemeReference] = cloudThemes.map { .cloud(PresentationCloudTheme(theme: $0, resolvedWallpaper: nil)) }.filter { !removedThemeIndexes.contains($0.index) } var availableThemes = defaultThemes if defaultThemes.first(where: { $0.index == themeReference.index }) == nil && cloudThemes.first(where: { $0.index == themeReference.index }) == nil { diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift index 7d7b3adc7c..f3510c90ef 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift @@ -574,7 +574,7 @@ final class WallpaperColorPanelNode: ASDisplayNode { self.updateLayout(size: size, transition: animated ? .animated(duration: 0.3, curve: .easeInOut) : .immediate) } - if self.state.firstColor?.rgb != previousFirstColor?.rgb || self.state.secondColor?.rgb != previousSecondColor?.rgb || self.state.preview != previousPreview { + if self.state.firstColor?.argb != previousFirstColor?.argb || self.state.secondColor?.argb != previousSecondColor?.argb || self.state.preview != previousPreview { self.colorsChanged?(firstColorIsDefault ? nil : firstColor, secondColor, !self.state.preview) } } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index 66d72abd63..449c4cbc31 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -111,14 +111,14 @@ private func updatedFileWallpaper(id: Int64? = nil, accessHash: Int64? = nil, sl var secondColorValue: Int32? var intensityValue: Int32? if let firstColor = firstColor { - firstColorValue = Int32(bitPattern: firstColor.rgb) + firstColorValue = Int32(bitPattern: firstColor.argb) intensityValue = intensity } else if isPattern { firstColorValue = 0xd6e2ee intensityValue = 50 } if let secondColor = secondColor { - secondColorValue = Int32(bitPattern: secondColor.rgb) + secondColorValue = Int32(bitPattern: secondColor.argb) } return .file(id: id ?? 0, accessHash: accessHash ?? 0, isCreator: false, isDefault: false, isPattern: isPattern, isDark: false, slug: slug, file: file, settings: WallpaperSettings(color: firstColorValue, bottomColor: secondColorValue, intensity: intensityValue, rotation: rotation)) @@ -554,7 +554,7 @@ public class WallpaperGalleryController: ViewController { case let .wallpaper(wallpaper, _): switch wallpaper { case .color: - currentEntry = .wallpaper(.color(Int32(color.rgb)), nil) + currentEntry = .wallpaper(.color(Int32(color.argb)), nil) default: break } diff --git a/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift b/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift index 8efcfea57d..00c66d895f 100644 --- a/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift +++ b/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift @@ -514,9 +514,9 @@ func openChatWallpaper(context: AccountContext, message: Message, present: @esca case let .slug(slug, options, firstColor, secondColor, intensity, rotation): source = .slug(slug, content.file, options, firstColor, secondColor, intensity, rotation, message) case let .color(color): - source = .wallpaper(.color(Int32(color.rgb)), nil, nil, nil, nil, nil, message) + source = .wallpaper(.color(Int32(color.argb)), nil, nil, nil, nil, nil, message) case let .gradient(topColor, bottomColor, rotation): - source = .wallpaper(.gradient(Int32(topColor.rgb), Int32(bottomColor.rgb), WallpaperSettings(rotation: rotation)), nil, nil, nil, nil, rotation, message) + source = .wallpaper(.gradient(Int32(topColor.argb), Int32(bottomColor.argb), WallpaperSettings(rotation: rotation)), nil, nil, nil, nil, rotation, message) } let controller = WallpaperGalleryController(context: context, source: source) diff --git a/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift b/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift index b925a93939..63770b1c89 100644 --- a/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift @@ -264,9 +264,9 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) present(controller!, nil) case let .color(color): - signal = .single(.color(Int32(color.rgb))) + signal = .single(.color(Int32(color.argb))) case let .gradient(topColor, bottomColor, rotation): - signal = .single(.gradient(Int32(topColor.rgb), Int32(bottomColor.rgb), WallpaperSettings())) + signal = .single(.gradient(Int32(topColor.argb), Int32(bottomColor.argb), WallpaperSettings())) } let _ = (signal