Add view once tooltip

This commit is contained in:
Ilya Laktyushin 2023-09-06 16:20:45 +04:00
parent 39a2c0f9d0
commit cdb156d253
4 changed files with 47 additions and 8 deletions

View File

@ -9911,3 +9911,5 @@ Sorry for the inconvenience.";
"Story.Editor.TooltipReachedReactionLimitTitle" = "Limit Reached";
"Story.Editor.TooltipReachedReactionLimitText" = "You can't add up more than %@ to a story.";
"Gallery.ViewOncePhotoTooltip" = "This photo can only be viewed once.";
"Gallery.ViewOnceVideoTooltip" = "This video can only be viewed once.";

View File

@ -47,6 +47,7 @@ swift_library(
"//submodules/TelegramUI/Components/MultiAnimationRenderer:MultiAnimationRenderer",
"//submodules/TelegramUI/Components/SliderContextItem:SliderContextItem",
"//submodules/TooltipUI",
"//submodules/TelegramNotices",
],
visibility = [
"//visibility:public",

View File

@ -12,6 +12,7 @@ import ScreenCaptureDetection
import AppBundle
import LocalizedPeerData
import TooltipUI
import TelegramNotices
private func galleryMediaForMedia(media: Media) -> Media? {
if let media = media as? TelegramMediaImage {
@ -55,7 +56,7 @@ private func mediaForMessage(message: Message) -> Media? {
}
private final class SecretMediaPreviewControllerNode: GalleryControllerNode {
private var timeoutNode: RadialStatusNode?
fileprivate var timeoutNode: RadialStatusNode?
private var validLayout: (ContainerViewLayout, CGFloat)?
@ -245,9 +246,9 @@ public final class SecretMediaPreviewController: ViewController {
self.displayNode = SecretMediaPreviewControllerNode(controllerInteraction: controllerInteraction)
self.displayNodeDidLoad()
self.controllerNode.statusPressed = { [weak self] sourceView in
self.controllerNode.statusPressed = { [weak self] _ in
if let self {
self.presentViewOnceTooltip(sourceView: sourceView)
self.presentViewOnceTooltip()
}
}
@ -427,6 +428,18 @@ 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) {
@ -546,11 +559,11 @@ public final class SecretMediaPreviewController: ViewController {
}
}
private func presentViewOnceTooltip(sourceView: UIView) {
guard self.currentNodeMessageIsViewOnce else {
private func presentViewOnceTooltip() {
guard self.currentNodeMessageIsViewOnce, let sourceView = self.controllerNode.timeoutNode?.view else {
return
}
if let tooltipController = self.tooltipController {
self.tooltipController = nil
tooltipController.dismiss()
@ -559,12 +572,13 @@ public final class SecretMediaPreviewController: ViewController {
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 = "This video can only be viewed once."
text = presentationData.strings.Gallery_ViewOnceVideoTooltip
} else {
text = "This photo can only be viewed once."
text = presentationData.strings.Gallery_ViewOncePhotoTooltip
}
let tooltipController = TooltipScreen(

View File

@ -179,6 +179,7 @@ private enum ApplicationSpecificGlobalNotice: Int32 {
case displayChatListArchiveTooltip = 45
case displayStoryReactionTooltip = 46
case storyStealthModeReplyCount = 47
case viewOnceTooltip = 48
var key: ValueBoxKey {
let v = ValueBoxKey(length: 4)
@ -424,6 +425,10 @@ private struct ApplicationSpecificNoticeKeys {
static func storyStealthModeReplyCount() -> NoticeEntryKey {
return NoticeEntryKey(namespace: noticeNamespace(namespace: globalNamespace), key: ApplicationSpecificGlobalNotice.storyStealthModeReplyCount.key)
}
static func viewOnceTooltip() -> NoticeEntryKey {
return NoticeEntryKey(namespace: noticeNamespace(namespace: globalNamespace), key: ApplicationSpecificGlobalNotice.viewOnceTooltip.key)
}
}
public struct ApplicationSpecificNotice {
@ -1611,4 +1616,21 @@ public struct ApplicationSpecificNotice {
}
|> ignoreValues
}
public static func incrementViewOnceTooltip(accountManager: AccountManager<TelegramAccountManagerTypes>, count: Int = 1) -> Signal<Int, NoError> {
return accountManager.transaction { transaction -> Int in
var currentValue: Int32 = 0
if let value = transaction.getNotice(ApplicationSpecificNoticeKeys.viewOnceTooltip())?.get(ApplicationSpecificCounterNotice.self) {
currentValue = value.value
}
let previousValue = currentValue
currentValue += Int32(count)
if let entry = CodableEntry(ApplicationSpecificCounterNotice(value: currentValue)) {
transaction.setNotice(ApplicationSpecificNoticeKeys.viewOnceTooltip(), entry)
}
return Int(previousValue)
}
}
}