12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- //
- // KMConvertCollectionViewHeader.swift
- // PDF Reader Pro
- //
- // Created by kdanmobile on 2023/11/1.
- //
- import Cocoa
- typealias convertCollectionViewHeaderClickedCallBack = () -> ()
- class KMConvertCollectionViewHeader: KMBaseXibView{
-
- @IBOutlet var layerColorView: NSView!
-
- @IBOutlet var indicateLabel: NSTextField!
-
- @IBOutlet var imageView: NSImageView!
-
- @IBOutlet var infoLabel: NSTextField!
-
- @IBOutlet var containerView: NSView!
-
- var convertHeaderClickedCallBack: convertCollectionViewHeaderClickedCallBack?
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
-
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
- containerView.wantsLayer = true
- // 购买状态变化通知
- self.layerColorView.wantsLayer = true
- self.layerColorView.layer?.masksToBounds = true
- self.layerColorView.layer?.cornerRadius = 12
- self.layerColorView.layer?.backgroundColor = NSColor(red: 1.0, green: 94/255.0, blue: 44/255.0, alpha: 1.0).cgColor
-
- self.refreshData()
-
- NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"), object: nil)
- }
-
- override func setup() {
- indicateLabel.font = NSFont.boldSystemFont(ofSize: 14)
- indicateLabel.textColor = KMAppearance.Layout.h0Color()
- indicateLabel.stringValue = NSLocalizedString("Convert", comment: "")
- infoLabel.font = NSFont.boldSystemFont(ofSize: 11)
- infoLabel.textColor = NSColor.white
- infoLabel.stringValue = NSLocalizedString("Upgrade to Pro", comment: "")
- infoLabel.toolTip = NSLocalizedString("Upgrade to Pro", comment: "")
- }
-
- override func mouseUp(with event: NSEvent) {
- super.mouseUp(with: event)
- let point = event.locationInWindow
- let newPoint = convert(point, from: nil)
- if let data = self.containerView?.frame.contains(newPoint), data {
- if !KMMemberInfo.shared.isPermitConvert {
- self.convertHeaderClickedCallBack?()
- }
- }
- }
-
- func refreshData() {
- if KMMemberInfo.shared.isPermitConvert {
- containerView.isHidden = true
- } else {
- containerView.isHidden = false
- }
- }
-
- @objc func IAPProductPurchasedNotification(notification: Notification) {
- self.refreshData()
- }
-
- @objc func IAPProductRestoreFinishedNotification(notification: Notification) {
- self.refreshData()
- }
-
- }
|