KMNHomeViewController.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // KMNHomeViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/10/8.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNHomeViewController: NSViewController {
  10. @IBOutlet var leftContendBox: NSBox!
  11. @IBOutlet var homeOpenView: KMHomeOpenView!
  12. @IBOutlet var homeRecommondView: KMHomeRecommondView!
  13. @IBOutlet var rightInfoView: KMHomeRightView!
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. // Do view setup here.
  17. self.configLeftContendView()
  18. self.configRightContendView()
  19. self.initAdvertisementData()
  20. }
  21. override func viewDidAppear() {
  22. super.viewDidAppear()
  23. rightInfoView.resetScrollerStyle()
  24. rightInfoView.reloadData()
  25. }
  26. func configLeftContendView() {
  27. leftContendBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
  28. homeOpenView.delegate = self
  29. self.homeRecommondView.reloadData()
  30. }
  31. func configRightContendView() {
  32. rightInfoView.delegate = self
  33. rightInfoView.reloadData()
  34. }
  35. func initAdvertisementData() {
  36. KMAdvertisementManager.manager.fetchDataWithResponseObject { [weak self] data, responseObject, error in
  37. KMPrint("获取广告数据成功")
  38. if data != nil {
  39. let content = data!.recommondContent
  40. let item = content?.recommondContentPDFPro
  41. var infos: [KMAdvertisementItemInfo] = []
  42. for info in item?.content ?? [] {
  43. if info.version == "recommondPDF-PDFtoOfficePack" {
  44. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false {
  45. infos.append(info)
  46. }
  47. } else {
  48. infos.append(info)
  49. }
  50. }
  51. item?.content = infos
  52. if KMAdvertisementManager.manager.infoDict.allKeys.count > 0 {
  53. if let adsInfo = KMAdvertisementManager.manager.infoDict["adsInfo"] {
  54. let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["adsInfo"] as! NSDictionary
  55. let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
  56. let arrM = NSMutableArray.init()
  57. for dict in array {
  58. let adsInfo = KMAdsInfo.init()
  59. let mutableDictionary = NSMutableDictionary(dictionary: dict)
  60. adsInfo.infoDict = mutableDictionary
  61. arrM.add(adsInfo)
  62. }
  63. KMAdsInfoManager.shareInstance.adsInfoArrM = arrM
  64. }
  65. if let couponInfo = KMAdvertisementManager.manager.infoDict["couponContent"] {
  66. let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["couponContent"] as! NSDictionary
  67. let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
  68. if array.isEmpty == false {
  69. let dict = array[0]
  70. let adsInfo = KMCouponInfo.init()
  71. let mutableDictionary = NSMutableDictionary(dictionary: dict)
  72. adsInfo.infoDict = mutableDictionary
  73. KMAdsInfoManager.shareInstance.couponInfo = adsInfo
  74. }
  75. }
  76. }
  77. }
  78. DispatchQueue.main.async {
  79. self?.homeRecommondView.reloadData()
  80. }
  81. }
  82. }
  83. }
  84. //MARK: - KMHomeOpenViewDelegate
  85. extension KMNHomeViewController: KMHomeOpenViewDelegate {
  86. func homeOpenViewDidChooseFileURLs(_ view: KMHomeOpenView?, _ urls: [URL]) {
  87. if let url = urls.first {
  88. }
  89. }
  90. }
  91. //MARK: - KMHomeRightViewDelegate
  92. extension KMNHomeViewController: KMHomeRightViewDelegate {
  93. func homeRightViewDidManageQuickTools(_ view: KMHomeRightView) {
  94. let quickToolWindowController: KMNQuickToolWindowController = KMNQuickToolWindowController.init(windowNibName: "KMNQuickToolWindowController")
  95. quickToolWindowController.own_beginSheetModal(for: self.view.window) { string in
  96. }
  97. }
  98. func homeRightViewDidQuickToolsItemClicked(_ view: KMHomeRightView, _ toolType: HomeQuickToolType) {
  99. print("HomeQuickToolType = %d", toolType.rawValue)
  100. }
  101. }
  102. //MARK: - KMNQuickToolWindowDelegate
  103. extension KMNHomeViewController: KMNQuickToolWindowDelegate {
  104. func quickToolWindowControllerUpdate() {
  105. // KMNHomeQuickToolManager.defaultManager.quickToolsItemMutableArray
  106. }
  107. }