Update Ghostgram features

This commit is contained in:
ichmagmaus 812
2026-03-07 18:15:32 +01:00
parent 1a3303b059
commit 24a7ec39d9
902 changed files with 148302 additions and 62355 deletions
@@ -144,12 +144,14 @@ func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?,
recipientName = peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)
}
}
let model = TGMediaPickerGalleryModel(context: legacyController.context, items: items, focus: focusItem, selectionContext: selectionContext, editingContext: editingContext, hasCaptions: true, allowCaptionEntities: true, hasTimer: hasTimer, onlyCrop: false, inhibitDocumentCaptions: false, hasSelectionPanel: true, hasCamera: false, recipientName: recipientName, isScheduledMessages: isScheduledMessages, hasCoverButton: hasCoverButton)!
model.stickersContext = paintStickersContext
controller.model = model
model.controller = controller
model.willFinishEditingItem = { item, adjustments, representation, hasChanges in
model.willFinishEditingItem = { (item: TGMediaEditableItem?, adjustments: TGMediaEditAdjustments?, representation: Any?, hasChanges: Bool) in
guard let item else {
return
}
if hasChanges {
editingContext.setAdjustments(adjustments, for: item)
editingContext.setTemporaryRep(representation, for: item)
@@ -159,10 +161,16 @@ func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?,
selectionContext.setItem(item, selected: true)
}
}
model.didFinishEditingItem = { item, adjustments, result, thumbnail in
model.didFinishEditingItem = { (item: TGMediaEditableItem?, adjustments: TGMediaEditAdjustments?, result: UIImage?, thumbnail: UIImage?) in
guard let item, let result, let thumbnail else {
return
}
editingContext.setImage(result, thumbnailImage: thumbnail, for: item, synchronous: false)
}
model.saveItemCaption = { item, caption in
model.saveItemCaption = { (item: TGMediaEditableItem?, caption: NSAttributedString?) in
guard let item else {
return
}
editingContext.setCaption(caption, for: item)
if let selectionContext = selectionContext, let caption = caption, caption.length > 0, let item = item as? TGMediaSelectableItem {
selectionContext.setItem(item, selected: true)
@@ -226,7 +234,7 @@ func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?,
legacyController?.dismiss()
}
model.interfaceView.donePressed = { [weak controller] item in
model.interfaceView.donePressed = { [weak controller] (item: TGModernGalleryItem?) in
if let item = item as? TGMediaPickerGalleryItem {
completed(item.asset, false, nil, {
controller?.dismissWhenReady(animated: true)
@@ -235,7 +243,7 @@ func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?,
}
}
if !isScheduledMessages && peer != nil {
model.interfaceView.doneLongPressed = { [weak selectionContext, weak editingContext, weak legacyController, weak model] item in
model.interfaceView.doneLongPressed = { [weak selectionContext, weak editingContext, weak legacyController, weak model] (item: TGModernGalleryItem?) in
if let legacyController = legacyController, let item = item as? TGMediaPickerGalleryItem, let model = model, let selectionContext = selectionContext {
var effectiveHasSchedule = hasSchedule
@@ -1,3 +1,4 @@
import SGSimpleSettings
import Foundation
import UIKit
import Display
@@ -291,7 +292,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
fileprivate var avatarEditorPreviewView: AvatarEditorPreviewView?
private var cameraActivateAreaNode: AccessibilityAreaNode
private var placeholderNode: MediaPickerPlaceholderNode?
fileprivate var placeholderNode: MediaPickerPlaceholderNode?
private var manageNode: MediaPickerManageNode?
private var scrollingArea: SparseItemGridScrollingArea
private var isFastScrolling = false
@@ -317,6 +318,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
private var fastScrollContentOffset = ValuePromise<CGPoint>(ignoreRepeated: true)
private var fastScrollDisposable: Disposable?
fileprivate var currentContentOffset: GridNodeVisibleContentOffset?
fileprivate var scrolledToTop = true
fileprivate var scrolledExactlyToTop = true
fileprivate var isSwitchingAssetGroup = false
@@ -453,33 +455,9 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
guard let self else {
return
}
self.currentContentOffset = offset
self.updateNavigation(transition: .immediate)
var scrolledToTop = false
var scrolledExactlyToTop = false
if case let .known(contentOffset) = offset {
if contentOffset < 30.0 {
scrolledToTop = true
}
if contentOffset < 5.0 {
scrolledExactlyToTop = true
}
}
var updated = false
var transition: ContainedViewLayoutTransition = .animated(duration: 0.5, curve: .easeInOut)
if self.scrolledToTop != scrolledToTop {
self.scrolledToTop = scrolledToTop
updated = true
}
if self.scrolledExactlyToTop != scrolledExactlyToTop {
self.scrolledExactlyToTop = scrolledExactlyToTop
updated = true
transition = .animated(duration: 0.25, curve: .easeInOut)
}
if updated {
self.controller?.updateNavigationButtons(transition: transition)
}
self.updateTopEdgeEffect()
}
self.hiddenMediaDisposable = (self.hiddenMediaId.get()
@@ -687,8 +665,8 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
useModernCamera = true
}
if useLegacyCamera {
let enableAnimations = self.controller?.context.sharedContext.energyUsageSettings.fullTranslucency ?? true
if useLegacyCamera && !SGSimpleSettings.shared.disableGalleryCamera {
let enableAnimations = self.controller?.context.sharedContext.energyUsageSettings.fullTranslucency ?? true && !SGSimpleSettings.shared.disableGalleryCameraPreview
let cameraView = TGAttachmentCameraView(forSelfPortrait: false, videoModeByDefault: controller.bannedSendPhotos != nil && controller.bannedSendVideos == nil)!
cameraView.clipsToBounds = true
@@ -711,7 +689,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
self.gridNode.scrollView.addSubview(cameraView)
self.gridNode.addSubnode(self.cameraActivateAreaNode)
} else if useModernCamera, !Camera.isIpad {
} else if useModernCamera, !Camera.isIpad, !SGSimpleSettings.shared.disableGalleryCamera {
#if !targetEnvironment(simulator)
var cameraPosition: Camera.Position = .back
if case .assets(nil, .createAvatar) = controller.subject {
@@ -771,6 +749,41 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
}
}
func updateTopEdgeEffect() {
guard let offset = self.currentContentOffset else {
return
}
var scrolledToTop = false
var scrolledExactlyToTop = false
if case let .known(contentOffset) = offset {
if contentOffset < 30.0 {
scrolledToTop = true
}
if contentOffset < 5.0 {
scrolledExactlyToTop = true
}
}
if self.placeholderNode != nil {
scrolledToTop = true
scrolledExactlyToTop = true
}
var updated = false
var transition: ContainedViewLayoutTransition = .animated(duration: 0.5, curve: .easeInOut)
if self.scrolledToTop != scrolledToTop {
self.scrolledToTop = scrolledToTop
updated = true
}
if self.scrolledExactlyToTop != scrolledExactlyToTop {
self.scrolledExactlyToTop = scrolledExactlyToTop
updated = true
transition = .animated(duration: 0.25, curve: .easeInOut)
}
if updated {
self.controller?.updateNavigationButtons(transition: transition)
}
}
func setupSelectionGesture() {
guard self.selectionGesture == nil else {
return
@@ -831,14 +844,18 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
let isCameraActive = !self.isSuspended && !self.hasGallery && self.isCameraPreviewVisible
if let cameraView = self.cameraView {
if isCameraActive {
cameraView.resumePreview()
if !SGSimpleSettings.shared.disableGalleryCameraPreview {
cameraView.resumePreview()
}
} else {
cameraView.pausePreview()
}
} else if let camera = self.modernCamera, let cameraView = self.modernCameraView {
if isCameraActive {
cameraView.isEnabled = true
camera.startCapture()
if !SGSimpleSettings.shared.disableGalleryCameraPreview {
cameraView.isEnabled = true
camera.startCapture()
}
} else {
cameraView.isEnabled = false
camera.stopCapture()
@@ -1685,6 +1702,8 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
self.placeholderNode = placeholderNode
placeholderTransition = .immediate
self.updateTopEdgeEffect()
}
placeholderNode.update(layout: layout, theme: self.presentationData.theme, strings: self.presentationData.strings, hasCamera: false, transition: placeholderTransition)
placeholderTransition.updateFrame(node: placeholderNode, frame: innerBounds)
@@ -1849,6 +1868,8 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
}
if case let .noAccess(cameraAccess) = self.state {
self.controller?.titleView.isEnabled = false
var hasCamera = cameraAccess == .authorized
var story = false
if let subject = self.controller?.subject {
@@ -1885,6 +1906,8 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
placeholderTransition = .immediate
self.updateNavigation(transition: .immediate)
self.updateTopEdgeEffect()
}
placeholderNode.update(layout: layout, theme: self.presentationData.theme, strings: self.presentationData.strings, hasCamera: hasCamera, transition: placeholderTransition)
placeholderTransition.updateFrame(node: placeholderNode, frame: innerBounds)
@@ -2388,7 +2411,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
)
self.titleView.isHighlighted = true
let contextController = ContextController(
let contextController = makeContextController(
presentationData: self.presentationData,
source: .reference(MediaPickerContextReferenceContentSource(controller: self, sourceView: self.titleView)),
items: .single(ContextController.Items(content: .custom(content))),
@@ -2514,7 +2537,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
moreIsVisible = true
} else {
let title: String
let isEnabled: Bool
var isEnabled: Bool
if self.controllerNode.currentDisplayMode == .selected {
title = "" // self.presentationData.strings.Attachment_SelectedMedia(count)
isEnabled = false
@@ -2522,7 +2545,12 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
title = self.selectedCollectionValue?.localizedTitle ?? self.presentationData.strings.MediaPicker_Recents
isEnabled = true
}
self.titleView.updateTitle(title: title, isEnabled: isEnabled, animated: true)
var titleIsEnabled = isEnabled
if self.controllerNode.placeholderNode != nil {
titleIsEnabled = false
}
self.titleView.updateTitle(title: title, isEnabled: titleIsEnabled, animated: true)
self.cancelButtonNode.setState(isEnabled ? .cancel : .back, animated: true)
isBack = !isEnabled
@@ -2609,7 +2637,14 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
}
}
if let moreButton = self.rightButton {
if moreIsVisible, case .glass = self.style {
let moreButton: ComponentView<Empty>
if let current = self.rightButton {
moreButton = current
} else {
moreButton = ComponentView<Empty>()
self.rightButton = moreButton
}
let moreButtonSize = moreButton.update(
transition: buttonTransition,
component: AnyComponent(GlassBarButtonComponent(
@@ -2638,18 +2673,28 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
if let view = moreButton.view {
if view.superview == nil {
self.view.addSubview(view)
if transition.isAnimated {
let transition = ComponentTransition(transition)
transition.animateAlpha(view: view, from: 0.0, to: 1.0)
transition.animateScale(view: view, from: 0.1, to: 1.0)
}
}
view.bounds = CGRect(origin: .zero, size: moreButtonFrame.size)
view.center = moreButtonFrame.center
}
}
if let moreButtonView = self.rightButton?.view {
transition.updateAlpha(layer: moreButtonView.layer, alpha: moreIsVisible ? 1.0 : 0.0)
transition.updateTransformScale(layer: moreButtonView.layer, scale: moreIsVisible ? 1.0 : 0.1)
} else {
transition.updateAlpha(node: self.moreButtonNode.iconNode, alpha: moreIsVisible ? 1.0 : 0.0)
transition.updateTransformScale(node: self.moreButtonNode.iconNode, scale: moreIsVisible ? 1.0 : 0.1)
} else if let moreButton = self.rightButton {
self.rightButton = nil
if let view = moreButton.view {
if transition.isAnimated {
let transition = ComponentTransition(transition)
view.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, removeOnCompletion: false, completion: { _ in
view.removeFromSuperview()
})
transition.animateScale(view: view, from: 1.0, to: 0.1)
} else {
view.removeFromSuperview()
}
}
}
if case .assets(_, .story) = self.subject {
@@ -2923,7 +2968,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
self?.presentFilePicker()
})))
let contextController = ContextController(presentationData: self.presentationData, source: .reference(MediaPickerContextReferenceContentSource(controller: self, sourceView: view)), items: .single(ContextController.Items(content: .list(items))), gesture: gesture)
let contextController = makeContextController(presentationData: self.presentationData, source: .reference(MediaPickerContextReferenceContentSource(controller: self, sourceView: view)), items: .single(ContextController.Items(content: .list(items))), gesture: gesture)
self.presentInGlobalOverlay(contextController)
return
@@ -3084,7 +3129,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
return ContextController.Items(content: .list(items))
}
let contextController = ContextController(presentationData: self.presentationData, source: .reference(MediaPickerContextReferenceContentSource(controller: self, sourceView: view)), items: items, gesture: gesture)
let contextController = makeContextController(presentationData: self.presentationData, source: .reference(MediaPickerContextReferenceContentSource(controller: self, sourceView: view)), items: items, gesture: gesture)
self.presentInGlobalOverlay(contextController)
}
}