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 }