@@ -27,6 +27,7 @@ import EasyTipView
2727import SwiftUI
2828
2929class NCScan : UIViewController , NCScanCellCellDelegate {
30+
3031 @IBOutlet weak var collectionViewSource : UICollectionView !
3132 @IBOutlet weak var collectionViewDestination : UICollectionView !
3233 @IBOutlet weak var cancel : UIBarButtonItem !
@@ -51,10 +52,6 @@ class NCScan: UIViewController, NCScanCellCellDelegate {
5152 internal let utility = NCUtility ( )
5253 internal let database = NCManageDatabase . shared
5354 internal var filter : NCGlobal . TypeFilterScanDocument = NCPreferences ( ) . typeFilterScanDocument
54-
55- private var editMenuInteraction : UIEditMenuInteraction ?
56- private var traitRegistration : UITraitChangeRegistration ?
57-
5855 @MainActor
5956 internal var session : NCSession . Session {
6057 NCSession . shared. getSession ( controller: controller)
@@ -70,14 +67,6 @@ class NCScan: UIViewController, NCScanCellCellDelegate {
7067 view. backgroundColor = . secondarySystemGroupedBackground
7168 navigationItem. title = NSLocalizedString ( " _scanned_images_ " , comment: " " )
7269
73- let interaction = UIEditMenuInteraction ( delegate: self )
74- view. addInteraction ( interaction)
75- self . editMenuInteraction = interaction
76-
77- traitRegistration = registerForTraitChanges ( [ UITraitUserInterfaceStyle . self] ) { ( self : Self, _) in
78- self . updateIcons ( )
79- }
80-
8170 collectionViewSource. dragInteractionEnabled = true
8271 collectionViewSource. dragDelegate = self
8372 collectionViewSource. dropDelegate = self
@@ -122,6 +111,10 @@ class NCScan: UIViewController, NCScanCellCellDelegate {
122111
123112 override func viewDidAppear( _ animated: Bool ) {
124113 super. viewDidAppear ( animated)
114+
115+ // Re-evaluate in-app messages after viewDidAppear
116+ MoEngageAnalytics . shared. displayInAppNotificationSafely ( reason: " viewDidAppear " )
117+
125118 showTip ( )
126119 }
127120
@@ -137,7 +130,9 @@ class NCScan: UIViewController, NCScanCellCellDelegate {
137130
138131 // MARK: -
139132
140- private func updateIcons( ) {
133+ override func traitCollectionDidChange( _ previousTraitCollection: UITraitCollection ? ) {
134+ super. traitCollectionDidChange ( previousTraitCollection)
135+
141136 add. setImage ( utility. loadImage ( named: " plus " , colors: [ NCBrandColor . shared. iconImageColor] ) , for: . normal)
142137 transferDown. setImage ( utility. loadImage ( named: " arrow.down " , colors: [ NCBrandColor . shared. iconImageColor] ) , for: . normal)
143138 }
@@ -294,31 +289,33 @@ class NCScan: UIViewController, NCScanCellCellDelegate {
294289 }
295290
296291 @objc func handleLongPressGesture( recognizer: UIGestureRecognizer ) {
297- guard recognizer. state == . began else { return }
298- becomeFirstResponder ( )
299-
300- guard let recognizerView = recognizer. view,
301- UIPasteboard . general. hasImages else {
302- // if recognizer.state == UIGestureRecognizer.State.began {
303- // self.becomeFirstResponder()
304- // let pasteboard = UIPasteboard.general
305- // if let recognizerView = recognizer.view, let recognizerSuperView = recognizerView.superview, pasteboard.hasImages {
306- // UIMenuController.shared.menuItems = [UIMenuItem(title: "Paste", action: #selector(pasteImage))]
307- // UIMenuController.shared.showMenu(from: recognizerSuperView, rect: recognizerView.frame)
308- // }
292+ if recognizer. state == UIGestureRecognizer . State. began {
293+ self . becomeFirstResponder ( )
294+ let pasteboard = UIPasteboard . general
295+ if let recognizerView = recognizer. view, let recognizerSuperView = recognizerView. superview, pasteboard. hasImages {
296+ UIMenuController . shared. menuItems = [ UIMenuItem ( title: " Paste " , action: #selector( pasteImage ( _: ) ) ) ]
297+ UIMenuController . shared. showMenu ( from: recognizerSuperView, rect: recognizerView. frame)
298+ }
309299 // TIP
310300 dismissTip ( )
311- return
312301 }
302+ }
313303
314- let sourcePoint = recognizer. location ( in: recognizerView)
315- let configuration = UIEditMenuConfiguration (
316- identifier: nil ,
317- sourcePoint: sourcePoint
318- )
304+ @objc func pasteImage( _ sender: Any ? ) {
305+ let pasteboard = UIPasteboard . general
306+ if pasteboard. hasImages {
307+ guard let image = pasteboard. image? . fixedOrientation ( ) else { return }
308+ let fileName = utilityFileSystem. createFileName ( " scan.png " , fileDate: Date ( ) , fileType: PHAssetMediaType . image, notUseMask: true )
309+ let fileNamePath = utilityFileSystem. createServerUrl ( serverUrl: utilityFileSystem. directoryScan, fileName: fileName)
310+
311+ do {
312+ try image. pngData ( ) ? . write ( to: NSURL . fileURL ( withPath: fileNamePath) , options: . atomic)
313+ } catch {
314+ return
315+ }
319316
320- editMenuInteraction ? . presentEditMenu ( with : configuration )
321- dismissTip ( )
317+ loadImage ( )
318+ }
322319 }
323320
324321 func delete( with imageIndex: Int , sender: Any ) {
@@ -399,54 +396,3 @@ extension NCScan: NCViewerQuickLookDelegate {
399396 collectionViewDestination. reloadData ( )
400397 }
401398}
402-
403- extension NCScan : UIEditMenuInteractionDelegate {
404- func editMenuInteraction(
405- _ interaction: UIEditMenuInteraction ,
406- menuFor configuration: UIEditMenuConfiguration ,
407- suggestedActions: [ UIMenuElement ]
408- ) -> UIMenu ? {
409- guard UIPasteboard . general. hasImages else { return nil }
410-
411- let pasteAction = UIAction (
412- title: NSLocalizedString ( " _paste_file_ " , comment: " " ) ,
413- image: UIImage ( systemName: " doc.on.clipboard " )
414- ) { [ weak self] _ in
415- self ? . pasteImage ( )
416- }
417-
418- return UIMenu ( children: [ pasteAction] )
419- }
420-
421- func pasteImage( ) {
422- let pasteboard = UIPasteboard . general
423-
424- guard pasteboard. hasImages,
425- let image = pasteboard. image? . fixedOrientation ( ) ,
426- let data = image. pngData ( ) else {
427- return
428- }
429-
430- let fileName = utilityFileSystem. createFileName (
431- " scan.png " ,
432- fileDate: Date ( ) ,
433- fileType: . image,
434- notUseMask: true
435- )
436-
437- let fileNamePath = utilityFileSystem. createServerUrl (
438- serverUrl: utilityFileSystem. directoryScan,
439- fileName: fileName
440- )
441-
442- do {
443- try data. write (
444- to: URL ( fileURLWithPath: fileNamePath) ,
445- options: . atomic
446- )
447- loadImage ( )
448- } catch {
449- return
450- }
451- }
452- }
0 commit comments