KMNHomeViewController.swift 3.9 KB

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