diff --git a/submodules/MediaResources/Sources/CachedResourceRepresentations.swift b/submodules/MediaResources/Sources/CachedResourceRepresentations.swift index da317b350c..ea1cfbccc7 100644 --- a/submodules/MediaResources/Sources/CachedResourceRepresentations.swift +++ b/submodules/MediaResources/Sources/CachedResourceRepresentations.swift @@ -147,8 +147,8 @@ public final class CachedPatternWallpaperMaskRepresentation: CachedMediaResource public final class CachedPatternWallpaperRepresentation: CachedMediaResourceRepresentation { public let keepDuration: CachedMediaRepresentationKeepDuration = .general - public let color: Int32 - public let bottomColor: Int32? + public let color: UInt32 + public let bottomColor: UInt32? public let intensity: Int32 public let rotation: Int32? @@ -165,7 +165,7 @@ public final class CachedPatternWallpaperRepresentation: CachedMediaResourceRepr return id } - public init(color: Int32, bottomColor: Int32?, intensity: Int32, rotation: Int32?) { + public init(color: UInt32, bottomColor: UInt32?, intensity: Int32, rotation: Int32?) { self.color = color self.bottomColor = bottomColor self.intensity = intensity diff --git a/submodules/SegmentedControlNode/Sources/SegmentedControlNode.swift b/submodules/SegmentedControlNode/Sources/SegmentedControlNode.swift index 6d7100d238..da4106824a 100644 --- a/submodules/SegmentedControlNode/Sources/SegmentedControlNode.swift +++ b/submodules/SegmentedControlNode/Sources/SegmentedControlNode.swift @@ -143,6 +143,16 @@ public final class SegmentedControlNode: ASDisplayNode, UIGestureRecognizerDeleg } } + public func setSelectedIndex(_ index: Int, animated: Bool) { + guard index != self._selectedIndex else { + return + } + self._selectedIndex = index + if let layout = self.validLayout { + let _ = self.updateLayout(layout, transition: .animated(duration: 0.2, curve: .easeInOut)) + } + } + public var selectedIndexChanged: (Int) -> Void = { _ in } public var selectedIndexShouldChange: (Int, @escaping (Bool) -> Void) -> Void = { _, f in f(true) diff --git a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift index 1787297084..9b55729c2f 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.argb))) + return theme.withUpdated(name: nil, defaultWallpaper: .color(theme.chatList.backgroundColor.argb)) } })) } else { diff --git a/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift b/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift index 1208ef23e0..00055cedaf 100644 --- a/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift +++ b/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift @@ -91,7 +91,7 @@ final class SettingsThemeWallpaperNode: ASDisplayNode { apply() case let .color(color): let theme = context.sharedContext.currentPresentationData.with { $0 }.theme - let uiColor = UIColor(rgb: UInt32(bitPattern: color)) + let uiColor = UIColor(rgb: color) if uiColor.distance(to: theme.list.itemBlocksBackgroundColor) < 200 { self.imageNode.isHidden = false self.backgroundNode.isHidden = true @@ -101,12 +101,12 @@ final class SettingsThemeWallpaperNode: ASDisplayNode { } else { self.imageNode.isHidden = true self.backgroundNode.isHidden = false - self.backgroundNode.backgroundColor = UIColor(rgb: UInt32(bitPattern: color)) + self.backgroundNode.backgroundColor = UIColor(rgb: color) } case let .gradient(topColor, bottomColor, _): self.imageNode.isHidden = false self.backgroundNode.isHidden = true - self.imageNode.setSignal(gradientImage([UIColor(rgb: UInt32(bitPattern: topColor)), UIColor(rgb: UInt32(bitPattern: bottomColor))])) + self.imageNode.setSignal(gradientImage([UIColor(rgb: topColor), UIColor(rgb: bottomColor)])) let apply = self.imageNode.asyncLayout()(TransformImageArguments(corners: corners, imageSize: CGSize(), boundingSize: size, intrinsicInsets: UIEdgeInsets())) apply() case let .image(representations, _): @@ -136,11 +136,11 @@ final class SettingsThemeWallpaperNode: ASDisplayNode { if let intensity = file.settings.intensity { patternIntensity = CGFloat(intensity) / 100.0 } - patternColor = UIColor(rgb: UInt32(bitPattern: color), alpha: patternIntensity) + patternColor = UIColor(rgb: color, alpha: patternIntensity) patternColors.append(patternColor) if let bottomColor = file.settings.bottomColor { - patternColors.append(UIColor(rgb: UInt32(bitPattern: bottomColor), alpha: patternIntensity)) + patternColors.append(UIColor(rgb: bottomColor, alpha: patternIntensity)) } } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift index 072080e977..d8edeae7c6 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift @@ -149,11 +149,12 @@ final class ThemeAccentColorController: ViewController { if let strongSelf = self { let context = strongSelf.context let initialAccentColor = strongSelf.initialAccentColor + let autoNightModeTriggered = strongSelf.presentationData.autoNightModeTriggered var coloredWallpaper: TelegramWallpaper? if let backgroundColors = state.backgroundColors { - let color = Int32(bitPattern: backgroundColors.0.argb) - let bottomColor = backgroundColors.1.flatMap { Int32(bitPattern: $0.argb) } + let color = backgroundColors.0.argb + let bottomColor = backgroundColors.1.flatMap { $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 +168,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.argb), bottomColor: backgroundColors.1.flatMap { Int32(bitPattern: $0.argb) }, intensity: state.patternIntensity, rotation: state.rotation) + let representation = CachedPatternWallpaperRepresentation(color: backgroundColors.0.argb, bottomColor: backgroundColors.1.flatMap { $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) { @@ -248,7 +249,44 @@ final class ThemeAccentColorController: ViewController { let save: Signal - if !create, let theme = telegramTheme { + if create { + let title = generateThemeName(accentColor: state.accentColor) + let _ = (prepare |> then(createTheme(account: context.account, title: title, resource: nil, thumbnailData: nil, settings: settings)) + |> deliverOnMainQueue).start(next: { next in + if case let .result(resultTheme) = next { + let _ = applyTheme(accountManager: context.sharedContext.accountManager, account: context.account, theme: resultTheme).start() + let _ = (updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current in + // if let resource = resultTheme.file?.resource, let data = themeData { + // context.sharedContext.accountManager.mediaBox.storeResourceData(resource.id, data: data, synchronous: true) + // } + + let themeReference: PresentationThemeReference = .cloud(PresentationCloudTheme(theme: resultTheme, resolvedWallpaper: wallpaper)) + + var updatedTheme = current.theme + var updatedAutomaticThemeSwitchSetting = current.automaticThemeSwitchSetting + if autoNightModeTriggered { + updatedAutomaticThemeSwitchSetting.theme = themeReference + } else { + updatedTheme = themeReference + } + + var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers + themeSpecificChatWallpapers[themeReference.index] = nil + + var themeSpecificAccentColors = current.themeSpecificAccentColors + themeSpecificAccentColors[baseThemeReference.index] = PresentationThemeAccentColor(themeIndex: themeReference.index) + + return PresentationThemeSettings(theme: updatedTheme, themeSpecificAccentColors: themeSpecificAccentColors, themeSpecificChatWallpapers: themeSpecificChatWallpapers, useSystemFont: current.useSystemFont, fontSize: current.fontSize, automaticThemeSwitchSetting: updatedAutomaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) + }) |> deliverOnMainQueue).start(completed: { + if let strongSelf = self { + strongSelf.completion?() + strongSelf.dismiss() + } + }) + } + }, error: { error in + }) + } else if let theme = telegramTheme { let _ = (prepare |> then(updateTheme(account: context.account, accountManager: context.sharedContext.accountManager, theme: theme, title: theme.title, slug: theme.slug, resource: nil, settings: settings)) |> deliverOnMainQueue).start(next: { next in if case let .result(resultTheme) = next { @@ -260,13 +298,21 @@ final class ThemeAccentColorController: ViewController { let themeReference: PresentationThemeReference = .cloud(PresentationCloudTheme(theme: resultTheme, resolvedWallpaper: wallpaper)) + var updatedTheme = current.theme + var updatedAutomaticThemeSwitchSetting = current.automaticThemeSwitchSetting + if autoNightModeTriggered { + updatedAutomaticThemeSwitchSetting.theme = themeReference + } else { + updatedTheme = themeReference + } + var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers themeSpecificChatWallpapers[themeReference.index] = nil var themeSpecificAccentColors = current.themeSpecificAccentColors themeSpecificAccentColors[baseThemeReference.index] = PresentationThemeAccentColor(themeIndex: themeReference.index) - return PresentationThemeSettings(theme: themeReference, themeSpecificAccentColors: themeSpecificAccentColors, themeSpecificChatWallpapers: themeSpecificChatWallpapers, useSystemFont: current.useSystemFont, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) + return PresentationThemeSettings(theme: updatedTheme, themeSpecificAccentColors: themeSpecificAccentColors, themeSpecificChatWallpapers: themeSpecificChatWallpapers, useSystemFont: current.useSystemFont, fontSize: current.fontSize, automaticThemeSwitchSetting: updatedAutomaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) }) |> deliverOnMainQueue).start(completed: { if let strongSelf = self { strongSelf.completion?() @@ -274,37 +320,10 @@ final class ThemeAccentColorController: ViewController { } }) } - }, error: { error in + }, error: { _ in }) } else { - let title = generateThemeName(accentColor: state.accentColor) - let _ = (prepare |> then(createTheme(account: context.account, title: title, resource: nil, thumbnailData: nil, settings: settings)) - |> deliverOnMainQueue).start(next: { next in - if case let .result(resultTheme) = next { - let _ = applyTheme(accountManager: context.sharedContext.accountManager, account: context.account, theme: resultTheme).start() - let _ = (updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current in - // if let resource = resultTheme.file?.resource, let data = themeData { - // context.sharedContext.accountManager.mediaBox.storeResourceData(resource.id, data: data, synchronous: true) - // } - - let themeReference: PresentationThemeReference = .cloud(PresentationCloudTheme(theme: resultTheme, resolvedWallpaper: wallpaper)) - - var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers - themeSpecificChatWallpapers[themeReference.index] = nil - - var themeSpecificAccentColors = current.themeSpecificAccentColors - themeSpecificAccentColors[baseThemeReference.index] = PresentationThemeAccentColor(themeIndex: themeReference.index) - - return PresentationThemeSettings(theme: themeReference, themeSpecificAccentColors: themeSpecificAccentColors, themeSpecificChatWallpapers: themeSpecificChatWallpapers, useSystemFont: current.useSystemFont, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) - }) |> deliverOnMainQueue).start(completed: { - if let strongSelf = self { - strongSelf.completion?() - strongSelf.dismiss() - } - }) - } - }, error: { error in - }) + } } else if case .background = strongSelf.mode { let autoNightModeTriggered = strongSelf.presentationData.autoNightModeTriggered @@ -333,6 +352,11 @@ final class ThemeAccentColorController: ViewController { strongSelf.segmentedTitleView.theme = theme } } + self.controllerNode.requestSectionUpdate = { [weak self] section in + if let strongSelf = self { + strongSelf.segmentedTitleView.setIndex(section.rawValue, animated: true) + } + } let _ = (combineLatest( self.context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.presentationThemeSettings]) |> take(1), @@ -367,9 +391,9 @@ final class ThemeAccentColorController: ViewController { if let intensity = file.settings.intensity { patternIntensity = intensity } - patternColor = UIColor(rgb: UInt32(bitPattern: color)) + patternColor = UIColor(rgb: color) if let bottomColorValue = file.settings.bottomColor { - bottomColor = UIColor(rgb: UInt32(bitPattern: bottomColorValue)) + bottomColor = UIColor(rgb: bottomColorValue) } } patternWallpaper = wallpaper @@ -377,9 +401,9 @@ final class ThemeAccentColorController: ViewController { motion = file.settings.motion rotation = file.settings.rotation ?? 0 } else if case let .color(color) = wallpaper { - backgroundColors = (UIColor(rgb: UInt32(bitPattern: color)), nil) + backgroundColors = (UIColor(rgb: color), nil) } else if case let .gradient(topColor, bottomColor, settings) = wallpaper { - backgroundColors = (UIColor(rgb: UInt32(bitPattern: topColor)), UIColor(rgb: UInt32(bitPattern: bottomColor))) + backgroundColors = (UIColor(rgb: topColor), UIColor(rgb: bottomColor)) motion = settings.motion rotation = settings.rotation ?? 0 } else { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift index 531f1531f6..2e6b7ac083 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift @@ -199,9 +199,8 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate private var patternArgumentsPromise = Promise() private var patternArgumentsDisposable: Disposable? - private var tapGestureRecognizer: UITapGestureRecognizer? - var themeUpdated: ((PresentationTheme) -> Void)? + var requestSectionUpdate: ((ThemeColorSection) -> Void)? private var validLayout: (ContainerViewLayout, CGFloat, CGFloat)? @@ -423,8 +422,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.argb) - let bottomColor = backgroundColors.1.flatMap { Int32(bitPattern: $0.argb) } + let color = backgroundColors.0.argb + let bottomColor = backgroundColors.1.flatMap { $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 +435,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.argb), Int32(bitPattern: bottomColor.argb), WallpaperSettings(rotation: state.rotation)) + wallpaper = .gradient(backgroundColors.0.argb, bottomColor.argb, WallpaperSettings(rotation: state.rotation)) wallpaperSignal = gradientImage([backgroundColors.0, bottomColor], rotation: state.rotation) } else { - wallpaper = .color(Int32(bitPattern: backgroundColors.0.argb)) + wallpaper = .color(backgroundColors.0.argb) } } else if let themeReference = mode.themeReference, case let .builtin(theme) = themeReference, state.initialWallpaper == nil { var suggestedWallpaper: TelegramWallpaper @@ -447,12 +446,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.argb), Int32(bitPattern: bottomColor.argb), WallpaperSettings()) + suggestedWallpaper = .gradient(topColor.argb, 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.argb)) + suggestedWallpaper = .color(color.argb) backgroundColors = (color, nil) default: suggestedWallpaper = .builtin(WallpaperSettings()) @@ -510,8 +509,8 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate strongSelf.serviceBackgroundColorPromise.set(.single(serviceBackgroundColor)) if case let .color(value) = wallpaper { - strongSelf.backgroundColor = UIColor(rgb: UInt32(bitPattern: value)) - strongSelf.immediateBackgroundNode.backgroundColor = UIColor(rgb: UInt32(bitPattern: value)) + strongSelf.backgroundColor = UIColor(rgb: value) + strongSelf.immediateBackgroundNode.backgroundColor = UIColor(rgb: value) strongSelf.immediateBackgroundNode.image = nil strongSelf.signalBackgroundNode.isHidden = true strongSelf.signalBackgroundNode.contentAnimations = [] @@ -588,10 +587,6 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate self.pageControlNode.setPage(0.0) self.colorPanelNode.view.disablesInteractiveTransitionGestureRecognizer = true self.patternPanelNode.view.disablesInteractiveTransitionGestureRecognizer = true - - let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.chatTapped(_:))) -// self.scrollNode.view.addGestureRecognizer(tapGestureRecognizer) - self.tapGestureRecognizer = tapGestureRecognizer } func scrollViewDidScroll(_ scrollView: UIScrollView) { @@ -857,11 +852,14 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate let item = self.context.sharedContext.makeChatMessagePreviewItem(context: self.context, message: message, theme: self.theme, strings: self.presentationData.strings, wallpaper: self.wallpaper, fontSize: self.presentationData.fontSize, dateTimeFormat: self.presentationData.dateTimeFormat, nameOrder: self.presentationData.nameDisplayOrder, forcedResourceStatus: !message.media.isEmpty ? FileMediaResourceStatus(mediaStatus: .playbackStatus(.paused), fetchStatus: .Local) : nil, tapMessage: { [weak self] message in if message.flags.contains(.Incoming) { self?.updateSection(.accent) + self?.requestSectionUpdate?(.accent) } else { self?.updateSection(.messages) + self?.requestSectionUpdate?(.messages) } }, clickThroughMessage: { [weak self] in self?.updateSection(.background) + self?.requestSectionUpdate?(.background) }) return item } @@ -1038,19 +1036,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate self.setMotionEnabled(self.state.motion, animated: false) } } - - @objc private func chatTapped(_ gestureRecognizer: UITapGestureRecognizer) { -// self.updateState({ current in -// var updated = current -// if updated.displayPatternPanel { -// updated.displayPatternPanel = false -// } else { -// updated.colorPanelCollapsed = !updated.colorPanelCollapsed -// } -// return updated -// }, animated: true) - } - + @objc private func toggleMotion() { self.updateState({ current in var updated = current diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorPresets.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorPresets.swift index 712772cf0d..12dac6ea37 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorPresets.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorPresets.swift @@ -3,7 +3,7 @@ import Postbox import SyncCore import TelegramUIPreferences -private func patternWallpaper(slug: String, topColor: Int32, bottomColor: Int32?, intensity: Int32?, rotation: Int32?) -> TelegramWallpaper { +private func patternWallpaper(slug: String, topColor: UInt32, bottomColor: UInt32?, intensity: Int32?, rotation: Int32?) -> TelegramWallpaper { return TelegramWallpaper.file(id: 0, accessHash: 0, isCreator: false, isDefault: true, isPattern: true, isDark: false, slug: slug, file: TelegramMediaFile(fileId: MediaId(namespace: 0, id: 0), partialReference: nil, resource: LocalFileMediaResource(fileId: 0), previewRepresentations: [], immediateThumbnailData: nil, mimeType: "", size: nil, attributes: []), settings: WallpaperSettings(color: topColor, bottomColor: bottomColor, intensity: intensity ?? 50, rotation: rotation)) } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorSegmentedTitleView.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorSegmentedTitleView.swift index e815941ecf..37cdcf7299 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorSegmentedTitleView.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorSegmentedTitleView.swift @@ -21,6 +21,10 @@ final class ThemeColorSegmentedTitleView: UIView { } } + func setIndex(_ index: Int, animated: Bool) { + self.segmentedControlNode.setSelectedIndex(index, animated: animated) + } + var sectionUpdated: ((ThemeColorSection) -> Void)? var shouldUpdateSection: ((ThemeColorSection, @escaping (Bool) -> Void) -> Void)? diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridController.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridController.swift index 87c5221f9f..99d25dbc70 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridController.swift @@ -11,7 +11,7 @@ import TelegramPresentationData import TelegramUIPreferences import AccountContext -private func availableColors() -> [Int32] { +private func availableColors() -> [UInt32] { return [ 0xffffff, 0xd4dfea, @@ -49,7 +49,7 @@ private func availableColors() -> [Int32] { ] } -private func randomColor() -> Int32 { +private func randomColor() -> UInt32 { let colors = availableColors() return colors[1 ..< colors.count - 1].randomElement() ?? 0x000000 } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift index 1fa545df18..e1b471550c 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift @@ -88,7 +88,7 @@ final class ThemeColorsGridControllerNode: ASDisplayNode { private var disposable: Disposable? - init(context: AccountContext, presentationData: PresentationData, colors: [Int32], present: @escaping (ViewController, Any?) -> Void, pop: @escaping () -> Void, presentColorPicker: @escaping () -> Void) { + init(context: AccountContext, presentationData: PresentationData, colors: [UInt32], present: @escaping (ViewController, Any?) -> Void, pop: @escaping () -> Void, presentColorPicker: @escaping () -> Void) { self.context = context self.presentationData = presentationData self.present = present diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift index 37aa926a19..9444ef01e6 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift @@ -300,7 +300,7 @@ final class ThemeGridController: ViewController { var options: [String] = [] if isPattern { if let color = settings.color { - options.append("bg_color=\(UIColor(rgb: UInt32(bitPattern: color)).hexString)") + options.append("bg_color=\(UIColor(rgb: color).hexString)") } if let intensity = settings.intensity { options.append("intensity=\(intensity)") @@ -313,7 +313,7 @@ final class ThemeGridController: ViewController { } item = slug + optionsString case let .color(color): - item = "\(UIColor(rgb: UInt32(bitPattern: color)).hexString)" + item = "\(UIColor(rgb: color).hexString)" default: break } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift index 0fd20ce0fe..4fcb1f94fd 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift @@ -74,10 +74,10 @@ private struct ThemeGridControllerEntry: Comparable, Identifiable { case .builtin: return 0 case let .color(color): - return (Int64(1) << 32) | Int64(bitPattern: UInt64(UInt32(bitPattern: color))) + return (Int64(1) << 32) | Int64(bitPattern: UInt64(color)) case let .gradient(topColor, bottomColor, _): - var hash: UInt32 = UInt32(bitPattern: topColor) - hash = hash &* 31 &+ UInt32(bitPattern: bottomColor) + var hash: UInt32 = topColor + hash = hash &* 31 &+ bottomColor return (Int64(2) << 32) | Int64(hash) case let .file(id, _, _, _, _, _, _, _, settings): var hash: Int = id.hashValue diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift index b28bffa2a8..456dbdd291 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.argb))) + return .single(wallpaper?.wallpaper ?? .color(previewTheme.chatList.backgroundColor.argb)) }) } else { self.controllerNode.wallpaperPromise.set(.single(previewTheme.chat.defaultWallpaper)) diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift index c1262425f0..b3938cb1b9 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift @@ -149,7 +149,7 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { self.maskNode.image = generateMaskImage(color: self.previewTheme.chatList.backgroundColor) if case let .color(value) = self.previewTheme.chat.defaultWallpaper { - self.instantChatBackgroundNode.backgroundColor = UIColor(rgb: UInt32(bitPattern: value)) + self.instantChatBackgroundNode.backgroundColor = UIColor(rgb: value) } self.pageControlNode.isUserInteractionEnabled = false @@ -277,9 +277,9 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { if let intensity = file.settings.intensity { patternIntensity = CGFloat(intensity) / 100.0 } - var patternColors = [UIColor(rgb: UInt32(bitPattern: color), alpha: patternIntensity)] + var patternColors = [UIColor(rgb: color, alpha: patternIntensity)] if let bottomColor = file.settings.bottomColor { - patternColors.append(UIColor(rgb: UInt32(bitPattern: bottomColor), alpha: patternIntensity)) + patternColors.append(UIColor(rgb: bottomColor, alpha: patternIntensity)) } patternArguments = PatternWallpaperArguments(colors: patternColors, rotation: file.settings.rotation) } @@ -315,7 +315,7 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { self.chatListBackgroundNode.backgroundColor = self.previewTheme.chatList.backgroundColor self.maskNode.image = generateMaskImage(color: self.previewTheme.chatList.backgroundColor) if case let .color(value) = self.previewTheme.chat.defaultWallpaper { - self.instantChatBackgroundNode.backgroundColor = UIColor(rgb: UInt32(bitPattern: value)) + self.instantChatBackgroundNode.backgroundColor = UIColor(rgb: value) } self.toolbarNode.updateThemeAndStrings(theme: self.previewTheme, strings: self.presentationData.strings) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift index ebb57e1742..e38a162d3e 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift @@ -900,7 +900,6 @@ class ThemeSettingsAccentColorItemNode: ListViewItemNode, ItemListItemNode { } entries.append(.theme(index, item.generalThemeReference, theme, selected)) } - index += 1 } @@ -935,7 +934,7 @@ class ThemeSettingsAccentColorItemNode: ListViewItemNode, ItemListItemNode { item.openColorPicker(true) } } - + let previousEntries = strongSelf.entries ?? [] let updatePosition = currentItem != nil && (previousEntries.count != entries.count || (currentItem?.generalThemeReference.index != item.generalThemeReference.index)) let transition = preparedTransition(action: action, contextAction: contextAction, openColorPicker: openColorPicker, from: previousEntries, to: entries, updatePosition: updatePosition) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift index d87bfb173c..55d00073ae 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift @@ -323,10 +323,6 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { colorItems.append(.default) defaultColor = nil - let patternWallpaper: (String, Int32, Int32?, Int32?, Int32?) -> TelegramWallpaper = { slug, topColor, bottomColor, intensity, rotation in - return TelegramWallpaper.file(id: 0, accessHash: 0, isCreator: false, isDefault: true, isPattern: true, isDark: false, slug: slug, file: TelegramMediaFile(fileId: MediaId(namespace: 0, id: 0), partialReference: nil, resource: LocalFileMediaResource(fileId: 0), previewRepresentations: [], immediateThumbnailData: nil, mimeType: "", size: nil, attributes: []), settings: WallpaperSettings(color: topColor, bottomColor: bottomColor, intensity: intensity ?? 50, rotation: rotation)) - } - for preset in dayClassicColorPresets { colorItems.append(.preset(preset)) } @@ -706,9 +702,19 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The let _ = (cloudThemes.get() |> take(1) |> deliverOnMainQueue).start(next: { themes in + removedThemeIndexesPromise.set(.single(removedThemeIndexes.modify({ value in + var updated = value + updated.insert(theme.theme.id) + return updated + }))) + if isCurrent, let currentThemeIndex = themes.firstIndex(where: { $0.id == theme.theme.id }) { if let settings = theme.theme.settings { - selectAccentColorImpl?(nil) + if settings.baseTheme == .night { + selectAccentColorImpl?(PresentationThemeAccentColor(baseColor: .blue)) + } else { + selectAccentColorImpl?(nil) + } } else { let previousThemeIndex = themes.prefix(upTo: currentThemeIndex).reversed().firstIndex(where: { $0.file != nil }) let newTheme: PresentationThemeReference @@ -721,12 +727,6 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The } } - 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() }) })) @@ -907,6 +907,12 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The let _ = (cloudThemes.get() |> take(1) |> deliverOnMainQueue).start(next: { themes in + removedThemeIndexesPromise.set(.single(removedThemeIndexes.modify({ value in + var updated = value + updated.insert(cloudTheme.theme.id) + return updated + }))) + if isCurrent, let settings = cloudTheme.theme.settings { let colorThemes = themes.filter { theme in if let settings = theme.settings { @@ -922,17 +928,15 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The if let previousThemeIndex = previousThemeIndex { selectThemeImpl?(.cloud(PresentationCloudTheme(theme: themes[themes.index(before: previousThemeIndex.base)], resolvedWallpaper: nil))) } else { - selectAccentColorImpl?(nil) + if settings.baseTheme == .night { + selectAccentColorImpl?(PresentationThemeAccentColor(baseColor: .blue)) + } else { + selectAccentColorImpl?(nil) + } } } } - 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() }) })) @@ -1208,7 +1212,6 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The var updatedAutomaticThemeSwitchSetting = current.automaticThemeSwitchSetting if autoNightModeTriggered { - var updatedAutomaticThemeSwitchSetting = current.automaticThemeSwitchSetting updatedAutomaticThemeSwitchSetting.theme = generalThemeReference } else { updatedTheme = generalThemeReference diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index 449c4cbc31..cdb1b63984 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -28,7 +28,7 @@ public enum WallpaperListSource { case slug(String, TelegramMediaFile?, WallpaperPresentationOptions?, UIColor?, UIColor?, Int32?, Int32?, Message?) case asset(PHAsset) case contextResult(ChatContextResult) - case customColor(Int32?) + case customColor(UInt32?) } private func areMessagesEqual(_ lhsMessage: Message?, _ rhsMessage: Message?) -> Bool { @@ -107,18 +107,18 @@ private func updatedFileWallpaper(wallpaper: TelegramWallpaper, firstColor: UICo private func updatedFileWallpaper(id: Int64? = nil, accessHash: Int64? = nil, slug: String, file: TelegramMediaFile, firstColor: UIColor?, secondColor: UIColor?, intensity: Int32?, rotation: Int32?) -> TelegramWallpaper { let isPattern = file.mimeType == "image/png" - var firstColorValue: Int32? - var secondColorValue: Int32? + var firstColorValue: UInt32? + var secondColorValue: UInt32? var intensityValue: Int32? if let firstColor = firstColor { - firstColorValue = Int32(bitPattern: firstColor.argb) + firstColorValue = firstColor.argb intensityValue = intensity } else if isPattern { firstColorValue = 0xd6e2ee intensityValue = 50 } if let secondColor = secondColor { - secondColorValue = Int32(bitPattern: secondColor.argb) + secondColorValue = 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)) @@ -206,7 +206,7 @@ public class WallpaperGalleryController: ViewController { entries = [.contextResult(result)] centralEntryIndex = 0 case let .customColor(color): - let initialColor = color ?? 0x000000 + let initialColor: UInt32 = color ?? 0x000000 entries = [.wallpaper(.color(initialColor), nil)] centralEntryIndex = 0 } @@ -554,7 +554,7 @@ public class WallpaperGalleryController: ViewController { case let .wallpaper(wallpaper, _): switch wallpaper { case .color: - currentEntry = .wallpaper(.color(Int32(color.argb)), nil) + currentEntry = .wallpaper(.color(color.argb), nil) default: break } @@ -570,7 +570,7 @@ public class WallpaperGalleryController: ViewController { private func updateEntries(pattern: TelegramWallpaper?, intensity: Int32? = nil, preview: Bool = false) { var updatedEntries: [WallpaperGalleryEntry] = [] for entry in self.entries { - var entryColor: Int32? + var entryColor: UInt32? if case let .wallpaper(wallpaper, _) = entry { if case let .color(color) = wallpaper { entryColor = color @@ -781,9 +781,9 @@ public class WallpaperGalleryController: ViewController { if isPattern { if let color = settings.color { if let bottomColor = settings.bottomColor { - options.append("bg_color=\(UIColor(rgb: UInt32(bitPattern: color)).hexString)-\(UIColor(rgb: UInt32(bitPattern: bottomColor)).hexString)") + options.append("bg_color=\(UIColor(rgb: color).hexString)-\(UIColor(rgb: bottomColor).hexString)") } else { - options.append("bg_color=\(UIColor(rgb: UInt32(bitPattern: color)).hexString)") + options.append("bg_color=\(UIColor(rgb: color).hexString)") } } if let intensity = settings.intensity { @@ -801,9 +801,9 @@ public class WallpaperGalleryController: ViewController { controller = ShareController(context: context, subject: .url("https://t.me/bg/\(slug)\(optionsString)")) case let .color(color): - controller = ShareController(context: context, subject: .url("https://t.me/bg/\(UIColor(rgb: UInt32(bitPattern: color)).hexString)")) + controller = ShareController(context: context, subject: .url("https://t.me/bg/\(UIColor(rgb: color).hexString)")) case let .gradient(topColor, bottomColor, _): - controller = ShareController(context: context, subject:. url("https://t.me/bg/\(UIColor(rgb: UInt32(bitPattern: topColor)).hexString)-\(UIColor(rgb: UInt32(bitPattern: bottomColor)).hexString)")) + controller = ShareController(context: context, subject:. url("https://t.me/bg/\(UIColor(rgb: topColor).hexString)-\(UIColor(rgb: bottomColor).hexString)")) default: break } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index fe4bacc26c..7fe2436807 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -226,7 +226,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { case let .color(color): displaySize = CGSize(width: 1.0, height: 1.0) contentSize = displaySize - signal = solidColorImage(UIColor(rgb: UInt32(bitPattern: color))) + signal = solidColorImage(UIColor(rgb: color)) fetchSignal = .complete() statusSignal = .single(.Local) subtitleSignal = .single(nil) @@ -236,7 +236,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { case let .gradient(topColor, bottomColor, settings): displaySize = CGSize(width: 1.0, height: 1.0) contentSize = displaySize - signal = gradientImage([UIColor(rgb: UInt32(bitPattern: topColor)), UIColor(rgb: UInt32(bitPattern: bottomColor))], rotation: settings.rotation) + signal = gradientImage([UIColor(rgb: topColor), UIColor(rgb: bottomColor)], rotation: settings.rotation) fetchSignal = .complete() statusSignal = .single(.Local) subtitleSignal = .single(nil) @@ -263,11 +263,11 @@ final class WallpaperGalleryItemNode: GalleryItemNode { if let intensity = file.settings.intensity { patternIntensity = CGFloat(intensity) / 100.0 } - patternColor = UIColor(rgb: UInt32(bitPattern: color), alpha: patternIntensity) + patternColor = UIColor(rgb: color, alpha: patternIntensity) patternColors.append(patternColor) if let bottomColor = file.settings.bottomColor { - patternColors.append(UIColor(rgb: UInt32(bitPattern: bottomColor), alpha: patternIntensity)) + patternColors.append(UIColor(rgb: bottomColor, alpha: patternIntensity)) } } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift index d24532e2a4..93b581e63f 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift @@ -150,7 +150,7 @@ final class WallpaperPatternPanelNode: ASDisplayNode { var updatedWallpaper = wallpaper if case let .file(file) = updatedWallpaper { - let settings = WallpaperSettings(color: Int32(bitPattern: backgroundColors.0.rgb), bottomColor: backgroundColors.1.flatMap { Int32(bitPattern: $0.rgb) }, intensity: 100) + let settings = WallpaperSettings(color: backgroundColors.0.rgb, bottomColor: backgroundColors.1.flatMap { $0.rgb }, intensity: 100) updatedWallpaper = .file(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: file.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: settings) } diff --git a/submodules/SyncCore/Sources/TelegramWallpaper.swift b/submodules/SyncCore/Sources/TelegramWallpaper.swift index 8072f707d8..7b500b04de 100644 --- a/submodules/SyncCore/Sources/TelegramWallpaper.swift +++ b/submodules/SyncCore/Sources/TelegramWallpaper.swift @@ -3,12 +3,12 @@ import Postbox public struct WallpaperSettings: PostboxCoding, Equatable { public let blur: Bool public let motion: Bool - public let color: Int32? - public let bottomColor: Int32? + public let color: UInt32? + public let bottomColor: UInt32? public let intensity: Int32? public let rotation: Int32? - public init(blur: Bool = false, motion: Bool = false, color: Int32? = nil, bottomColor: Int32? = nil, intensity: Int32? = nil, rotation: Int32? = nil) { + public init(blur: Bool = false, motion: Bool = false, color: UInt32? = nil, bottomColor: UInt32? = nil, intensity: Int32? = nil, rotation: Int32? = nil) { self.blur = blur self.motion = motion self.color = color @@ -20,8 +20,8 @@ public struct WallpaperSettings: PostboxCoding, Equatable { public init(decoder: PostboxDecoder) { self.blur = decoder.decodeInt32ForKey("b", orElse: 0) != 0 self.motion = decoder.decodeInt32ForKey("m", orElse: 0) != 0 - self.color = decoder.decodeOptionalInt32ForKey("c") - self.bottomColor = decoder.decodeOptionalInt32ForKey("bc") + self.color = decoder.decodeOptionalInt32ForKey("c").flatMap { UInt32(bitPattern: $0) } + self.bottomColor = decoder.decodeOptionalInt32ForKey("bc").flatMap { UInt32(bitPattern: $0) } self.intensity = decoder.decodeOptionalInt32ForKey("i") self.rotation = decoder.decodeOptionalInt32ForKey("r") } @@ -30,12 +30,12 @@ public struct WallpaperSettings: PostboxCoding, Equatable { encoder.encodeInt32(self.blur ? 1 : 0, forKey: "b") encoder.encodeInt32(self.motion ? 1 : 0, forKey: "m") if let color = self.color { - encoder.encodeInt32(color, forKey: "c") + encoder.encodeInt32(Int32(bitPattern: color), forKey: "c") } else { encoder.encodeNil(forKey: "c") } if let bottomColor = self.bottomColor { - encoder.encodeInt32(bottomColor, forKey: "bc") + encoder.encodeInt32(Int32(bitPattern: bottomColor), forKey: "bc") } else { encoder.encodeNil(forKey: "bc") } @@ -76,8 +76,8 @@ public struct WallpaperSettings: PostboxCoding, Equatable { public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { case builtin(WallpaperSettings) - case color(Int32) - case gradient(Int32, Int32, WallpaperSettings) + case color(UInt32) + case gradient(UInt32, UInt32, WallpaperSettings) case image([TelegramMediaImageRepresentation], WallpaperSettings) case file(id: Int64, accessHash: Int64, isCreator: Bool, isDefault: Bool, isPattern: Bool, isDark: Bool, slug: String, file: TelegramMediaFile, settings: WallpaperSettings) @@ -87,7 +87,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() self = .builtin(settings) case 1: - self = .color(decoder.decodeInt32ForKey("c", orElse: 0)) + self = .color(UInt32(bitPattern: decoder.decodeInt32ForKey("c", orElse: 0))) case 2: let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() self = .image(decoder.decodeObjectArrayWithDecoderForKey("i"), settings) @@ -100,7 +100,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { } case 4: let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() - self = .gradient(decoder.decodeInt32ForKey("c1", orElse: 0), decoder.decodeInt32ForKey("c2", orElse: 0), settings) + self = .gradient(UInt32(bitPattern: decoder.decodeInt32ForKey("c1", orElse: 0)), UInt32(bitPattern: decoder.decodeInt32ForKey("c2", orElse: 0)), settings) default: assertionFailure() self = .color(0xffffff) @@ -123,11 +123,11 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { encoder.encodeObject(settings, forKey: "settings") case let .color(color): encoder.encodeInt32(1, forKey: "v") - encoder.encodeInt32(color, forKey: "c") + encoder.encodeInt32(Int32(bitPattern: color), forKey: "c") case let .gradient(topColor, bottomColor, settings): encoder.encodeInt32(4, forKey: "v") - encoder.encodeInt32(topColor, forKey: "c1") - encoder.encodeInt32(bottomColor, forKey: "c2") + encoder.encodeInt32(Int32(bitPattern: topColor), forKey: "c1") + encoder.encodeInt32(Int32(bitPattern: bottomColor), forKey: "c2") encoder.encodeObject(settings, forKey: "settings") case let .image(representations, settings): encoder.encodeInt32(2, forKey: "v") diff --git a/submodules/TelegramCore/Sources/Themes.swift b/submodules/TelegramCore/Sources/Themes.swift index 83032f6c96..5916c8308f 100644 --- a/submodules/TelegramCore/Sources/Themes.swift +++ b/submodules/TelegramCore/Sources/Themes.swift @@ -116,7 +116,6 @@ public enum ThemeUpdatedResult { } private func checkThemeUpdated(network: Network, theme: TelegramTheme) -> Signal { - let id = theme.settings != nil ? 0 : theme.file?.id?.id guard let documentId = id else { return .fail(.generic) diff --git a/submodules/TelegramCore/Sources/Wallpaper.swift b/submodules/TelegramCore/Sources/Wallpaper.swift index 9b13b9fae1..5dec913a20 100644 --- a/submodules/TelegramCore/Sources/Wallpaper.swift +++ b/submodules/TelegramCore/Sources/Wallpaper.swift @@ -9,7 +9,7 @@ extension WallpaperSettings { init(apiWallpaperSettings: Api.WallPaperSettings) { switch apiWallpaperSettings { case let .wallPaperSettings(flags, backgroundColor, secondBackgroundColor, intensity, rotation): - self = WallpaperSettings(blur: (flags & 1 << 1) != 0, motion: (flags & 1 << 2) != 0, color: backgroundColor, bottomColor: secondBackgroundColor, intensity: intensity, rotation: rotation) + self = WallpaperSettings(blur: (flags & 1 << 1) != 0, motion: (flags & 1 << 2) != 0, color: backgroundColor.flatMap { UInt32(bitPattern: $0) }, bottomColor: secondBackgroundColor.flatMap { UInt32(bitPattern: $0) }, intensity: intensity, rotation: rotation) } } } @@ -31,7 +31,7 @@ func apiWallpaperSettings(_ wallpaperSettings: WallpaperSettings) -> Api.WallPap if let _ = wallpaperSettings.bottomColor { flags |= (1 << 4) } - return .wallPaperSettings(flags: flags, backgroundColor: wallpaperSettings.color, secondBackgroundColor: wallpaperSettings.bottomColor, intensity: wallpaperSettings.intensity, rotation: wallpaperSettings.rotation) + return .wallPaperSettings(flags: flags, backgroundColor: wallpaperSettings.color.flatMap { Int32(bitPattern: $0) }, secondBackgroundColor: wallpaperSettings.bottomColor.flatMap { Int32(bitPattern: $0) }, intensity: wallpaperSettings.intensity, rotation: wallpaperSettings.rotation) } extension TelegramWallpaper { @@ -53,9 +53,9 @@ extension TelegramWallpaper { case let .wallPaperNoFile(flags, settings): if let settings = settings, case let .wallPaperSettings(flags, backgroundColor, secondBackgroundColor, intensity, rotation) = settings { if let color = backgroundColor, let bottomColor = secondBackgroundColor { - self = .gradient(color, bottomColor, WallpaperSettings(rotation: rotation)) + self = .gradient(UInt32(bitPattern: color), UInt32(bitPattern: bottomColor), WallpaperSettings(rotation: rotation)) } else if let color = backgroundColor { - self = .color(color) + self = .color(UInt32(bitPattern: color)) } else { self = .color(0xffffff) } diff --git a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift index 91ae63e582..98a7f512c1 100644 --- a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift +++ b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift @@ -39,12 +39,12 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i } case let .color(color): backgroundImage = generateImage(CGSize(width: 1.0, height: 1.0), rotatedContext: { size, context in - context.setFillColor(UIColor(rgb: UInt32(bitPattern: color)).withAlphaComponent(1.0).cgColor) + context.setFillColor(UIColor(argb: color).withAlphaComponent(1.0).cgColor) context.fill(CGRect(origin: CGPoint(), size: size)) }) case let .gradient(topColor, bottomColor, settings): backgroundImage = generateImage(CGSize(width: 640.0, height: 1280.0), rotatedContext: { size, context in - let gradientColors = [UIColor(rgb: UInt32(bitPattern: topColor)).cgColor, UIColor(rgb: UInt32(bitPattern: bottomColor)).cgColor] as CFArray + let gradientColors = [UIColor(argb: topColor).cgColor, UIColor(argb: bottomColor).cgColor] as CFArray var locations: [CGFloat] = [0.0, 1.0] let colorSpace = CGColorSpaceCreateDeviceRGB() diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift index e86c431f6c..122097a4cf 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift @@ -83,9 +83,9 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit defaultWallpaper = forcedWallpaper } else if let backgroundColors = backgroundColors { if let secondColor = backgroundColors.1 { - defaultWallpaper = .gradient(Int32(bitPattern: backgroundColors.0.rgb), Int32(bitPattern: secondColor.rgb), WallpaperSettings()) + defaultWallpaper = .gradient(backgroundColors.0.argb, secondColor.argb, WallpaperSettings()) } else { - defaultWallpaper = .color(Int32(bitPattern: backgroundColors.0.rgb)) + defaultWallpaper = .color(backgroundColors.0.argb) } } diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift index 9e0723a004..2001f01610 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift @@ -47,7 +47,7 @@ public func customizeDefaultDarkTintedPresentationTheme(theme: PresentationTheme if bubbleColors == nil, editing { if let accentColor = accentColor { let color = accentColor.withMultiplied(hue: 1.024, saturation: 0.573, brightness: 0.18) - suggestedWallpaper = .color(Int32(bitPattern: color.rgb)) + suggestedWallpaper = .color(color.argb) } let accentColor = accentColor ?? defaultDarkTintedAccentColor @@ -224,9 +224,9 @@ public func customizeDefaultDarkTintedPresentationTheme(theme: PresentationTheme defaultWallpaper = forcedWallpaper } else if let backgroundColors = backgroundColors { if let secondColor = backgroundColors.1 { - defaultWallpaper = .gradient(Int32(bitPattern: backgroundColors.0.rgb), Int32(bitPattern: secondColor.rgb), WallpaperSettings()) + defaultWallpaper = .gradient(backgroundColors.0.argb, secondColor.argb, WallpaperSettings()) } else { - defaultWallpaper = .color(Int32(bitPattern: backgroundColors.0.rgb)) + defaultWallpaper = .color(backgroundColors.0.argb) } } else if let forcedWallpaper = suggestedWallpaper { defaultWallpaper = forcedWallpaper @@ -728,7 +728,7 @@ public func makeDefaultDarkTintedPresentationTheme(extendingThemeReference: Pres ) let chat = PresentationThemeChat( - defaultWallpaper: .color(Int32(bitPattern: accentColor.withMultiplied(hue: 1.024, saturation: 0.573, brightness: 0.18).rgb)), + defaultWallpaper: .color(accentColor.withMultiplied(hue: 1.024, saturation: 0.573, brightness: 0.18).argb), message: message, serviceMessage: serviceMessage, inputPanel: inputPanel, diff --git a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift index 273125f57c..b6de6a4ce5 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift @@ -41,7 +41,7 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ac 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(topColor.argb, bottomColor.argb, WallpaperSettings()) } else { bubbleColors = (UIColor(rgb: 0xe1ffc7), nil) suggestedWallpaper = .builtin(WallpaperSettings()) @@ -201,9 +201,9 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ac defaultWallpaper = forcedWallpaper } else if let backgroundColors = backgroundColors { if let secondColor = backgroundColors.1 { - defaultWallpaper = .gradient(Int32(bitPattern: backgroundColors.0.rgb), Int32(bitPattern: secondColor.rgb), WallpaperSettings()) + defaultWallpaper = .gradient(backgroundColors.0.argb, secondColor.argb, WallpaperSettings()) } else { - defaultWallpaper = .color(Int32(bitPattern: backgroundColors.0.rgb)) + defaultWallpaper = .color(backgroundColors.0.argb) } } else if let forcedWallpaper = suggestedWallpaper { defaultWallpaper = forcedWallpaper diff --git a/submodules/TelegramPresentationData/Sources/PresentationData.swift b/submodules/TelegramPresentationData/Sources/PresentationData.swift index bade3aa869..b8a1f3eb5d 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationData.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationData.swift @@ -395,9 +395,9 @@ public func serviceColor(for wallpaper: (TelegramWallpaper, UIImage?)) -> UIColo case .builtin: return UIColor(rgb: 0x748391, alpha: 0.45) case let .color(color): - return serviceColor(with: UIColor(rgb: UInt32(bitPattern: color))) + return serviceColor(with: UIColor(argb: color)) case let .gradient(topColor, bottomColor, _): - let mixedColor = UIColor(rgb: UInt32(bitPattern: topColor)).mixedWith(UIColor(rgb: UInt32(bitPattern: bottomColor)), alpha: 0.5) + let mixedColor = UIColor(argb: topColor).mixedWith(UIColor(argb: bottomColor), alpha: 0.5) return serviceColor(with: mixedColor) case .image: if let image = wallpaper.1 { @@ -408,9 +408,9 @@ public func serviceColor(for wallpaper: (TelegramWallpaper, UIImage?)) -> UIColo case let .file(file): if file.isPattern { if let color = file.settings.color { - var mixedColor = UIColor(rgb: UInt32(bitPattern: color)) + var mixedColor = UIColor(argb: color) if let bottomColor = file.settings.bottomColor { - mixedColor = mixedColor.mixedWith(UIColor(rgb: UInt32(bitPattern: bottomColor)), alpha: 0.5) + mixedColor = mixedColor.mixedWith(UIColor(argb: bottomColor), alpha: 0.5) } return serviceColor(with: mixedColor) } else { @@ -450,9 +450,9 @@ public func chatServiceBackgroundColor(wallpaper: TelegramWallpaper, mediaBox: M case .builtin: return .single(UIColor(rgb: 0x748391, alpha: 0.45)) case let .color(color): - return .single(serviceColor(with: UIColor(rgb: UInt32(bitPattern: color)))) + return .single(serviceColor(with: UIColor(argb: color))) case let .gradient(topColor, bottomColor, _): - let mixedColor = UIColor(rgb: UInt32(bitPattern: topColor)).mixedWith(UIColor(rgb: UInt32(bitPattern: bottomColor)), alpha: 0.5) + let mixedColor = UIColor(argb: topColor).mixedWith(UIColor(rgb: bottomColor), alpha: 0.5) return .single(serviceColor(with: mixedColor)) case let .image(representations, _): if let largest = largestImageRepresentation(representations) { @@ -477,9 +477,9 @@ public func chatServiceBackgroundColor(wallpaper: TelegramWallpaper, mediaBox: M case let .file(file): if file.isPattern { if let color = file.settings.color { - var mixedColor = UIColor(rgb: UInt32(bitPattern: color)) + var mixedColor = UIColor(argb: color) if let bottomColor = file.settings.bottomColor { - mixedColor = mixedColor.mixedWith(UIColor(rgb: UInt32(bitPattern: bottomColor)), alpha: 0.5) + mixedColor = mixedColor.mixedWith(UIColor(rgb: bottomColor), alpha: 0.5) } return .single(serviceColor(with: mixedColor)) } else { diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift index 817e2ddefe..0d067a502b 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift @@ -42,7 +42,7 @@ extension TelegramWallpaper: Codable { let optionKeys = ["motion", "blur"] if value.count == 6, let color = UIColor(hexString: value) { - self = .color(Int32(bitPattern: color.rgb)) + self = .color(color.argb) } else { let components = value.components(separatedBy: " ") var blur = false @@ -63,11 +63,11 @@ extension TelegramWallpaper: Codable { } } - self = .gradient(Int32(bitPattern: topColor.rgb), Int32(bitPattern: bottomColor.rgb), WallpaperSettings(blur: blur, motion: motion, rotation: rotation)) + self = .gradient(topColor.argb, bottomColor.argb, WallpaperSettings(blur: blur, motion: motion, rotation: rotation)) } else { var slug: String? - var color: Int32? - var bottomColor: Int32? + var color: UInt32? + var bottomColor: UInt32? var intensity: Int32? var rotation: Int32? @@ -82,9 +82,9 @@ extension TelegramWallpaper: Codable { } if component.count == 6, let value = UIColor(hexString: component) { if color == nil { - color = Int32(bitPattern: value.rgb) + color = value.argb } else if bottomColor == nil { - bottomColor = Int32(bitPattern: value.rgb) + bottomColor = value.argb } } else if component.count <= 3, let value = Int32(component) { if intensity == nil { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift index d8337d31e0..024fe914e9 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift @@ -337,6 +337,9 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode let tapAction = contentNode.tapActionAtPoint(CGPoint(x: point.x - contentNode.frame.minX, y: point.y - contentNode.frame.minY), gesture: .tap) switch tapAction { case .none: + if let _ = strongSelf.item?.controllerInteraction.tapMessage { + return .waitForSingleTap + } break case .ignore: return .fail diff --git a/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift b/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift index 6d9ac34c7f..adcb351dec 100644 --- a/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift +++ b/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift @@ -454,9 +454,9 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource, var colors: [UIColor] = [] if let bottomColor = representation.bottomColor { - colors.append(UIColor(rgb: UInt32(bitPattern: bottomColor))) + colors.append(UIColor(rgb: bottomColor)) } - colors.append(UIColor(rgb: UInt32(bitPattern: representation.color))) + colors.append(UIColor(rgb: representation.color)) let intensity = CGFloat(representation.intensity) / 100.0 diff --git a/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift b/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift index 00c66d895f..4f028eda14 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.argb)), nil, nil, nil, nil, nil, message) + source = .wallpaper(.color(color.argb), nil, nil, nil, nil, nil, message) case let .gradient(topColor, bottomColor, rotation): - source = .wallpaper(.gradient(Int32(topColor.argb), Int32(bottomColor.argb), WallpaperSettings(rotation: rotation)), nil, nil, nil, nil, rotation, message) + source = .wallpaper(.gradient(topColor.argb, 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 63770b1c89..4336e2c6ff 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.argb))) + signal = .single(.color(color.argb)) case let .gradient(topColor, bottomColor, rotation): - signal = .single(.gradient(Int32(topColor.argb), Int32(bottomColor.argb), WallpaperSettings())) + signal = .single(.gradient(topColor.argb, bottomColor.argb, WallpaperSettings())) } let _ = (signal diff --git a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift index 7b57a58d28..105a6e3e3a 100644 --- a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift +++ b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift @@ -1122,7 +1122,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { controllerInteraction = defaultChatControllerInteraction } - return ChatMessageItem(presentationData: ChatPresentationData(theme: ChatPresentationThemeData(theme: theme, wallpaper: wallpaper), fontSize: fontSize, strings: strings, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameOrder, disableAnimations: false, largeEmoji: false, animatedEmojiScale: 1.0, isPreview: true), context: context, chatLocation: .peer(message.id.peerId), associatedData: ChatMessageItemAssociatedData(automaticDownloadPeerType: .contact, automaticDownloadNetworkType: .cellular, isRecentActions: false, isScheduledMessages: false, contactsPeerIds: Set(), animatedEmojiStickers: [:], forcedResourceStatus: forcedResourceStatus), controllerInteraction: defaultChatControllerInteraction, content: .message(message: message, read: true, selection: .none, attributes: ChatMessageEntryAttributes()), disableDate: true, additionalContent: nil) + return ChatMessageItem(presentationData: ChatPresentationData(theme: ChatPresentationThemeData(theme: theme, wallpaper: wallpaper), fontSize: fontSize, strings: strings, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameOrder, disableAnimations: false, largeEmoji: false, animatedEmojiScale: 1.0, isPreview: true), context: context, chatLocation: .peer(message.id.peerId), associatedData: ChatMessageItemAssociatedData(automaticDownloadPeerType: .contact, automaticDownloadNetworkType: .cellular, isRecentActions: false, isScheduledMessages: false, contactsPeerIds: Set(), animatedEmojiStickers: [:], forcedResourceStatus: forcedResourceStatus), controllerInteraction: controllerInteraction, content: .message(message: message, read: true, selection: .none, attributes: ChatMessageEntryAttributes()), disableDate: true, additionalContent: nil) } public func makeChatMessageDateHeaderItem(context: AccountContext, timestamp: Int32, theme: PresentationTheme, strings: PresentationStrings, wallpaper: TelegramWallpaper, fontSize: PresentationFontSize, dateTimeFormat: PresentationDateTimeFormat, nameOrder: PresentationPersonNameOrder) -> ListViewItemHeader { diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index ee87ceaf5f..f3ae0e043f 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -759,10 +759,10 @@ public func drawThemeImage(context c: CGContext, theme: PresentationTheme, wallp c.draw(cgImage, in: CGRect(origin: CGPoint(x: (drawingRect.size.width - size.width) / 2.0, y: (drawingRect.size.height - size.height) / 2.0), size: size)) } case let .color(color): - c.setFillColor(UIColor(rgb: UInt32(bitPattern: color)).cgColor) + c.setFillColor(UIColor(rgb: color).cgColor) c.fill(drawingRect) case let .gradient(topColor, bottomColor, _): - let gradientColors = [UIColor(rgb: UInt32(bitPattern: topColor)), UIColor(rgb: UInt32(bitPattern: bottomColor))].map { $0.cgColor } as CFArray + let gradientColors = [UIColor(rgb: topColor), UIColor(rgb: bottomColor)].map { $0.cgColor } as CFArray var locations: [CGFloat] = [0.0, 1.0] let colorSpace = CGColorSpaceCreateDeviceRGB() let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! @@ -1091,8 +1091,8 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the incomingColor = UIColor(rgb: 0xffffff) if let accentColor = accentColor { if let wallpaper = wallpaper, case let .file(file) = wallpaper { - topBackgroundColor = file.settings.color.flatMap { UIColor(rgb: UInt32(bitPattern: $0)) } ?? UIColor(rgb: 0xd6e2ee) - bottomBackgroundColor = file.settings.bottomColor.flatMap { UIColor(rgb: UInt32(bitPattern: $0)) } + topBackgroundColor = file.settings.color.flatMap { UIColor(rgb: $0) } ?? UIColor(rgb: 0xd6e2ee) + bottomBackgroundColor = file.settings.bottomColor.flatMap { UIColor(rgb: $0) } } else { if let bubbleColors = bubbleColors { topBackgroundColor = UIColor(rgb: 0xd6e2ee) @@ -1139,15 +1139,15 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the if let wallpaper = wallpaper { switch wallpaper { case let .color(color): - topBackgroundColor = UIColor(rgb: UInt32(bitPattern: color)) + topBackgroundColor = UIColor(rgb: color) case let .gradient(topColor, bottomColor, settings): - topBackgroundColor = UIColor(rgb: UInt32(bitPattern: topColor)) - bottomBackgroundColor = UIColor(rgb: UInt32(bitPattern: bottomColor)) + topBackgroundColor = UIColor(rgb: topColor) + bottomBackgroundColor = UIColor(rgb: bottomColor) rotation = settings.rotation case let .file(file): if let color = file.settings.color { - topBackgroundColor = UIColor(rgb: UInt32(bitPattern: color)) - bottomBackgroundColor = file.settings.bottomColor.flatMap { UIColor(rgb: UInt32(bitPattern: $0)) } + topBackgroundColor = UIColor(rgb: color) + bottomBackgroundColor = file.settings.bottomColor.flatMap { UIColor(rgb: $0) } } rotation = file.settings.rotation default: @@ -1199,16 +1199,16 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the case .builtin: backgroundColor = (UIColor(rgb: 0xd6e2ee), nil) case let .color(color): - backgroundColor = (UIColor(rgb: UInt32(bitPattern: color)), nil) + backgroundColor = (UIColor(rgb: color), nil) case let .gradient(topColor, bottomColor, settings): - backgroundColor = (UIColor(rgb: UInt32(bitPattern: topColor)), UIColor(rgb: UInt32(bitPattern: bottomColor))) + backgroundColor = (UIColor(rgb: topColor), UIColor(rgb: bottomColor)) rotation = settings.rotation case .image: backgroundColor = (.black, nil) case let .file(file): rotation = file.settings.rotation if file.isPattern, let color = file.settings.color { - backgroundColor = (UIColor(rgb: UInt32(bitPattern: color)), file.settings.bottomColor.flatMap { UIColor(rgb: UInt32(bitPattern: $0)) }) + backgroundColor = (UIColor(rgb: color), file.settings.bottomColor.flatMap { UIColor(rgb: $0) }) } else { backgroundColor = (theme.chatList.backgroundColor, nil) }