From b11b306c30ed88bf17ffbd83f12b91809db8fc0b Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 28 May 2021 21:58:08 +0400 Subject: [PATCH 1/3] Build webrtc without debugging --- submodules/TgVoipWebrtc/tgcalls | 2 +- third-party/webrtc/BUILD | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/submodules/TgVoipWebrtc/tgcalls b/submodules/TgVoipWebrtc/tgcalls index 66671a2df2..f89519e4fb 160000 --- a/submodules/TgVoipWebrtc/tgcalls +++ b/submodules/TgVoipWebrtc/tgcalls @@ -1 +1 @@ -Subproject commit 66671a2df214183f36400c34eabb3e7ecd9fe275 +Subproject commit f89519e4fbfe7c0abceefcc60acd22d3b763598e diff --git a/third-party/webrtc/BUILD b/third-party/webrtc/BUILD index 124b1afd6b..1cbc0d6c87 100644 --- a/third-party/webrtc/BUILD +++ b/third-party/webrtc/BUILD @@ -9,8 +9,8 @@ config_setting( ) optimization_flags = select({ - ":debug_build": ["-Os"], - "//conditions:default": [], + ":debug_build": ["-Os", "-DNDEBUG"], + "//conditions:default": ["-DNDEBUG"], }) rnnoise_sources = [ "dependencies/third_party/rnnoise/src/" + x for x in [ From 154c74a6076d6e2afbcc6f3078db8ec3530e9eec Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sat, 29 May 2021 01:10:45 +0400 Subject: [PATCH 2/3] Theme updates --- .../Sources/GalleryControllerNode.swift | 4 +- .../GalleryUI/Sources/GalleryPagerNode.swift | 11 ++++- .../Sources/GradientBackground.swift | 4 +- .../Sources/SoftwareGradientBackground.swift | 15 ++++++- .../CachedResourceRepresentations.swift | 19 ++++----- .../Sources/Themes/EditThemeController.swift | 2 +- .../Themes/ThemeAccentColorController.swift | 8 +++- .../Themes/ThemeSettingsController.swift | 2 +- .../Themes/WallpaperGalleryController.swift | 17 ++++++-- .../Sources/Themes/WallpaperGalleryItem.swift | 42 ++++++++++++------- .../ChatControllerBackgroundNode.swift | 6 +-- .../TelegramUI/Sources/ChatController.swift | 2 +- .../Sources/ChatControllerNode.swift | 2 + .../Sources/ChatMessageBubbleBackdrop.swift | 2 +- .../Sources/ChatTextInputPanelNode.swift | 1 + .../Sources/FetchCachedRepresentations.swift | 21 +++++++--- .../TelegramUI/Sources/UpgradedAccounts.swift | 2 +- submodules/TgVoipWebrtc/tgcalls | 2 +- .../Sources/WallpaperBackgroundNode.swift | 6 ++- .../Sources/WallpaperResources.swift | 8 ++-- 20 files changed, 115 insertions(+), 61 deletions(-) diff --git a/submodules/GalleryUI/Sources/GalleryControllerNode.swift b/submodules/GalleryUI/Sources/GalleryControllerNode.swift index f5905c7910..b38bd35f73 100644 --- a/submodules/GalleryUI/Sources/GalleryControllerNode.swift +++ b/submodules/GalleryUI/Sources/GalleryControllerNode.swift @@ -38,7 +38,7 @@ open class GalleryControllerNode: ASDisplayNode, UIScrollViewDelegate, UIGesture } } - public init(controllerInteraction: GalleryControllerInteraction, pageGap: CGFloat = 20.0) { + public init(controllerInteraction: GalleryControllerInteraction, pageGap: CGFloat = 20.0, disableTapNavigation: Bool = false) { self.backgroundNode = ASDisplayNode() self.backgroundNode.backgroundColor = UIColor.black self.scrollView = UIScrollView() @@ -48,7 +48,7 @@ open class GalleryControllerNode: ASDisplayNode, UIScrollViewDelegate, UIGesture self.scrollView.contentInsetAdjustmentBehavior = .never } - self.pager = GalleryPagerNode(pageGap: pageGap) + self.pager = GalleryPagerNode(pageGap: pageGap, disableTapNavigation: disableTapNavigation) self.footerNode = GalleryFooterNode(controllerInteraction: controllerInteraction) super.init() diff --git a/submodules/GalleryUI/Sources/GalleryPagerNode.swift b/submodules/GalleryUI/Sources/GalleryPagerNode.swift index 5dc2538661..d45d1feba6 100644 --- a/submodules/GalleryUI/Sources/GalleryPagerNode.swift +++ b/submodules/GalleryUI/Sources/GalleryPagerNode.swift @@ -78,6 +78,7 @@ public struct GalleryPagerTransaction { public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGestureRecognizerDelegate { private let pageGap: CGFloat + private let disableTapNavigation: Bool private let scrollView: UIScrollView @@ -111,8 +112,10 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest public var completeCustomDismiss: () -> Void = { } public var baseNavigationController: () -> NavigationController? = { return nil } - public init(pageGap: CGFloat) { + public init(pageGap: CGFloat, disableTapNavigation: Bool) { self.pageGap = pageGap + self.disableTapNavigation = disableTapNavigation + self.scrollView = UIScrollView() if #available(iOSApplicationExtension 11.0, iOS 11.0, *) { self.scrollView.contentInsetAdjustmentBehavior = .never @@ -434,6 +437,9 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest } private func canGoToPreviousItem() -> Bool { + if self.disableTapNavigation { + return false + } if let index = self.centralItemIndex, index > 0 { return true } else { @@ -442,6 +448,9 @@ public final class GalleryPagerNode: ASDisplayNode, UIScrollViewDelegate, UIGest } private func canGoToNextItem() -> Bool { + if self.disableTapNavigation { + return false + } if let index = self.centralItemIndex, index < self.items.count - 1 { return true } else { diff --git a/submodules/GradientBackground/Sources/GradientBackground.swift b/submodules/GradientBackground/Sources/GradientBackground.swift index 392c2f1416..c2c1babfae 100644 --- a/submodules/GradientBackground/Sources/GradientBackground.swift +++ b/submodules/GradientBackground/Sources/GradientBackground.swift @@ -3,6 +3,6 @@ import UIKit import Display import AsyncDisplayKit -public func createGradientBackgroundNode() -> GradientBackgroundNode { - return GradientBackgroundNode() +public func createGradientBackgroundNode(useSharedAnimationPhase: Bool = false) -> GradientBackgroundNode { + return GradientBackgroundNode(useSharedAnimationPhase: useSharedAnimationPhase) } diff --git a/submodules/GradientBackground/Sources/SoftwareGradientBackground.swift b/submodules/GradientBackground/Sources/SoftwareGradientBackground.swift index 35c44b3d41..3e3c30b51e 100644 --- a/submodules/GradientBackground/Sources/SoftwareGradientBackground.swift +++ b/submodules/GradientBackground/Sources/SoftwareGradientBackground.swift @@ -180,14 +180,22 @@ public final class GradientBackgroundNode: ASDisplayNode { private let cloneNodes = SparseBag>() - override public init() { + private let useSharedAnimationPhase: Bool + static var sharedPhase: Int = 0 + + public init(useSharedAnimationPhase: Bool = false) { + self.useSharedAnimationPhase = useSharedAnimationPhase self.contentView = UIImageView() super.init() self.view.addSubview(self.contentView) - self.phase = 0 + if useSharedAnimationPhase { + self.phase = GradientBackgroundNode.sharedPhase + } else { + self.phase = 0 + } } deinit { @@ -280,6 +288,9 @@ public final class GradientBackgroundNode: ASDisplayNode { } else { self.phase = self.phase - 1 } + if self.useSharedAnimationPhase { + GradientBackgroundNode.sharedPhase = self.phase + } if let size = self.validLayout { self.updateLayout(size: size, transition: transition) } diff --git a/submodules/MediaResources/Sources/CachedResourceRepresentations.swift b/submodules/MediaResources/Sources/CachedResourceRepresentations.swift index ea1cfbccc7..800c5022d7 100644 --- a/submodules/MediaResources/Sources/CachedResourceRepresentations.swift +++ b/submodules/MediaResources/Sources/CachedResourceRepresentations.swift @@ -147,34 +147,31 @@ public final class CachedPatternWallpaperMaskRepresentation: CachedMediaResource public final class CachedPatternWallpaperRepresentation: CachedMediaResourceRepresentation { public let keepDuration: CachedMediaRepresentationKeepDuration = .general - public let color: UInt32 - public let bottomColor: UInt32? + public let colors: [UInt32] public let intensity: Int32 public let rotation: Int32? public var uniqueId: String { - var id: String - if let bottomColor = self.bottomColor { - id = "pattern-wallpaper-\(self.color)-\(bottomColor)-\(self.intensity)" - } else { - id = "pattern-wallpaper-\(self.color)-\(self.intensity)" + var id: String = "pattern-wallpaper" + for color in self.colors { + id.append("-\(color)") } + id.append("-\(self.intensity)") if let rotation = self.rotation, rotation != 0 { id += "-\(rotation)deg" } return id } - public init(color: UInt32, bottomColor: UInt32?, intensity: Int32, rotation: Int32?) { - self.color = color - self.bottomColor = bottomColor + public init(colors: [UInt32], intensity: Int32, rotation: Int32?) { + self.colors = colors self.intensity = intensity self.rotation = rotation } public func isEqual(to: CachedMediaResourceRepresentation) -> Bool { if let to = to as? CachedPatternWallpaperRepresentation { - return self.color == to.color && self.bottomColor == to.bottomColor && self.intensity == intensity && self.rotation == to.rotation + return self.colors == to.colors && self.intensity == intensity && self.rotation == to.rotation } else { return false } diff --git a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift index e18b60b3b5..20298a0251 100644 --- a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift +++ b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift @@ -514,7 +514,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll let prepare: Signal if let resolvedWallpaper = resolvedWallpaper, case let .file(file) = resolvedWallpaper, resolvedWallpaper.isPattern { let resource = file.file.resource - let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0xd6e2ee, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation) + let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors.count >= 1 ? file.settings.colors : [0xd6e2ee], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation) var data: Data? if let path = context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift index 8af418e841..342ef4020f 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift @@ -173,7 +173,7 @@ final class ThemeAccentColorController: ViewController { let prepareWallpaper: Signal if let patternWallpaper = state.patternWallpaper, case let .file(file) = patternWallpaper, !state.backgroundColors.isEmpty { let resource = file.file.resource - let representation = CachedPatternWallpaperRepresentation(color: state.backgroundColors.count >= 1 ? state.backgroundColors[0] : 0, bottomColor: state.backgroundColors.count >= 2 ? state.backgroundColors[1] : 0, intensity: state.patternIntensity, rotation: state.rotation) + let representation = CachedPatternWallpaperRepresentation(colors: state.backgroundColors.count >= 1 ? state.backgroundColors : [0], 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) { @@ -454,13 +454,15 @@ final class ThemeAccentColorController: ViewController { if case .colors(_, true) = strongSelf.mode { let themeSpecificAccentColor = settings.themeSpecificAccentColors[themeReference.index] accentColor = themeSpecificAccentColor?.color ?? defaultDayAccentColor - + + var referenceTheme: PresentationTheme? if let accentColor = themeSpecificAccentColor, let customWallpaper = settings.themeSpecificChatWallpapers[coloredThemeIndex(reference: themeReference, accentColor: accentColor)] { wallpaper = customWallpaper } else if let customWallpaper = settings.themeSpecificChatWallpapers[themeReference.index] { wallpaper = customWallpaper } else { let theme = makePresentationTheme(mediaBox: strongSelf.context.sharedContext.accountManager.mediaBox, themeReference: themeReference, accentColor: themeSpecificAccentColor?.color, wallpaper: themeSpecificAccentColor?.wallpaper) ?? defaultPresentationTheme + referenceTheme = theme wallpaper = theme.chat.defaultWallpaper } @@ -485,6 +487,8 @@ final class ThemeAccentColorController: ViewController { } else { if let themeReference = strongSelf.mode.themeReference, themeReference == .builtin(.dayClassic), settings.themeSpecificAccentColors[themeReference.index] == nil { messageColors = (UIColor(rgb: 0xe1ffc7), nil) + } else if let referenceTheme = referenceTheme { + messageColors = (referenceTheme.chat.message.outgoing.bubble.withoutWallpaper.fill, referenceTheme.chat.message.outgoing.bubble.withoutWallpaper.gradientFill) } else { messageColors = nil } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift index 7c27c86b75..ad84662ed8 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift @@ -1240,7 +1240,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The |> mapToSignal { cachedWallpaper in if let wallpaper = cachedWallpaper?.wallpaper, case let .file(file) = wallpaper { let resource = file.file.resource - let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0xd6e2ee, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : 0xd6e2ee, intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation) + let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors.count >= 1 ? file.settings.colors : [0xd6e2ee], intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation) let _ = fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource)).start() diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index 26964a166e..0ecd8eef7d 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -360,7 +360,7 @@ public class WallpaperGalleryController: ViewController { }, replaceRootController: { controller, ready in }, editMedia: { _ in }) - self.displayNode = WallpaperGalleryControllerNode(controllerInteraction: controllerInteraction, pageGap: 0.0) + self.displayNode = WallpaperGalleryControllerNode(controllerInteraction: controllerInteraction, pageGap: 0.0, disableTapNavigation: true) self.displayNodeDidLoad() (self.displayNode as? WallpaperGalleryControllerNode)?.nativeStatusBar = self.statusBar @@ -498,7 +498,7 @@ public class WallpaperGalleryController: ViewController { } } else if case let .file(file) = wallpaper, let resource = resource { if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity { - let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation) + let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation) var data: Data? if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) { @@ -671,14 +671,23 @@ public class WallpaperGalleryController: ViewController { } if let entry = self.currentEntry(), case let .wallpaper(wallpaper, _) = entry, case let .file(_, _, _, _, true, _, _, _ , settings) = wallpaper, !settings.colors.isEmpty { - if self.patternPanelNode?.backgroundColors != nil, let snapshotView = self.patternPanelNode?.scrollNode.view.snapshotContentTree() { + /*if self.patternPanelNode?.backgroundColors != nil, let snapshotView = self.patternPanelNode?.scrollNode.view.snapshotContentTree() { self.patternPanelNode?.view.addSubview(snapshotView) snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) { [weak snapshotView] _ in snapshotView?.removeFromSuperview() } - } + }*/ //self.patternPanelNode?.backgroundColors = ([settings.colors[0]], nil) } + + if self.colorsPanelEnabled || self.patternPanelEnabled { + self.colorsPanelEnabled = false + self.patternPanelEnabled = false + + if let (layout, _) = self.validLayout { + self.containerLayoutUpdated(layout, transition: .animated(duration: 0.3, curve: .spring)) + } + } } } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index 681011ffcf..b5dde5f34b 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -284,9 +284,10 @@ final class WallpaperGalleryItemNode: GalleryItemNode { switch entry { case let .wallpaper(wallpaper, _): + self.nativeNode.update(wallpaper: wallpaper) + if case let .file(_, _, _, _, isPattern, _, _, _, settings) = wallpaper, isPattern { self.nativeNode.isHidden = false - self.nativeNode.update(wallpaper: wallpaper) self.patternButtonNode.isSelected = isPattern if isPattern && settings.colors.count >= 3 { @@ -629,11 +630,11 @@ final class WallpaperGalleryItemNode: GalleryItemNode { })) } else if self.arguments.patternEnabled != previousArguments.patternEnabled { self.patternButtonNode.isSelected = self.arguments.patternEnabled - - if let (layout, _) = self.validLayout { - self.updateButtonsLayout(layout: layout, offset: CGPoint(), transition: .immediate) - self.updateMessagesLayout(layout: layout, offset: CGPoint(), transition: .immediate) - } + } + + if let (layout, _) = self.validLayout { + self.updateButtonsLayout(layout: layout, offset: CGPoint(), transition: .immediate) + self.updateMessagesLayout(layout: layout, offset: CGPoint(), transition: .immediate) } } @@ -949,9 +950,8 @@ final class WallpaperGalleryItemNode: GalleryItemNode { motionAlpha = 0.0 patternAlpha = 1.0 - patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0) - colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0) - playAlpha = 1.0 + patternFrame = leftButtonFrame + playAlpha = 0.0 colorsAlpha = 1.0 case .image: @@ -959,13 +959,18 @@ final class WallpaperGalleryItemNode: GalleryItemNode { blurFrame = leftButtonFrame motionAlpha = 1.0 motionFrame = rightButtonFrame - case .gradient: + case let .gradient(colors, _): motionAlpha = 0.0 patternAlpha = 1.0 - patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0) - colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0) - playAlpha = 1.0 + if colors.count >= 2 { + playAlpha = 1.0 + patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0) + colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0) + } else { + playAlpha = 0.0 + patternFrame = leftButtonFrame + } colorsAlpha = 1.0 case let .file(file): @@ -973,9 +978,14 @@ final class WallpaperGalleryItemNode: GalleryItemNode { motionAlpha = 0.0 patternAlpha = 1.0 - patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0) - colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0) - playAlpha = 1.0 + if file.settings.colors.count >= 2 { + playAlpha = 1.0 + patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0) + colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0) + } else { + playAlpha = 0.0 + patternFrame = leftButtonFrame + } colorsAlpha = 1.0 } else { diff --git a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift index 887df43235..590376ce4f 100644 --- a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift +++ b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift @@ -75,7 +75,7 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i case let .file(file): if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity { var image: UIImage? - let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in + let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in if data.complete { image = UIImage(contentsOfFile: data.path)?.precomposed() } @@ -175,7 +175,7 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me } case let .file(file): if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity { - let representation = CachedPatternWallpaperRepresentation(color: file.settings.colors.count >= 1 ? file.settings.colors[0] : 0, bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : 0, intensity: intensity, rotation: file.settings.rotation) + let representation = CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation) let effectiveMediaBox: MediaBox if FileManager.default.fileExists(atPath: mediaBox.cachedRepresentationCompletePath(file.file.resource.id, representation: representation)) { @@ -214,7 +214,7 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me } }) - return .single((interrimImage, false)) |> then(effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 1 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: false) + return .single((interrimImage, false)) |> then(effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: false) |> map { data -> (UIImage?, Bool)? in return (UIImage(contentsOfFile: data.path)?.precomposed(), true) }) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index d6c4b39a39..649c3009fa 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -432,7 +432,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.botStart = botStart self.peekData = peekData - self.chatBackgroundNode = WallpaperBackgroundNode(context: context) + self.chatBackgroundNode = WallpaperBackgroundNode(context: context, useSharedAnimationPhase: true) var locationBroadcastPanelSource: LocationBroadcastPanelSource var groupCallPanelSource: GroupCallPanelSource diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 5062c8e5e0..a063395154 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -1610,6 +1610,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { } self.updatePlainInputSeparator(transition: .immediate) self.inputPanelBackgroundSeparatorNode.backgroundColor = self.chatPresentationInterfaceState.theme.chat.inputPanel.panelSeparatorColor + + self.backgroundNode.updateBubbleTheme(bubbleTheme: chatPresentationInterfaceState.theme, bubbleCorners: chatPresentationInterfaceState.bubbleCorners) } let keepSendButtonEnabled = chatPresentationInterfaceState.interfaceState.forwardMessageIds != nil || chatPresentationInterfaceState.interfaceState.editMessage != nil diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleBackdrop.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleBackdrop.swift index 4b75a924eb..a5760aa555 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleBackdrop.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleBackdrop.swift @@ -101,7 +101,7 @@ final class ChatMessageBubbleBackdrop: ASDisplayNode { let maskMode = self.fixedMaskMode ?? inputMaskMode if self.currentType != type || self.theme != theme || self.currentMaskMode != maskMode || self.essentialGraphics !== essentialGraphics || self.backgroundNode !== backgroundNode { - let typeUpdated = self.currentType != type + let typeUpdated = self.currentType != type || self.theme != theme || self.currentMaskMode != maskMode || self.backgroundNode !== backgroundNode self.currentType = type self.theme = theme diff --git a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift index db297ace30..ec5157ccf5 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift @@ -2211,6 +2211,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { backgroundView.frame = self.textInputBackgroundNode.frame func updateIsCaretHidden(view: UIView, isHidden: Bool) { + return; if String(describing: type(of: view)).contains("TextSelectionView") { view.isHidden = isHidden } else { diff --git a/submodules/TelegramUI/Sources/FetchCachedRepresentations.swift b/submodules/TelegramUI/Sources/FetchCachedRepresentations.swift index 3af52d0feb..9280f95e5a 100644 --- a/submodules/TelegramUI/Sources/FetchCachedRepresentations.swift +++ b/submodules/TelegramUI/Sources/FetchCachedRepresentations.swift @@ -19,6 +19,7 @@ import WallpaperResources import Svg import GZip import TelegramUniversalVideoContent +import GradientBackground public func fetchCachedResourceRepresentation(account: Account, resource: MediaResource, representation: CachedMediaResourceRepresentation) -> Signal { if let representation = representation as? CachedStickerAJpegRepresentation { @@ -480,11 +481,7 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource, let path = NSTemporaryDirectory() + "\(Int64.random(in: Int64.min ... Int64.max))" let url = URL(fileURLWithPath: path) - var colors: [UIColor] = [] - if let bottomColor = representation.bottomColor { - colors.append(UIColor(rgb: bottomColor)) - } - colors.append(UIColor(rgb: representation.color)) + let colors: [UIColor] = representation.colors.map(UIColor.init(rgb:)) let intensity = CGFloat(representation.intensity) / 100.0 @@ -510,6 +507,16 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource, if colors.count == 1, let color = colors.first { c.setFillColor(color.cgColor) c.fill(rect) + } else if colors.count >= 3 { + let drawingRect = rect + let image = GradientBackgroundNode.generatePreview(size: CGSize(width: 60.0, height: 60.0), colors: colors) + c.translateBy(x: drawingRect.midX, y: drawingRect.midY) + c.scaleBy(x: 1.0, y: -1.0) + c.translateBy(x: -drawingRect.midX, y: -drawingRect.midY) + c.draw(image.cgImage!, in: drawingRect) + c.translateBy(x: drawingRect.midX, y: drawingRect.midY) + c.scaleBy(x: 1.0, y: -1.0) + c.translateBy(x: -drawingRect.midX, y: -drawingRect.midY) } else { let gradientColors = colors.map { $0.cgColor } as CFArray let delta: CGFloat = 1.0 / (CGFloat(colors.count) - 1.0) @@ -535,6 +542,10 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource, c.clip(to: rect, mask: cgImage) } + if colors.count >= 3 { + c.setBlendMode(.softLight) + } + if colors.count == 1, let color = colors.first { c.setFillColor(patternColor(for: color, intensity: intensity).cgColor) c.fill(rect) diff --git a/submodules/TelegramUI/Sources/UpgradedAccounts.swift b/submodules/TelegramUI/Sources/UpgradedAccounts.swift index 7ab947c193..bc733d53e0 100644 --- a/submodules/TelegramUI/Sources/UpgradedAccounts.swift +++ b/submodules/TelegramUI/Sources/UpgradedAccounts.swift @@ -167,7 +167,7 @@ public func upgradedAccounts(accountManager: AccountManager, rootPath: String, e let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start() if wallpaper.isPattern { if !file.settings.colors.isEmpty, let intensity = file.settings.intensity { - let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true).start() + let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true).start() } } else { if file.settings.blur { diff --git a/submodules/TgVoipWebrtc/tgcalls b/submodules/TgVoipWebrtc/tgcalls index f89519e4fb..c918c50087 160000 --- a/submodules/TgVoipWebrtc/tgcalls +++ b/submodules/TgVoipWebrtc/tgcalls @@ -1 +1 @@ -Subproject commit f89519e4fbfe7c0abceefcc60acd22d3b763598e +Subproject commit c918c50087466adf5fdca47f2f62de58eccf514b diff --git a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift index 1c01d2e496..a245616ccc 100644 --- a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift +++ b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift @@ -178,6 +178,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode { } private let context: AccountContext + private let useSharedAnimationPhase: Bool private let contentNode: ASDisplayNode private var gradientBackgroundNode: GradientBackgroundNode? @@ -245,8 +246,9 @@ public final class WallpaperBackgroundNode: ASDisplayNode { } } - public init(context: AccountContext) { + public init(context: AccountContext, useSharedAnimationPhase: Bool = false) { self.context = context + self.useSharedAnimationPhase = useSharedAnimationPhase self.imageContentMode = .scaleAspectFill self.contentNode = ASDisplayNode() @@ -289,7 +291,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode { if gradientColors.count >= 3 { if self.gradientBackgroundNode == nil { - let gradientBackgroundNode = createGradientBackgroundNode() + let gradientBackgroundNode = createGradientBackgroundNode(useSharedAnimationPhase: self.useSharedAnimationPhase) self.gradientBackgroundNode = gradientBackgroundNode self.insertSubnode(gradientBackgroundNode, aboveSubnode: self.contentNode) gradientBackgroundNode.addSubnode(self.patternImageNode) diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 4768846afe..143fc34be6 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -810,10 +810,8 @@ public func drawThemeImage(context c: CGContext, theme: PresentationTheme, wallp let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! c.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: drawingRect.height), end: CGPoint(x: 0.0, y: 0.0), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) } - case .file: + case let .file(file): c.setFillColor(theme.chatList.backgroundColor.cgColor) - c.fill(drawingRect) - if let image = wallpaperImage, let cgImage = image.cgImage { let size = image.size.aspectFilled(drawingRect.size) 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)) @@ -1026,7 +1024,7 @@ public func themeImage(account: Account, accountManager: AccountManager, source: let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start() if wallpaper.wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity { - return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true) + return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true) |> mapToSignal { data in if data.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: data.path)), let image = UIImage(data: data) { return .single((theme, image, thumbnailData)) @@ -1325,7 +1323,7 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the if wallpaper.wallpaper.isPattern { if !file.settings.colors.isEmpty, let intensity = file.settings.intensity { - return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: file.settings.colors[0], bottomColor: file.settings.colors.count >= 2 ? file.settings.colors[1] : file.settings.colors[0], intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true) + return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(colors: file.settings.colors, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true) |> mapToSignal { _ in return .single((effectiveBackgroundColor, incomingColor, outgoingColor, nil, rotation)) } From 648f2e50c2ee5bab883bdaddeebf623fe1411b3a Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sat, 29 May 2021 02:17:57 +0400 Subject: [PATCH 3/3] Wallpaper updates --- .../Themes/ThemeAccentColorController.swift | 5 +- .../ThemeAccentColorControllerNode.swift | 2 +- .../Themes/ThemeColorSegmentedTitleView.swift | 2 +- .../Themes/WallpaperColorPanelNode.swift | 89 ------------------- .../Themes/WallpaperColorPickerNode.swift | 1 + .../Themes/WallpaperGalleryController.swift | 40 +++++---- .../Sources/Themes/WallpaperGalleryItem.swift | 20 +++-- .../Themes/WallpaperOptionButtonNode.swift | 12 +-- 8 files changed, 47 insertions(+), 124 deletions(-) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift index 342ef4020f..4e7b089bf9 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift @@ -69,10 +69,7 @@ final class ThemeAccentColorController: ViewController { self.mode = mode self.presentationData = context.sharedContext.currentPresentationData.with { $0 } - var section: ThemeColorSection = .accent - if case .background = mode { - section = .background - } + var section: ThemeColorSection = .background self.section = section self.segmentedTitleView = ThemeColorSegmentedTitleView(theme: self.presentationData.theme, strings: self.presentationData.strings, selectedSection: section) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift index 6db4ff4ec9..fca2934f44 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift @@ -30,8 +30,8 @@ private func generateMaskImage(color: UIColor) -> UIImage? { } enum ThemeColorSection: Int { - case accent case background + case accent case messages } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorSegmentedTitleView.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorSegmentedTitleView.swift index 37cdcf7299..a8d182994d 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorSegmentedTitleView.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorSegmentedTitleView.swift @@ -31,7 +31,7 @@ final class ThemeColorSegmentedTitleView: UIView { init(theme: PresentationTheme, strings: PresentationStrings, selectedSection: ThemeColorSection) { self.theme = theme - let sections = [strings.Theme_Colors_Accent, strings.Theme_Colors_Background, strings.Theme_Colors_Messages] + let sections = [strings.Theme_Colors_Background, strings.Theme_Colors_Accent, strings.Theme_Colors_Messages] self.segmentedControlNode = SegmentedControlNode(theme: SegmentedControlTheme(theme: theme), items: sections.map { SegmentedControlItem(title: $0) }, selectedIndex: selectedSection.rawValue) super.init(frame: CGRect()) diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift index 2833d44dcd..4ffe09b9b0 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift @@ -479,95 +479,6 @@ final class WallpaperColorPanelNode: ASDisplayNode { }, animated: strongSelf.state.colors.count >= 2) } } - /*self.multiColorFieldNode.colorSelected = { [weak self] in - if let strongSelf = self { - strongSelf.secondColorFieldNode.setSkipEndEditingIfNeeded() - strongSelf.updateState({ current in - var updated = current - if updated.selection != .none { - updated.selection = .index(0) - } - return updated - }) - - strongSelf.colorSelected?() - } - }*/ - - /*self.firstColorFieldNode.colorChanged = { [weak self] color, ended in - if let strongSelf = self { - strongSelf.updateState({ current in - var updated = current - updated.firstColor = color - return updated - }) - } - } - self.firstColorFieldNode.colorRemoved = { [weak self] in - if let strongSelf = self { - strongSelf.colorRemoved?() - strongSelf.updateState({ current in - var updated = current - updated.selection = .index(0) - if let defaultColor = current.defaultColor, updated.secondColor == nil { - updated.firstColor = nil - } else { - updated.firstColor = updated.secondColor ?? updated.firstColor - } - updated.secondColor = nil - return updated - }, animated: strongSelf.state.secondColor != nil) - } - } - self.firstColorFieldNode.colorSelected = { [weak self] in - if let strongSelf = self { - strongSelf.secondColorFieldNode.setSkipEndEditingIfNeeded() - strongSelf.updateState({ current in - var updated = current - if updated.selection != .none { - updated.selection = .index(0) - } - return updated - }) - - strongSelf.colorSelected?() - } - } - - self.secondColorFieldNode.colorChanged = { [weak self] color, ended in - if let strongSelf = self { - strongSelf.updateState({ current in - var updated = current - updated.secondColor = color - return updated - }) - } - } - self.secondColorFieldNode.colorRemoved = { [weak self] in - if let strongSelf = self { - strongSelf.colorRemoved?() - strongSelf.updateState({ current in - var updated = current - if updated.selection != .none { - updated.selection = .index(0) - } - updated.secondColor = nil - return updated - }) - } - } - self.secondColorFieldNode.colorSelected = { [weak self] in - if let strongSelf = self { - strongSelf.firstColorFieldNode.setSkipEndEditingIfNeeded() - strongSelf.updateState({ current in - var updated = current - updated.selection = .index(1) - return updated - }) - - strongSelf.colorSelected?() - } - }*/ self.colorPickerNode.colorChanged = { [weak self] color in if let strongSelf = self { diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperColorPickerNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperColorPickerNode.swift index cf89d9b0d7..48b935af57 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperColorPickerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperColorPickerNode.swift @@ -238,6 +238,7 @@ final class WallpaperColorPickerNode: ASDisplayNode { self.brightnessNode.hitTestSlop = UIEdgeInsets(top: -16.0, left: -16.0, bottom: -16.0, right: -16.0) self.brightnessKnobNode = ASImageNode() self.brightnessKnobNode.image = pointerImage + self.brightnessKnobNode.isUserInteractionEnabled = false self.colorNode = WallpaperColorHueSaturationNode() self.colorNode.hitTestSlop = UIEdgeInsets(top: -16.0, left: -16.0, bottom: -16.0, right: -16.0) self.colorKnobNode = WallpaperColorKnobNode() diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index 0ecd8eef7d..4ad112d787 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -369,10 +369,13 @@ public class WallpaperGalleryController: ViewController { self.galleryNode.dismiss = { [weak self] in self?.presentingViewController?.dismiss(animated: false, completion: nil) } - + + var currentCentralItemIndex: Int? self.galleryNode.pager.centralItemIndexUpdated = { [weak self] index in if let strongSelf = self { - strongSelf.bindCentralItemNode(animated: true) + let updated = currentCentralItemIndex != index + currentCentralItemIndex = index + strongSelf.bindCentralItemNode(animated: true, updated: updated) } } @@ -585,10 +588,10 @@ public class WallpaperGalleryController: ViewController { super.viewDidAppear(animated) self.galleryNode.modalAnimateIn() - self.bindCentralItemNode(animated: false) + self.bindCentralItemNode(animated: false, updated: false) } - private func bindCentralItemNode(animated: Bool) { + private func bindCentralItemNode(animated: Bool, updated: Bool) { if let node = self.galleryNode.pager.centralItemNode() as? WallpaperGalleryItemNode { self.centralItemSubtitle.set(node.subtitle.get()) self.centralItemStatus.set(node.status.get()) @@ -599,6 +602,7 @@ public class WallpaperGalleryController: ViewController { node.requestPatternPanel = { [weak self] enabled, initialWallpaper in if let strongSelf = self, let (layout, _) = strongSelf.validLayout { strongSelf.colorsPanelEnabled = false + strongSelf.colorsPanelNode?.view.endEditing(true) strongSelf.patternInitialWallpaper = enabled ? initialWallpaper : nil switch initialWallpaper { @@ -637,12 +641,13 @@ public class WallpaperGalleryController: ViewController { } } - node.requestColorsPanel = { [weak self] colors in - if let strongSelf = self, let (layout, _) = strongSelf.validLayout { + node.toggleColorsPanel = { [weak self] colors in + if let strongSelf = self, let (layout, _) = strongSelf.validLayout, let colors = colors, let itemNode = strongSelf.galleryNode.pager.centralItemNode() as? WallpaperGalleryItemNode { strongSelf.patternPanelEnabled = false - strongSelf.colorsPanelEnabled = colors != nil - strongSelf.galleryNode.scrollView.isScrollEnabled = colors == nil - if let colors = colors { + strongSelf.colorsPanelEnabled = !strongSelf.colorsPanelEnabled + strongSelf.galleryNode.scrollView.isScrollEnabled = !strongSelf.colorsPanelEnabled + + if strongSelf.colorsPanelEnabled { strongSelf.colorsPanelNode?.updateState({ _ in return WallpaperColorPanelNodeState( selection: 0, @@ -654,9 +659,10 @@ public class WallpaperGalleryController: ViewController { simpleGradientGeneration: false ) }, animated: false) - } else { - //strongSelf.updateEntries(pattern: .color(0), preview: false) } + + itemNode.updateIsColorsPanelActive(strongSelf.colorsPanelEnabled, animated: true) + strongSelf.containerLayoutUpdated(layout, transition: .animated(duration: 0.3, curve: .spring)) } } @@ -680,12 +686,14 @@ public class WallpaperGalleryController: ViewController { //self.patternPanelNode?.backgroundColors = ([settings.colors[0]], nil) } - if self.colorsPanelEnabled || self.patternPanelEnabled { - self.colorsPanelEnabled = false - self.patternPanelEnabled = false + if updated { + if self.colorsPanelEnabled || self.patternPanelEnabled { + self.colorsPanelEnabled = false + self.patternPanelEnabled = false - if let (layout, _) = self.validLayout { - self.containerLayoutUpdated(layout, transition: .animated(duration: 0.3, curve: .spring)) + if let (layout, _) = self.validLayout { + self.containerLayoutUpdated(layout, transition: .animated(duration: 0.3, curve: .spring)) + } } } } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index b5dde5f34b..1f643fd4e9 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -101,6 +101,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { private var patternButtonNode: WallpaperOptionButtonNode private var colorsButtonNode: WallpaperOptionButtonNode private var playButtonNode: HighlightableButtonNode + private let playButtonBackgroundNode: NavigationBackgroundNode private let messagesContainerNode: ASDisplayNode private var messageNodes: [ListViewItemNode]? @@ -115,7 +116,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { let actionButton = Promise(nil) var action: (() -> Void)? var requestPatternPanel: ((Bool, TelegramWallpaper) -> Void)? - var requestColorsPanel: (([UIColor]?) -> Void)? + var toggleColorsPanel: (([UIColor]?) -> Void)? var requestRotateGradient: ((Int32) -> Void)? private var validLayout: (ContainerViewLayout, CGFloat)? @@ -153,7 +154,9 @@ final class WallpaperGalleryItemNode: GalleryItemNode { self.patternButtonNode.setEnabled(false) self.colorsButtonNode = WallpaperOptionButtonNode(title: self.presentationData.strings.WallpaperPreview_WallpaperColors, value: .colors(false, [.clear])) + self.playButtonBackgroundNode = NavigationBackgroundNode(color: UIColor(white: 0.0, alpha: 0.3)) self.playButtonNode = HighlightableButtonNode() + self.playButtonNode.insertSubnode(self.playButtonBackgroundNode, at: 0) self.playButtonPlayImage = generateImage(CGSize(width: 48.0, height: 48.0), rotatedContext: { size, context in context.clear(CGRect(origin: CGPoint(), size: size)) @@ -439,7 +442,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { } else { subtitleSignal = .single(nil) } - if file.id == 0 { + if file.slug.isEmpty { actionSignal = .single(nil) } else { actionSignal = .single(defaultAction) @@ -626,7 +629,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { strongSelf.motionButtonNode.buttonColor = color strongSelf.colorsButtonNode.buttonColor = color - strongSelf.playButtonNode.setBackgroundImage(generateFilledCircleImage(diameter: 48.0, color: color), for: []) + strongSelf.playButtonBackgroundNode.color = color })) } else if self.arguments.patternEnabled != previousArguments.patternEnabled { self.patternButtonNode.isSelected = self.arguments.patternEnabled @@ -685,6 +688,10 @@ final class WallpaperGalleryItemNode: GalleryItemNode { var colors: [UInt32]? { return self.calculateGradientColors()?.map({ $0.rgb }) } + + func updateIsColorsPanelActive(_ value: Bool, animated: Bool) { + self.colorsButtonNode.setSelected(value, animated: false) + } @objc func toggleBlur() { let value = !self.blurButtonNode.isSelected @@ -796,10 +803,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { guard let currentGradientColors = self.calculateGradientColors() else { return } - let value = !self.colorsButtonNode.isSelected - self.colorsButtonNode.setSelected(value, animated: false) - - self.requestColorsPanel?(value ? currentGradientColors : nil) + self.toggleColorsPanel?(currentGradientColors) } @objc private func togglePlay() { @@ -1022,6 +1026,8 @@ final class WallpaperGalleryItemNode: GalleryItemNode { transition.updateAlpha(node: self.colorsButtonNode, alpha: colorsAlpha * alpha) transition.updateFrame(node: self.playButtonNode, frame: playFrame) + transition.updateFrame(node: self.playButtonBackgroundNode, frame: CGRect(origin: CGPoint(), size: playFrame.size)) + self.playButtonBackgroundNode.update(size: playFrame.size, cornerRadius: playFrame.size.height / 2.0, transition: transition) transition.updateAlpha(node: self.playButtonNode, alpha: playAlpha * alpha) transition.updateSublayerTransformScale(node: self.playButtonNode, scale: max(0.1, playAlpha)) } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift index d5bb3c168f..5ef4731c73 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperOptionButtonNode.swift @@ -35,7 +35,7 @@ private func generateColorsImage(diameter: CGFloat, colors: [UIColor]) -> UIImag } final class WallpaperOptionButtonNode: HighlightTrackingButtonNode { - private let backgroundNode: ASDisplayNode + private let backgroundNode: NavigationBackgroundNode private let checkNode: CheckNode private let colorNode: ASImageNode private let textNode: ASTextNode @@ -66,8 +66,7 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode { init(title: String, value: WallpaperOptionButtonValue) { self._value = value - self.backgroundNode = ASDisplayNode() - self.backgroundNode.backgroundColor = UIColor(rgb: 0x000000, alpha: 0.3) + self.backgroundNode = NavigationBackgroundNode(color: UIColor(rgb: 0x000000, alpha: 0.3)) self.backgroundNode.cornerRadius = 14.0 self.checkNode = CheckNode(theme: CheckNodeTheme(backgroundColor: .white, strokeColor: .clear, borderColor: .white, overlayBorder: false, hasInset: false, hasShadow: false, borderWidth: 1.5)) @@ -133,7 +132,7 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode { var buttonColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.3) { didSet { - self.backgroundNode.backgroundColor = self.buttonColor + self.backgroundNode.color = self.buttonColor } } @@ -222,10 +221,11 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode { override func layout() { super.layout() - + self.backgroundNode.frame = self.bounds + self.backgroundNode.update(size: self.backgroundNode.bounds.size, cornerRadius: 15.0, transition: .immediate) - guard let textSize = self.textSize else { + guard let _ = self.textSize else { return }