123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- //
- // KMNHomeViewController.swift
- // PDF Reader Pro
- //
- // Created by Niehaoyu on 2024/10/8.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNHomeViewController: NSViewController {
- @IBOutlet var leftContendBox: NSBox!
- @IBOutlet var homeOpenView: KMHomeOpenView!
- @IBOutlet var homeRecommondView: KMHomeRecommondView!
-
- @IBOutlet var rightInfoView: KMHomeRightView!
-
- var demoVC: WCCompWindowController = WCCompWindowController(windowNibName: "WCCompWindowController")
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
-
- self.configLeftContendView()
-
- self.configRightContendView()
-
- self.initAdvertisementData()
- }
-
- override func viewDidAppear() {
- super.viewDidAppear()
-
-
- rightInfoView.resetScrollerStyle()
- rightInfoView.reloadData()
-
- }
-
- func configLeftContendView() {
-
- leftContendBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
-
- homeOpenView.delegate = self
-
- self.homeRecommondView.reloadData()
- }
-
- func configRightContendView() {
-
- rightInfoView.delegate = self
- rightInfoView.reloadData()
-
- }
-
- func initAdvertisementData() {
- KMAdvertisementManager.manager.fetchDataWithResponseObject { [weak self] data, responseObject, error in
- KMPrint("获取广告数据成功")
- if data != nil {
- let content = data!.recommondContent
-
- let item = content?.recommondContentPDFPro
- var infos: [KMAdvertisementItemInfo] = []
- for info in item?.content ?? [] {
- if info.version == "recommondPDF-PDFtoOfficePack" {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false {
- infos.append(info)
- }
- } else {
- infos.append(info)
- }
- }
- item?.content = infos
-
- if KMAdvertisementManager.manager.infoDict.allKeys.count > 0 {
- if let adsInfo = KMAdvertisementManager.manager.infoDict["adsInfo"] {
- let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["adsInfo"] as! NSDictionary
- let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
-
- let arrM = NSMutableArray.init()
- for dict in array {
- let adsInfo = KMAdsInfo.init()
- let mutableDictionary = NSMutableDictionary(dictionary: dict)
- adsInfo.infoDict = mutableDictionary
- arrM.add(adsInfo)
- }
- KMAdsInfoManager.shareInstance.adsInfoArrM = arrM
- }
-
- if let couponInfo = KMAdvertisementManager.manager.infoDict["couponContent"] {
- let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["couponContent"] as! NSDictionary
- let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
- if array.isEmpty == false {
- let dict = array[0]
- let adsInfo = KMCouponInfo.init()
- let mutableDictionary = NSMutableDictionary(dictionary: dict)
- adsInfo.infoDict = mutableDictionary
- KMAdsInfoManager.shareInstance.couponInfo = adsInfo
- }
- }
- }
-
- }
- DispatchQueue.main.async {
- self?.homeRecommondView.reloadData()
- }
- }
- }
-
- @IBAction func showDemo(_ sender: Any) {
- demoVC.window?.center()
- demoVC.showWindow(nil)
-
- }
-
- }
- //MARK: - KMHomeOpenViewDelegate
- extension KMNHomeViewController: KMHomeOpenViewDelegate {
- func homeOpenViewDidChooseFileURLs(_ view: KMHomeOpenView?, _ urls: [URL]) {
- if let url = urls.first {
-
- }
-
- }
- }
- //MARK: - KMHomeRightViewDelegate
- extension KMNHomeViewController: KMHomeRightViewDelegate {
- //点击管理快捷工具按钮
- func homeRightViewDidManageQuickTools(_ view: KMHomeRightView) {
- let quickToolWindowController: KMNQuickToolWindowController = KMNQuickToolWindowController.init(windowNibName: "KMNQuickToolWindowController")
- quickToolWindowController.own_beginSheetModal(for: self.view.window) { string in
-
- }
- }
-
- //点击快捷工具列表中的某一项
- func homeRightViewDidQuickToolsItemClicked(_ view: KMHomeRightView, _ toolType: HomeQuickToolType) {
- print("HomeQuickToolType = %d", toolType.rawValue)
- }
-
- //最近文件列表删除更新结束后回调
- func homeRightViewDidRecentFilesUpdated(_ view: KMHomeRightView) {
-
- }
-
- //选择打开文件
- func homeRightViewDidChooseFileToOpen(_ view: KMHomeRightView, _ fileURL: URL) {
-
- }
- }
- //MARK: - KMNQuickToolWindowDelegate
- extension KMNHomeViewController: KMNQuickToolWindowDelegate {
- func quickToolWindowControllerUpdate() {
- // KMNHomeQuickToolManager.defaultManager.quickToolsItemMutableArray
- }
-
- }
|