KMConvertCollectionViewHeader.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // KMConvertCollectionViewHeader.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2023/11/1.
  6. //
  7. import Cocoa
  8. typealias convertCollectionViewHeaderClickedCallBack = () -> ()
  9. class KMConvertCollectionViewHeader: KMBaseXibView{
  10. @IBOutlet var layerColorView: NSView!
  11. @IBOutlet var indicateLabel: NSTextField!
  12. @IBOutlet var imageView: NSImageView!
  13. @IBOutlet var infoLabel: NSTextField!
  14. @IBOutlet var containerView: NSView!
  15. var convertHeaderClickedCallBack: convertCollectionViewHeaderClickedCallBack?
  16. deinit {
  17. NotificationCenter.default.removeObserver(self)
  18. }
  19. override func draw(_ dirtyRect: NSRect) {
  20. super.draw(dirtyRect)
  21. }
  22. override func awakeFromNib() {
  23. super.awakeFromNib()
  24. containerView.wantsLayer = true
  25. // containerView.layer?.cornerRadius = 12
  26. // if IAPProductsManager.defaultManager().isAvailableAdvancedPDFToOffice {
  27. // containerView.isHidden = true
  28. // }
  29. // 购买状态变化通知
  30. self.layerColorView.wantsLayer = true
  31. self.layerColorView.layer?.masksToBounds = true
  32. self.layerColorView.layer?.cornerRadius = 12
  33. self.layerColorView.layer?.backgroundColor = NSColor(red: 1.0, green: 94/255.0, blue: 44/255.0, alpha: 1.0).cgColor
  34. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"), object: nil)
  35. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"), object: nil)
  36. }
  37. override func setup() {
  38. indicateLabel.font = NSFont.boldSystemFont(ofSize: 14)
  39. indicateLabel.textColor = KMAppearance.Layout.h0Color()
  40. indicateLabel.stringValue = NSLocalizedString("Convert", comment: "")
  41. infoLabel.font = NSFont.boldSystemFont(ofSize: 11)
  42. infoLabel.textColor = NSColor.white
  43. infoLabel.stringValue = NSLocalizedString("Upgrade to Pro", comment: "")
  44. infoLabel.toolTip = NSLocalizedString("Upgrade to Pro", comment: "")
  45. }
  46. override func mouseUp(with event: NSEvent) {
  47. super.mouseUp(with: event)
  48. let point = event.locationInWindow
  49. let newPoint = convert(point, from: nil)
  50. if let data = self.containerView?.frame.contains(newPoint), data {
  51. if !IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  52. self.convertHeaderClickedCallBack?()
  53. }
  54. }
  55. }
  56. @objc func IAPProductPurchasedNotification(notification: Notification) {
  57. containerView.isHidden = true
  58. }
  59. @objc func IAPProductRestoreFinishedNotification(notification: Notification) {
  60. containerView.isHidden = true
  61. }
  62. }