123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // KMHomeRecommondView.swift
- // PDF Reader Pro
- //
- // Created by Niehaoyu on 2024/10/10.
- //
- import Cocoa
- import KMComponentLibrary
- class KMHomeRecommondView: BaseXibView {
-
- @IBOutlet var dividerView: ComponentDivider!
-
- @IBOutlet var productsBGView: NSView!
- @IBOutlet var productsLabel: NSTextField!
-
- @IBOutlet var othersBGView: NSView!
- @IBOutlet var othersLabel: NSTextField!
- @IBOutlet var othersTopConst: NSLayoutConstraint!
-
- @IBOutlet var adsView: NSView!
- @IBOutlet var adsImageView: NSImageView!
- @IBOutlet var adsCloseBtn: NSButton!
-
-
- //MARK: - func
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- //MARK: - Setter
- open var inputData: KMAdvertisementContent? {
- didSet {
- self.reloadData()
- }
- }
-
-
- func reloadData() {
-
- if let subviews = productsBGView?.subviews {
- for view in subviews {
- if view is ComponentCSelector {
- view.removeFromSuperview()
- }
- }
- }
-
- if let subviews = othersBGView?.subviews {
- for view in subviews {
- if view is ComponentNavBarItem {
- view.removeFromSuperview()
- }
- }
- }
-
- let products = KMAdvertisementManager.manager.info.recommondContent?.recommondContentPDFPro
-
- if let productContents = products?.content {
- productsBGView.isHidden = false
- othersTopConst.constant = 100
-
- var viewXValue: CGFloat = 0
-
- for item: KMAdvertisementItemInfo in productContents {
- let view = ComponentCSelector()
- view.frame = CGRectMake(viewXValue, 0, 43, 24)
- productsBGView.addSubview(view)
- viewXValue += 55
- view.properties = ComponentCSelectorProperty(size: .s, state: .normal, text: nil, iconImage: NSImage(named: "file_icon"))
- view.setTarget(self, action: #selector(productsItemClick(_:)))
- }
-
- } else {
- productsBGView.isHidden = true
- othersTopConst.constant = 24
- }
-
- let others = KMAdvertisementManager.manager.info.recommondContent?.recommondContentOther
- if let productContents = others?.content {
- othersBGView.isHidden = false
- var viewYValue: CGFloat = CGRectGetHeight(othersBGView.frame) - 28 - 36
-
- for item: KMAdvertisementItemInfo in productContents {
- let view = ComponentNavBarItem()
- view.frame = CGRectMake(0, viewYValue, CGRectGetWidth(othersBGView.frame), 36)
- view.autoresizingMask = [.width, .minYMargin]
- othersBGView.addSubview(view)
- view.properties = ComponentNavbarItemProperty(state: .normal,
- text: KMAdvertisementModelTransition.transitionLanguage(langeuage: item.name),
- iconImage: NSImage(named: "file_icon"))
- view.setTarget(self, action: #selector(othersItemClick(_:)))
- viewYValue -= 44
- }
-
- } else {
- othersBGView.isHidden = true
- }
-
- if IAPProductsManager.default().isAvailableAllFunction() {
- adsView.isHidden = true
- } else {
- adsView.isHidden = false
- let adsData = KMAdvertisementManager.manager.info.advertisement?.content
- guard let model = adsData?.first else {
- adsView.isHidden = true
- return
- }
- let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: model.image, highlight: false))
- self.adsImageView.image = KMAdvertisementImage.imageWithURL(url: url, completion: { [weak self] image in
- self?.adsImageView.image = image
- })
- }
-
- }
-
- //MARK: - func
- @objc func productsItemClick(_ sender: NSView) {
- if let subviews = productsBGView?.subviews {
- for view in subviews {
- if view is ComponentCSelector {
- (view as! ComponentCSelector).properties.state = .normal
- (view as! ComponentCSelector).reloadData()
- }
- }
- }
- }
-
- @objc func othersItemClick(_ sender: NSView) {
- if let subviews = othersBGView?.subviews {
- for view in subviews {
- if view is ComponentNavBarItem {
- (view as! ComponentNavBarItem).properties.state = .normal
- (view as! ComponentNavBarItem).reloadData()
- }
- }
- }
- }
-
- @IBAction func closeAdsImageview(_ sender: Any) {
-
- }
-
-
- }
|