mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Cherry-pick media timer and web app improvements
This commit is contained in:
@@ -11,6 +11,8 @@ import RadialStatusNode
|
||||
import ScreenCaptureDetection
|
||||
import AppBundle
|
||||
import LocalizedPeerData
|
||||
import TooltipUI
|
||||
import TelegramNotices
|
||||
|
||||
private func galleryMediaForMedia(media: Media) -> Media? {
|
||||
if let media = media as? TelegramMediaImage {
|
||||
@@ -54,26 +56,34 @@ private func mediaForMessage(message: Message) -> Media? {
|
||||
}
|
||||
|
||||
private final class SecretMediaPreviewControllerNode: GalleryControllerNode {
|
||||
private var timeoutNode: RadialStatusNode?
|
||||
fileprivate var timeoutNode: RadialStatusNode?
|
||||
|
||||
private var validLayout: (ContainerViewLayout, CGFloat)?
|
||||
|
||||
|
||||
var beginTimeAndTimeout: (Double, Double)? {
|
||||
didSet {
|
||||
if let (beginTime, timeout) = self.beginTimeAndTimeout {
|
||||
var beginTime = beginTime
|
||||
if self.timeoutNode == nil {
|
||||
let timeoutNode = RadialStatusNode(backgroundNodeColor: UIColor(white: 0.0, alpha: 0.5))
|
||||
self.timeoutNode = timeoutNode
|
||||
var iconImage: UIImage?
|
||||
if let image = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/SecretMediaIcon"), color: .white) {
|
||||
let factor: CGFloat = 0.48
|
||||
iconImage = generateImage(CGSize(width: floor(image.size.width * factor), height: floor(image.size.height * factor)), contextGenerator: { size, context in
|
||||
context.clear(CGRect(origin: CGPoint(), size: size))
|
||||
context.draw(image.cgImage!, in: CGRect(origin: CGPoint(), size: size))
|
||||
})
|
||||
let icon: RadialStatusNodeState.SecretTimeoutIcon
|
||||
let timeoutValue = Int32(timeout)
|
||||
if timeoutValue == viewOnceTimeout {
|
||||
beginTime = CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970
|
||||
|
||||
if let image = generateTintedImage(image: UIImage(bundleImageName: "Media Gallery/ViewOnce"), color: .white) {
|
||||
icon = .image(image)
|
||||
} else {
|
||||
icon = .flame
|
||||
}
|
||||
} else {
|
||||
icon = .flame
|
||||
}
|
||||
timeoutNode.transitionToState(.secretTimeout(color: .white, icon: iconImage, beginTime: beginTime, timeout: timeout, sparks: true), completion: {})
|
||||
timeoutNode.transitionToState(.secretTimeout(color: .white, icon: icon, beginTime: beginTime, timeout: timeout, sparks: true), completion: {})
|
||||
self.addSubnode(timeoutNode)
|
||||
|
||||
timeoutNode.addTarget(self, action: #selector(self.statusTapGesture), forControlEvents: .touchUpInside)
|
||||
|
||||
if let (layout, navigationHeight) = self.validLayout {
|
||||
self.layoutTimeoutNode(layout, navigationBarHeight: navigationHeight, transition: .immediate)
|
||||
@@ -86,6 +96,13 @@ private final class SecretMediaPreviewControllerNode: GalleryControllerNode {
|
||||
}
|
||||
}
|
||||
|
||||
var statusPressed: (UIView) -> Void = { _ in }
|
||||
@objc private func statusTapGesture() {
|
||||
if let sourceView = self.timeoutNode?.view {
|
||||
self.statusPressed(sourceView)
|
||||
}
|
||||
}
|
||||
|
||||
override func animateIn(animateContent: Bool, useSimpleAnimation: Bool) {
|
||||
super.animateIn(animateContent: animateContent, useSimpleAnimation: useSimpleAnimation)
|
||||
|
||||
@@ -139,8 +156,12 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
private var messageView: MessageView?
|
||||
private var currentNodeMessageId: MessageId?
|
||||
private var currentNodeMessageIsVideo = false
|
||||
private var currentNodeMessageIsViewOnce = false
|
||||
private var tempFile: TempBoxFile?
|
||||
|
||||
private let centralItemAttributesDisposable = DisposableSet();
|
||||
private let footerContentNode = Promise<(GalleryFooterContentNode?, GalleryOverlayContentNode?)>()
|
||||
|
||||
private let _hiddenMedia = Promise<(MessageId, Media)?>(nil)
|
||||
private var hiddenMediaManagerIndex: Int?
|
||||
|
||||
@@ -148,6 +169,8 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
|
||||
private var screenCaptureEventsDisposable: Disposable?
|
||||
|
||||
private weak var tooltipController: TooltipScreen?
|
||||
|
||||
public init(context: AccountContext, messageId: MessageId) {
|
||||
self.context = context
|
||||
self.messageId = messageId
|
||||
@@ -177,6 +200,15 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
return nil
|
||||
}
|
||||
})
|
||||
|
||||
self.centralItemAttributesDisposable.add(self.footerContentNode.get().start(next: { [weak self] footerContentNode, _ in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
self.controllerNode.updatePresentationState({
|
||||
$0.withUpdatedFooterContentNode(footerContentNode)
|
||||
}, transition: .immediate)
|
||||
}))
|
||||
}
|
||||
|
||||
required public init(coder aDecoder: NSCoder) {
|
||||
@@ -193,6 +225,7 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
if let tempFile = self.tempFile {
|
||||
TempBox.shared.dispose(tempFile)
|
||||
}
|
||||
self.centralItemAttributesDisposable.dispose()
|
||||
}
|
||||
|
||||
@objc func donePressed() {
|
||||
@@ -213,6 +246,12 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
self.displayNode = SecretMediaPreviewControllerNode(controllerInteraction: controllerInteraction)
|
||||
self.displayNodeDidLoad()
|
||||
|
||||
self.controllerNode.statusPressed = { [weak self] _ in
|
||||
if let self {
|
||||
self.presentViewOnceTooltip()
|
||||
}
|
||||
}
|
||||
|
||||
self.controllerNode.statusBar = self.statusBar
|
||||
self.controllerNode.navigationBar = self.navigationBar
|
||||
|
||||
@@ -231,6 +270,11 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
self.controllerNode.dismiss = { [weak self] in
|
||||
self?._hiddenMedia.set(.single(nil))
|
||||
self?.presentingViewController?.dismiss(animated: false, completion: nil)
|
||||
|
||||
if let tooltipController = self?.tooltipController {
|
||||
self?.tooltipController = nil
|
||||
tooltipController.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
self.controllerNode.beginCustomDismiss = { [weak self] _ in
|
||||
@@ -263,16 +307,20 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
}
|
||||
|
||||
if let attribute = message.autoclearAttribute {
|
||||
strongSelf.currentNodeMessageIsViewOnce = attribute.timeout == viewOnceTimeout
|
||||
|
||||
if let countdownBeginTime = attribute.countdownBeginTime {
|
||||
if let videoDuration = videoDuration {
|
||||
if let videoDuration = videoDuration, attribute.timeout != viewOnceTimeout {
|
||||
beginTimeAndTimeout = (CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970, videoDuration)
|
||||
} else {
|
||||
beginTimeAndTimeout = (Double(countdownBeginTime), Double(attribute.timeout))
|
||||
}
|
||||
}
|
||||
} else if let attribute = message.autoremoveAttribute {
|
||||
strongSelf.currentNodeMessageIsViewOnce = attribute.timeout == viewOnceTimeout
|
||||
|
||||
if let countdownBeginTime = attribute.countdownBeginTime {
|
||||
if let videoDuration = videoDuration {
|
||||
if let videoDuration = videoDuration, attribute.timeout != viewOnceTimeout {
|
||||
beginTimeAndTimeout = (CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970, videoDuration)
|
||||
} else {
|
||||
beginTimeAndTimeout = (Double(countdownBeginTime), Double(attribute.timeout))
|
||||
@@ -284,17 +332,29 @@ 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 {
|
||||
strongSelf.controllerNode.beginTimeAndTimeout = beginTimeAndTimeout
|
||||
}
|
||||
|
||||
if !message.flags.contains(.Incoming) {
|
||||
if strongSelf.currentNodeMessageIsVideo {
|
||||
if let node = strongSelf.controllerNode.pager.centralItemNode() {
|
||||
strongSelf.footerContentNode.set(node.footerContent())
|
||||
}
|
||||
} else if !message.flags.contains(.Incoming) {
|
||||
if let _ = beginTimeAndTimeout {
|
||||
strongSelf.controllerNode.updatePresentationState({
|
||||
$0.withUpdatedFooterContentNode(nil)
|
||||
@@ -373,9 +433,26 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
self.controllerNode.animateIn(animateContent: !nodeAnimatesItself, useSimpleAnimation: false)
|
||||
}
|
||||
}
|
||||
|
||||
if self.currentNodeMessageIsViewOnce {
|
||||
let _ = (ApplicationSpecificNotice.incrementViewOnceTooltip(accountManager: self.context.sharedContext.accountManager)
|
||||
|> deliverOnMainQueue).start(next: { [weak self] count in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
if count < 2 {
|
||||
self.presentViewOnceTooltip()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func dismiss(forceAway: Bool) {
|
||||
if let tooltipController = self.tooltipController {
|
||||
self.tooltipController = nil
|
||||
tooltipController.dismiss()
|
||||
}
|
||||
|
||||
var animatedOutNode = true
|
||||
var animatedOutInterface = false
|
||||
|
||||
@@ -430,7 +507,15 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
}
|
||||
|
||||
guard let item = galleryItemForEntry(context: self.context, presentationData: self.presentationData, entry: MessageHistoryEntry(message: message, isRead: false, location: nil, monthLocation: nil, attributes: MutableMessageHistoryEntryAttributes(authorIsContact: false)), streamVideos: false, hideControls: true, isSecret: true, playbackRate: { nil }, tempFilePath: tempFilePath, playbackCompleted: { [weak self] in
|
||||
self?.dismiss(forceAway: false)
|
||||
if let self {
|
||||
if self.currentNodeMessageIsViewOnce {
|
||||
if let node = self.controllerNode.pager.centralItemNode() as? UniversalVideoGalleryItemNode {
|
||||
node.seekToStart()
|
||||
}
|
||||
} else {
|
||||
self.dismiss(forceAway: false)
|
||||
}
|
||||
}
|
||||
}, present: { _, _ in }) else {
|
||||
self._ready.set(.single(true))
|
||||
return
|
||||
@@ -452,7 +537,7 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
}
|
||||
if let attribute = message.autoclearAttribute {
|
||||
if let countdownBeginTime = attribute.countdownBeginTime {
|
||||
if let videoDuration = videoDuration {
|
||||
if let videoDuration = videoDuration, attribute.timeout != viewOnceTimeout {
|
||||
beginTimeAndTimeout = (CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970, videoDuration)
|
||||
} else {
|
||||
beginTimeAndTimeout = (Double(countdownBeginTime), Double(attribute.timeout))
|
||||
@@ -460,7 +545,7 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
}
|
||||
} else if let attribute = message.autoremoveAttribute {
|
||||
if let countdownBeginTime = attribute.countdownBeginTime {
|
||||
if let videoDuration = videoDuration {
|
||||
if let videoDuration = videoDuration, attribute.timeout != viewOnceTimeout {
|
||||
beginTimeAndTimeout = (CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970, videoDuration)
|
||||
} else {
|
||||
beginTimeAndTimeout = (Double(countdownBeginTime), Double(attribute.timeout))
|
||||
@@ -478,12 +563,54 @@ public final class SecretMediaPreviewController: ViewController {
|
||||
if !self.didSetReady {
|
||||
self._ready.set(.single(true))
|
||||
}
|
||||
if !self.currentNodeMessageIsVideo {
|
||||
if !(self.currentNodeMessageIsVideo || self.currentNodeMessageIsViewOnce) {
|
||||
self.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func presentViewOnceTooltip() {
|
||||
guard self.currentNodeMessageIsViewOnce, let sourceView = self.controllerNode.timeoutNode?.view else {
|
||||
return
|
||||
}
|
||||
|
||||
if let tooltipController = self.tooltipController {
|
||||
self.tooltipController = nil
|
||||
tooltipController.dismiss()
|
||||
}
|
||||
|
||||
let absoluteFrame = sourceView.convert(sourceView.bounds, to: nil)
|
||||
let location = CGRect(origin: CGPoint(x: absoluteFrame.midX, y: absoluteFrame.maxY + 2.0), size: CGSize())
|
||||
|
||||
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
|
||||
let iconName = "anim_autoremove_on"
|
||||
let text: String
|
||||
if self.currentNodeMessageIsVideo {
|
||||
text = presentationData.strings.Gallery_ViewOnceVideoTooltip
|
||||
} else {
|
||||
text = presentationData.strings.Gallery_ViewOncePhotoTooltip
|
||||
}
|
||||
|
||||
let tooltipController = TooltipScreen(
|
||||
account: self.context.account,
|
||||
sharedContext: self.context.sharedContext,
|
||||
text: .plain(text: text),
|
||||
balancedTextLayout: true,
|
||||
constrainWidth: 210.0,
|
||||
style: .customBlur(UIColor(rgb: 0x18181a), 0.0),
|
||||
arrowStyle: .small,
|
||||
icon: .animation(name: iconName, delay: 0.1, tintColor: nil),
|
||||
location: .point(location, .top),
|
||||
displayDuration: .default,
|
||||
inset: 8.0,
|
||||
shouldDismissOnTouch: { _, _ in
|
||||
return .ignore
|
||||
}
|
||||
)
|
||||
self.tooltipController = tooltipController
|
||||
self.present(tooltipController, in: .window(.root))
|
||||
}
|
||||
|
||||
public override func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
super.containerLayoutUpdated(layout, transition: transition)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user