123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- //
- // KMAccountInfoView.swift
- // PDF Master
- //
- // Created by lizhe on 2023/2/24.
- //
- import Cocoa
- typealias KMAccountInfoViewCloseAction = (_ view: KMAccountInfoView) -> Void
- typealias KMAccountInfoViewCancellationAction = (_ view: KMAccountInfoView) -> Void
- typealias KMAccountInfoViewLogOutAction = (_ view: KMAccountInfoView) -> Void
- typealias KMAccountInfoViewPurchaseInfoAction = (_ view: KMAccountInfoView) -> Void
- typealias KMAccountInfoViewSubcriptionAction = (_ view: KMAccountInfoView) -> Void
- class KMAccountInfoView: KMBaseXibView {
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var closeButton: NSButton!
-
- @IBOutlet weak var infoContentView: NSView!
- @IBOutlet weak var moreButton: NSButton!
- @IBOutlet weak var imageViewButton: NSButton!
- @IBOutlet weak var accountDescribeLabel: NSTextField!
- @IBOutlet weak var accountLabel: NSTextField!
- @IBOutlet weak var closeBox: KMBox!
- @IBOutlet weak var statusTitleLabel: NSTextField!
- @IBOutlet weak var statusLabel: NSTextField!
- @IBOutlet weak var tagLabel: NSTextField!
- @IBOutlet weak var tagContentView: NSView!
- @IBOutlet weak var statusTimeLabel: NSTextField!
- @IBOutlet weak var purchaseInfoButton: NSButton!
- @IBOutlet weak var lineView: NSView!
- @IBOutlet weak var subscribeButton: NSButton!
- @IBOutlet weak var statusContentView: NSView!
- @IBOutlet weak var purchaseInfoContentView: NSView!
- @IBOutlet weak var subscribeButtonContentView: NSView!
-
-
- @IBOutlet weak var subscriptionInfoContentViewHeightConstraint: NSLayoutConstraint!
- @IBOutlet weak var subscriptionInfoContentViewTopConstraint: NSLayoutConstraint!
- @IBOutlet weak var lineViewTopConttraint: NSLayoutConstraint!
-
- var closeAction: KMAccountInfoViewCloseAction?
- var cancellationAction: KMAccountInfoViewCancellationAction?
- var logOutAction: KMAccountInfoViewLogOutAction?
- var purchaseInfoAction: KMAccountInfoViewPurchaseInfoAction?
- var subcriptionAction: KMAccountInfoViewSubcriptionAction?
- var userInfo: KMLightMemberUserInfo? {
- didSet {
- self.reloadData()
- }
- }
-
- var purchaseState: KMPurchaseManagerState = .unknow {
- didSet {
- self.reloadData()
- }
- }
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func setup() {
- super.setup()
-
- self.closeBox.moveCallback = { [weak self] (mouseEntered, mouseBox) in
- if mouseEntered {
- self?.closeButton.image = NSImage(named: "control_btn_icon_close_hov")
- } else {
- self?.closeButton.image = NSImage(named: "control_btn_icon_close")
- }
- }
- }
-
- override func updateUI() {
- super.updateUI()
-
- self.titleLabel.textColor = NSColor.km_init(hex: "#252629")
- self.titleLabel.font = NSFont.SFProTextSemiboldFont(20.0)
-
- self.accountLabel.textColor = NSColor.km_init(hex: "#252629")
- self.accountLabel.font = NSFont.SFProTextRegularFont(14.0)
-
- self.accountDescribeLabel.textColor = NSColor.km_init(hex: "#616469")
- self.accountDescribeLabel.font = NSFont.SFProTextSemiboldFont(12.0)
-
- self.imageViewButton.backgroundColor(NSColor.km_init(hex: "#1770F4"))
- self.imageViewButton.font = NSFont.SFProTextSemiboldFont(28.0)
- self.imageViewButton.contentTintColor = NSColor.km_init(hex: "#FFFFFF")
- self.imageViewButton.border(NSColor.km_init(hex: "#1770F4"), 1, 24)
-
- self.infoContentView.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
- self.infoContentView.border(NSColor.km_init(hex: "#F7F8FA"), 0, 6)
-
- self.purchaseInfoButton.font = NSFont.SFProTextRegularFont(14)
- self.purchaseInfoButton.contentTintColor = NSColor.km_init(hex: "#1770F4")
-
- self.statusTitleLabel.textColor = NSColor.km_init(hex: "#616469")
- self.statusTitleLabel.font = NSFont.SFProTextRegularFont(12.0)
-
- self.statusLabel.textColor = NSColor.km_init(hex: "#252629")
- self.statusLabel.font = NSFont.SFProTextSemiboldFont(16.0)
-
- self.statusTimeLabel.textColor = NSColor.km_init(hex: "#616469")
- self.statusTimeLabel.font = NSFont.SFProTextRegularFont(12.0)
-
- self.subscribeButton.contentTintColor = NSColor.km_init(hex: "#FFFFFF")
- self.subscribeButton.backgroundColor(NSColor.km_init(hex: "#FF852E"))
- self.subscribeButton.font = NSFont.SFProTextRegularFont(16)
- self.subscribeButton.border(NSColor.clear, 0, 20)
-
- self.tagLabel.font = NSFont.SFProTextRegularFont(12)
- self.tagLabel.textColor = NSColor.km_init(hex: "#252629")
-
- self.tagContentView.border(NSColor.km_init(hex: "#DFE1E5"), 1, 4)
- self.tagContentView.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
-
- self.lineView.backgroundColor(NSColor.km_init(hex: "#ECECEC"))
- self.updateMoreButtonState(select: false)
- }
-
- override func reloadData() {
- super.reloadData()
-
- if self.userInfo != nil {
- self.accountLabel.stringValue = userInfo!.email
- self.imageViewButton.title = userInfo?.email.substring(to: 1) ?? ""
-
- if KMLightMemberManager.manager.info.subscriptionInfoList[0].payType == 1 {
- self.tagContentView.isHidden = false
- } else {
- self.tagContentView.isHidden = true
- }
- }
-
- self.statusTimeLabel.stringValue = ""
- self.statusLabel.textColor = NSColor.km_init(hex: "#252629")
-
- //初始化
- self.purchaseInfoContentView.isHidden = KMLightMemberManager.manager.existOrderInfo() ? false:true
- self.subscribeButtonContentView.isHidden = true
- self.statusContentView.isHidden = true
- self.subscriptionInfoContentViewHeightConstraint.constant = 74
- self.subscriptionInfoContentViewTopConstraint.constant = 20
- self.lineViewTopConttraint.constant = 16
- self.lineView.isHidden = false
-
- if purchaseState == .unknow {
- #if VERSION_DMG
- self.subscriptionInfoContentViewHeightConstraint.constant = 0
- self.subscriptionInfoContentViewTopConstraint.constant = 0
- self.lineViewTopConttraint.constant = 12
- self.lineView.isHidden = true
- #endif
- } else if purchaseState == .subscription ||
- purchaseState == .trial {
- self.statusContentView.isHidden = false
- #if VERSION_DMG
- self.purchaseInfoContentView.isHidden = false
- if KMLightMemberManager.manager.info.subscriptionInfoList[0].payType == 1 {
- self.subscribeButtonContentView.isHidden = true
- } else {
- self.subscribeButtonContentView.isHidden = false
- }
- #else
- self.purchaseInfoContentView.isHidden = true
- #endif
- self.statusLabel.stringValue = NSLocalizedString("On Subscription", comment: "")
- if purchaseState == .trial {
- self.statusLabel.stringValue = NSLocalizedString("On Trial", comment: "")
- }
-
- let dateString = userInfo?.subscriptionInfoList[0].endDate ?? ""
- self.statusTimeLabel.stringValue = "\(self.fetchDate(dateString: dateString)) \n\(NSLocalizedString("Subscription expire on", comment: ""))"
- } else if purchaseState == .subscriptionExpired ||
- purchaseState == .trialExpired {
- self.statusContentView.isHidden = false
- self.subscribeButtonContentView.isHidden = false
-
- #if VERSION_DMG
- self.purchaseInfoContentView.isHidden = false
- #else
- self.purchaseInfoContentView.isHidden = true
- #endif
- self.statusLabel.stringValue = NSLocalizedString("Expired", comment: "")
- self.statusLabel.textColor = NSColor.km_init(hex: "#F3465B")
-
- let dateString = userInfo?.subscriptionInfoList[0].endDate ?? ""
- self.statusTimeLabel.stringValue = "\(self.fetchDate(dateString: dateString)) \n\(NSLocalizedString("Subscription expire on", comment: ""))"
- }
-
- if self.userInfo != nil {
- if KMLightMemberManager.manager.info.subscriptionInfoList[0].payType == 1 {
- let dateString = userInfo?.subscriptionInfoList[0].endDate ?? ""
- self.statusTimeLabel.stringValue = "\(self.fetchDate(dateString: dateString))\n\(NSLocalizedString("Subscription renewal date", comment: ""))"
- }
- }
-
- self.updateLanguage()
- }
-
- override func updateLanguage() {
- super.updateLanguage()
-
- self.purchaseInfoButton.title = NSLocalizedString("Order Information", comment: "")
-
- self.tagLabel.stringValue = NSLocalizedString("Auto-renewal", comment: "")
- self.statusTitleLabel.stringValue = NSLocalizedString("Status", comment: "")
- self.accountDescribeLabel.stringValue = NSLocalizedString("Email Address", comment: "")
- self.titleLabel.stringValue = NSLocalizedString("Account Information", comment: "")
-
- // self.logOutButton.stringValue = NSLocalizedString("Log Out", comment: "")
-
- let timeString = self.statusTimeLabel.stringValue
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.lineHeightMultiple = 1.32
- paragraphStyle.alignment = .right
- self.statusTimeLabel.attributedStringValue = NSMutableAttributedString(string: NSLocalizedString(timeString, comment: ""), attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
-
- let paragraphStyle2 = NSMutableParagraphStyle()
- paragraphStyle2.lineHeightMultiple = 1.32
- paragraphStyle2.alignment = .left
- self.statusLabel.attributedStringValue = NSMutableAttributedString(string: NSLocalizedString(self.statusLabel.stringValue, comment: ""), attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle2])
- }
-
- func fetchDate(dateString: String) -> String {
- let dateFormatter = DateFormatter()
- dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
- let date = dateFormatter.date(from: dateString)
- let targetDateFormatter = DateFormatter()
- targetDateFormatter.dateFormat = "yyyy-MM-dd"
- let formattedDate = targetDateFormatter.string(from: date ?? NSDate() as Date)
- KMPrint(formattedDate) // 输出:2024-06-28
- return formattedDate
- }
- }
- extension KMAccountInfoView {
- func updateMoreButtonState(select: Bool) {
- if select {
- self.moreButton.backgroundColor(NSColor.km_init(hex: "#CED0D4", alpha: 0.6))
- self.moreButton.border(NSColor.km_init(hex: "#CED0D4"), 1, 4)
- } else {
- self.moreButton.backgroundColor(NSColor.clear)
- self.moreButton.border(NSColor.km_init(hex: "#CED0D4"), 0, 4)
- }
- }
- }
- protocol KMAccountInfoViewAction {}
- extension KMAccountInfoView: KMAccountInfoViewAction {
- @IBAction func closeButtonAction(_ sender: Any) {
- guard let callBack = closeAction else { return }
-
- callBack(self)
- }
-
-
- @IBAction func moreButtonAction(_ sender: NSButton) {
- self.updateMoreButtonState(select: true)
- let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr([NSLocalizedString("Log out", comment: ""), NSLocalizedString("Cancel", comment: "")])
- let createFilePopover: NSPopover = NSPopover.init()
- createFilePopover.contentViewController = vc
- createFilePopover.delegate = self
- createFilePopover.animates = true
- createFilePopover.behavior = .semitransient
- createFilePopover.setValue(true, forKey: "shouldHideAnchor")
- createFilePopover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: 10, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .maxY)
-
- // vc.customBoxWidthLayoutConstraint.constant = sender.frame.width
- vc.downCallback = { [unowned self] (downEntered: Bool, count: String) -> Void in
- if downEntered {
- if count == NSLocalizedString("Cancel", comment: "") {
- createFilePopover.close()
-
- guard let callBack = self.cancellationAction else { return }
-
- callBack(self)
- } else if count == "Log out" {
- guard let callBack = logOutAction else { return }
-
- callBack(self)
- }
- }
- }
- }
-
- @IBAction func purchaseButtonAction(_ sender: Any) {
- guard let callBack = purchaseInfoAction else { return }
-
- callBack(self)
- }
-
- @IBAction func subcriptionButtonAction(_ sender: Any) {
- guard let callBack = subcriptionAction else { return }
-
- callBack(self)
- }
-
- }
- extension KMAccountInfoView: NSPopoverDelegate {
- func popoverWillClose(_ notification: Notification) {
- self.updateMoreButtonState(select: false)
- }
- }
|