123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // 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
- 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 logOutView: NSView!
- @IBOutlet weak var closeBox: KMBox!
-
- var logOutButton: KMDesignButton!
-
- var closeAction: KMAccountInfoViewCloseAction?
- var cancellationAction: KMAccountInfoViewCancellationAction?
- var logOutAction: KMAccountInfoViewLogOutAction?
- var userInfo: KMLightMemberUserInfo? {
- 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(hex: "#252629")
- self.titleLabel.font = NSFont.SFProTextSemibold(20.0)
-
- self.accountLabel.textColor = NSColor(hex: "#252629")
- self.accountLabel.font = NSFont.SFProTextRegular(14.0)
-
- self.accountDescribeLabel.textColor = NSColor(hex: "#616469")
- self.accountDescribeLabel.font = NSFont.SFProTextSemibold(12.0)
-
- self.imageViewButton.backgroundColor(NSColor(hex: "#1770F4"))
- self.imageViewButton.font = NSFont.SFProTextSemibold(28.0)
- self.imageViewButton.contentTintColor = NSColor(hex: "#FFFFFF")
- self.imageViewButton.border(NSColor(hex: "#1770F4"), 1, 24)
-
- self.infoContentView.backgroundColor(NSColor(hex: "#F7F8FA"))
- self.infoContentView.border(NSColor(hex: "#F7F8FA"), 0, 6)
-
- self.updateMoreButtonState(select: false)
-
- logOutButton = KMDesignButton(withType: .Text)
- self.logOutView.addSubview(logOutButton.view)
- self.logOutButton.stringValue = NSLocalizedString("Log Out", comment: "")
- logOutButton.view.frame = self.logOutView.bounds
- logOutButton.view.autoresizingMask = [.width, .height]
- logOutButton.target = self
- logOutButton.action = #selector(logOutButtonAction)
- logOutButton.button(type: .Sec, size: .m)
- }
-
- override func reloadData() {
- super.reloadData()
-
- if self.userInfo != nil {
- self.accountLabel.stringValue = userInfo!.email
- self.imageViewButton.title = userInfo?.email.substring(to: 1) ?? ""
- }
- }
-
- override func updateLanguage() {
- super.updateLanguage()
-
- self.accountDescribeLabel.stringValue = NSLocalizedString("Email Address", comment: "")
-
- self.titleLabel.stringValue = NSLocalizedString("Account Information", comment: "")
-
- self.logOutButton.stringValue = NSLocalizedString("Log Out", comment: "")
- }
- }
- extension KMAccountInfoView {
- func updateMoreButtonState(select: Bool) {
- if select {
- self.moreButton.backgroundColor(NSColor(hex: "#CED0D4", alpha: 0.6))
- self.moreButton.border(NSColor(hex: "#CED0D4"), 1, 4)
- } else {
- self.moreButton.backgroundColor(NSColor.clear)
- self.moreButton.border(NSColor(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("Cancellation", 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 {
- createFilePopover.close()
-
- guard let callBack = self.cancellationAction else { return }
-
- callBack(self)
- }
- }
- }
-
- @IBAction func logOutButtonAction(_ sender: Any) {
- guard let callBack = logOutAction else { return }
-
- callBack(self)
- }
- }
- extension KMAccountInfoView: NSPopoverDelegate {
- func popoverWillClose(_ notification: Notification) {
- self.updateMoreButtonState(select: false)
- }
- }
|