AccountRightController.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 Benefits", comment: "")
  46. cell?.titleLabel.stringValue = NSLocalizedString("Expired", comment: "")
  47. }
  48. cell?.moreButton.title = NSLocalizedString("Get Benefits", comment: "") + " >"
  49. cell?.moreButton.isHidden = row != 0
  50. cell?.moreButton.setTitleColor(KMAppearance.themeColor())
  51. cell?.itemClick = { [weak self] idx,_ in
  52. if idx == 1 { // 更多权益
  53. self?.itemClick?(idx)
  54. }
  55. }
  56. return cell
  57. }
  58. if let model = self.rightDatas.safe_element(for: row-1) as? AccountRightInfoModel { // 权益
  59. var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "titleCell"), owner: nil) as? AccountRightCellView
  60. if cell == nil {
  61. cell = AccountRightCellView()
  62. }
  63. cell?.model = model
  64. cell?.itemClick = { [weak self] idx, params in
  65. if idx == 1 { // cancel
  66. self?.itemClick?(2)
  67. }
  68. }
  69. return cell
  70. }
  71. // 过期
  72. var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "titleCell"), owner: nil) as? AccountRightCellView
  73. if cell == nil {
  74. cell = AccountRightCellView()
  75. }
  76. let model = self.expiredDatas.safe_element(for: row-2-self.rightDatas.count) as? AccountRightInfoModel
  77. cell?.model = model
  78. cell?.itemClick = { [weak self] idx, params in
  79. if idx == 1 { // renew
  80. KMTools.openURL(urlString: model?.buy_url ?? "")
  81. }
  82. }
  83. return cell
  84. }
  85. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  86. if row == 0 || row == self.rightDatas.count + 1 {
  87. return 16 + 22 + 8
  88. } else {
  89. return 14 + 111 + 8
  90. }
  91. }
  92. }