KMNHomeViewController.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. self.rightInfoView.resetScrollerStyle()
  24. }
  25. func configLeftContendView() {
  26. leftContendBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
  27. homeOpenView.delegate = self
  28. }
  29. func configRightContendView() {
  30. rightInfoView.delegate = self
  31. rightInfoView.reloadData()
  32. }
  33. func initAdvertisementData() {
  34. KMAdvertisementManager.manager.fetchDataWithResponseObject { [weak self] data, responseObject, error in
  35. KMPrint("获取广告数据成功")
  36. if data != nil {
  37. let content = data!.recommondContent
  38. let item = content?.recommondContentPDFPro
  39. var infos: [KMAdvertisementItemInfo] = []
  40. for info in item?.content ?? [] {
  41. if info.version == "recommondPDF-PDFtoOfficePack" {
  42. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false {
  43. infos.append(info)
  44. }
  45. } else {
  46. infos.append(info)
  47. }
  48. }
  49. item?.content = infos
  50. if KMAdvertisementManager.manager.infoDict.allKeys.count > 0 {
  51. if let adsInfo = KMAdvertisementManager.manager.infoDict["adsInfo"] {
  52. let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["adsInfo"] as! NSDictionary
  53. let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
  54. let arrM = NSMutableArray.init()
  55. for dict in array {
  56. let adsInfo = KMAdsInfo.init()
  57. let mutableDictionary = NSMutableDictionary(dictionary: dict)
  58. adsInfo.infoDict = mutableDictionary
  59. arrM.add(adsInfo)
  60. }
  61. KMAdsInfoManager.shareInstance.adsInfoArrM = arrM
  62. }
  63. if let couponInfo = KMAdvertisementManager.manager.infoDict["couponContent"] {
  64. let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["couponContent"] as! NSDictionary
  65. let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
  66. if array.isEmpty == false {
  67. let dict = array[0]
  68. let adsInfo = KMCouponInfo.init()
  69. let mutableDictionary = NSMutableDictionary(dictionary: dict)
  70. adsInfo.infoDict = mutableDictionary
  71. KMAdsInfoManager.shareInstance.couponInfo = adsInfo
  72. }
  73. }
  74. }
  75. self?.homeRecommondView.reloadData()
  76. }
  77. }
  78. }
  79. }
  80. //MARK: - KMHomeOpenViewDelegate
  81. extension KMNHomeViewController: KMHomeOpenViewDelegate {
  82. func homeOpenViewDidChooseFileURLs(_ view: KMHomeOpenView?, _ urls: [URL]) {
  83. if let url = urls.first {
  84. }
  85. }
  86. }
  87. //MARK: - KMHomeRightViewDelegate
  88. extension KMNHomeViewController: KMHomeRightViewDelegate {
  89. func homeRightViewDidManageQuickTools(_ view: KMHomeRightView) {
  90. }
  91. func homeRightViewDidQuickToolsItemClicked(_ view: KMHomeRightView, _ identify: String) {
  92. }
  93. }