Chat wallpaper improvements

This commit is contained in:
Ilya Laktyushin 2023-04-06 20:10:57 +04:00
parent 34062b0a06
commit 4fa1d5462d
11 changed files with 112 additions and 139 deletions

View File

@ -196,7 +196,7 @@ func uploadCustomWallpaper(context: AccountContext, wallpaper: WallpaperGalleryE
}).start() }).start()
} }
public func uploadCustomPeerWallpaper(context: AccountContext, wallpaper: WallpaperGalleryEntry, mode: WallpaperPresentationOptions, cropRect: CGRect?, peerId: PeerId, completion: @escaping () -> Void) { public func uploadCustomPeerWallpaper(context: AccountContext, wallpaper: WallpaperGalleryEntry, mode: WallpaperPresentationOptions, cropRect: CGRect?, brightnessMultiplier: CGFloat?, peerId: PeerId, completion: @escaping () -> Void) {
let imageSignal: Signal<UIImage, NoError> let imageSignal: Signal<UIImage, NoError>
switch wallpaper { switch wallpaper {
case let .wallpaper(wallpaper, _): case let .wallpaper(wallpaper, _):

View File

@ -17,6 +17,39 @@ enum WallpaperGalleryToolbarDoneButtonType {
case none case none
} }
final class WallpaperLightButtonBackgroundNode: ASDisplayNode {
private let backgroundNode: NavigationBackgroundNode
private let overlayNode: ASDisplayNode
private let lightNode: ASDisplayNode
override init() {
self.backgroundNode = NavigationBackgroundNode(color: UIColor(rgb: 0x000000, alpha: 0.01), enableBlur: true)
self.overlayNode = ASDisplayNode()
self.overlayNode.backgroundColor = UIColor(rgb: 0xffffff, alpha: 0.55)
self.overlayNode.layer.compositingFilter = "overlayBlendMode"
self.lightNode = ASDisplayNode()
self.lightNode.backgroundColor = UIColor(rgb: 0xf2f2f2, alpha: 0.3)
super.init()
self.clipsToBounds = true
self.addSubnode(self.backgroundNode)
self.addSubnode(self.overlayNode)
//self.addSubnode(self.lightNode)
}
func updateLayout(size: CGSize) {
let frame = CGRect(origin: .zero, size: size)
self.backgroundNode.frame = frame
self.overlayNode.frame = frame
self.lightNode.frame = frame
self.backgroundNode.update(size: size, transition: .immediate)
}
}
final class WallpaperGalleryToolbarNode: ASDisplayNode { final class WallpaperGalleryToolbarNode: ASDisplayNode {
private var theme: PresentationTheme private var theme: PresentationTheme
private let strings: PresentationStrings private let strings: PresentationStrings
@ -33,11 +66,9 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
} }
private let doneButton = HighlightTrackingButtonNode() private let doneButton = HighlightTrackingButtonNode()
private let doneButtonBackgroundNode: NavigationBackgroundNode private let doneButtonBackgroundNode: WallpaperLightButtonBackgroundNode
private let doneButtonTitleNode: ImmediateTextNode private let doneButtonTitleNode: ImmediateTextNode
private let doneButtonVibrancyView: UIVisualEffectView
private let doneButtonVibrancyTitleNode: ImmediateTextNode
private let doneButtonSolidBackgroundNode: ASDisplayNode private let doneButtonSolidBackgroundNode: ASDisplayNode
private let doneButtonSolidTitleNode: ImmediateTextNode private let doneButtonSolidTitleNode: ImmediateTextNode
@ -51,25 +82,13 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
self.cancelButtonType = cancelButtonType self.cancelButtonType = cancelButtonType
self.doneButtonType = doneButtonType self.doneButtonType = doneButtonType
self.doneButtonBackgroundNode = NavigationBackgroundNode(color: UIColor(rgb: 0xf2f2f2, alpha: 0.75)) self.doneButtonBackgroundNode = WallpaperLightButtonBackgroundNode()
self.doneButtonBackgroundNode.cornerRadius = 14.0 self.doneButtonBackgroundNode.cornerRadius = 14.0
let blurEffect: UIBlurEffect
if #available(iOS 13.0, *) {
blurEffect = UIBlurEffect(style: .extraLight)
} else {
blurEffect = UIBlurEffect(style: .light)
}
self.doneButtonVibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect))
self.doneButtonTitleNode = ImmediateTextNode() self.doneButtonTitleNode = ImmediateTextNode()
self.doneButtonTitleNode.displaysAsynchronously = false self.doneButtonTitleNode.displaysAsynchronously = false
self.doneButtonTitleNode.isUserInteractionEnabled = false self.doneButtonTitleNode.isUserInteractionEnabled = false
self.doneButtonVibrancyTitleNode = ImmediateTextNode()
self.doneButtonVibrancyTitleNode.displaysAsynchronously = false
self.doneButtonVibrancyTitleNode.isUserInteractionEnabled = false
self.doneButtonSolidBackgroundNode = ASDisplayNode() self.doneButtonSolidBackgroundNode = ASDisplayNode()
self.doneButtonSolidBackgroundNode.alpha = 0.0 self.doneButtonSolidBackgroundNode.alpha = 0.0
self.doneButtonSolidBackgroundNode.clipsToBounds = true self.doneButtonSolidBackgroundNode.clipsToBounds = true
@ -87,8 +106,6 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
super.init() super.init()
self.addSubnode(self.doneButtonBackgroundNode) self.addSubnode(self.doneButtonBackgroundNode)
self.doneButtonVibrancyView.contentView.addSubnode(self.doneButtonVibrancyTitleNode)
self.doneButtonBackgroundNode.view.addSubview(self.doneButtonVibrancyView)
self.doneButtonBackgroundNode.addSubnode(self.doneButtonTitleNode) self.doneButtonBackgroundNode.addSubnode(self.doneButtonTitleNode)
self.addSubnode(self.doneButtonSolidBackgroundNode) self.addSubnode(self.doneButtonSolidBackgroundNode)
@ -109,8 +126,8 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
} else { } else {
strongSelf.doneButtonBackgroundNode.layer.removeAnimation(forKey: "opacity") strongSelf.doneButtonBackgroundNode.layer.removeAnimation(forKey: "opacity")
strongSelf.doneButtonBackgroundNode.alpha = 0.55 strongSelf.doneButtonBackgroundNode.alpha = 0.55
strongSelf.doneButtonVibrancyTitleNode.layer.removeAnimation(forKey: "opacity") strongSelf.doneButtonTitleNode.layer.removeAnimation(forKey: "opacity")
strongSelf.doneButtonVibrancyTitleNode.alpha = 0.55 strongSelf.doneButtonTitleNode.alpha = 0.55
} }
} else { } else {
if strongSelf.isSolid { if strongSelf.isSolid {
@ -121,8 +138,8 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
} else { } else {
strongSelf.doneButtonBackgroundNode.alpha = 1.0 strongSelf.doneButtonBackgroundNode.alpha = 1.0
strongSelf.doneButtonBackgroundNode.layer.animateAlpha(from: 0.55, to: 1.0, duration: 0.2) strongSelf.doneButtonBackgroundNode.layer.animateAlpha(from: 0.55, to: 1.0, duration: 0.2)
strongSelf.doneButtonVibrancyTitleNode.alpha = 1.0 strongSelf.doneButtonTitleNode.alpha = 1.0
strongSelf.doneButtonVibrancyTitleNode.layer.animateAlpha(from: 0.55, to: 1.0, duration: 0.2) strongSelf.doneButtonTitleNode.layer.animateAlpha(from: 0.55, to: 1.0, duration: 0.2)
} }
} }
} }
@ -146,7 +163,6 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
transition.updateAlpha(node: self.doneButtonBackgroundNode, alpha: isSolid ? 0.0 : 1.0) transition.updateAlpha(node: self.doneButtonBackgroundNode, alpha: isSolid ? 0.0 : 1.0)
transition.updateAlpha(node: self.doneButtonSolidBackgroundNode, alpha: isSolid ? 1.0 : 0.0) transition.updateAlpha(node: self.doneButtonSolidBackgroundNode, alpha: isSolid ? 1.0 : 0.0)
transition.updateAlpha(node: self.doneButtonTitleNode, alpha: isSolid ? 0.0 : 1.0) transition.updateAlpha(node: self.doneButtonTitleNode, alpha: isSolid ? 0.0 : 1.0)
transition.updateAlpha(node: self.doneButtonVibrancyTitleNode, alpha: isSolid ? 0.0 : 1.0)
transition.updateAlpha(node: self.doneButtonSolidTitleNode, alpha: isSolid ? 1.0 : 0.0) transition.updateAlpha(node: self.doneButtonSolidTitleNode, alpha: isSolid ? 1.0 : 0.0)
} }
@ -167,8 +183,7 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
doneTitle = "" doneTitle = ""
self.doneButton.isUserInteractionEnabled = false self.doneButton.isUserInteractionEnabled = false
} }
self.doneButtonTitleNode.attributedText = NSAttributedString(string: doneTitle, font: Font.semibold(17.0), textColor: UIColor(rgb: 0x000000, alpha: 0.25)) self.doneButtonTitleNode.attributedText = NSAttributedString(string: doneTitle, font: Font.semibold(17.0), textColor: .white)
self.doneButtonVibrancyTitleNode.attributedText = NSAttributedString(string: doneTitle, font: Font.semibold(17.0), textColor: .white)
self.doneButtonSolidBackgroundNode.backgroundColor = theme.list.itemCheckColors.fillColor self.doneButtonSolidBackgroundNode.backgroundColor = theme.list.itemCheckColors.fillColor
self.doneButtonSolidTitleNode.attributedText = NSAttributedString(string: doneTitle, font: Font.semibold(17.0), textColor: theme.list.itemCheckColors.foregroundColor) self.doneButtonSolidTitleNode.attributedText = NSAttributedString(string: doneTitle, font: Font.semibold(17.0), textColor: theme.list.itemCheckColors.foregroundColor)
@ -181,16 +196,12 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
let doneFrame = CGRect(origin: CGPoint(x: inset, y: 2.0), size: CGSize(width: size.width - inset * 2.0, height: buttonHeight)) let doneFrame = CGRect(origin: CGPoint(x: inset, y: 2.0), size: CGSize(width: size.width - inset * 2.0, height: buttonHeight))
self.doneButton.frame = doneFrame self.doneButton.frame = doneFrame
self.doneButtonBackgroundNode.frame = doneFrame self.doneButtonBackgroundNode.frame = doneFrame
self.doneButtonBackgroundNode.update(size: doneFrame.size, cornerRadius: 14.0, transition: transition) self.doneButtonBackgroundNode.updateLayout(size: doneFrame.size)
self.doneButtonVibrancyView.frame = self.doneButtonBackgroundNode.bounds
self.doneButtonSolidBackgroundNode.frame = doneFrame self.doneButtonSolidBackgroundNode.frame = doneFrame
let doneTitleSize = self.doneButtonTitleNode.updateLayout(doneFrame.size) let doneTitleSize = self.doneButtonTitleNode.updateLayout(doneFrame.size)
self.doneButtonTitleNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((doneFrame.width - doneTitleSize.width) / 2.0), y: floorToScreenPixels((doneFrame.height - doneTitleSize.height) / 2.0)), size: doneTitleSize) self.doneButtonTitleNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((doneFrame.width - doneTitleSize.width) / 2.0), y: floorToScreenPixels((doneFrame.height - doneTitleSize.height) / 2.0)), size: doneTitleSize)
let _ = self.doneButtonVibrancyTitleNode.updateLayout(doneFrame.size)
self.doneButtonVibrancyTitleNode.frame = self.doneButtonTitleNode.frame
let _ = self.doneButtonSolidTitleNode.updateLayout(doneFrame.size) let _ = self.doneButtonSolidTitleNode.updateLayout(doneFrame.size)
self.doneButtonSolidTitleNode.frame = self.doneButtonTitleNode.frame.offsetBy(dx: doneFrame.minX, dy: doneFrame.minY) self.doneButtonSolidTitleNode.frame = self.doneButtonTitleNode.frame.offsetBy(dx: doneFrame.minX, dy: doneFrame.minY)
} }

