mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Chat wallpaper fixes
This commit is contained in:
parent
0ca302e947
commit
bd782b0402
@ -523,9 +523,42 @@ public class WallpaperGalleryController: ViewController {
|
||||
let options = centralItemNode.options
|
||||
if !strongSelf.entries.isEmpty {
|
||||
let entry = strongSelf.entries[centralItemNode.index]
|
||||
|
||||
let apply = strongSelf.apply
|
||||
if case .peer = strongSelf.mode {
|
||||
strongSelf.apply?(entry, options, centralItemNode.editedFullSizeImage, centralItemNode.editedCropRect, centralItemNode.brightness)
|
||||
if case let .wallpaper(wallpaper, _) = entry, options.contains(.blur) {
|
||||
var resource: MediaResource?
|
||||
switch wallpaper {
|
||||
case let .file(file):
|
||||
resource = file.file.resource
|
||||
case let .image(representations, _):
|
||||
if let largestSize = largestImageRepresentation(representations) {
|
||||
resource = largestSize.resource
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
if let resource = resource {
|
||||
let representation = CachedBlurredWallpaperRepresentation()
|
||||
var data: Data?
|
||||
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
|
||||
data = maybeData
|
||||
} else if let path = strongSelf.context.sharedContext.accountManager.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
|
||||
data = maybeData
|
||||
}
|
||||
|
||||
if let data = data {
|
||||
strongSelf.context.sharedContext.accountManager.mediaBox.storeResourceData(resource.id, data: data, synchronous: true)
|
||||
let _ = (strongSelf.context.sharedContext.accountManager.mediaBox.cachedResourceRepresentation(resource, representation: representation, complete: true, fetch: true)
|
||||
|> filter({ $0.complete })
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { _ in
|
||||
apply?(entry, options, nil, nil, centralItemNode.brightness)
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
apply?(entry, options, centralItemNode.editedFullSizeImage, centralItemNode.editedCropRect, centralItemNode.brightness)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -595,7 +628,6 @@ public class WallpaperGalleryController: ViewController {
|
||||
if options.contains(.blur) {
|
||||
if let resource = resource {
|
||||
let representation = CachedBlurredWallpaperRepresentation()
|
||||
|
||||
var data: Data?
|
||||
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
|
||||
data = maybeData
|
||||
|
@ -640,7 +640,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
|
||||
self.nativeNode.isHidden = false
|
||||
self.patternButtonNode.isSelected = file.isPattern
|
||||
|
||||
if file.isPattern && file.settings.colors.count >= 3 {
|
||||
if file.settings.colors.count >= 3 {
|
||||
self.playButtonNode.setIcon(self.playButtonPlayImage)
|
||||
} else {
|
||||
self.playButtonNode.setIcon(self.playButtonRotateImage)
|
||||
@ -733,7 +733,6 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
|
||||
let dimensions = file.file.dimensions ?? PixelDimensions(width: 2000, height: 4000)
|
||||
contentSize = dimensions.cgSize
|
||||
displaySize = dimensions.cgSize.dividedByScreenScale().integralFloor
|
||||
|
||||
var convertedRepresentations: [ImageRepresentationWithReference] = []
|
||||
for representation in file.file.previewRepresentations {
|
||||
convertedRepresentations.append(ImageRepresentationWithReference(representation: representation, reference: reference(for: representation.resource, media: file.file, message: message, slug: file.slug)))
|
||||
|
@ -239,7 +239,7 @@ public final class TextNodeWithEntities {
|
||||
let id = InlineStickerItemLayer.Key(id: stickerItem.emoji.fileId, index: index)
|
||||
validIds.append(id)
|
||||
|
||||
let itemSize = floor(stickerItem.fontSize * 24.0 / 17.0)
|
||||
let itemSize = floorToScreenPixels(stickerItem.fontSize * 24.0 / 17.0)
|
||||
|
||||
var itemFrame = CGRect(origin: item.rect.offsetBy(dx: textLayout.insets.left, dy: textLayout.insets.top + 1.0).center, size: CGSize()).insetBy(dx: -itemSize / 2.0, dy: -itemSize / 2.0)
|
||||
itemFrame.origin.x = floorToScreenPixels(itemFrame.origin.x)
|
||||
|
@ -858,17 +858,19 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
strongSelf.chatDisplayNode.dismissInput()
|
||||
let wallpaperPreviewController = WallpaperGalleryController(context: strongSelf.context, source: .wallpaper(wallpaper, nil, [], nil, nil, nil), mode: .peer(EnginePeer(peer), true))
|
||||
wallpaperPreviewController.apply = { [weak wallpaperPreviewController] entry, options, _, _, _ in
|
||||
if case let .wallpaper(wallpaper, _) = entry, case let .file(file) = wallpaper, !file.isPattern && options.contains(.blur) {
|
||||
uploadCustomPeerWallpaper(context: strongSelf.context, wallpaper: entry, mode: options, editedImage: nil, cropRect: nil, brightness: nil, peerId: message.id.peerId, completion: {
|
||||
wallpaperPreviewController?.dismiss()
|
||||
})
|
||||
} else {
|
||||
let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id, settings: nil)
|
||||
|> deliverOnMainQueue).start()
|
||||
Queue.mainQueue().after(0.1) {
|
||||
wallpaperPreviewController?.dismiss()
|
||||
wallpaperPreviewController.apply = { [weak wallpaperPreviewController] entry, options, _, _, brightness in
|
||||
var settings: WallpaperSettings?
|
||||
if case let .wallpaper(wallpaper, _) = entry, case let .file(file) = wallpaper, !file.isPattern {
|
||||
var intensity: Int32?
|
||||
if let brightness {
|
||||
intensity = max(0, min(100, Int32(brightness * 100.0)))
|
||||
}
|
||||
settings = WallpaperSettings(blur: options.contains(.blur), motion: options.contains(.motion), intensity: intensity)
|
||||
}
|
||||
let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id, settings: settings)
|
||||
|> deliverOnMainQueue).start()
|
||||
Queue.mainQueue().after(0.1) {
|
||||
wallpaperPreviewController?.dismiss()
|
||||
}
|
||||
}
|
||||
strongSelf.push(wallpaperPreviewController)
|
||||
|
@ -1058,12 +1058,12 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
|
||||
if let (size, displayMode) = self.validLayout {
|
||||
self.updateLayout(size: size, displayMode: displayMode, transition: .immediate)
|
||||
self.updateBubbles()
|
||||
|
||||
if scheduleLoopingEvent {
|
||||
self.animateEvent(transition: .animated(duration: 0.7, curve: .linear), extendAnimation: false)
|
||||
}
|
||||
}
|
||||
self.updateBubbles()
|
||||
|
||||
self.updateDimming()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user