123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- //
- // AccountRightController.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/10/30.
- //
- import Cocoa
- // https://www.anyrecover.com/support/cancel-subscription/
- class AccountRightController: NSViewController {
- @IBOutlet weak var scrollView: NSScrollView!
- @IBOutlet weak var tableView: NSTableView!
-
- var rightDatas: [AccountRightInfoModel] = []
- var expiredDatas: [AccountRightInfoModel] = []
-
- var itemClick: KMCommonClickBlock?
-
- convenience init() {
- self.init(nibName: "AccountRightController", bundle: nil)
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- self.tableView.backgroundColor = NSColor(hex: "#F9F9FD")
- self.tableView.delegate = self
- self.tableView.dataSource = self
- self.tableView.selectionHighlightStyle = .none
- }
- }
- extension AccountRightController: NSTableViewDelegate, NSTableViewDataSource {
- func numberOfRows(in tableView: NSTableView) -> Int {
- let datas = self.rightDatas + self.expiredDatas
- if datas.count == 0 {
- return 1
- }
- let expiredCnt = self.expiredDatas.isEmpty ? 0 : (1 + self.expiredDatas.count)
- return 1 + self.rightDatas.count + expiredCnt
- }
-
- func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
- if row == 0 || row == self.rightDatas.count + 1 {
- var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "titleCell"), owner: nil) as? AccountRightTitleCellView
- if cell == nil {
- cell = AccountRightTitleCellView()
- }
- if row == 0 {
- cell?.titleLabel.stringValue = NSLocalizedString("Rights and Interests", comment: "")
- } else {
- cell?.titleLabel.stringValue = NSLocalizedString("Expired", comment: "")
- }
-
- cell?.moreButton.title = NSLocalizedString("Get Benefits", comment: "") + " >"
- cell?.moreButton.isHidden = row != 0
- cell?.moreButton.setTitleColor(KMAppearance.themeColor())
-
- cell?.itemClick = { [weak self] idx,_ in
- if idx == 1 { // 更多权益
- self?.itemClick?(idx)
- }
- }
- return cell
- }
-
- if let model = self.rightDatas.safe_element(for: row-1) as? AccountRightInfoModel { // 权益
- var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "titleCell"), owner: nil) as? AccountRightCellView
- if cell == nil {
- cell = AccountRightCellView()
- }
- cell?.model = model
-
- cell?.itemClick = { [weak self] idx, params in
- if idx == 1 { // cancel
- self?.itemClick?(2)
- }
- }
- return cell
- }
-
- // 过期
- var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "titleCell"), owner: nil) as? AccountRightCellView
- if cell == nil {
- cell = AccountRightCellView()
- }
- let model = self.expiredDatas.safe_element(for: row-2-self.rightDatas.count) as? AccountRightInfoModel
- cell?.model = model
- cell?.itemClick = { [weak self] idx, params in
- if idx == 1 { // renew
- KMTools.openURL(urlString: model?.buy_url ?? "")
- }
- }
- return cell
- }
-
- func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
- if row == 0 || row == self.rightDatas.count + 1 {
- return 16 + 22 + 8
- } else {
- return 14 + 111 + 8
- }
- }
- }
|