1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //
- // 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
- // containerView.layer?.cornerRadius = 12
- // if IAPProductsManager.defaultManager().isAvailableAdvancedPDFToOffice {
- // containerView.isHidden = 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 !IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- self.convertHeaderClickedCallBack?()
- }
- }
- }
-
- func refreshData() {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- containerView.isHidden = true
- } else {
- containerView.isHidden = false
- }
- }
-
- @objc func IAPProductPurchasedNotification(notification: Notification) {
- self.refreshData()
- }
-
- @objc func IAPProductRestoreFinishedNotification(notification: Notification) {
- self.refreshData()
- }
-
- }
|