View File

@ -42,41 +42,25 @@ final class WallpaperNavigationButtonNode: HighlightTrackingButtonNode {
private let content: Content private let content: Content
private let backgroundNode: NavigationBackgroundNode private let backgroundNode: WallpaperLightButtonBackgroundNode
private let vibrancyView: UIVisualEffectView
private let iconNode: ASImageNode private let iconNode: ASImageNode
private let darkIconNode: ASImageNode
private let textNode: ImmediateTextNode private let textNode: ImmediateTextNode
private let darkTextNode: ImmediateTextNode
func setIcon(_ image: UIImage?) { func setIcon(_ image: UIImage?) {
self.iconNode.image = generateTintedImage(image: image, color: .white) self.iconNode.image = generateTintedImage(image: image, color: .white)
self.darkIconNode.image = generateTintedImage(image: image, color: UIColor(rgb: 0x000000, alpha: 0.25))
} }
init(content: Content) { init(content: Content) {
self.content = content self.content = content
self.backgroundNode = NavigationBackgroundNode(color: UIColor(rgb: 0xf2f2f2, alpha: 0.75)) self.backgroundNode = WallpaperLightButtonBackgroundNode()
let blurEffect: UIBlurEffect
if #available(iOS 13.0, *) {
blurEffect = UIBlurEffect(style: .extraLight)
} else {
blurEffect = UIBlurEffect(style: .light)
}
self.vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect))
self.iconNode = ASImageNode() self.iconNode = ASImageNode()
self.iconNode.displaysAsynchronously = false self.iconNode.displaysAsynchronously = false
self.iconNode.contentMode = .center self.iconNode.contentMode = .center
self.darkIconNode = ASImageNode()
self.darkIconNode.displaysAsynchronously = false
self.darkIconNode.contentMode = .center
var title: String var title: String
switch content { switch content {
case let .text(text): case let .text(text):
@ -84,23 +68,16 @@ final class WallpaperNavigationButtonNode: HighlightTrackingButtonNode {
case let .icon(icon, _): case let .icon(icon, _):
title = "" title = ""
self.iconNode.image = generateTintedImage(image: icon, color: .white) self.iconNode.image = generateTintedImage(image: icon, color: .white)
self.darkIconNode.image = generateTintedImage(image: icon, color: UIColor(rgb: 0x000000, alpha: 0.25))
} }
self.textNode = ImmediateTextNode() self.textNode = ImmediateTextNode()
self.textNode.attributedText = NSAttributedString(string: title, font: Font.semibold(15.0), textColor: .white) self.textNode.attributedText = NSAttributedString(string: title, font: Font.semibold(15.0), textColor: .white)
self.darkTextNode = ImmediateTextNode()
self.darkTextNode.attributedText = NSAttributedString(string: title, font: Font.semibold(15.0), textColor: UIColor(rgb: 0x000000, alpha: 0.25))
super.init() super.init()
self.addSubnode(self.backgroundNode) self.addSubnode(self.backgroundNode)
self.vibrancyView.contentView.addSubnode(self.iconNode) self.addSubnode(self.iconNode)
self.vibrancyView.contentView.addSubnode(self.textNode) self.addSubnode(self.textNode)
self.backgroundNode.view.addSubview(self.vibrancyView)
self.backgroundNode.addSubnode(self.darkIconNode)
self.backgroundNode.addSubnode(self.darkTextNode)
self.highligthedChanged = { [weak self] highlighted in self.highligthedChanged = { [weak self] highlighted in
if let strongSelf = self { if let strongSelf = self {
@ -117,11 +94,11 @@ final class WallpaperNavigationButtonNode: HighlightTrackingButtonNode {
var buttonColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.3) { var buttonColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.3) {
didSet { didSet {
if self.buttonColor == UIColor(rgb: 0x000000, alpha: 0.3) { // if self.buttonColor == UIColor(rgb: 0x000000, alpha: 0.3) {
self.backgroundNode.updateColor(color: UIColor(rgb: 0xf2f2f2, alpha: 0.75), transition: .immediate) // self.backgroundNode.updateColor(color: UIColor(rgb: 0xf2f2f2, alpha: 0.75), transition: .immediate)
} else { // } else {
self.backgroundNode.updateColor(color: self.buttonColor, transition: .immediate) // self.backgroundNode.updateColor(color: self.buttonColor, transition: .immediate)
} // }
} }
} }
@ -130,7 +107,6 @@ final class WallpaperNavigationButtonNode: HighlightTrackingButtonNode {
switch self.content { switch self.content {
case .text: case .text:
let size = self.textNode.updateLayout(constrainedSize) let size = self.textNode.updateLayout(constrainedSize)
let _ = self.darkTextNode.updateLayout(constrainedSize)
self.textSize = size self.textSize = size
return CGSize(width: ceil(size.width) + 16.0, height: 28.0) return CGSize(width: ceil(size.width) + 16.0, height: 28.0)
case let .icon(_, size): case let .icon(_, size):
@ -143,15 +119,13 @@ final class WallpaperNavigationButtonNode: HighlightTrackingButtonNode {
let size = self.bounds.size let size = self.bounds.size
self.backgroundNode.frame = self.bounds self.backgroundNode.frame = self.bounds
self.backgroundNode.update(size: self.backgroundNode.bounds.size, cornerRadius: self.bounds.size.height / 2.0, transition: .immediate) self.backgroundNode.updateLayout(size: self.backgroundNode.bounds.size)
self.vibrancyView.frame = self.bounds self.backgroundNode.cornerRadius = size.height / 2.0
self.iconNode.frame = self.bounds self.iconNode.frame = self.bounds
self.darkIconNode.frame = self.bounds
if let textSize = self.textSize { if let textSize = self.textSize {
self.textNode.frame = CGRect(x: floorToScreenPixels((size.width - textSize.width) / 2.0), y: floorToScreenPixels((size.height - textSize.height) / 2.0), width: textSize.width, height: textSize.height) self.textNode.frame = CGRect(x: floorToScreenPixels((size.width - textSize.width) / 2.0), y: floorToScreenPixels((size.height - textSize.height) / 2.0), width: textSize.width, height: textSize.height)
self.darkTextNode.frame = self.textNode.frame
} }
} }
} }
@ -159,15 +133,11 @@ final class WallpaperNavigationButtonNode: HighlightTrackingButtonNode {
final class WallpaperOptionButtonNode: HighlightTrackingButtonNode { final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
private let backgroundNode: NavigationBackgroundNode private let backgroundNode: NavigationBackgroundNode
private let vibrancyView: UIVisualEffectView
private let checkNode: CheckNode private let checkNode: CheckNode
private let darkCheckNode: CheckNode
private let colorNode: ASImageNode private let colorNode: ASImageNode
private let textNode: ImmediateTextNode private let textNode: ImmediateTextNode
private let darkTextNode: ImmediateTextNode
private var textSize: CGSize? private var textSize: CGSize?
@ -189,14 +159,12 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
self._value = .colors(newValue, colors) self._value = .colors(newValue, colors)
} }
self.checkNode.setSelected(newValue, animated: false) self.checkNode.setSelected(newValue, animated: false)
self.darkCheckNode.setSelected(newValue, animated: false)
} }
} }
var title: String { var title: String {
didSet { didSet {
self.textNode.attributedText = NSAttributedString(string: title, font: Font.medium(13), textColor: .white) self.textNode.attributedText = NSAttributedString(string: title, font: Font.medium(13), textColor: .white)
self.darkTextNode.attributedText = NSAttributedString(string: title, font: Font.medium(13), textColor: UIColor(rgb: 0x000000, alpha: 0.25))
} }
} }
@ -204,62 +172,38 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
self._value = value self._value = value
self.title = title self.title = title
self.backgroundNode = NavigationBackgroundNode(color: UIColor(rgb: 0xffffff, alpha: 0.4)) self.backgroundNode = NavigationBackgroundNode(color: UIColor(rgb: 0x000000, alpha: 0.01))
self.backgroundNode.cornerRadius = 14.0 self.backgroundNode.cornerRadius = 14.0
let blurEffect: UIBlurEffect
if #available(iOS 13.0, *) {
blurEffect = UIBlurEffect(style: .extraLight)
} else {
blurEffect = UIBlurEffect(style: .light)
}
self.vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect))
let darkColor = UIColor(rgb: 0x000000, alpha: 0.25)
self.checkNode = CheckNode(theme: CheckNodeTheme(backgroundColor: .white, strokeColor: .clear, borderColor: .white, overlayBorder: false, hasInset: false, hasShadow: false, borderWidth: 1.5)) self.checkNode = CheckNode(theme: CheckNodeTheme(backgroundColor: .white, strokeColor: .clear, borderColor: .white, overlayBorder: false, hasInset: false, hasShadow: false, borderWidth: 1.5))
self.checkNode.isUserInteractionEnabled = false self.checkNode.isUserInteractionEnabled = false
self.darkCheckNode = CheckNode(theme: CheckNodeTheme(backgroundColor: darkColor, strokeColor: .clear, borderColor: darkColor, overlayBorder: false, hasInset: false, hasShadow: false, borderWidth: 1.5))
self.darkCheckNode.isUserInteractionEnabled = false
self.colorNode = ASImageNode() self.colorNode = ASImageNode()
self.textNode = ImmediateTextNode() self.textNode = ImmediateTextNode()
self.textNode.displaysAsynchronously = false self.textNode.displaysAsynchronously = false
self.textNode.attributedText = NSAttributedString(string: title, font: Font.medium(13), textColor: .white) self.textNode.attributedText = NSAttributedString(string: title, font: Font.medium(13), textColor: .white)
self.darkTextNode = ImmediateTextNode()
self.darkTextNode.displaysAsynchronously = false
self.darkTextNode.attributedText = NSAttributedString(string: title, font: Font.medium(13), textColor: UIColor(rgb: 0x000000, alpha: 0.25))
super.init() super.init()
switch value { switch value {
case let .check(selected): case let .check(selected):
self.checkNode.isHidden = false self.checkNode.isHidden = false
self.darkCheckNode.isHidden = false
self.colorNode.isHidden = true self.colorNode.isHidden = true
self.checkNode.selected = selected self.checkNode.selected = selected
self.darkCheckNode.selected = selected
case let .color(_, color): case let .color(_, color):
self.checkNode.isHidden = true self.checkNode.isHidden = true
self.darkCheckNode.isHidden = true
self.colorNode.isHidden = false self.colorNode.isHidden = false
self.colorNode.image = generateFilledCircleImage(diameter: 18.0, color: color) self.colorNode.image = generateFilledCircleImage(diameter: 18.0, color: color)
case let .colors(_, colors): case let .colors(_, colors):
self.checkNode.isHidden = true self.checkNode.isHidden = true
self.darkCheckNode.isHidden = true
self.colorNode.isHidden = false self.colorNode.isHidden = false
self.colorNode.image = generateColorsImage(diameter: 18.0, colors: colors) self.colorNode.image = generateColorsImage(diameter: 18.0, colors: colors)
} }
self.addSubnode(self.backgroundNode) self.addSubnode(self.backgroundNode)
self.vibrancyView.contentView.addSubnode(self.checkNode) self.addSubnode(self.checkNode)
self.vibrancyView.contentView.addSubnode(self.textNode) self.addSubnode(self.textNode)
self.backgroundNode.view.addSubview(self.vibrancyView)
self.addSubnode(self.darkCheckNode)
self.addSubnode(self.darkTextNode)
self.addSubnode(self.colorNode) self.addSubnode(self.colorNode)
self.highligthedChanged = { [weak self] highlighted in self.highligthedChanged = { [weak self] highlighted in
@ -283,11 +227,11 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
var buttonColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.3) { var buttonColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.3) {
didSet { didSet {
if self.buttonColor == UIColor(rgb: 0x000000, alpha: 0.3) { // if self.buttonColor == UIColor(rgb: 0x000000, alpha: 0.3) {
self.backgroundNode.updateColor(color: UIColor(rgb: 0xf2f2f2, alpha: 0.75), transition: .immediate) // self.backgroundNode.updateColor(color: UIColor(rgb: 0xf2f2f2, alpha: 0.75), transition: .immediate)
} else { // } else {
self.backgroundNode.updateColor(color: self.buttonColor, transition: .immediate) // self.backgroundNode.updateColor(color: self.buttonColor, transition: .immediate)
} // }
} }
} }
@ -357,7 +301,6 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
self._value = .colors(selected, colors) self._value = .colors(selected, colors)
} }
self.checkNode.setSelected(selected, animated: animated) self.checkNode.setSelected(selected, animated: animated)
self.darkCheckNode.setSelected(selected, animated: animated)
} }
func setEnabled(_ enabled: Bool) { func setEnabled(_ enabled: Bool) {
@ -371,7 +314,6 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
override func measure(_ constrainedSize: CGSize) -> CGSize { override func measure(_ constrainedSize: CGSize) -> CGSize {
let size = self.textNode.updateLayout(constrainedSize) let size = self.textNode.updateLayout(constrainedSize)
let _ = self.darkTextNode.updateLayout(constrainedSize)
self.textSize = size self.textSize = size
return CGSize(width: ceil(size.width) + 48.0, height: 30.0) return CGSize(width: ceil(size.width) + 48.0, height: 30.0)
} }
@ -381,7 +323,6 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
self.backgroundNode.frame = self.bounds self.backgroundNode.frame = self.bounds
self.backgroundNode.update(size: self.backgroundNode.bounds.size, cornerRadius: 15.0, transition: .immediate) self.backgroundNode.update(size: self.backgroundNode.bounds.size, cornerRadius: 15.0, transition: .immediate)
self.vibrancyView.frame = self.bounds
guard let _ = self.textSize else { guard let _ = self.textSize else {
return return
@ -392,12 +333,10 @@ final class WallpaperOptionButtonNode: HighlightTrackingButtonNode {
let checkSize = CGSize(width: 18.0, height: 18.0) let checkSize = CGSize(width: 18.0, height: 18.0)
let checkFrame = CGRect(origin: CGPoint(x: padding, y: padding), size: checkSize) let checkFrame = CGRect(origin: CGPoint(x: padding, y: padding), size: checkSize)
self.checkNode.frame = checkFrame self.checkNode.frame = checkFrame
self.darkCheckNode.frame = checkFrame
self.colorNode.frame = checkFrame self.colorNode.frame = checkFrame
if let textSize = self.textSize { if let textSize = self.textSize {
self.textNode.frame = CGRect(x: max(padding + checkSize.width + spacing, padding + checkSize.width + floor((self.bounds.width - padding - checkSize.width - textSize.width) / 2.0) - 2.0), y: floorToScreenPixels((self.bounds.height - textSize.height) / 2.0), width: textSize.width, height: textSize.height) self.textNode.frame = CGRect(x: max(padding + checkSize.width + spacing, padding + checkSize.width + floor((self.bounds.width - padding - checkSize.width - textSize.width) / 2.0) - 2.0), y: floorToScreenPixels((self.bounds.height - textSize.height) / 2.0), width: textSize.width, height: textSize.height)
self.darkTextNode.frame = self.textNode.frame
} }
} }
} }

View File

@ -479,7 +479,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1434950843] = { return Api.MessageAction.parse_messageActionSetChatTheme($0) } dict[-1434950843] = { return Api.MessageAction.parse_messageActionSetChatTheme($0) }
dict[-1136350937] = { return Api.MessageAction.parse_messageActionSetChatWallPaper($0) } dict[-1136350937] = { return Api.MessageAction.parse_messageActionSetChatWallPaper($0) }
dict[1007897979] = { return Api.MessageAction.parse_messageActionSetMessagesTTL($0) } dict[1007897979] = { return Api.MessageAction.parse_messageActionSetMessagesTTL($0) }
dict[-632006598] = { return Api.MessageAction.parse_messageActionSetSameChatWallPaper($0) } dict[-1065845395] = { return Api.MessageAction.parse_messageActionSetSameChatWallPaper($0) }
dict[1474192222] = { return Api.MessageAction.parse_messageActionSuggestProfilePhoto($0) } dict[1474192222] = { return Api.MessageAction.parse_messageActionSuggestProfilePhoto($0) }
dict[228168278] = { return Api.MessageAction.parse_messageActionTopicCreate($0) } dict[228168278] = { return Api.MessageAction.parse_messageActionTopicCreate($0) }
dict[-1064024032] = { return Api.MessageAction.parse_messageActionTopicEdit($0) } dict[-1064024032] = { return Api.MessageAction.parse_messageActionTopicEdit($0) }

