KMAccountInfoView.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // KMAccountInfoView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/2/24.
  6. //
  7. import Cocoa
  8. typealias KMAccountInfoViewCloseAction = (_ view: KMAccountInfoView) -> Void
  9. typealias KMAccountInfoViewCancellationAction = (_ view: KMAccountInfoView) -> Void
  10. typealias KMAccountInfoViewLogOutAction = (_ view: KMAccountInfoView) -> Void
  11. class KMAccountInfoView: KMBaseXibView {
  12. @IBOutlet weak var titleLabel: NSTextField!
  13. @IBOutlet weak var closeButton: NSButton!
  14. @IBOutlet weak var infoContentView: NSView!
  15. @IBOutlet weak var moreButton: NSButton!
  16. @IBOutlet weak var imageViewButton: NSButton!
  17. @IBOutlet weak var accountDescribeLabel: NSTextField!
  18. @IBOutlet weak var accountLabel: NSTextField!
  19. @IBOutlet weak var logOutView: NSView!
  20. @IBOutlet weak var closeBox: KMBox!
  21. var logOutButton: KMDesignButton!
  22. var closeAction: KMAccountInfoViewCloseAction?
  23. var cancellationAction: KMAccountInfoViewCancellationAction?
  24. var logOutAction: KMAccountInfoViewLogOutAction?
  25. var userInfo: KMLightMemberUserInfo? {
  26. didSet {
  27. self.reloadData()
  28. }
  29. }
  30. override func draw(_ dirtyRect: NSRect) {
  31. super.draw(dirtyRect)
  32. // Drawing code here.
  33. }
  34. override func setup() {
  35. super.setup()
  36. self.closeBox.moveCallback = { [weak self] (mouseEntered, mouseBox) in
  37. if mouseEntered {
  38. self?.closeButton.image = NSImage(named: "control_btn_icon_close_hov")
  39. } else {
  40. self?.closeButton.image = NSImage(named: "control_btn_icon_close")
  41. }
  42. }
  43. }
  44. override func updateUI() {
  45. super.updateUI()
  46. self.titleLabel.textColor = NSColor(hex: "#252629")
  47. self.titleLabel.font = NSFont.SFProTextSemibold(20.0)
  48. self.accountLabel.textColor = NSColor(hex: "#252629")
  49. self.accountLabel.font = NSFont.SFProTextRegular(14.0)
  50. self.accountDescribeLabel.textColor = NSColor(hex: "#616469")
  51. self.accountDescribeLabel.font = NSFont.SFProTextSemibold(12.0)
  52. self.imageViewButton.backgroundColor(NSColor(hex: "#1770F4"))
  53. self.imageViewButton.font = NSFont.SFProTextSemibold(28.0)
  54. self.imageViewButton.contentTintColor = NSColor(hex: "#FFFFFF")
  55. self.imageViewButton.border(NSColor(hex: "#1770F4"), 1, 24)
  56. self.infoContentView.backgroundColor(NSColor(hex: "#F7F8FA"))
  57. self.infoContentView.border(NSColor(hex: "#F7F8FA"), 0, 6)
  58. self.updateMoreButtonState(select: false)
  59. logOutButton = KMDesignButton(withType: .Text)
  60. self.logOutView.addSubview(logOutButton.view)
  61. self.logOutButton.stringValue = NSLocalizedString("Log Out", comment: "")
  62. logOutButton.view.frame = self.logOutView.bounds
  63. logOutButton.view.autoresizingMask = [.width, .height]
  64. logOutButton.target = self
  65. logOutButton.action = #selector(logOutButtonAction)
  66. logOutButton.button(type: .Sec, size: .m)
  67. }
  68. override func reloadData() {
  69. super.reloadData()
  70. if self.userInfo != nil {
  71. self.accountLabel.stringValue = userInfo!.email
  72. self.imageViewButton.title = userInfo?.email.substring(to: 1) ?? ""
  73. }
  74. }
  75. override func updateLanguage() {
  76. super.updateLanguage()
  77. self.accountDescribeLabel.stringValue = NSLocalizedString("Email Address", comment: "")
  78. self.titleLabel.stringValue = NSLocalizedString("Account Information", comment: "")
  79. self.logOutButton.stringValue = NSLocalizedString("Log Out", comment: "")
  80. }
  81. }
  82. extension KMAccountInfoView {
  83. func updateMoreButtonState(select: Bool) {
  84. if select {
  85. self.moreButton.backgroundColor(NSColor(hex: "#CED0D4", alpha: 0.6))
  86. self.moreButton.border(NSColor(hex: "#CED0D4"), 1, 4)
  87. } else {
  88. self.moreButton.backgroundColor(NSColor.clear)
  89. self.moreButton.border(NSColor(hex: "#CED0D4"), 0, 4)
  90. }
  91. }
  92. }
  93. protocol KMAccountInfoViewAction {}
  94. extension KMAccountInfoView: KMAccountInfoViewAction {
  95. @IBAction func closeButtonAction(_ sender: Any) {
  96. guard let callBack = closeAction else { return }
  97. callBack(self)
  98. }
  99. @IBAction func moreButtonAction(_ sender: NSButton) {
  100. self.updateMoreButtonState(select: true)
  101. let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr([NSLocalizedString("Cancellation", comment: "")])
  102. let createFilePopover: NSPopover = NSPopover.init()
  103. createFilePopover.contentViewController = vc
  104. createFilePopover.delegate = self
  105. createFilePopover.animates = true
  106. createFilePopover.behavior = .semitransient
  107. createFilePopover.setValue(true, forKey: "shouldHideAnchor")
  108. 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)
  109. // vc.customBoxWidthLayoutConstraint.constant = sender.frame.width
  110. vc.downCallback = { [unowned self] (downEntered: Bool, count: String) -> Void in
  111. if downEntered {
  112. createFilePopover.close()
  113. guard let callBack = self.cancellationAction else { return }
  114. callBack(self)
  115. }
  116. }
  117. }
  118. @IBAction func logOutButtonAction(_ sender: Any) {
  119. guard let callBack = logOutAction else { return }
  120. callBack(self)
  121. }
  122. }
  123. extension KMAccountInfoView: NSPopoverDelegate {
  124. func popoverWillClose(_ notification: Notification) {
  125. self.updateMoreButtonState(select: false)
  126. }
  127. }