Various improvements

This commit is contained in:
Ilya Laktyushin 2023-08-31 21:41:02 +04:00
parent 70db4d9718
commit 24b671a53c
5 changed files with 40 additions and 10 deletions

View File

@ -9875,3 +9875,6 @@ Sorry for the inconvenience.";
"Story.Editor.TooltipMutedWithAudio" = "Original audio will be removed";
"Story.Editor.TooltipUnmutedWithAudio" = "Original audio will be preserved";
"SecretImage.ViewOnce.Title" = "Disappearing Photo";
"SecretVideo.ViewOnce.Title" = "Disappearing Video";

View File

@ -184,6 +184,7 @@ public func galleryItemForEntry(
location: location,
translateToLanguage: translateToLanguage,
peerIsCopyProtected: peerIsCopyProtected,
isSecret: isSecret,
displayInfoOnTop: displayInfoOnTop,
performAction: performAction,
openActionOptions: openActionOptions,
@ -265,6 +266,7 @@ public func galleryItemForEntry(
location: location,
translateToLanguage: translateToLanguage,
peerIsCopyProtected: peerIsCopyProtected,
isSecret: isSecret,
displayInfoOnTop: displayInfoOnTop,
performAction: performAction,
openActionOptions: openActionOptions,

View File

@ -115,18 +115,20 @@ class ChatImageGalleryItem: GalleryItem {
let location: MessageHistoryEntryLocation?
let translateToLanguage: String?
let peerIsCopyProtected: Bool
let isSecret: Bool
let displayInfoOnTop: Bool
let performAction: (GalleryControllerInteractionTapAction) -> Void
let openActionOptions: (GalleryControllerInteractionTapAction, Message) -> Void
let present: (ViewController, Any?) -> Void
init(context: AccountContext, presentationData: PresentationData, message: Message, location: MessageHistoryEntryLocation?, translateToLanguage: String? = nil, peerIsCopyProtected: Bool = false, displayInfoOnTop: Bool, performAction: @escaping (GalleryControllerInteractionTapAction) -> Void, openActionOptions: @escaping (GalleryControllerInteractionTapAction, Message) -> Void, present: @escaping (ViewController, Any?) -> Void) {
init(context: AccountContext, presentationData: PresentationData, message: Message, location: MessageHistoryEntryLocation?, translateToLanguage: String? = nil, peerIsCopyProtected: Bool = false, isSecret: Bool = false, displayInfoOnTop: Bool, performAction: @escaping (GalleryControllerInteractionTapAction) -> Void, openActionOptions: @escaping (GalleryControllerInteractionTapAction, Message) -> Void, present: @escaping (ViewController, Any?) -> Void) {
self.context = context
self.presentationData = presentationData
self.message = message
self.location = location
self.translateToLanguage = translateToLanguage
self.peerIsCopyProtected = peerIsCopyProtected
self.isSecret = isSecret
self.displayInfoOnTop = displayInfoOnTop
self.performAction = performAction
self.openActionOptions = openActionOptions
@ -136,7 +138,7 @@ class ChatImageGalleryItem: GalleryItem {
func node(synchronous: Bool) -> GalleryItemNode {
let node = ChatImageGalleryItemNode(context: self.context, presentationData: self.presentationData, performAction: self.performAction, openActionOptions: self.openActionOptions, present: self.present)
node.setMessage(self.message, displayInfo: !self.displayInfoOnTop, translateToLanguage: self.translateToLanguage, peerIsCopyProtected: self.peerIsCopyProtected)
node.setMessage(self.message, displayInfo: !self.displayInfoOnTop, translateToLanguage: self.translateToLanguage, peerIsCopyProtected: self.peerIsCopyProtected, isSecret: self.isSecret)
for media in self.message.media {
if let invoice = media as? TelegramMediaInvoice, let extendedMedia = invoice.extendedMedia, case let .full(fullMedia) = extendedMedia, let image = fullMedia as? TelegramMediaImage {
node.setImage(userLocation: .peer(self.message.id.peerId), imageReference: .message(message: MessageReference(self.message), media: image))
@ -175,7 +177,7 @@ class ChatImageGalleryItem: GalleryItem {
if self.displayInfoOnTop {
node.titleContentView?.setMessage(self.message, presentationData: self.presentationData, accountPeerId: self.context.account.peerId)
}
node.setMessage(self.message, displayInfo: !self.displayInfoOnTop, translateToLanguage: self.translateToLanguage, peerIsCopyProtected: self.peerIsCopyProtected)
node.setMessage(self.message, displayInfo: !self.displayInfoOnTop, translateToLanguage: self.translateToLanguage, peerIsCopyProtected: self.peerIsCopyProtected, isSecret: self.isSecret)
}
}
@ -204,6 +206,7 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode {
private var message: Message?
private var translateToLanguage: String?
private var peerIsCopyProtected: Bool = false
private var isSecret: Bool = false
private let presentationData: PresentationData
private let imageNode: TransformImageNode
@ -328,11 +331,12 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode {
transition.updateFrame(node: self.statusNode, frame: CGRect(origin: CGPoint(), size: statusSize))
}
fileprivate func setMessage(_ message: Message, displayInfo: Bool, translateToLanguage: String?, peerIsCopyProtected: Bool) {
fileprivate func setMessage(_ message: Message, displayInfo: Bool, translateToLanguage: String?, peerIsCopyProtected: Bool, isSecret: Bool) {
self.message = message
self.translateToLanguage = translateToLanguage
self.peerIsCopyProtected = peerIsCopyProtected
self.imageNode.captureProtected = message.isCopyProtected()
self.isSecret = isSecret
self.imageNode.captureProtected = message.isCopyProtected() || peerIsCopyProtected || isSecret
self.footerContentNode.setMessage(message, displayInfo: displayInfo, translateToLanguage: translateToLanguage, peerIsCopyProtected: peerIsCopyProtected)
}

View File

@ -60,7 +60,7 @@ private final class SecretMediaPreviewControllerNode: GalleryControllerNode {
var beginTimeAndTimeout: (Double, Double)? {
didSet {
if let (beginTime, timeout) = self.beginTimeAndTimeout {
if let (beginTime, timeout) = self.beginTimeAndTimeout, Int32(timeout) != viewOnceTimeout {
if self.timeoutNode == nil {
let timeoutNode = RadialStatusNode(backgroundNodeColor: UIColor(white: 0.0, alpha: 0.5))
self.timeoutNode = timeoutNode
@ -289,10 +289,18 @@ public final class SecretMediaPreviewController: ViewController {
if file.isAnimated {
strongSelf.title = strongSelf.presentationData.strings.SecretGif_Title
} else {
strongSelf.title = strongSelf.presentationData.strings.SecretVideo_Title
if strongSelf.currentNodeMessageIsViewOnce {
strongSelf.title = strongSelf.presentationData.strings.SecretVideo_ViewOnce_Title
} else {
strongSelf.title = strongSelf.presentationData.strings.SecretVideo_Title
}
}
} else {
strongSelf.title = strongSelf.presentationData.strings.SecretImage_Title
if strongSelf.currentNodeMessageIsViewOnce {
strongSelf.title = strongSelf.presentationData.strings.SecretImage_ViewOnce_Title
} else {
strongSelf.title = strongSelf.presentationData.strings.SecretImage_Title
}
}
if let beginTimeAndTimeout = beginTimeAndTimeout {

View File

@ -1466,6 +1466,7 @@ public class CameraScreen: ViewController {
})
}
fileprivate var captureStartTimestamp: Double?
private func setupCamera() {
guard self.camera == nil else {
return
@ -1575,6 +1576,7 @@ public class CameraScreen: ViewController {
camera.focus(at: CGPoint(x: 0.5, y: 0.5), autoFocus: true)
camera.startCapture()
self.captureStartTimestamp = CACurrentMediaTime()
self.camera = camera
@ -2515,8 +2517,19 @@ public class CameraScreen: ViewController {
guard let self, !self.didStopCameraCapture else {
return
}
self.didStopCameraCapture = true
self.node.pauseCameraCapture()
let currentTimestamp = CACurrentMediaTime()
if let startTimestamp = self.node.captureStartTimestamp {
let difference = currentTimestamp - startTimestamp
if difference < 2.0 {
Queue.mainQueue().after(2.0 - difference) {
self.didStopCameraCapture = true
self.node.pauseCameraCapture()
}
} else {
self.didStopCameraCapture = true
self.node.pauseCameraCapture()
}
}
}
let resumeCameraCapture = { [weak self] in