diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift index 7eac3c54a4..181bcab3e2 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift @@ -16,41 +16,6 @@ import AccountContext import SearchBarNode import SearchUI -private func areWallpapersEqual(_ lhs: TelegramWallpaper, _ rhs: TelegramWallpaper) -> Bool { - switch lhs { - case .builtin: - if case .builtin = rhs { - return true - } else { - return false - } - case let .color(color): - if case .color(color) = rhs { - return true - } else { - return false - } - case let .gradient(topColor, bottomColor, _): - if case .gradient(topColor, bottomColor, _) = rhs { - return true - } else { - return false - } - case let .image(representations, _): - if case .image(representations, _) = rhs { - return true - } else { - return false - } - case let .file(_, _, _, _, _, _, lhsSlug, _, lhsSettings): - if case let .file(_, _, _, _, _, _, rhsSlug, _, rhsSettings) = rhs, lhsSlug == rhsSlug, lhsSettings.color == rhsSettings.color && lhsSettings.intensity == rhsSettings.intensity { - return true - } else { - return false - } - } -} - struct ThemeGridControllerNodeState: Equatable { let editing: Bool var selectedIndices: Set @@ -386,13 +351,13 @@ final class ThemeGridControllerNode: ASDisplayNode { var isSelectedEditable = true if case .builtin = presentationData.chatWallpaper { isSelectedEditable = false - } else if areWallpapersEqual(presentationData.chatWallpaper, presentationData.theme.chat.defaultWallpaper) { + } else if presentationData.chatWallpaper.isBasicallyEqual(to: presentationData.theme.chat.defaultWallpaper) { isSelectedEditable = false } entries.insert(ThemeGridControllerEntry(index: 0, wallpaper: presentationData.chatWallpaper, isEditable: isSelectedEditable, isSelected: true), at: 0) var defaultWallpaper: TelegramWallpaper? - if !areWallpapersEqual(presentationData.chatWallpaper, presentationData.theme.chat.defaultWallpaper) { + if !presentationData.chatWallpaper.isBasicallyEqual(to: presentationData.theme.chat.defaultWallpaper) { if case .builtin = presentationData.theme.chat.defaultWallpaper { } else { defaultWallpaper = presentationData.theme.chat.defaultWallpaper @@ -420,9 +385,9 @@ final class ThemeGridControllerNode: ASDisplayNode { if case let .file(file) = wallpaper, deletedWallpaperSlugs.contains(file.slug) || (file.isPattern && file.settings.color == nil) { continue } - let selected = areWallpapersEqual(presentationData.chatWallpaper, wallpaper) + let selected = presentationData.chatWallpaper.isBasicallyEqual(to: wallpaper) var isDefault = false - if let defaultWallpaper = defaultWallpaper, areWallpapersEqual(defaultWallpaper, wallpaper) { + if let defaultWallpaper = defaultWallpaper, defaultWallpaper.isBasicallyEqual(to: wallpaper) { isDefault = true } var isEditable = true diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift index 409b174ea5..db7cd0e027 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift @@ -10,7 +10,7 @@ import TelegramUIPreferences import ItemListUI import PresentationDataUtils -private func generateSwatchImage(theme: PresentationTheme, color: PresentationThemeAccentColor, bubbles: (UIColor, UIColor?)?, selected: Bool) -> UIImage? { +private func generateSwatchImage(theme: PresentationTheme, color: PresentationThemeAccentColor, bubbles: (UIColor, UIColor?)?, selected: Bool, more: Bool) -> UIImage? { return generateImage(CGSize(width: 40.0, height: 40.0), rotatedContext: { size, context in let bounds = CGRect(origin: CGPoint(), size: size) context.clear(bounds) @@ -55,13 +55,34 @@ private func generateSwatchImage(theme: PresentationTheme, color: PresentationTh context.restoreGState() context.strokeEllipse(in: bounds.insetBy(dx: 1.0, dy: 1.0)) - context.setFillColor(UIColor.white.cgColor) - let dotSize = CGSize(width: 4.0, height: 4.0) - context.fillEllipse(in: CGRect(origin: CGPoint(x: 11.0, y: 18.0), size: dotSize)) - context.fillEllipse(in: CGRect(origin: CGPoint(x: 18.0, y: 18.0), size: dotSize)) - context.fillEllipse(in: CGRect(origin: CGPoint(x: 25.0, y: 18.0), size: dotSize)) + if more { + context.setFillColor(UIColor.white.cgColor) + let dotSize = CGSize(width: 4.0, height: 4.0) + context.fillEllipse(in: CGRect(origin: CGPoint(x: 11.0, y: 18.0), size: dotSize)) + context.fillEllipse(in: CGRect(origin: CGPoint(x: 18.0, y: 18.0), size: dotSize)) + context.fillEllipse(in: CGRect(origin: CGPoint(x: 25.0, y: 18.0), size: dotSize)) + } } else { - context.fillEllipse(in: bounds) + context.saveGState() + context.addEllipse(in: bounds) + context.clip() + + if let colors = bubbles { + var colors: (UIColor, UIColor) = (colors.0, colors.1 ?? colors.0) + + let gradientColors = [colors.0.cgColor, colors.1.cgColor] as CFArray + var locations: [CGFloat] = [0.0, 1.0] + let colorSpace = CGColorSpaceCreateDeviceRGB() + let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! + + context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: CGGradientDrawingOptions()) + + context.fill(CGRect(x: 0.0, y: 0.0, width: size.width / 2.0, height: size.height)) + } else { + context.fill(bounds) + } + + context.restoreGState() } })?.stretchableImage(withLeftCapWidth: 15, topCapHeight: 15) } @@ -96,17 +117,22 @@ private func generateCustomSwatchImage() -> UIImage? { }) } +enum ThemeSettingsAccentColor { + case `default` + case color(PresentationThemeBaseColor) +} + class ThemeSettingsAccentColorItem: ListViewItem, ItemListItem { var sectionId: ItemListSectionId let theme: PresentationTheme - let colors: [PresentationThemeBaseColor] - let currentColor: PresentationThemeAccentColor - let updated: (PresentationThemeAccentColor) -> Void + let colors: [ThemeSettingsAccentColor] + let currentColor: PresentationThemeAccentColor? + let updated: (PresentationThemeAccentColor?) -> Void let openColorPicker: () -> Void let tag: ItemListItemTag? - init(theme: PresentationTheme, sectionId: ItemListSectionId, colors: [PresentationThemeBaseColor], currentColor: PresentationThemeAccentColor, updated: @escaping (PresentationThemeAccentColor) -> Void, openColorPicker: @escaping () -> Void, tag: ItemListItemTag? = nil) { + init(theme: PresentationTheme, sectionId: ItemListSectionId, colors: [ThemeSettingsAccentColor], currentColor: PresentationThemeAccentColor?, updated: @escaping (PresentationThemeAccentColor?) -> Void, openColorPicker: @escaping () -> Void, tag: ItemListItemTag? = nil) { self.theme = theme self.colors = colors self.currentColor = currentColor @@ -164,8 +190,8 @@ private final class ThemeSettingsAccentColorNode : ASDisplayNode { self.addSubnode(self.iconNode) } - func setup(theme: PresentationTheme, color: PresentationThemeAccentColor, bubbles: (UIColor, UIColor?)?, selected: Bool, action: @escaping () -> Void) { - self.iconNode.image = generateSwatchImage(theme: theme, color: color, bubbles: bubbles, selected: selected) + func setup(theme: PresentationTheme, color: PresentationThemeAccentColor, bubbles: (UIColor, UIColor?)?, selected: Bool, more: Bool, action: @escaping () -> Void) { + self.iconNode.image = generateSwatchImage(theme: theme, color: color, bubbles: bubbles, selected: selected, more: more) self.action = { action() } @@ -348,20 +374,34 @@ class ThemeSettingsAccentColorItemNode: ListViewItemNode, ItemListItemNode { updated = true } - let accentColor: PresentationThemeAccentColor - let selected = item.currentColor.baseColor == color - if selected { - accentColor = item.currentColor - selectedNode = imageNode - } else { - accentColor = PresentationThemeAccentColor(baseColor: color) + let selected: Bool + var accentColor: PresentationThemeAccentColor + var itemColor: PresentationThemeAccentColor? + switch color { + case .default: + selected = item.currentColor == nil + accentColor = PresentationThemeAccentColor(baseColor: .blue, accentColor: 0x007ee5, bubbleColors: (0xe1ffc7, nil)) + case let .color(color): + selected = item.currentColor?.baseColor == color + if let currentColor = item.currentColor, selected { + accentColor = currentColor + } else { + accentColor = PresentationThemeAccentColor(baseColor: color) + } + itemColor = accentColor } - - imageNode.setup(theme: item.theme, color: accentColor, bubbles: accentColor.customBubbleColors, selected: selected, action: { [weak self, weak imageNode] in + + if selected { + selectedNode = imageNode + } + + imageNode.setup(theme: item.theme, color: accentColor, bubbles: accentColor.customBubbleColors, selected: selected, more: itemColor != nil, action: { [weak self, weak imageNode] in if selected { - item.openColorPicker() + if itemColor != nil { + item.openColorPicker() + } } else { - item.updated(accentColor) + item.updated(itemColor) } if let imageNode = imageNode { self?.scrollToNode(imageNode, animated: true) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift index e0283e6d8e..3c833fd91c 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift @@ -71,7 +71,7 @@ private final class ThemeSettingsControllerArguments { let selectTheme: (PresentationThemeReference) -> Void let selectFontSize: (PresentationFontSize) -> Void let openWallpaperSettings: () -> Void - let selectAccentColor: (PresentationThemeAccentColor) -> Void + let selectAccentColor: (PresentationThemeAccentColor?) -> Void let openAccentColorPicker: (PresentationThemeReference) -> Void let openAutoNightTheme: () -> Void let openTextSize: () -> Void @@ -81,7 +81,7 @@ private final class ThemeSettingsControllerArguments { let editTheme: (PresentationCloudTheme) -> Void let contextAction: (Bool, PresentationThemeReference, ASDisplayNode, ContextGesture?) -> Void - init(context: AccountContext, selectTheme: @escaping (PresentationThemeReference) -> Void, selectFontSize: @escaping (PresentationFontSize) -> Void, openWallpaperSettings: @escaping () -> Void, selectAccentColor: @escaping (PresentationThemeAccentColor) -> Void, openAccentColorPicker: @escaping (PresentationThemeReference) -> Void, openAutoNightTheme: @escaping () -> Void, openTextSize: @escaping () -> Void, toggleLargeEmoji: @escaping (Bool) -> Void, disableAnimations: @escaping (Bool) -> Void, selectAppIcon: @escaping (String) -> Void, editTheme: @escaping (PresentationCloudTheme) -> Void, contextAction: @escaping (Bool, PresentationThemeReference, ASDisplayNode, ContextGesture?) -> Void) { + init(context: AccountContext, selectTheme: @escaping (PresentationThemeReference) -> Void, selectFontSize: @escaping (PresentationFontSize) -> Void, openWallpaperSettings: @escaping () -> Void, selectAccentColor: @escaping (PresentationThemeAccentColor?) -> Void, openAccentColorPicker: @escaping (PresentationThemeReference) -> Void, openAutoNightTheme: @escaping () -> Void, openTextSize: @escaping () -> Void, toggleLargeEmoji: @escaping (Bool) -> Void, disableAnimations: @escaping (Bool) -> Void, selectAppIcon: @escaping (String) -> Void, editTheme: @escaping (PresentationCloudTheme) -> Void, contextAction: @escaping (Bool, PresentationThemeReference, ASDisplayNode, ContextGesture?) -> Void) { self.context = context self.selectTheme = selectTheme self.selectFontSize = selectFontSize @@ -306,10 +306,15 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { arguments.openWallpaperSettings() }) case let .accentColor(theme, currentTheme, color): - var defaultColor = PresentationThemeAccentColor(baseColor: .blue) + var colorItems: [ThemeSettingsAccentColor] = [] + var defaultColor: PresentationThemeAccentColor? = PresentationThemeAccentColor(baseColor: .blue) var colors = PresentationThemeBaseColor.allCases if case let .builtin(name) = currentTheme { - if name == .night || name == .nightAccent { + if name == .dayClassic { + colorItems.append(.default) + defaultColor = nil + } + if name != .day { colors = colors.filter { $0 != .black } } if name == .night { @@ -320,10 +325,13 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { } } let currentColor = color ?? defaultColor - if currentColor.baseColor != .custom { + if currentColor?.baseColor != .custom { colors = colors.filter { $0 != .custom } } - return ThemeSettingsAccentColorItem(theme: theme, sectionId: self.section, colors: colors, currentColor: currentColor, updated: { color in + + colorItems.append(contentsOf: colors.map { .color($0) }) + + return ThemeSettingsAccentColorItem(theme: theme, sectionId: self.section, colors: colorItems, currentColor: currentColor, updated: { color in arguments.selectAccentColor(color) }, openColorPicker: { arguments.openAccentColorPicker(currentTheme) @@ -381,7 +389,7 @@ private func themeSettingsControllerEntries(presentationData: PresentationData, entries.append(.themeItem(presentationData.theme, presentationData.strings, availableThemes, themeReference, themeSpecificAccentColors, themeSpecificAccentColors[themeReference.index])) - if case let .builtin(theme) = themeReference, theme != .dayClassic { + if case let .builtin(theme) = themeReference { entries.append(.accentColor(presentationData.theme, themeReference, themeSpecificAccentColors[themeReference.index])) } @@ -469,17 +477,18 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The currentTheme = current.automaticThemeSwitchSetting.theme } - guard let theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: currentTheme, accentColor: color.color, bubbleColors: nil) else { + guard let theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: currentTheme, accentColor: color?.color, bubbleColors: nil) else { return current } var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers var themeSpecificAccentColors = current.themeSpecificAccentColors themeSpecificAccentColors[currentTheme.index] = color - - if let wallpaper = current.themeSpecificChatWallpapers[currentTheme.index], wallpaper.hasWallpaper { - } else { - themeSpecificChatWallpapers[currentTheme.index] = theme.chat.defaultWallpaper + + if case let .builtin(theme) = currentTheme, theme == .dayClassic || theme == .nightAccent { + if let wallpaper = current.themeSpecificChatWallpapers[currentTheme.index], wallpaper.isColorOrGradient { + themeSpecificChatWallpapers[currentTheme.index] = nil + } } return PresentationThemeSettings(theme: current.theme, themeSpecificAccentColors: themeSpecificAccentColors, themeSpecificChatWallpapers: themeSpecificChatWallpapers, useSystemFont: current.useSystemFont, fontSize: current.fontSize, automaticThemeSwitchSetting: current.automaticThemeSwitchSetting, largeEmoji: current.largeEmoji, disableAnimations: current.disableAnimations) diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index 8f77b07edf..02bad5d901 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -386,6 +386,7 @@ public class WallpaperGalleryController: ViewController { let autoNightModeTriggered = strongSelf.presentationData.autoNightModeTriggered let _ = (updatePresentationThemeSettingsInteractively(accountManager: strongSelf.context.sharedContext.accountManager, { current in var themeSpecificChatWallpapers = current.themeSpecificChatWallpapers + var wallpaper = wallpaper.isBasicallyEqual(to: strongSelf.presentationData.theme.chat.defaultWallpaper) ? nil : wallpaper if autoNightModeTriggered { themeSpecificChatWallpapers[current.automaticThemeSwitchSetting.theme.index] = wallpaper } else { diff --git a/submodules/SyncCore/Sources/TelegramWallpaper.swift b/submodules/SyncCore/Sources/TelegramWallpaper.swift index 0d9bdb0955..6a4272756b 100644 --- a/submodules/SyncCore/Sources/TelegramWallpaper.swift +++ b/submodules/SyncCore/Sources/TelegramWallpaper.swift @@ -144,6 +144,41 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { } } + public func isBasicallyEqual(to wallpaper: TelegramWallpaper) -> Bool { + switch self { + case .builtin: + if case .builtin = wallpaper { + return true + } else { + return false + } + case let .color(color): + if case .color(color) = wallpaper { + return true + } else { + return false + } + case let .gradient(topColor, bottomColor, _): + if case .gradient(topColor, bottomColor, _) = wallpaper { + return true + } else { + return false + } + case let .image(representations, _): + if case .image(representations, _) = wallpaper { + return true + } else { + return false + } + case let .file(_, _, _, _, _, _, lhsSlug, _, lhsSettings): + if case let .file(_, _, _, _, _, _, rhsSlug, _, rhsSettings) = wallpaper, lhsSlug == rhsSlug, lhsSettings.color == rhsSettings.color && lhsSettings.intensity == rhsSettings.intensity { + return true + } else { + return false + } + } + } + public var settings: WallpaperSettings? { switch self { case let .builtin(settings), let .gradient(_, _, settings), let .image(_, settings), let .file(_, _, _, _, _, _, _, _, settings): diff --git a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift index 6d9ba86a8d..fa3faf030e 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift @@ -22,12 +22,29 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ac var actionSheet = theme.actionSheet var bubbleColors = bubbleColors + var outgoingAccent: UIColor? + var suggestedWallpaper: TelegramWallpaper? if bubbleColors == nil, editing { if day { let accentColor = accentColor ?? defaultDayAccentColor bubbleColors = (accentColor.withMultiplied(hue: 0.966, saturation: 0.61, brightness: 0.98), accentColor) } else { - bubbleColors = (UIColor(rgb: 0xe1ffc7), nil) + if let accentColor = accentColor { + let hsb = accentColor.hsb + bubbleColors = (UIColor(hue: hsb.0, saturation: hsb.2 > 0.0 ? 0.14 : 0.0, brightness: 0.79 + hsb.2 * 0.21, alpha: 1.0), nil) + if accentColor.lightness > 0.705 { + outgoingAccent = UIColor(hue: hsb.0, saturation: min(1.0, hsb.1 * 1.1), brightness: min(hsb.2, 0.6), alpha: 1.0) + } else { + outgoingAccent = accentColor + } + + 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()) + } else { + bubbleColors = (UIColor(rgb: 0xe1ffc7), nil) + suggestedWallpaper = .builtin(WallpaperSettings()) + } } } @@ -97,39 +114,36 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ac let saturationFactor: CGFloat = 1.1 outgoingPrimaryTextColor = UIColor(rgb: 0x000000) outgoingSecondaryTextColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.344 * hueFactor, saturation: 4.554 * saturationFactor, brightness: 0.549).withAlphaComponent(0.8) - outgoingAccentTextColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.302 * hueFactor, saturation: 4.554 * saturationFactor, brightness: 0.655) - outgoingLinkTextColor = UIColor(rgb: 0x004bad) - outgoingScamColor = UIColor(rgb: 0xff3b30) - outgoingControlColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.283 * hueFactor, saturation: 3.176, brightness: 0.765) - outgoingInactiveControlColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.207 * hueFactor, saturation: 1.721, brightness: 0.851) - outgoingPendingActivityColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.342 * hueFactor, saturation: 2.902, brightness: 0.714) - outgoingFileTitleColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.285 * hueFactor, saturation: 2.946, brightness: 0.667) + + if let outgoingAccent = outgoingAccent { + outgoingAccentTextColor = outgoingAccent + outgoingLinkTextColor = outgoingAccent + outgoingScamColor = UIColor(rgb: 0xff3b30) + outgoingControlColor = outgoingAccent + outgoingInactiveControlColor = outgoingAccent //1111 + outgoingFileTitleColor = outgoingAccent + outgoingPollsProgressColor = accentColor + outgoingSelectionColor = outgoingAccent.withMultiplied(hue: 1.0, saturation: 1.292, brightness: 0.871) + outgoingSelectionBaseColor = outgoingControlColor + outgoingCheckColor = outgoingAccent + } else { + outgoingAccentTextColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.302 * hueFactor, saturation: 4.554 * saturationFactor, brightness: 0.655) + outgoingLinkTextColor = UIColor(rgb: 0x004bad) + outgoingScamColor = UIColor(rgb: 0xff3b30) + outgoingControlColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.283 * hueFactor, saturation: 3.176, brightness: 0.765) + outgoingInactiveControlColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.207 * hueFactor, saturation: 1.721, brightness: 0.851) + outgoingFileTitleColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.285 * hueFactor, saturation: 2.946, brightness: 0.667) + outgoingPollsProgressColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.283 * hueFactor, saturation: 3.176, brightness: 0.765) + outgoingSelectionColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.013 * hueFactor, saturation: 1.292, brightness: 0.871) + outgoingSelectionBaseColor = outgoingControlColor + outgoingCheckColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.344 * hueFactor, saturation: 4.554 * saturationFactor, brightness: 0.549).withAlphaComponent(0.8) + } + outgoingPendingActivityColor = outgoingCheckColor + outgoingFileDescriptionColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.257 * hueFactor, saturation: 1.842, brightness: 0.698) outgoingFileDurationColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.344 * hueFactor, saturation: 4.554, brightness: 0.549).withAlphaComponent(0.8) outgoingMediaPlaceholderColor = outgoingBubbleFillColor?.withMultiplied(hue: 0.998, saturation: 1.129, brightness: 0.949) outgoingPollsButtonColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.207 * hueFactor, saturation: 1.721, brightness: 0.851) - outgoingPollsProgressColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.283 * hueFactor, saturation: 3.176, brightness: 0.765) - outgoingSelectionColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.013 * hueFactor, saturation: 1.292, brightness: 0.871) - outgoingSelectionBaseColor = outgoingControlColor - outgoingCheckColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.344 * hueFactor, saturation: 4.554 * saturationFactor, brightness: 0.549).withAlphaComponent(0.8) - -// outgoingPrimaryTextColor = UIColor(rgb: 0x000000) -// outgoingSecondaryTextColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.008, saturation: 5.667, brightness: 0.898) -// outgoingAccentTextColor = outgoingSecondaryTextColor -// outgoingLinkTextColor = UIColor(rgb: 0x004bad) -// outgoingScamColor = UIColor(rgb: 0xff3b30) -// outgoingControlColor = outgoingSecondaryTextColor -// outgoingInactiveControlColor = outgoingSecondaryTextColor -// outgoingPendingActivityColor = outgoingSecondaryTextColor -// outgoingFileTitleColor = outgoingSecondaryTextColor -// outgoingFileDescriptionColor = outgoingSecondaryTextColor -// outgoingFileDurationColor = outgoingSecondaryTextColor -// outgoingMediaPlaceholderColor = outgoingBubbleFillColor?.withMultiplied(hue: 0.998, saturation: 1.129, brightness: 0.949) -// outgoingPollsButtonColor = outgoingSecondaryTextColor?.withAlphaComponent(0.38) -// outgoingPollsProgressColor = outgoingSecondaryTextColor -// outgoingSelectionColor = outgoingBubbleFillColor?.withMultiplied(hue: 1.013, saturation: 1.292, brightness: 0.871) -// outgoingSelectionBaseColor = outgoingControlColor -// outgoingCheckColor = outgoingSecondaryTextColor if day { if let distance = outgoingBubbleFillColor?.distance(to: UIColor(rgb: 0xffffff)), distance < 200 { @@ -164,6 +178,8 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ac } else { defaultWallpaper = .color(Int32(bitPattern: backgroundColors.0.rgb)) } + } else if let forcedWallpaper = suggestedWallpaper { + defaultWallpaper = forcedWallpaper } chat = chat.withUpdated( diff --git a/submodules/TelegramPresentationData/Sources/PresentationData.swift b/submodules/TelegramPresentationData/Sources/PresentationData.swift index 00bdede6a9..c12775dcbb 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationData.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationData.swift @@ -497,7 +497,9 @@ public func updatedPresentationData(accountManager: AccountManager, applicationI if let themeSpecificWallpaper = themeSettings.themeSpecificChatWallpapers[themeSettings.theme.index] { currentWallpaper = themeSpecificWallpaper } else { - let theme = makePresentationTheme(mediaBox: accountManager.mediaBox, themeReference: themeSettings.theme, accentColor: nil, bubbleColors: nil) ?? defaultPresentationTheme + let effectiveAccentColor = themeSettings.themeSpecificAccentColors[themeSettings.theme.index]?.color + let effectiveBubbleColors = themeSettings.themeSpecificAccentColors[themeSettings.theme.index]?.customBubbleColors + let theme = makePresentationTheme(mediaBox: accountManager.mediaBox, themeReference: themeSettings.theme, accentColor: effectiveAccentColor, bubbleColors: effectiveBubbleColors) ?? defaultPresentationTheme currentWallpaper = theme.chat.defaultWallpaper } diff --git a/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift b/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift index 6e2a569957..a74f121ba2 100644 --- a/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift +++ b/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift @@ -20,6 +20,15 @@ public extension TelegramWallpaper { } } + var isColorOrGradient: Bool { + switch self { + case .color, .gradient: + return true + default: + return false + } + } + var isBuiltin: Bool { switch self { case .builtin: diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 29f5ed3047..8361697a5f 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -1004,9 +1004,21 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the var accentColor = accentColor switch theme { case .dayClassic: - backgroundColor = UIColor(rgb: 0xd6e2ee) incomingColor = UIColor(rgb: 0xffffff) - outgoingColor = (UIColor(rgb: 0xe1ffc7), UIColor(rgb: 0xe1ffc7)) + if let accentColor = accentColor { + if let bubbleColors = bubbleColors { + backgroundColor = UIColor(rgb: 0xffffff) + outgoingColor = bubbleColors + } else { + backgroundColor = accentColor.withMultiplied(hue: 1.019, saturation: 0.867, brightness: 0.965) + let hsb = accentColor.hsb + let bubbleColor = UIColor(hue: hsb.0, saturation: hsb.2 > 0.0 ? 0.14 : 0.0, brightness: 0.79 + hsb.2 * 0.21, alpha: 1.0) + outgoingColor = (bubbleColor, bubbleColor) + } + } else { + backgroundColor = UIColor(rgb: 0xd6e2ee) + outgoingColor = (UIColor(rgb: 0xe1ffc7), UIColor(rgb: 0xe1ffc7)) + } case .day: backgroundColor = UIColor(rgb: 0xffffff) incomingColor = UIColor(rgb: 0xd5dde6)