mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Fix first time pattern background loading
This commit is contained in:
parent
6aa79050b0
commit
4b19b57a86
@ -173,6 +173,13 @@ final class SettingsThemeWallpaperNode: ASDisplayNode {
|
||||
self.arguments = PatternWallpaperArguments(colors: [.clear], rotation: nil, customPatternColor: isLight ? .black : .white)
|
||||
}
|
||||
imageSignal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .thumbnail, autoFetchFullSize: true)
|
||||
|> mapToSignal { value -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> in
|
||||
if let value = value {
|
||||
return .single(value)
|
||||
} else {
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.imageNode.alpha = 1.0
|
||||
|
||||
|
@ -11,7 +11,46 @@ import TelegramPresentationData
|
||||
import TelegramUIPreferences
|
||||
import AccountContext
|
||||
|
||||
private func availableColors() -> [UInt32] {
|
||||
private func availableColors(theme: PresentationTheme) -> [UInt32] {
|
||||
if theme.overallDarkAppearance {
|
||||
return ([
|
||||
0xffffff,
|
||||
0xd4dfea,
|
||||
0xb3cde1,
|
||||
0x6ab7ea,
|
||||
0x008dd0,
|
||||
0xd3e2da,
|
||||
0xc8e6c9,
|
||||
0xc5e1a5,
|
||||
0x61b06e,
|
||||
0xcdcfaf,
|
||||
0xa7a895,
|
||||
0x7c6f72,
|
||||
0xffd7ae,
|
||||
0xffb66d,
|
||||
0xde8751,
|
||||
0xefd5e0,
|
||||
0xdba1b9,
|
||||
0xffafaf,
|
||||
0xf16a60,
|
||||
0xe8bcea,
|
||||
0x9592ed,
|
||||
0xd9bc60,
|
||||
0xb17e49,
|
||||
0xd5cef7,
|
||||
0xdf506b,
|
||||
0x8bd2cc,
|
||||
0x3c847e,
|
||||
0x22612c,
|
||||
0x244d7c,
|
||||
0x3d3b85,
|
||||
0x65717d,
|
||||
0x18222d,
|
||||
0x000000
|
||||
] as [UInt32]).filter { color in
|
||||
return UIColor(rgb: color).hsb.b <= 0.4
|
||||
}
|
||||
} else {
|
||||
return [
|
||||
0xffffff,
|
||||
0xd4dfea,
|
||||
@ -47,11 +86,7 @@ private func availableColors() -> [UInt32] {
|
||||
0x18222d,
|
||||
0x000000
|
||||
]
|
||||
}
|
||||
|
||||
private func randomColor() -> UInt32 {
|
||||
let colors = availableColors()
|
||||
return colors[1 ..< colors.count - 1].randomElement() ?? 0x000000
|
||||
}
|
||||
}
|
||||
|
||||
final class ThemeColorsGridController: ViewController {
|
||||
@ -120,7 +155,7 @@ final class ThemeColorsGridController: ViewController {
|
||||
}
|
||||
|
||||
override func loadDisplayNode() {
|
||||
self.displayNode = ThemeColorsGridControllerNode(context: self.context, presentationData: self.presentationData, colors: availableColors(), present: { [weak self] controller, arguments in
|
||||
self.displayNode = ThemeColorsGridControllerNode(context: self.context, presentationData: self.presentationData, colors: availableColors(theme: self.presentationData.theme), present: { [weak self] controller, arguments in
|
||||
self?.present(controller, in: .window(.root), with: arguments, blockInteraction: true)
|
||||
}, pop: { [weak self] in
|
||||
if let strongSelf = self, let navigationController = strongSelf.navigationController as? NavigationController {
|
||||
|
@ -251,6 +251,13 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
let fileReference = FileMediaReference.standalone(media: file.file)
|
||||
if wallpaper.isPattern {
|
||||
signal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: false)
|
||||
|> mapToSignal { value -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> in
|
||||
if let value = value {
|
||||
return .single(value)
|
||||
} else {
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
signal = .complete()
|
||||
}
|
||||
|
@ -739,6 +739,13 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio
|
||||
}
|
||||
if ["image/png", "image/svg+xml", "application/x-tgwallpattern"].contains(file.mimeType) {
|
||||
return patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: representations, mode: .thumbnail)
|
||||
|> mapToSignal { value -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> in
|
||||
if let value = value {
|
||||
return .single(value)
|
||||
} else {
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return wallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, fileReference: FileMediaReference.message(message: MessageReference(message), media: file), representations: representations, alwaysShowThumbnailFirst: false, thumbnail: true, autoFetchFullSize: true)
|
||||
}
|
||||
|
@ -503,12 +503,13 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
|
||||
let dimensions = file.dimensions ?? PixelDimensions(width: 2000, height: 4000)
|
||||
convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: reference(for: file.resource, media: file, message: nil)))
|
||||
|
||||
let signal = patternWallpaperImage(account: self.context.account, accountManager: self.context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: true)
|
||||
let signal = patternWallpaperImage(account: self.context.account, accountManager: self.context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: true, onlyFullSize: true)
|
||||
self.patternImageDisposable.set((signal
|
||||
|> deliverOnMainQueue).start(next: { [weak self] generator in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
if let generator = generator {
|
||||
strongSelf.validPatternImage = ValidPatternImage(wallpaper: wallpaper, generate: generator)
|
||||
strongSelf.validPatternGeneratedImage = nil
|
||||
if let size = strongSelf.validLayout {
|
||||
@ -516,6 +517,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
|
||||
} else {
|
||||
strongSelf._isReady.set(true)
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -401,14 +401,14 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana
|
||||
}
|
||||
}
|
||||
|
||||
public func patternWallpaperImage(account: Account, accountManager: AccountManager, representations: [ImageRepresentationWithReference], mode: PatternWallpaperDrawMode, autoFetchFullSize: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
||||
public func patternWallpaperImage(account: Account, accountManager: AccountManager, representations: [ImageRepresentationWithReference], mode: PatternWallpaperDrawMode, autoFetchFullSize: Bool = false, onlyFullSize: Bool = false) -> Signal<((TransformImageArguments) -> DrawingContext?)?, NoError> {
|
||||
return patternWallpaperDatas(account: account, accountManager: accountManager, representations: representations, mode: mode, autoFetchFullSize: autoFetchFullSize)
|
||||
|> mapToSignal { (thumbnailData, fullSizeData, fullSizeComplete) in
|
||||
return patternWallpaperImageInternal(thumbnailData: thumbnailData, fullSizeData: fullSizeData, fullSizeComplete: fullSizeComplete, mode: mode)
|
||||
return patternWallpaperImageInternal(thumbnailData: thumbnailData, fullSizeData: fullSizeData, fullSizeComplete: fullSizeComplete, mode: mode, onlyFullSize: onlyFullSize)
|
||||
}
|
||||
}
|
||||
|
||||
public func patternWallpaperImageInternal(thumbnailData: Data?, fullSizeData: Data?, fullSizeComplete: Bool, mode: PatternWallpaperDrawMode) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
||||
public func patternWallpaperImageInternal(thumbnailData: Data?, fullSizeData: Data?, fullSizeComplete: Bool, mode: PatternWallpaperDrawMode, onlyFullSize: Bool = false) -> Signal<((TransformImageArguments) -> DrawingContext?)?, NoError> {
|
||||
var prominent = false
|
||||
if case .thumbnail = mode {
|
||||
prominent = true
|
||||
@ -435,6 +435,12 @@ public func patternWallpaperImageInternal(thumbnailData: Data?, fullSizeData: Da
|
||||
}
|
||||
}
|
||||
|
||||
if onlyFullSize {
|
||||
if fullSizeData == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return { arguments in
|
||||
var scale = scale
|
||||
if scale.isZero {
|
||||
|
Loading…
x
Reference in New Issue
Block a user