KMConvertCollectionViewHeader.swift 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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: BaseXibView{
  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. self.refreshData()
  35. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"), object: nil)
  36. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"), object: nil)
  37. }
  38. func setup() {
  39. indicateLabel.font = NSFont.boldSystemFont(ofSize: 14)
  40. indicateLabel.textColor = KMAppearance.Layout.h0Color()
  41. indicateLabel.stringValue = NSLocalizedString("Convert", comment: "")
  42. infoLabel.font = NSFont.boldSystemFont(ofSize: 11)
  43. infoLabel.textColor = NSColor.white
  44. infoLabel.stringValue = NSLocalizedString("Upgrade to Pro", comment: "")
  45. infoLabel.toolTip = NSLocalizedString("Upgrade to Pro", comment: "")
  46. }
  47. override func mouseUp(with event: NSEvent) {
  48. super.mouseUp(with: event)
  49. let point = event.locationInWindow
  50. let newPoint = convert(point, from: nil)
  51. if let data = self.containerView?.frame.contains(newPoint), data {
  52. if !IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  53. self.convertHeaderClickedCallBack?()
  54. }
  55. }
  56. }
  57. func refreshData() {
  58. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  59. containerView.isHidden = true
  60. } else {
  61. containerView.isHidden = false
  62. }
  63. }
  64. @objc func IAPProductPurchasedNotification(notification: Notification) {
  65. self.refreshData()
  66. }
  67. @objc func IAPProductRestoreFinishedNotification(notification: Notification) {
  68. self.refreshData()
  69. }
  70. }