AccountRightController.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // AccountRightController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/10/30.
  6. //
  7. import Cocoa
  8. // https://www.anyrecover.com/support/cancel-subscription/
  9. class AccountRightController: NSViewController {
  10. @IBOutlet weak var scrollView: NSScrollView!
  11. @IBOutlet weak var tableView: NSTableView!
  12. var rightDatas: [AccountRightInfoModel] = []
  13. var expiredDatas: [AccountRightInfoModel] = []
  14. var itemClick: KMCommonClickBlock?
  15. convenience init() {
  16. self.init(nibName: "AccountRightController", bundle: nil)
  17. }
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. // Do view setup here.
  21. self.tableView.backgroundColor = NSColor(hex: "#F9F9FD")
  22. self.tableView.delegate = self
  23. self.tableView.dataSource = self
  24. self.tableView.selectionHighlightStyle = .none
  25. }
  26. }
  27. extension AccountRightController: NSTableViewDelegate, NSTableViewDataSource {
  28. func numberOfRows(in tableView: NSTableView) -> Int {
  29. let datas = self.rightDatas + self.expiredDatas
  30. if datas.count == 0 {
  31. return 1
  32. }
  33. let expiredCnt = self.expiredDatas.isEmpty ? 0 : (1 + self.expiredDatas.count)
  34. return 1 + self.rightDatas.count + expiredCnt
  35. }
  36. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  37. if row == 0 || row == self.rightDatas.count + 1 {
  38. var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "titleCell"), owner: nil) as? AccountRightTitleCellView
  39. if cell == nil {
  40. cell = AccountRightTitleCellView()
  41. }
  42. if row == 0 {
  43. cell?.titleLabel.stringValue = NSLocalizedString("Rights and Interests", comment: "")
  44. } else {
  45. cell?.titleLabel.stringValue = NSLocalizedString("Expired", comment: "")
  46. }
  47. cell?.moreButton.title = NSLocalizedString("Get Benefits", comment: "") + " >"
  48. cell?.moreButton.isHidden = row != 0
  49. cell?.moreButton.setTitleColor(KMAppearance.themeColor())
  50. cell?.itemClick = { [weak self] idx,_ in
  51. if idx == 1 { // 更多权益
  52. self?.itemClick?(idx)
  53. }
  54. }
  55. return cell
  56. }
  57. if let model = self.rightDatas.safe_element(for: row-1) as? AccountRightInfoModel { // 权益
  58. var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "titleCell"), owner: nil) as? AccountRightCellView
  59. if cell == nil {
  60. cell = AccountRightCellView()
  61. }
  62. cell?.model = model
  63. cell?.itemClick = { [weak self] idx, params in
  64. if idx == 1 { // cancel
  65. self?.itemClick?(2)
  66. }
  67. }
  68. return cell
  69. }
  70. // 过期
  71. var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "titleCell"), owner: nil) as? AccountRightCellView
  72. if cell == nil {
  73. cell = AccountRightCellView()
  74. }
  75. let model = self.expiredDatas.safe_element(for: row-2-self.rightDatas.count) as? AccountRightInfoModel
  76. cell?.model = model
  77. cell?.itemClick = { [weak self] idx, params in
  78. if idx == 1 { // renew
  79. KMTools.openURL(urlString: model?.buy_url ?? "")
  80. }
  81. }
  82. return cell
  83. }
  84. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  85. if row == 0 || row == self.rightDatas.count + 1 {
  86. return 16 + 22 + 8
  87. } else {
  88. return 14 + 111 + 8
  89. }
  90. }
  91. }