mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-01 16:06:59 +00:00
Fix blurred background preview
This commit is contained in:
parent
3dd5e94715
commit
bea2f13f24
@ -430,7 +430,13 @@ final class ThemeAccentColorController: ViewController {
|
||||
motion = settings.motion
|
||||
rotation = settings.rotation ?? 0
|
||||
} else {
|
||||
backgroundColors = []
|
||||
if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: strongSelf.context.sharedContext.accountManager.mediaBox, knockoutMode: false) {
|
||||
backgroundColors = [averageColor(from: image).rgb]
|
||||
} else if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: strongSelf.context.account.postbox.mediaBox, knockoutMode: false) {
|
||||
backgroundColors = [averageColor(from: image).rgb]
|
||||
} else {
|
||||
backgroundColors = [UIColor.gray.rgb]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -525,19 +525,21 @@ final class WallpaperColorPanelNode: ASDisplayNode {
|
||||
if colorWasRemovable != self.multiColorFieldNode.isRemovable {
|
||||
updateLayout = true
|
||||
}
|
||||
|
||||
if let index = self.state.selection {
|
||||
if self.state.colors.count > index {
|
||||
self.colorPickerNode.color = UIColor(rgb: self.state.colors[index])
|
||||
}
|
||||
}
|
||||
|
||||
if updateLayout, let size = self.validLayout {
|
||||
if let index = self.state.selection {
|
||||
if self.state.colors.count > index {
|
||||
self.colorPickerNode.color = UIColor(rgb: self.state.colors[index])
|
||||
}
|
||||
}
|
||||
|
||||
self.updateLayout(size: size, transition: animated ? .animated(duration: 0.3, curve: .easeInOut) : .immediate)
|
||||
}
|
||||
|
||||
if let index = state.selection {
|
||||
self.multiColorFieldNode.setColor(UIColor(rgb: self.state.colors[index]), update: false)
|
||||
if self.state.colors.count > index {
|
||||
self.multiColorFieldNode.setColor(UIColor(rgb: self.state.colors[index]), update: false)
|
||||
}
|
||||
}
|
||||
|
||||
for i in 0 ..< state.colors.count {
|
||||
|
@ -242,7 +242,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable {
|
||||
case let .image(representations, _):
|
||||
return .image(representations, settings)
|
||||
case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, _):
|
||||
return .file(id: id, accessHash: accessHash, isCreator: isCreator, isDefault: isDefault, isPattern: settings.colors.isEmpty ? isPattern : true, isDark: isDark, slug: slug, file: file, settings: settings)
|
||||
return .file(id: id, accessHash: accessHash, isCreator: isCreator, isDefault: isDefault, isPattern: isPattern, isDark: isDark, slug: slug, file: file, settings: settings)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ swift_library(
|
||||
"//submodules/AppBundle:AppBundle",
|
||||
"//submodules/StringPluralization:StringPluralization",
|
||||
"//submodules/Sunrise:Sunrise",
|
||||
"//submodules/TinyThumbnail:TinyThumbnail",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -8,6 +8,7 @@ import SwiftSignalKit
|
||||
import Postbox
|
||||
import MediaResources
|
||||
import AppBundle
|
||||
import TinyThumbnail
|
||||
|
||||
private var backgroundImageForWallpaper: (TelegramWallpaper, Bool, UIImage)?
|
||||
|
||||
@ -225,24 +226,46 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
||||
} else {
|
||||
if file.settings.blur {
|
||||
let representation = CachedBlurredWallpaperRepresentation()
|
||||
|
||||
let effectiveMediaBox: MediaBox
|
||||
|
||||
if FileManager.default.fileExists(atPath: mediaBox.cachedRepresentationCompletePath(file.file.resource.id, representation: representation)) {
|
||||
effectiveMediaBox = mediaBox
|
||||
} else {
|
||||
effectiveMediaBox = accountMediaBox
|
||||
}
|
||||
|
||||
return effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true)
|
||||
|> map { data -> (UIImage?, Bool)? in
|
||||
if data.complete {
|
||||
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
|
||||
} else {
|
||||
return nil
|
||||
let effectiveMediaBox = mediaBox
|
||||
|
||||
return effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true)
|
||||
|> map { data -> (UIImage?, Bool)? in
|
||||
if data.complete {
|
||||
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|> afterNext { image in
|
||||
cacheWallpaper(image?.0)
|
||||
}
|
||||
} else {
|
||||
return Signal { subscriber in
|
||||
let fetch = fetchedMediaResource(mediaBox: accountMediaBox, reference: MediaResourceReference.wallpaper(wallpaper: WallpaperReference.slug(file.slug), resource: file.file.resource)).start()
|
||||
var didOutputBlurred = false
|
||||
let data = accountMediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true).start(next: { data in
|
||||
if data.complete {
|
||||
if let image = UIImage(contentsOfFile: data.path)?.precomposed() {
|
||||
mediaBox.copyResourceData(file.file.resource.id, fromTempPath: data.path)
|
||||
subscriber.putNext((image, true))
|
||||
}
|
||||
} else if !didOutputBlurred {
|
||||
didOutputBlurred = true
|
||||
if let immediateThumbnailData = file.file.immediateThumbnailData, let decodedData = decodeTinyThumbnail(data: immediateThumbnailData) {
|
||||
if let image = UIImage(data: decodedData)?.precomposed() {
|
||||
subscriber.putNext((image, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return ActionDisposable {
|
||||
fetch.dispose()
|
||||
data.dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|> afterNext { image in
|
||||
cacheWallpaper(image?.0)
|
||||
}
|
||||
} else {
|
||||
var path: String?
|
||||
@ -259,12 +282,20 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
||||
} else {
|
||||
return Signal { subscriber in
|
||||
let fetch = fetchedMediaResource(mediaBox: accountMediaBox, reference: MediaResourceReference.wallpaper(wallpaper: WallpaperReference.slug(file.slug), resource: file.file.resource)).start()
|
||||
var didOutputBlurred = false
|
||||
let data = accountMediaBox.resourceData(file.file.resource).start(next: { data in
|
||||
if data.complete {
|
||||
if let image = UIImage(contentsOfFile: data.path)?.precomposed() {
|
||||
mediaBox.copyResourceData(file.file.resource.id, fromTempPath: data.path)
|
||||
subscriber.putNext((image, true))
|
||||
}
|
||||
} else if !didOutputBlurred {
|
||||
didOutputBlurred = true
|
||||
if let immediateThumbnailData = file.file.immediateThumbnailData, let decodedData = decodeTinyThumbnail(data: immediateThumbnailData) {
|
||||
if let image = UIImage(data: decodedData)?.precomposed() {
|
||||
subscriber.putNext((image, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user