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)
|
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)
|
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 {
|
} else {
|
||||||
self.imageNode.alpha = 1.0
|
self.imageNode.alpha = 1.0
|
||||||
|
|
||||||
|
@ -11,47 +11,82 @@ import TelegramPresentationData
|
|||||||
import TelegramUIPreferences
|
import TelegramUIPreferences
|
||||||
import AccountContext
|
import AccountContext
|
||||||
|
|
||||||
private func availableColors() -> [UInt32] {
|
private func availableColors(theme: PresentationTheme) -> [UInt32] {
|
||||||
return [
|
if theme.overallDarkAppearance {
|
||||||
0xffffff,
|
return ([
|
||||||
0xd4dfea,
|
0xffffff,
|
||||||
0xb3cde1,
|
0xd4dfea,
|
||||||
0x6ab7ea,
|
0xb3cde1,
|
||||||
0x008dd0,
|
0x6ab7ea,
|
||||||
0xd3e2da,
|
0x008dd0,
|
||||||
0xc8e6c9,
|
0xd3e2da,
|
||||||
0xc5e1a5,
|
0xc8e6c9,
|
||||||
0x61b06e,
|
0xc5e1a5,
|
||||||
0xcdcfaf,
|
0x61b06e,
|
||||||
0xa7a895,
|
0xcdcfaf,
|
||||||
0x7c6f72,
|
0xa7a895,
|
||||||
0xffd7ae,
|
0x7c6f72,
|
||||||
0xffb66d,
|
0xffd7ae,
|
||||||
0xde8751,
|
0xffb66d,
|
||||||
0xefd5e0,
|
0xde8751,
|
||||||
0xdba1b9,
|
0xefd5e0,
|
||||||
0xffafaf,
|
0xdba1b9,
|
||||||
0xf16a60,
|
0xffafaf,
|
||||||
0xe8bcea,
|
0xf16a60,
|
||||||
0x9592ed,
|
0xe8bcea,
|
||||||
0xd9bc60,
|
0x9592ed,
|
||||||
0xb17e49,
|
0xd9bc60,
|
||||||
0xd5cef7,
|
0xb17e49,
|
||||||
0xdf506b,
|
0xd5cef7,
|
||||||
0x8bd2cc,
|
0xdf506b,
|
||||||
0x3c847e,
|
0x8bd2cc,
|
||||||
0x22612c,
|
0x3c847e,
|
||||||
0x244d7c,
|
0x22612c,
|
||||||
0x3d3b85,
|
0x244d7c,
|
||||||
0x65717d,
|
0x3d3b85,
|
||||||
0x18222d,
|
0x65717d,
|
||||||
0x000000
|
0x18222d,
|
||||||
]
|
0x000000
|
||||||
}
|
] as [UInt32]).filter { color in
|
||||||
|
return UIColor(rgb: color).hsb.b <= 0.4
|
||||||
private func randomColor() -> UInt32 {
|
}
|
||||||
let colors = availableColors()
|
} else {
|
||||||
return colors[1 ..< colors.count - 1].randomElement() ?? 0x000000
|
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
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class ThemeColorsGridController: ViewController {
|
final class ThemeColorsGridController: ViewController {
|
||||||
@ -120,7 +155,7 @@ final class ThemeColorsGridController: ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func loadDisplayNode() {
|
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)
|
self?.present(controller, in: .window(.root), with: arguments, blockInteraction: true)
|
||||||
}, pop: { [weak self] in
|
}, pop: { [weak self] in
|
||||||
if let strongSelf = self, let navigationController = strongSelf.navigationController as? NavigationController {
|
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)
|
let fileReference = FileMediaReference.standalone(media: file.file)
|
||||||
if wallpaper.isPattern {
|
if wallpaper.isPattern {
|
||||||
signal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: false)
|
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 {
|
} else {
|
||||||
signal = .complete()
|
signal = .complete()
|
||||||
}
|
}
|
||||||
|
@ -739,6 +739,13 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio
|
|||||||
}
|
}
|
||||||
if ["image/png", "image/svg+xml", "application/x-tgwallpattern"].contains(file.mimeType) {
|
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)
|
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 {
|
} 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)
|
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,18 +503,20 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
|
|||||||
let dimensions = file.dimensions ?? PixelDimensions(width: 2000, height: 4000)
|
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)))
|
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
|
self.patternImageDisposable.set((signal
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] generator in
|
|> deliverOnMainQueue).start(next: { [weak self] generator in
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
strongSelf.validPatternImage = ValidPatternImage(wallpaper: wallpaper, generate: generator)
|
if let generator = generator {
|
||||||
strongSelf.validPatternGeneratedImage = nil
|
strongSelf.validPatternImage = ValidPatternImage(wallpaper: wallpaper, generate: generator)
|
||||||
if let size = strongSelf.validLayout {
|
strongSelf.validPatternGeneratedImage = nil
|
||||||
strongSelf.loadPatternForSizeIfNeeded(size: size, transition: .immediate)
|
if let size = strongSelf.validLayout {
|
||||||
} else {
|
strongSelf.loadPatternForSizeIfNeeded(size: size, transition: .immediate)
|
||||||
strongSelf._isReady.set(true)
|
} 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)
|
return patternWallpaperDatas(account: account, accountManager: accountManager, representations: representations, mode: mode, autoFetchFullSize: autoFetchFullSize)
|
||||||
|> mapToSignal { (thumbnailData, fullSizeData, fullSizeComplete) in
|
|> 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
|
var prominent = false
|
||||||
if case .thumbnail = mode {
|
if case .thumbnail = mode {
|
||||||
prominent = true
|
prominent = true
|
||||||
@ -435,6 +435,12 @@ public func patternWallpaperImageInternal(thumbnailData: Data?, fullSizeData: Da
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if onlyFullSize {
|
||||||
|
if fullSizeData == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { arguments in
|
return { arguments in
|
||||||
var scale = scale
|
var scale = scale
|
||||||
if scale.isZero {
|
if scale.isZero {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user