View File

@ -263,7 +263,7 @@ public extension Api {
case messageActionSetChatTheme(emoticon: String) case messageActionSetChatTheme(emoticon: String)
case messageActionSetChatWallPaper(wallpaper: Api.WallPaper) case messageActionSetChatWallPaper(wallpaper: Api.WallPaper)
case messageActionSetMessagesTTL(flags: Int32, period: Int32, autoSettingFrom: Int64?) case messageActionSetMessagesTTL(flags: Int32, period: Int32, autoSettingFrom: Int64?)
case messageActionSetSameChatWallPaper case messageActionSetSameChatWallPaper(wallpaper: Api.WallPaper)
case messageActionSuggestProfilePhoto(photo: Api.Photo) case messageActionSuggestProfilePhoto(photo: Api.Photo)
case messageActionTopicCreate(flags: Int32, title: String, iconColor: Int32, iconEmojiId: Int64?) case messageActionTopicCreate(flags: Int32, title: String, iconColor: Int32, iconEmojiId: Int64?)
case messageActionTopicEdit(flags: Int32, title: String?, iconEmojiId: Int64?, closed: Api.Bool?, hidden: Api.Bool?) case messageActionTopicEdit(flags: Int32, title: String?, iconEmojiId: Int64?, closed: Api.Bool?, hidden: Api.Bool?)
@ -522,11 +522,11 @@ public extension Api {
serializeInt32(period, buffer: buffer, boxed: false) serializeInt32(period, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 0) != 0 {serializeInt64(autoSettingFrom!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 0) != 0 {serializeInt64(autoSettingFrom!, buffer: buffer, boxed: false)}
break break
case .messageActionSetSameChatWallPaper: case .messageActionSetSameChatWallPaper(let wallpaper):
if boxed { if boxed {
buffer.appendInt32(-632006598) buffer.appendInt32(-1065845395)
} }
wallpaper.serialize(buffer, true)
break break
case .messageActionSuggestProfilePhoto(let photo): case .messageActionSuggestProfilePhoto(let photo):
if boxed { if boxed {
@ -637,8 +637,8 @@ public extension Api {
return ("messageActionSetChatWallPaper", [("wallpaper", wallpaper as Any)]) return ("messageActionSetChatWallPaper", [("wallpaper", wallpaper as Any)])
case .messageActionSetMessagesTTL(let flags, let period, let autoSettingFrom): case .messageActionSetMessagesTTL(let flags, let period, let autoSettingFrom):
return ("messageActionSetMessagesTTL", [("flags", flags as Any), ("period", period as Any), ("autoSettingFrom", autoSettingFrom as Any)]) return ("messageActionSetMessagesTTL", [("flags", flags as Any), ("period", period as Any), ("autoSettingFrom", autoSettingFrom as Any)])
case .messageActionSetSameChatWallPaper: case .messageActionSetSameChatWallPaper(let wallpaper):
return ("messageActionSetSameChatWallPaper", []) return ("messageActionSetSameChatWallPaper", [("wallpaper", wallpaper as Any)])
case .messageActionSuggestProfilePhoto(let photo): case .messageActionSuggestProfilePhoto(let photo):
return ("messageActionSuggestProfilePhoto", [("photo", photo as Any)]) return ("messageActionSuggestProfilePhoto", [("photo", photo as Any)])
case .messageActionTopicCreate(let flags, let title, let iconColor, let iconEmojiId): case .messageActionTopicCreate(let flags, let title, let iconColor, let iconEmojiId):
@ -1092,7 +1092,17 @@ public extension Api {
} }
} }
public static func parse_messageActionSetSameChatWallPaper(_ reader: BufferReader) -> MessageAction? { public static func parse_messageActionSetSameChatWallPaper(_ reader: BufferReader) -> MessageAction? {
return Api.MessageAction.messageActionSetSameChatWallPaper var _1: Api.WallPaper?
if let signature = reader.readInt32() {
_1 = Api.parse(reader, signature: signature) as? Api.WallPaper
}
let _c1 = _1 != nil
if _c1 {
return Api.MessageAction.messageActionSetSameChatWallPaper(wallpaper: _1!)
}
else {
return nil
}
} }
public static func parse_messageActionSuggestProfilePhoto(_ reader: BufferReader) -> MessageAction? { public static func parse_messageActionSuggestProfilePhoto(_ reader: BufferReader) -> MessageAction? {
var _1: Api.Photo? var _1: Api.Photo?

View File

@ -6884,11 +6884,11 @@ public extension Api.functions.messages {
public extension Api.functions.messages { public extension Api.functions.messages {
static func setChatWallPaper(flags: Int32, peer: Api.InputPeer, wallpaper: Api.InputWallPaper?, settings: Api.WallPaperSettings?, id: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) { static func setChatWallPaper(flags: Int32, peer: Api.InputPeer, wallpaper: Api.InputWallPaper?, settings: Api.WallPaperSettings?, id: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer() let buffer = Buffer()
buffer.appendInt32(-609568219) buffer.appendInt32(-1879389471)
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
peer.serialize(buffer, true) peer.serialize(buffer, true)
if Int(flags) & Int(1 << 0) != 0 {wallpaper!.serialize(buffer, true)} if Int(flags) & Int(1 << 0) != 0 {wallpaper!.serialize(buffer, true)}
if Int(flags) & Int(1 << 0) != 0 {settings!.serialize(buffer, true)} if Int(flags) & Int(1 << 2) != 0 {settings!.serialize(buffer, true)}
if Int(flags) & Int(1 << 1) != 0 {serializeInt32(id!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 1) != 0 {serializeInt32(id!, buffer: buffer, boxed: false)}
return (FunctionDescription(name: "messages.setChatWallPaper", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("wallpaper", String(describing: wallpaper)), ("settings", String(describing: settings)), ("id", String(describing: id))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in return (FunctionDescription(name: "messages.setChatWallPaper", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("wallpaper", String(describing: wallpaper)), ("settings", String(describing: settings)), ("id", String(describing: id))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
let reader = BufferReader(buffer) let reader = BufferReader(buffer)

View File

@ -110,8 +110,8 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe
return TelegramMediaAction(action: .requestedPeer(buttonId: buttonId, peerId: peer.peerId)) return TelegramMediaAction(action: .requestedPeer(buttonId: buttonId, peerId: peer.peerId))
case let .messageActionSetChatWallPaper(wallpaper): case let .messageActionSetChatWallPaper(wallpaper):
return TelegramMediaAction(action: .setChatWallpaper(wallpaper: TelegramWallpaper(apiWallpaper: wallpaper))) return TelegramMediaAction(action: .setChatWallpaper(wallpaper: TelegramWallpaper(apiWallpaper: wallpaper)))
case .messageActionSetSameChatWallPaper: case let .messageActionSetSameChatWallPaper(wallpaper):
return TelegramMediaAction(action: .setSameChatWallpaper) return TelegramMediaAction(action: .setSameChatWallpaper(wallpaper: TelegramWallpaper(apiWallpaper: wallpaper)))
} }
} }

View File

@ -102,7 +102,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case attachMenuBotAllowed case attachMenuBotAllowed
case requestedPeer(buttonId: Int32, peerId: PeerId) case requestedPeer(buttonId: Int32, peerId: PeerId)
case setChatWallpaper(wallpaper: TelegramWallpaper) case setChatWallpaper(wallpaper: TelegramWallpaper)
case setSameChatWallpaper case setSameChatWallpaper(wallpaper: TelegramWallpaper)
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0) let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
@ -190,7 +190,11 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
self = .unknown self = .unknown
} }
case 34: case 34:
self = .setSameChatWallpaper if let wallpaper = decoder.decode(TelegramWallpaperNativeCodable.self, forKey: "wallpaper")?.value {
self = .setSameChatWallpaper(wallpaper: wallpaper)
} else {
self = .unknown
}
default: default:
self = .unknown self = .unknown
} }
@ -355,8 +359,9 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case let .setChatWallpaper(wallpaper): case let .setChatWallpaper(wallpaper):
encoder.encodeInt32(33, forKey: "_rawValue") encoder.encodeInt32(33, forKey: "_rawValue")
encoder.encode(TelegramWallpaperNativeCodable(wallpaper), forKey: "wallpaper") encoder.encode(TelegramWallpaperNativeCodable(wallpaper), forKey: "wallpaper")
case .setSameChatWallpaper: case let .setSameChatWallpaper(wallpaper):
encoder.encodeInt32(34, forKey: "_rawValue") encoder.encodeInt32(34, forKey: "_rawValue")
encoder.encode(TelegramWallpaperNativeCodable(wallpaper), forKey: "wallpaper")
} }
} }

View File

@ -134,15 +134,17 @@ func _internal_setChatWallpaper(account: Account, peerId: PeerId, wallpaper: Tel
} }
}) })
var flags: Int32 = 0
var inputWallpaper: Api.InputWallPaper? var inputWallpaper: Api.InputWallPaper?
var inputSettings: Api.WallPaperSettings? var inputSettings: Api.WallPaperSettings?
if let inputWallpaperAndInputSettings = wallpaper?.apiInputWallpaperAndSettings { if let inputWallpaperAndInputSettings = wallpaper?.apiInputWallpaperAndSettings {
flags |= 1 << 0
inputWallpaper = inputWallpaperAndInputSettings.0 inputWallpaper = inputWallpaperAndInputSettings.0
inputSettings = inputWallpaperAndInputSettings.1 inputSettings = inputWallpaperAndInputSettings.1
} }
return account.network.request(Api.functions.messages.setChatWallPaper(flags: flags, peer: inputPeer, wallpaper: inputWallpaper, settings: inputSettings, id: nil))
let flags: Int32 = 1 << 0
return account.network.request(Api.functions.messages.setChatWallPaper(flags: flags, peer: inputPeer, wallpaper: inputWallpaper ?? .inputWallPaperNoFile(id: 0), settings: inputSettings ?? apiWallpaperSettings(WallpaperSettings()), id: nil))
|> `catch` { error in |> `catch` { error in
return .complete() return .complete()
} }
@ -158,7 +160,7 @@ public enum SetExistingChatWallpaperError {
case generic case generic
} }
func _internal_setExistingChatWallpaper(account: Account, messageId: MessageId) -> Signal<Void, SetExistingChatWallpaperError> { func _internal_setExistingChatWallpaper(account: Account, messageId: MessageId, wallpaper: TelegramWallpaper?) -> Signal<Void, SetExistingChatWallpaperError> {
return account.postbox.transaction { transaction -> Peer? in return account.postbox.transaction { transaction -> Peer? in
if let peer = transaction.getPeer(messageId.peerId), let message = transaction.getMessage(messageId) { if let peer = transaction.getPeer(messageId.peerId), let message = transaction.getMessage(messageId) {
if let action = message.media.first(where: { $0 is TelegramMediaAction }) as? TelegramMediaAction, case let .setChatWallpaper(wallpaper) = action.action { if let action = message.media.first(where: { $0 is TelegramMediaAction }) as? TelegramMediaAction, case let .setChatWallpaper(wallpaper) = action.action {
@ -180,8 +182,14 @@ func _internal_setExistingChatWallpaper(account: Account, messageId: MessageId)
guard let peer = peer, let inputPeer = apiInputPeer(peer) else { guard let peer = peer, let inputPeer = apiInputPeer(peer) else {
return .complete() return .complete()
} }
let flags: Int32 = 1 << 1 var flags: Int32 = 1 << 1
return account.network.request(Api.functions.messages.setChatWallPaper(flags: flags, peer: inputPeer, wallpaper: nil, settings: nil, id: messageId.id))
var inputSettings: Api.WallPaperSettings?
if let inputWallpaperAndInputSettings = wallpaper?.apiInputWallpaperAndSettings {
flags |= 1 << 2
inputSettings = inputWallpaperAndInputSettings.1
}
return account.network.request(Api.functions.messages.setChatWallPaper(flags: flags, peer: inputPeer, wallpaper: nil, settings: inputSettings, id: messageId.id))
|> `catch` { _ -> Signal<Api.Updates, SetExistingChatWallpaperError> in |> `catch` { _ -> Signal<Api.Updates, SetExistingChatWallpaperError> in
return .fail(.generic) return .fail(.generic)
} }

View File

@ -21,8 +21,8 @@ public extension TelegramEngine {
return _internal_setChatWallpaper(account: self.account, peerId: peerId, wallpaper: wallpaper) return _internal_setChatWallpaper(account: self.account, peerId: peerId, wallpaper: wallpaper)
} }
public func setExistingChatWallpaper(messageId: MessageId) -> Signal<Void, SetExistingChatWallpaperError> { public func setExistingChatWallpaper(messageId: MessageId, wallpaper: TelegramWallpaper?) -> Signal<Void, SetExistingChatWallpaperError> {
return _internal_setExistingChatWallpaper(account: self.account, messageId: messageId) return _internal_setExistingChatWallpaper(account: self.account, messageId: messageId, wallpaper: wallpaper)
} }
} }
} }

View File

@ -846,7 +846,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
strongSelf.chatDisplayNode.dismissInput() strongSelf.chatDisplayNode.dismissInput()
let wallpaperPreviewController = WallpaperGalleryController(context: strongSelf.context, source: .wallpaper(wallpaper, nil, [], nil, nil, nil), mode: .peer(EnginePeer(peer), true)) let wallpaperPreviewController = WallpaperGalleryController(context: strongSelf.context, source: .wallpaper(wallpaper, nil, [], nil, nil, nil), mode: .peer(EnginePeer(peer), true))
wallpaperPreviewController.apply = { wallpaper, options, _ in wallpaperPreviewController.apply = { wallpaper, options, _ in
let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id) let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id, wallpaper: nil)
|> deliverOnMainQueue).start(completed: { [weak wallpaperPreviewController] in |> deliverOnMainQueue).start(completed: { [weak wallpaperPreviewController] in
wallpaperPreviewController?.dismiss() wallpaperPreviewController?.dismiss()
}) })
@ -18537,7 +18537,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
controller.navigationPresentation = .modal controller.navigationPresentation = .modal
controller.apply = { [weak self] wallpaper, options, cropRect in controller.apply = { [weak self] wallpaper, options, cropRect in
if let strongSelf = self { if let strongSelf = self {
uploadCustomPeerWallpaper(context: strongSelf.context, wallpaper: wallpaper, mode: options, cropRect: cropRect, peerId: peerId, completion: { uploadCustomPeerWallpaper(context: strongSelf.context, wallpaper: wallpaper, mode: options, cropRect: cropRect, brightnessMultiplier: nil, peerId: peerId, completion: {
dismissControllers() dismissControllers()
}) })
} }