From ca5abf140bc36d6384c0c8daf0275bc733bcc10b Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 14 Jun 2021 17:47:35 +0400 Subject: [PATCH] Background fixes --- .../Themes/WallpaperGalleryController.swift | 14 ++++++++----- .../TelegramCore/Sources/Wallpapers.swift | 2 +- .../Sources/WallpaperBackgroundNode.swift | 21 ++++++++++++++----- .../Sources/WallpaperResources.swift | 4 ++-- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index a64e77dce1..54386adbd9 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -171,6 +171,7 @@ public class WallpaperGalleryController: ViewController { return self._ready } private var didSetReady = false + private var didBeginSettingReady = false private let disposable = MetaDisposable() @@ -581,11 +582,6 @@ public class WallpaperGalleryController: ViewController { } } } - - let ready = self.galleryNode.pager.ready() |> timeout(2.0, queue: Queue.mainQueue(), alternate: .single(Void())) |> afterNext { [weak self] _ in - self?.didSetReady = true - } - self._ready.set(ready |> map { true }) } private func currentEntry() -> WallpaperGalleryEntry? { @@ -723,6 +719,14 @@ public class WallpaperGalleryController: ViewController { } } } + if !self.didBeginSettingReady { + self.didBeginSettingReady = true + + let ready = self.galleryNode.pager.ready() |> timeout(2.0, queue: Queue.mainQueue(), alternate: .single(Void())) |> afterNext { [weak self] _ in + self?.didSetReady = true + } + self._ready.set(ready |> map { true }) + } } } diff --git a/submodules/TelegramCore/Sources/Wallpapers.swift b/submodules/TelegramCore/Sources/Wallpapers.swift index 4557a74894..eff57ceb87 100644 --- a/submodules/TelegramCore/Sources/Wallpapers.swift +++ b/submodules/TelegramCore/Sources/Wallpapers.swift @@ -7,7 +7,7 @@ import SyncCore public func telegramWallpapers(postbox: Postbox, network: Network, forceUpdate: Bool = false) -> Signal<[TelegramWallpaper], NoError> { let fetch: ([TelegramWallpaper]?, Int32?) -> Signal<[TelegramWallpaper], NoError> = { current, hash in - network.request(Api.functions.account.getWallPapers(hash: hash ?? 0)) + network.request(Api.functions.account.getWallPapers(hash: 0))//hash ?? 0)) |> retryRequest |> mapToSignal { result -> Signal<([TelegramWallpaper], Int32), NoError> in switch result { diff --git a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift index 56b9fd05f9..cc94ccf2c4 100644 --- a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift +++ b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift @@ -380,9 +380,11 @@ public final class WallpaperBackgroundNode: ASDisplayNode { if case let .color(color) = wallpaper { gradientColors = [color] + self._isReady.set(true) } else if case let .gradient(colors, settings) = wallpaper { gradientColors = colors gradientAngle = settings.rotation ?? 0 + self._isReady.set(true) } else if case let .file(_, _, _, _, isPattern, _, _, _, settings) = wallpaper, isPattern { gradientColors = settings.colors gradientAngle = settings.rotation ?? 0 @@ -437,9 +439,15 @@ public final class WallpaperBackgroundNode: ASDisplayNode { if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: self.context.sharedContext.accountManager.mediaBox, knockoutMode: false) { self.contentNode.contents = image.cgImage self.wallpaperDisposable.set(nil) + Queue.mainQueue().justDispatch { + self._isReady.set(true) + } } else if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: self.context.account.postbox.mediaBox, knockoutMode: false) { self.contentNode.contents = image.cgImage self.wallpaperDisposable.set(nil) + Queue.mainQueue().justDispatch { + self._isReady.set(true) + } } else { self.wallpaperDisposable.set((chatControllerBackgroundImageSignal(wallpaper: wallpaper, mediaBox: self.context.sharedContext.accountManager.mediaBox, accountMediaBox: self.context.account.postbox.mediaBox) |> deliverOnMainQueue).start(next: { [weak self] image in @@ -447,6 +455,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode { return } strongSelf.contentNode.contents = image?.0?.cgImage + strongSelf._isReady.set(true) })) } self.contentNode.isHidden = false @@ -466,11 +475,14 @@ public final class WallpaperBackgroundNode: ASDisplayNode { var invertPattern: Bool = false var patternIsLight: Bool = false + var patternIsBlack: Bool = false switch wallpaper { case let .file(_, _, _, _, isPattern, _, _, file, settings) where isPattern: var updated = true - let isLight = UIColor.average(of: settings.colors.map(UIColor.init(rgb:))).hsb.b > 0.3 + let brightness = UIColor.average(of: settings.colors.map(UIColor.init(rgb:))).hsb.b + let isLight = brightness > 0.3 + patternIsBlack = brightness <= 0.01 if let previousWallpaper = self.validPatternImage?.wallpaper { switch previousWallpaper { case let .file(_, _, _, _, _, _, _, previousFile, _): @@ -528,10 +540,10 @@ public final class WallpaperBackgroundNode: ASDisplayNode { self.patternImageNode.layer.compositingFilter = nil } else { self.patternImageNode.alpha = intensity - if patternIsLight { - self.patternImageNode.layer.compositingFilter = "softLightBlendMode" - } else { + if patternIsBlack { self.patternImageNode.layer.compositingFilter = nil + } else { + self.patternImageNode.layer.compositingFilter = "softLightBlendMode" } } self.patternImageNode.isHidden = false @@ -553,7 +565,6 @@ public final class WallpaperBackgroundNode: ASDisplayNode { self.backgroundColor = nil self.gradientBackgroundNode?.contentView.alpha = 1.0 self.contentNode.alpha = 1.0 - self._isReady.set(true) } if let validPatternImage = self.validPatternImage { diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 28140f4a76..f39da26c29 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -87,7 +87,7 @@ public func wallpaperDatas(account: Account, accountManager: AccountManager, fil } } else { let fetchedThumbnail: Signal - if let _ = decodedThumbnailData { + if let _ = decodedThumbnailData, false { fetchedThumbnail = .complete() } else { fetchedThumbnail = fetchedMediaResource(mediaBox: account.postbox.mediaBox, reference: representations[smallestIndex].reference) @@ -96,7 +96,7 @@ public func wallpaperDatas(account: Account, accountManager: AccountManager, fil let fetchedFullSize = fetchedMediaResource(mediaBox: account.postbox.mediaBox, reference: representations[largestIndex].reference) let thumbnailData: Signal - if let decodedThumbnailData = decodedThumbnailData { + if let decodedThumbnailData = decodedThumbnailData, false { thumbnailData = .single(decodedThumbnailData) } else { thumbnailData = Signal { subscriber in