Wallpaper fixes

This commit is contained in:
Ali 2021-06-22 22:12:24 +04:00
parent 7a4ea093e5
commit de77745fb1
4 changed files with 44 additions and 15 deletions

View File

@ -38,11 +38,9 @@ var dayColorPresets: [PresentationThemeAccentColor] = [
PresentationThemeAccentColor(index: 104, baseColor: .preset, accentColor: 0xea8ced, bubbleColors: (0xea8ced, 0x00c2ed), wallpaper: nil)
]
//CJNyxPMgSVAEAAAAvW9sMwc51cw?bg_color=7fa381~fff5c5~336f55~fbe37d&intensity=-20
var nightColorPresets: [PresentationThemeAccentColor] = [
PresentationThemeAccentColor(index: 101, baseColor: .preset, accentColor: 0x007aff, bubbleColors: (0x007aff, 0xff53f4), wallpaper: nil),
PresentationThemeAccentColor(index: 101, baseColor: .preset, accentColor: 0x007aff, bubbleColors: (0x007aff, 0xff53f4), wallpaper: patternWallpaper(data: .variant4, colors: [0xe4b2ea, 0x8376c2, 0xeab9d9, 0xb493e6], intensity: -35, rotation: nil)),
PresentationThemeAccentColor(index: 102, baseColor: .preset, accentColor: 0x00b09b, bubbleColors: (0xaee946, 0x00b09b), wallpaper: patternWallpaper(data: .variant9, colors: [0xe4b2ea, 0x8376c2, 0xeab9d9, 0xb493e6], intensity: -35, rotation: nil)),
PresentationThemeAccentColor(index: 103, baseColor: .preset, accentColor: 0xd33213, bubbleColors: (0xf9db00, 0xd33213), wallpaper: nil),
PresentationThemeAccentColor(index: 104, baseColor: .preset, accentColor: 0xea8ced, bubbleColors: (0xea8ced, 0x00c2ed), wallpaper: nil)
PresentationThemeAccentColor(index: 103, baseColor: .preset, accentColor: 0xd33213, bubbleColors: (0xf9db00, 0xd33213), wallpaper: patternWallpaper(data: .variant2, colors: [0xfec496, 0xdd6cb9, 0x962fbf, 0x4f5bd5], intensity: -40, rotation: nil)),
PresentationThemeAccentColor(index: 104, baseColor: .preset, accentColor: 0xea8ced, bubbleColors: (0xea8ced, 0x00c2ed), wallpaper: patternWallpaper(data: .variant6, colors: [0x8adbf2, 0x888dec, 0xe39fea, 0x679ced], intensity: -30, rotation: nil))
]

View File

