mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-02 10:50:11 +00:00
Video avatar fixes
This commit is contained in:
parent
e6b15ed025
commit
ad88356d7f
@ -2210,31 +2210,41 @@ public func chatAvatarGalleryPhoto(account: Account, representations: [ImageRepr
|
|||||||
|
|
||||||
var blurredThumbnailImage: UIImage?
|
var blurredThumbnailImage: UIImage?
|
||||||
if let thumbnailImage = thumbnailImage {
|
if let thumbnailImage = thumbnailImage {
|
||||||
let thumbnailSize = CGSize(width: thumbnailImage.width, height: thumbnailImage.height)
|
if max(thumbnailImage.width, thumbnailImage.height) > 200 {
|
||||||
|
blurredThumbnailImage = UIImage(cgImage: thumbnailImage)
|
||||||
let initialThumbnailContextFittingSize = fittedSize.fitted(CGSize(width: 350.0, height: 350.0))
|
} else {
|
||||||
|
let thumbnailSize = CGSize(width: thumbnailImage.width, height: thumbnailImage.height)
|
||||||
let thumbnailContextSize = thumbnailSize.aspectFilled(initialThumbnailContextFittingSize)
|
|
||||||
let thumbnailContext = DrawingContext(size: thumbnailContextSize, scale: 1.0)
|
let initialThumbnailContextFittingSize = fittedSize.fitted(CGSize(width: 100.0, height: 100.0))
|
||||||
thumbnailContext.withFlippedContext { c in
|
|
||||||
c.draw(thumbnailImage, in: CGRect(origin: CGPoint(), size: thumbnailContextSize))
|
let thumbnailContextSize = thumbnailSize.aspectFitted(initialThumbnailContextFittingSize)
|
||||||
}
|
let thumbnailContext = DrawingContext(size: thumbnailContextSize, scale: 1.0, clear: false)
|
||||||
imageFastBlur(Int32(thumbnailContextSize.width), Int32(thumbnailContextSize.height), Int32(thumbnailContext.bytesPerRow), thumbnailContext.bytes)
|
thumbnailContext.withFlippedContext { c in
|
||||||
|
|
||||||
blurredThumbnailImage = thumbnailContext.generateImage()
|
|
||||||
}
|
|
||||||
|
|
||||||
if let blurredThumbnailImage = blurredThumbnailImage, fullSizeImage == nil {
|
|
||||||
let context = DrawingContext(size: blurredThumbnailImage.size, scale: blurredThumbnailImage.scale, clear: true)
|
|
||||||
context.withFlippedContext { c in
|
|
||||||
c.setBlendMode(.copy)
|
|
||||||
if let cgImage = blurredThumbnailImage.cgImage {
|
|
||||||
c.interpolationQuality = .none
|
c.interpolationQuality = .none
|
||||||
drawImage(context: c, image: cgImage, orientation: imageOrientation, in: CGRect(origin: CGPoint(), size: blurredThumbnailImage.size))
|
c.draw(thumbnailImage, in: CGRect(origin: CGPoint(), size: thumbnailContextSize))
|
||||||
c.setBlendMode(.normal)
|
}
|
||||||
|
imageFastBlur(Int32(thumbnailContextSize.width), Int32(thumbnailContextSize.height), Int32(thumbnailContext.bytesPerRow), thumbnailContext.bytes)
|
||||||
|
|
||||||
|
var thumbnailContextFittingSize = CGSize(width: floor(arguments.drawingSize.width * 0.5), height: floor(arguments.drawingSize.width * 0.5))
|
||||||
|
if thumbnailContextFittingSize.width < 150.0 || thumbnailContextFittingSize.height < 150.0 {
|
||||||
|
thumbnailContextFittingSize = thumbnailContextFittingSize.aspectFilled(CGSize(width: 150.0, height: 150.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
if thumbnailContextFittingSize.width > thumbnailContextSize.width {
|
||||||
|
let additionalContextSize = thumbnailContextFittingSize
|
||||||
|
let additionalBlurContext = DrawingContext(size: additionalContextSize, scale: 1.0, clear: false)
|
||||||
|
additionalBlurContext.withFlippedContext { c in
|
||||||
|
c.interpolationQuality = .default
|
||||||
|
if let image = thumbnailContext.generateImage()?.cgImage {
|
||||||
|
c.draw(image, in: CGRect(origin: CGPoint(), size: additionalContextSize))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageFastBlur(Int32(additionalContextSize.width), Int32(additionalContextSize.height), Int32(additionalBlurContext.bytesPerRow), additionalBlurContext.bytes)
|
||||||
|
blurredThumbnailImage = additionalBlurContext.generateImage()
|
||||||
|
} else {
|
||||||
|
blurredThumbnailImage = thumbnailContext.generateImage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let context = DrawingContext(size: arguments.drawingSize, clear: true)
|
let context = DrawingContext(size: arguments.drawingSize, clear: true)
|
||||||
|
@ -633,20 +633,17 @@ private func settingsItems(data: PeerInfoScreenData?, context: AccountContext, p
|
|||||||
items[section] = []
|
items[section] = []
|
||||||
}
|
}
|
||||||
|
|
||||||
if let peer = data.peer {
|
items[.edit]!.append(PeerInfoScreenActionItem(id: 0, text: presentationData.strings.Settings_SetProfilePhotoOrVideo, icon: UIImage(bundleImageName: "Settings/SetAvatar"), action: {
|
||||||
if peer.smallProfileImage == nil {
|
interaction.openSettings(.avatar)
|
||||||
items[.edit]!.append(PeerInfoScreenActionItem(id: 0, text: presentationData.strings.Settings_SetProfilePhotoOrVideo, icon: UIImage(bundleImageName: "Settings/SetAvatar"), action: {
|
|
||||||
interaction.openSettings(.avatar)
|
|
||||||
}))
|
|
||||||
} else if peer.addressName == nil {
|
|
||||||
items[.edit]!.append(PeerInfoScreenActionItem(id: 1, text: presentationData.strings.Settings_SetUsername, icon: UIImage(bundleImageName: "Settings/SetUsername"), action: {
|
|
||||||
interaction.openSettings(.username)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
items[.edit]!.append(PeerInfoScreenActionItem(id: 2, text: presentationData.strings.Settings_EditAccount, icon: UIImage(bundleImageName: "Settings/EditAccount"), action: {
|
|
||||||
interaction.openSettings(.edit)
|
|
||||||
}))
|
}))
|
||||||
|
if let peer = data.peer, peer.addressName == nil {
|
||||||
|
items[.edit]!.append(PeerInfoScreenActionItem(id: 1, text: presentationData.strings.Settings_SetUsername, icon: UIImage(bundleImageName: "Settings/SetUsername"), action: {
|
||||||
|
interaction.openSettings(.username)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
// items[.edit]!.append(PeerInfoScreenActionItem(id: 2, text: presentationData.strings.Settings_EditAccount, icon: UIImage(bundleImageName: "Settings/EditAccount"), action: {
|
||||||
|
// interaction.openSettings(.edit)
|
||||||
|
// }))
|
||||||
|
|
||||||
|
|
||||||
if let settings = data.globalSettings {
|
if let settings = data.globalSettings {
|
||||||
@ -4211,7 +4208,20 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||||||
hasPhotos = true
|
hasPhotos = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let paintStickersContext = LegacyPaintStickersContext(context: strongSelf.context)
|
||||||
|
paintStickersContext.presentStickersController = { completion in
|
||||||
|
let controller = DrawingStickersScreen(context: strongSelf.context, selectSticker: { fileReference, node, rect in
|
||||||
|
let coder = PostboxEncoder()
|
||||||
|
coder.encodeRootObject(fileReference.media)
|
||||||
|
completion?(coder.makeData(), fileReference.media.isAnimatedSticker, node.view, rect)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
strongSelf.controller?.present(controller, in: .window(.root))
|
||||||
|
return controller
|
||||||
|
}
|
||||||
|
|
||||||
let mixin = TGMediaAvatarMenuMixin(context: legacyController.context, parentController: emptyController, hasSearchButton: true, hasDeleteButton: hasPhotos && hasRemove, hasViewButton: false, personalPhoto: strongSelf.isSettings, isVideo: currentIsVideo, saveEditedPhotos: false, saveCapturedMedia: false, signup: false)!
|
let mixin = TGMediaAvatarMenuMixin(context: legacyController.context, parentController: emptyController, hasSearchButton: true, hasDeleteButton: hasPhotos && hasRemove, hasViewButton: false, personalPhoto: strongSelf.isSettings, isVideo: currentIsVideo, saveEditedPhotos: false, saveCapturedMedia: false, signup: false)!
|
||||||
|
mixin.stickersContext = paintStickersContext
|
||||||
let _ = strongSelf.currentAvatarMixin.swap(mixin)
|
let _ = strongSelf.currentAvatarMixin.swap(mixin)
|
||||||
mixin.requestSearchController = { [weak self] assetsController in
|
mixin.requestSearchController = { [weak self] assetsController in
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
@ -5280,7 +5290,8 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||||||
|
|
||||||
let effectiveAreaExpansionFraction: CGFloat
|
let effectiveAreaExpansionFraction: CGFloat
|
||||||
if self.isSettings {
|
if self.isSettings {
|
||||||
effectiveAreaExpansionFraction = self.headerNode.isAvatarExpanded ? 1.0 : 0.0
|
effectiveAreaExpansionFraction = 0.0
|
||||||
|
// effectiveAreaExpansionFraction = self.headerNode.isAvatarExpanded ? 1.0 : 0.0
|
||||||
} else if self.state.isEditing {
|
} else if self.state.isEditing {
|
||||||
effectiveAreaExpansionFraction = 0.0
|
effectiveAreaExpansionFraction = 0.0
|
||||||
} else {
|
} else {
|
||||||
@ -5308,12 +5319,8 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||||||
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .done, isForExpandedView: false))
|
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .done, isForExpandedView: false))
|
||||||
} else {
|
} else {
|
||||||
if self.isSettings {
|
if self.isSettings {
|
||||||
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .search, isForExpandedView: false))
|
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .edit, isForExpandedView: false))
|
||||||
if let item = self.headerNode.avatarListNode.listContainerNode.currentItemNode?.item, case let .image(image) = item, !image.2.isEmpty {
|
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .search, isForExpandedView: true))
|
||||||
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .editVideo, isForExpandedView: true))
|
|
||||||
} else {
|
|
||||||
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .editPhoto, isForExpandedView: true))
|
|
||||||
}
|
|
||||||
} else if peerInfoCanEdit(peer: self.data?.peer, cachedData: self.data?.cachedData) {
|
} else if peerInfoCanEdit(peer: self.data?.peer, cachedData: self.data?.cachedData) {
|
||||||
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .edit, isForExpandedView: false))
|
navigationButtons.append(PeerInfoHeaderNavigationButtonSpec(key: .edit, isForExpandedView: false))
|
||||||
}
|
}
|
||||||
@ -5839,7 +5846,9 @@ public final class PeerInfoScreen: ViewController {
|
|||||||
super.didMove(toParent: viewController)
|
super.didMove(toParent: viewController)
|
||||||
|
|
||||||
if self.isSettings && viewController == nil {
|
if self.isSettings && viewController == nil {
|
||||||
self.controllerNode.resetHeaderExpansion()
|
Queue.mainQueue().after(0.1) {
|
||||||
|
self.controllerNode.resetHeaderExpansion()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user