From 852b328878bc6a209e623710eba48fdda43ec7da Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 17 Aug 2019 01:15:13 +0300 Subject: [PATCH] Custom theme eaccent color improvements --- .../Display/Display/PageControlNode.swift | 6 ++-- submodules/Display/Display/UIKitUtils.swift | 13 ++++++++ .../DefaultDarkPresentationTheme.swift | 32 +++++++++++++++++-- .../Sources/DefaultDayPresentationTheme.swift | 4 +-- .../TelegramUI/ChatController.swift | 2 +- ...SendMessageActionSheetControllerNode.swift | 2 ++ 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/submodules/Display/Display/PageControlNode.swift b/submodules/Display/Display/PageControlNode.swift index 1353ef6dd4..283d7f6bd3 100644 --- a/submodules/Display/Display/PageControlNode.swift +++ b/submodules/Display/Display/PageControlNode.swift @@ -8,9 +8,10 @@ public final class PageControlNode: ASDisplayNode { public var dotColor: UIColor { didSet { if !oldValue.isEqual(self.dotColor) { + let oldImage = self.normalDotImage self.normalDotImage = generateFilledCircleImage(diameter: dotSize, color: self.dotColor)! for dotNode in self.dotNodes { - if dotNode === oldValue { + if dotNode.image === oldImage { dotNode.image = self.normalDotImage } } @@ -20,9 +21,10 @@ public final class PageControlNode: ASDisplayNode { public var inactiveDotColor: UIColor { didSet { if !oldValue.isEqual(self.inactiveDotColor) { + let oldImage = self.inactiveDotImage self.inactiveDotImage = generateFilledCircleImage(diameter: dotSize, color: self.inactiveDotColor)! for dotNode in self.dotNodes { - if dotNode === oldValue { + if dotNode.image === oldImage { dotNode.image = self.inactiveDotImage } } diff --git a/submodules/Display/Display/UIKitUtils.swift b/submodules/Display/Display/UIKitUtils.swift index d9029c5ac8..db471b3670 100644 --- a/submodules/Display/Display/UIKitUtils.swift +++ b/submodules/Display/Display/UIKitUtils.swift @@ -109,6 +109,19 @@ public extension UIColor { } } + var lightness: CGFloat { + var red: CGFloat = 0.0 + var green: CGFloat = 0.0 + var blue: CGFloat = 0.0 + if self.getRed(&red, green: &green, blue: &blue, alpha: nil) { + return 0.2126 * red + 0.7152 * green + 0.0722 * blue + } else if self.getWhite(&red, alpha: nil) { + return red + } else { + return 0.0 + } + } + func withMultipliedBrightnessBy(_ factor: CGFloat) -> UIColor { var hue: CGFloat = 0.0 var saturation: CGFloat = 0.0 diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift index 3c86176bb3..1ebfbebb4e 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift @@ -13,18 +13,44 @@ private func makeDarkPresentationTheme(accentColor: UIColor, baseColor: Presenta let outgoingBubbleHighlightedFillColor: UIColor let outgoingScamColor: UIColor + let outgoingPrimaryTextColor: UIColor + let outgoingSecondaryTextColor: UIColor + let outgoingLinkTextColor: UIColor + let outgoingCheckColor: UIColor + if accentColor.rgb == UIColor.white.rgb { badgeFillColor = .white badgeTextColor = .black outgoingBubbleFillColor = UIColor(rgb: 0x313131) outgoingBubbleHighlightedFillColor = UIColor(rgb: 0x464646) outgoingScamColor = destructiveColor + + outgoingPrimaryTextColor = .white + outgoingSecondaryTextColor = UIColor(rgb: 0xffffff, alpha: 0.5) + outgoingLinkTextColor = .white + outgoingCheckColor = UIColor(rgb: 0xffffff, alpha: 0.5) } else { badgeFillColor = destructiveColor badgeTextColor = .white outgoingBubbleFillColor = accentColor outgoingBubbleHighlightedFillColor = accentColor.withMultipliedBrightnessBy(1.421) - outgoingScamColor = .white + + + if accentColor.lightness > 0.72 { + outgoingScamColor = .black + + outgoingPrimaryTextColor = .black + outgoingSecondaryTextColor = UIColor(rgb: 0x000000, alpha: 0.5) + outgoingLinkTextColor = .black + outgoingCheckColor = UIColor(rgb: 0x000000, alpha: 0.5) + } else { + outgoingScamColor = .white + + outgoingPrimaryTextColor = .white + outgoingSecondaryTextColor = UIColor(rgb: 0xffffff, alpha: 0.5) + outgoingLinkTextColor = .white + outgoingCheckColor = UIColor(rgb: 0xffffff, alpha: 0.5) + } } let rootTabBar = PresentationThemeRootTabBar( @@ -176,11 +202,11 @@ private func makeDarkPresentationTheme(accentColor: UIColor, baseColor: Presenta let message = PresentationThemeChatMessage( incoming: PresentationThemePartedColors(bubble: PresentationThemeBubbleColor(withWallpaper: PresentationThemeBubbleColorComponents(fill: UIColor(rgb: 0x262628), highlightedFill: UIColor(rgb: 0x353539), stroke: UIColor(rgb: 0x262628)), withoutWallpaper: PresentationThemeBubbleColorComponents(fill: UIColor(rgb: 0x262628), highlightedFill: UIColor(rgb: 0x353539), stroke: UIColor(rgb: 0x262628))), primaryTextColor: .white, secondaryTextColor: UIColor(rgb: 0xffffff, alpha: 0.5), linkTextColor: accentColor, linkHighlightColor: accentColor.withAlphaComponent(0.5), scamColor: destructiveColor, textHighlightColor: UIColor(rgb: 0xffe438), accentTextColor: accentColor, accentControlColor: accentColor, mediaActiveControlColor: accentColor, mediaInactiveControlColor: accentColor.withAlphaComponent(0.4), pendingActivityColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileTitleColor: accentColor, fileDescriptionColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileDurationColor: UIColor(rgb: 0xffffff, alpha: 0.5), mediaPlaceholderColor: UIColor(rgb: 0x1f1f1f).mixedWith(.white, alpha: 0.05), polls: PresentationThemeChatBubblePolls(radioButton: UIColor(rgb: 0x737373), radioProgress: accentColor, highlight: accentColor.withAlphaComponent(0.12), separator: UIColor(rgb: 0x000000), bar: accentColor), actionButtonsFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), actionButtonsStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2, alpha: 0.18)), actionButtonsTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff))), - outgoing: PresentationThemePartedColors(bubble: PresentationThemeBubbleColor(withWallpaper: PresentationThemeBubbleColorComponents(fill: outgoingBubbleFillColor, highlightedFill: outgoingBubbleHighlightedFillColor, stroke: outgoingBubbleFillColor), withoutWallpaper: PresentationThemeBubbleColorComponents(fill: outgoingBubbleFillColor, highlightedFill: outgoingBubbleHighlightedFillColor, stroke: outgoingBubbleFillColor)), primaryTextColor: .white, secondaryTextColor: UIColor(rgb: 0xffffff, alpha: 0.5), linkTextColor: .white, linkHighlightColor: UIColor.white.withAlphaComponent(0.5), scamColor: outgoingScamColor, textHighlightColor: UIColor(rgb: 0xffe438), accentTextColor: .white, accentControlColor: .white, mediaActiveControlColor: .white, mediaInactiveControlColor: UIColor(rgb: 0xffffff, alpha: 0.3), pendingActivityColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileTitleColor: .white, fileDescriptionColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileDurationColor: UIColor(rgb: 0xffffff, alpha: 0.5), mediaPlaceholderColor: UIColor(rgb: 0x313131).mixedWith(.white, alpha: 0.05), polls: PresentationThemeChatBubblePolls(radioButton: .white, radioProgress: .white, highlight: UIColor(white: 1.0, alpha: 0.12), separator: UIColor(white: 1.0, alpha: 0.3), bar: .white), actionButtonsFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), actionButtonsStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2, alpha: 0.18)), actionButtonsTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff))), + outgoing: PresentationThemePartedColors(bubble: PresentationThemeBubbleColor(withWallpaper: PresentationThemeBubbleColorComponents(fill: outgoingBubbleFillColor, highlightedFill: outgoingBubbleHighlightedFillColor, stroke: outgoingBubbleFillColor), withoutWallpaper: PresentationThemeBubbleColorComponents(fill: outgoingBubbleFillColor, highlightedFill: outgoingBubbleHighlightedFillColor, stroke: outgoingBubbleFillColor)), primaryTextColor: outgoingPrimaryTextColor, secondaryTextColor: outgoingSecondaryTextColor, linkTextColor: outgoingLinkTextColor, linkHighlightColor: UIColor.white.withAlphaComponent(0.5), scamColor: outgoingScamColor, textHighlightColor: UIColor(rgb: 0xffe438), accentTextColor: .white, accentControlColor: .white, mediaActiveControlColor: .white, mediaInactiveControlColor: UIColor(rgb: 0xffffff, alpha: 0.3), pendingActivityColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileTitleColor: .white, fileDescriptionColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileDurationColor: UIColor(rgb: 0xffffff, alpha: 0.5), mediaPlaceholderColor: UIColor(rgb: 0x313131).mixedWith(.white, alpha: 0.05), polls: PresentationThemeChatBubblePolls(radioButton: .white, radioProgress: .white, highlight: UIColor(white: 1.0, alpha: 0.12), separator: UIColor(white: 1.0, alpha: 0.3), bar: .white), actionButtonsFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), actionButtonsStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2, alpha: 0.18)), actionButtonsTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff))), freeform: PresentationThemeBubbleColor(withWallpaper: PresentationThemeBubbleColorComponents(fill: UIColor(rgb: 0x1f1f1f), highlightedFill: UIColor(rgb: 0x2a2a2a), stroke: UIColor(rgb: 0x1f1f1f)), withoutWallpaper: PresentationThemeBubbleColorComponents(fill: UIColor(rgb: 0x1f1f1f), highlightedFill: UIColor(rgb: 0x2a2a2a), stroke: UIColor(rgb: 0x1f1f1f))), infoPrimaryTextColor: .white, infoLinkTextColor: accentColor, - outgoingCheckColor: .white, + outgoingCheckColor: outgoingCheckColor, mediaDateAndStatusFillColor: UIColor(white: 0.0, alpha: 0.5), mediaDateAndStatusTextColor: .white, shareButtonFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), diff --git a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift index c703c44808..12b1027df6 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift @@ -8,13 +8,11 @@ private func makeDefaultDayPresentationTheme(accentColor: UIColor, serviceBackgr let constructiveColor: UIColor = UIColor(rgb: 0x00c900) let secretColor: UIColor = UIColor(rgb: 0x00b12c) - let accentColorHSV = accentColor.hsv - let outgoingPrimaryTextColor: UIColor let outgoingSecondaryTextColor: UIColor let outgoingLinkTextColor: UIColor let outgoingCheckColor: UIColor - if accentColorHSV.2 > 0.83 { + if accentColor.lightness > 0.72 { outgoingPrimaryTextColor = .black outgoingSecondaryTextColor = UIColor(rgb: 0x000000, alpha: 0.6) outgoingLinkTextColor = .black diff --git a/submodules/TelegramUI/TelegramUI/ChatController.swift b/submodules/TelegramUI/TelegramUI/ChatController.swift index 34867666fa..d785d6dc4f 100644 --- a/submodules/TelegramUI/TelegramUI/ChatController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatController.swift @@ -5831,7 +5831,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } - if case let .peer(peerId) = self.chatLocation, let messageId = messageLocation.messageId, (messageId.peerId != peerId && !forceInCurrentChat) || self.presentationInterfaceState.isScheduledMessages { + if case let .peer(peerId) = self.chatLocation, let messageId = messageLocation.messageId, (messageId.peerId != peerId && !forceInCurrentChat) || (self.presentationInterfaceState.isScheduledMessages && messageId.id != 0) { if let navigationController = self.navigationController as? NavigationController { self.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: self.context, chatLocation: .peer(messageId.peerId), messageId: messageId, keepStack: .always)) } diff --git a/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift index 787b9d43f9..64e78945e9 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift @@ -117,6 +117,7 @@ private final class ActionSheetItemNode: ASDisplayNode { } @objc private func buttonPressed() { + self.buttonNode.isUserInteractionEnabled = false self.action() } } @@ -613,6 +614,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, } @objc private func sendButtonPressed() { + self.sendButtonNode.isUserInteractionEnabled = false self.send?() } }