KMConvertCollectionViewHeader.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // 购买状态变化通知
  26. self.layerColorView.wantsLayer = true
  27. self.layerColorView.layer?.masksToBounds = true
  28. self.layerColorView.layer?.cornerRadius = 12
  29. self.layerColorView.layer?.backgroundColor = NSColor(red: 1.0, green: 94/255.0, blue: 44/255.0, alpha: 1.0).cgColor
  30. self.refreshData()
  31. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"), object: nil)
  32. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"), object: nil)
  33. }
  34. override func setup() {
  35. indicateLabel.font = NSFont.boldSystemFont(ofSize: 14)
  36. indicateLabel.textColor = KMAppearance.Layout.h0Color()
  37. indicateLabel.stringValue = NSLocalizedString("Convert", comment: "")
  38. infoLabel.font = NSFont.boldSystemFont(ofSize: 11)
  39. infoLabel.textColor = NSColor.white
  40. infoLabel.stringValue = NSLocalizedString("Upgrade to Pro", comment: "")
  41. infoLabel.toolTip = NSLocalizedString("Upgrade to Pro", comment: "")
  42. }
  43. override func mouseUp(with event: NSEvent) {
  44. super.mouseUp(with: event)
  45. let point = event.locationInWindow
  46. let newPoint = convert(point, from: nil)
  47. if let data = self.containerView?.frame.contains(newPoint), data {
  48. if !KMMemberInfo.shared.isPermitConvert {
  49. self.convertHeaderClickedCallBack?()
  50. }
  51. }
  52. }
  53. func refreshData() {
  54. if KMMemberInfo.shared.isPermitConvert {
  55. containerView.isHidden = true
  56. } else {
  57. containerView.isHidden = false
  58. }
  59. }
  60. @objc func IAPProductPurchasedNotification(notification: Notification) {
  61. self.refreshData()
  62. }
  63. @objc func IAPProductRestoreFinishedNotification(notification: Notification) {
  64. self.refreshData()
  65. }
  66. }