@ -72,11 +72,11 @@ class WallpaperGalleryItem: GalleryItem {
private let progressDiameter: CGFloat = 50.0
private let motionAmount: CGFloat = 32.0
private func reference(for resource: MediaResource, media: Media, message: Message?) -> MediaResourceReference {
private func reference(for resource: MediaResource, media: Media, message: Message?, slug: String?) -> MediaResourceReference {
if let message = message {
return .media(media: .message(message: MessageReference(message), media: media), resource: resource)
}
return .wallpaper(wallpaper: nil, resource: resource)
return .wallpaper(wallpaper: slug.flatMap(WallpaperReference.slug), resource: resource)
}
final class WallpaperGalleryItemNode: GalleryItemNode {
@ -382,9 +382,9 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
var convertedRepresentations: [ImageRepresentationWithReference] = []
for representation in file.file.previewRepresentations {
convertedRepresentations.append(ImageRepresentationWithReference(representation: representation, reference: reference(for: representation.resource, media: file.file, message: message)))
convertedRepresentations.append(ImageRepresentationWithReference(representation: representation, reference: reference(for: representation.resource, media: file.file, message: message, slug: file.slug)))
}
convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: reference(for: file.file.resource, media: file.file, message: message)))
convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: reference(for: file.file.resource, media: file.file, message: message, slug: file.slug)))
if wallpaper.isPattern {
var patternColors: [UIColor] = []

View File

@ -69,6 +69,19 @@ public func stickerPackFileReference(_ file: TelegramMediaFile) -> FileMediaRefe
return .standalone(media: file)
}
private func areResourcesEqual(_ lhs: MediaResource, _ rhs: MediaResource) -> Bool {
if let lhsResource = lhs as? CloudDocumentMediaResource, let rhsResource = rhs as? CloudDocumentMediaResource {
if lhsResource.fileId == rhsResource.fileId {
return true
}
} else if let lhsResource = lhs as? CloudDocumentSizeMediaResource, let rhsResource = rhs as? CloudDocumentSizeMediaResource {
if lhsResource.documentId == rhsResource.documentId && lhsResource.sizeSpec == rhsResource.sizeSpec {
return true
}
}
return lhs.id.isEqual(to: rhs.id)
}
private func findMediaResource(media: Media, previousMedia: Media?, resource: MediaResource) -> TelegramMediaResource? {
if let image = media as? TelegramMediaImage {
for representation in image.representations {
@ -87,11 +100,11 @@ private func findMediaResource(media: Media, previousMedia: Media?, resource: Me
}
}
} else if let file = media as? TelegramMediaFile {
if file.resource.id.isEqual(to: resource.id) {
if areResourcesEqual(file.resource, resource) {
return file.resource
} else {
for representation in file.previewRepresentations {
if representation.resource.id.isEqual(to: resource.id) {
if areResourcesEqual(representation.resource, resource) {
return representation.resource
}
}
@ -387,7 +400,13 @@ final class MediaReferenceRevalidationContext {
}
func wallpapers(postbox: Postbox, network: Network, background: Bool, wallpaper: WallpaperReference?) -> Signal<[TelegramWallpaper], RevalidateMediaReferenceError> {
return self.genericItem(key: .wallpapers, background: background, request: { next, error in
let key: MediaReferenceRevalidationKey
if let wallpaper = wallpaper {
key = .wallpaper(wallpaper: wallpaper)
} else {
key = .wallpapers
}
return self.genericItem(key: key, background: background, request: { next, error in
let signal: Signal<[TelegramWallpaper]?, RevalidateMediaReferenceError>
if let wallpaper = wallpaper, case let .slug(slug) = wallpaper {
signal = getWallpaper(network: network, slug: slug)
@ -399,7 +418,6 @@ final class MediaReferenceRevalidationContext {
signal = telegramWallpapers(postbox: postbox, network: network, forceUpdate: true)
|> last
|> mapError { _ -> RevalidateMediaReferenceError in
return .generic
}
}
return (signal

View File

@ -550,15 +550,22 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
let contentAlpha = abs(intensity)
self.gradientBackgroundNode?.contentView.alpha = contentAlpha
self.contentNode.alpha = contentAlpha
if self.patternImageNode.image != nil {
self.patternImageNode.backgroundColor = nil
} else {
self.patternImageNode.backgroundColor = .black
}
} else {
self.backgroundColor = nil
self.gradientBackgroundNode?.contentView.alpha = 1.0
self.contentNode.alpha = 1.0
self.patternImageNode.backgroundColor = nil
}
default:
self.patternImageDisposable.set(nil)
self.validPatternImage = nil
self.patternImageNode.isHidden = true
self.patternImageNode.backgroundColor = nil
self.backgroundColor = nil
self.gradientBackgroundNode?.contentView.alpha = 1.0
self.contentNode.alpha = 1.0
@ -574,7 +581,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
var patternIsLight: Bool = false
switch wallpaper {
case let .file(_, _, _, _, isPattern, _, _, file, settings) where isPattern:
case let .file(_, _, _, _, isPattern, _, slug, file, settings) where isPattern:
var updated = true
let brightness = UIColor.average(of: settings.colors.map(UIColor.init(rgb:))).hsb.b
patternIsLight = brightness > 0.3
@ -600,7 +607,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
if let message = message {
return .media(media: .message(message: MessageReference(message), media: media), resource: resource)
}
return .wallpaper(wallpaper: nil, resource: resource)
return .wallpaper(wallpaper: .slug(slug), resource: resource)
}
var convertedRepresentations: [ImageRepresentationWithReference] = []
@ -642,6 +649,11 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
if invertPattern {
patternColor = .clear
patternBackgroundColor = .clear
if self.patternImageNode.image == nil {
self.patternImageNode.backgroundColor = .black
} else {
self.patternImageNode.backgroundColor = nil
}
} else {
if patternIsLight {
patternColor = .black
@ -649,6 +661,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
patternColor = .white
}
patternBackgroundColor = .clear
self.patternImageNode.backgroundColor = nil
}
let updatedGeneratedImage = ValidPatternGeneratedImage(wallpaper: validPatternImage.wallpaper, size: size, patternColor: patternColor.rgb, backgroundColor: patternBackgroundColor.rgb, invertPattern: invertPattern)